summaryrefslogtreecommitdiff
path: root/cipher.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2001-06-05 20:50:16 +0000
committerBen Lindstrom <mouring@eviladmin.org>2001-06-05 20:50:16 +0000
commita3828d48121544bb84a61c0a9c3260c6537f6d84 (patch)
tree6946bcbcf3405b3eef599dbb1fdbb0f98371a705 /cipher.c
parent322915d5e4786ab60dd94766d602ddb8c0e31168 (diff)
- markus@cvs.openbsd.org 2001/05/28 22:51:11
[cipher.c cipher.h] simpler 3des for ssh1
Diffstat (limited to 'cipher.c')
-rw-r--r--cipher.c33
1 files changed, 14 insertions, 19 deletions
diff --git a/cipher.c b/cipher.c
index 5350703ef..fd93299ed 100644
--- a/cipher.c
+++ b/cipher.c
@@ -35,7 +35,7 @@
35 */ 35 */
36 36
37#include "includes.h" 37#include "includes.h"
38RCSID("$OpenBSD: cipher.c,v 1.43 2001/02/04 15:32:23 stevesk Exp $"); 38RCSID("$OpenBSD: cipher.c,v 1.44 2001/05/28 22:51:10 markus Exp $");
39 39
40#include "xmalloc.h" 40#include "xmalloc.h"
41#include "log.h" 41#include "log.h"
@@ -100,6 +100,7 @@ des3_setkey(CipherContext *cc, const u_char *key, u_int keylen)
100void 100void
101des3_setiv(CipherContext *cc, const u_char *iv, u_int ivlen) 101des3_setiv(CipherContext *cc, const u_char *iv, u_int ivlen)
102{ 102{
103 memset(cc->u.des3.iv1, 0, sizeof(cc->u.des3.iv1));
103 memset(cc->u.des3.iv2, 0, sizeof(cc->u.des3.iv2)); 104 memset(cc->u.des3.iv2, 0, sizeof(cc->u.des3.iv2));
104 memset(cc->u.des3.iv3, 0, sizeof(cc->u.des3.iv3)); 105 memset(cc->u.des3.iv3, 0, sizeof(cc->u.des3.iv3));
105 if (iv == NULL) 106 if (iv == NULL)
@@ -149,29 +150,23 @@ void
149des3_ssh1_encrypt(CipherContext *cc, u_char *dest, const u_char *src, 150des3_ssh1_encrypt(CipherContext *cc, u_char *dest, const u_char *src,
150 u_int len) 151 u_int len)
151{ 152{
152 des_cblock iv1; 153 des_ncbc_encrypt(src, dest, len, cc->u.des3.key1, &cc->u.des3.iv1,
153 des_cblock *iv2 = &cc->u.des3.iv2; 154 DES_ENCRYPT);
154 des_cblock *iv3 = &cc->u.des3.iv3; 155 des_ncbc_encrypt(dest, dest, len, cc->u.des3.key2, &cc->u.des3.iv2,
155 156 DES_DECRYPT);
156 memcpy(&iv1, iv2, 8); 157 des_ncbc_encrypt(dest, dest, len, cc->u.des3.key3, &cc->u.des3.iv3,
157 158 DES_ENCRYPT);
158 des_ncbc_encrypt(src, dest, len, cc->u.des3.key1, &iv1, DES_ENCRYPT);
159 des_ncbc_encrypt(dest, dest, len, cc->u.des3.key2, iv2, DES_DECRYPT);
160 des_ncbc_encrypt(dest, dest, len, cc->u.des3.key3, iv3, DES_ENCRYPT);
161} 159}
162void 160void
163des3_ssh1_decrypt(CipherContext *cc, u_char *dest, const u_char *src, 161des3_ssh1_decrypt(CipherContext *cc, u_char *dest, const u_char *src,
164 u_int len) 162 u_int len)
165{ 163{
166 des_cblock iv1; 164 des_ncbc_encrypt(src, dest, len, cc->u.des3.key3, &cc->u.des3.iv3,
167 des_cblock *iv2 = &cc->u.des3.iv2; 165 DES_DECRYPT);
168 des_cblock *iv3 = &cc->u.des3.iv3; 166 des_ncbc_encrypt(dest, dest, len, cc->u.des3.key2, &cc->u.des3.iv2,
169 167 DES_ENCRYPT);
170 memcpy(&iv1, iv2, 8); 168 des_ncbc_encrypt(dest, dest, len, cc->u.des3.key1, &cc->u.des3.iv1,
171 169 DES_DECRYPT);
172 des_ncbc_encrypt(src, dest, len, cc->u.des3.key3, iv3, DES_DECRYPT);
173 des_ncbc_encrypt(dest, dest, len, cc->u.des3.key2, iv2, DES_ENCRYPT);
174 des_ncbc_encrypt(dest, dest, len, cc->u.des3.key1, &iv1, DES_DECRYPT);
175} 170}
176 171
177/* Blowfish */ 172/* Blowfish */