summaryrefslogtreecommitdiff
path: root/cipher.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2001-06-25 05:01:22 +0000
committerBen Lindstrom <mouring@eviladmin.org>2001-06-25 05:01:22 +0000
commitbba81213b972ce15fbbaca60b9ffabb42371ce8f (patch)
treee6bd40752969f2b93d179cfb9aaae9074ca45956 /cipher.c
parent34f91883a6f3123656b0a8017d68b658f7cf2403 (diff)
- itojun@cvs.openbsd.org 2001/06/23 15:12:20
[auth1.c auth2.c auth2-chall.c authfd.c authfile.c auth-rhosts.c canohost.c channels.c cipher.c clientloop.c deattack.c dh.c hostfile.c kex.c kexdh.c kexgex.c key.c nchan.c packet.c radix.c readpass.c scp.c servconf.c serverloop.c session.c sftp.c sftp-client.c sftp-glob.c sftp-int.c sftp-server.c ssh-add.c ssh-agent.c ssh.c sshconnect1.c sshconnect2.c sshconnect.c sshd.c ssh-keygen.c ssh-keyscan.c] more strict prototypes. raise warning level in Makefile.inc. markus ok'ed TODO; cleanup headers
Diffstat (limited to 'cipher.c')
-rw-r--r--cipher.c63
1 files changed, 31 insertions, 32 deletions
diff --git a/cipher.c b/cipher.c
index fd93299ed..a7aacf284 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.44 2001/05/28 22:51:10 markus Exp $"); 38RCSID("$OpenBSD: cipher.c,v 1.45 2001/06/23 15:12:18 itojun Exp $");
39 39
40#include "xmalloc.h" 40#include "xmalloc.h"
41#include "log.h" 41#include "log.h"
@@ -43,24 +43,23 @@ RCSID("$OpenBSD: cipher.c,v 1.44 2001/05/28 22:51:10 markus Exp $");
43 43
44#include <openssl/md5.h> 44#include <openssl/md5.h>
45 45
46
47/* no encryption */ 46/* no encryption */
48void 47static void
49none_setkey(CipherContext *cc, const u_char *key, u_int keylen) 48none_setkey(CipherContext *cc, const u_char *key, u_int keylen)
50{ 49{
51} 50}
52void 51static void
53none_setiv(CipherContext *cc, const u_char *iv, u_int ivlen) 52none_setiv(CipherContext *cc, const u_char *iv, u_int ivlen)
54{ 53{
55} 54}
56void 55static void
57none_crypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len) 56none_crypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len)
58{ 57{
59 memcpy(dest, src, len); 58 memcpy(dest, src, len);
60} 59}
61 60
62/* DES */ 61/* DES */
63void 62static void
64des_ssh1_setkey(CipherContext *cc, const u_char *key, u_int keylen) 63des_ssh1_setkey(CipherContext *cc, const u_char *key, u_int keylen)
65{ 64{
66 static int dowarn = 1; 65 static int dowarn = 1;
@@ -71,18 +70,18 @@ des_ssh1_setkey(CipherContext *cc, const u_char *key, u_int keylen)
71 } 70 }
72 des_set_key((void *)key, cc->u.des.key); 71 des_set_key((void *)key, cc->u.des.key);
73} 72}
74void 73static void
75des_ssh1_setiv(CipherContext *cc, const u_char *iv, u_int ivlen) 74des_ssh1_setiv(CipherContext *cc, const u_char *iv, u_int ivlen)
76{ 75{
77 memset(cc->u.des.iv, 0, sizeof(cc->u.des.iv)); 76 memset(cc->u.des.iv, 0, sizeof(cc->u.des.iv));
78} 77}
79void 78static void
80des_ssh1_encrypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len) 79des_ssh1_encrypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len)
81{ 80{
82 des_ncbc_encrypt(src, dest, len, cc->u.des.key, &cc->u.des.iv, 81 des_ncbc_encrypt(src, dest, len, cc->u.des.key, &cc->u.des.iv,
83 DES_ENCRYPT); 82 DES_ENCRYPT);
84} 83}
85void 84static void
86des_ssh1_decrypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len) 85des_ssh1_decrypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len)
87{ 86{
88 des_ncbc_encrypt(src, dest, len, cc->u.des.key, &cc->u.des.iv, 87 des_ncbc_encrypt(src, dest, len, cc->u.des.key, &cc->u.des.iv,
@@ -90,14 +89,14 @@ des_ssh1_decrypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len)
90} 89}
91 90
92/* 3DES */ 91/* 3DES */
93void 92static void
94des3_setkey(CipherContext *cc, const u_char *key, u_int keylen) 93des3_setkey(CipherContext *cc, const u_char *key, u_int keylen)
95{ 94{
96 des_set_key((void *) key, cc->u.des3.key1); 95 des_set_key((void *) key, cc->u.des3.key1);
97 des_set_key((void *) (key+8), cc->u.des3.key2); 96 des_set_key((void *) (key+8), cc->u.des3.key2);
98 des_set_key((void *) (key+16), cc->u.des3.key3); 97 des_set_key((void *) (key+16), cc->u.des3.key3);
99} 98}
100void 99static void
101des3_setiv(CipherContext *cc, const u_char *iv, u_int ivlen) 100des3_setiv(CipherContext *cc, const u_char *iv, u_int ivlen)
102{ 101{
103 memset(cc->u.des3.iv1, 0, sizeof(cc->u.des3.iv1)); 102 memset(cc->u.des3.iv1, 0, sizeof(cc->u.des3.iv1));
@@ -107,14 +106,14 @@ des3_setiv(CipherContext *cc, const u_char *iv, u_int ivlen)
107 return; 106 return;
108 memcpy(cc->u.des3.iv3, (char *)iv, 8); 107 memcpy(cc->u.des3.iv3, (char *)iv, 8);
109} 108}
110void 109static void
111des3_cbc_encrypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len) 110des3_cbc_encrypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len)
112{ 111{
113 des_ede3_cbc_encrypt(src, dest, len, 112 des_ede3_cbc_encrypt(src, dest, len,
114 cc->u.des3.key1, cc->u.des3.key2, cc->u.des3.key3, 113 cc->u.des3.key1, cc->u.des3.key2, cc->u.des3.key3,
115 &cc->u.des3.iv3, DES_ENCRYPT); 114 &cc->u.des3.iv3, DES_ENCRYPT);
116} 115}
117void 116static void
118des3_cbc_decrypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len) 117des3_cbc_decrypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len)
119{ 118{
120 des_ede3_cbc_encrypt(src, dest, len, 119 des_ede3_cbc_encrypt(src, dest, len,
@@ -136,7 +135,7 @@ des3_cbc_decrypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len)
136 * result of that there is no longer any known iv1 to use when 135 * result of that there is no longer any known iv1 to use when
137 * choosing the X block. 136 * choosing the X block.
138 */ 137 */
139void 138static void
140des3_ssh1_setkey(CipherContext *cc, const u_char *key, u_int keylen) 139des3_ssh1_setkey(CipherContext *cc, const u_char *key, u_int keylen)
141{ 140{
142 des_set_key((void *) key, cc->u.des3.key1); 141 des_set_key((void *) key, cc->u.des3.key1);
@@ -146,7 +145,7 @@ des3_ssh1_setkey(CipherContext *cc, const u_char *key, u_int keylen)
146 else 145 else
147 des_set_key((void *) (key+16), cc->u.des3.key3); 146 des_set_key((void *) (key+16), cc->u.des3.key3);
148} 147}
149void 148static void
150des3_ssh1_encrypt(CipherContext *cc, u_char *dest, const u_char *src, 149des3_ssh1_encrypt(CipherContext *cc, u_char *dest, const u_char *src,
151 u_int len) 150 u_int len)
152{ 151{
@@ -157,7 +156,7 @@ des3_ssh1_encrypt(CipherContext *cc, u_char *dest, const u_char *src,
157 des_ncbc_encrypt(dest, dest, len, cc->u.des3.key3, &cc->u.des3.iv3, 156 des_ncbc_encrypt(dest, dest, len, cc->u.des3.key3, &cc->u.des3.iv3,
158 DES_ENCRYPT); 157 DES_ENCRYPT);
159} 158}
160void 159static void
161des3_ssh1_decrypt(CipherContext *cc, u_char *dest, const u_char *src, 160des3_ssh1_decrypt(CipherContext *cc, u_char *dest, const u_char *src,
162 u_int len) 161 u_int len)
163{ 162{
@@ -170,12 +169,12 @@ des3_ssh1_decrypt(CipherContext *cc, u_char *dest, const u_char *src,
170} 169}
171 170
172/* Blowfish */ 171/* Blowfish */
173void 172static void
174blowfish_setkey(CipherContext *cc, const u_char *key, u_int keylen) 173blowfish_setkey(CipherContext *cc, const u_char *key, u_int keylen)
175{ 174{
176 BF_set_key(&cc->u.bf.key, keylen, (u_char *)key); 175 BF_set_key(&cc->u.bf.key, keylen, (u_char *)key);
177} 176}
178void 177static void
179blowfish_setiv(CipherContext *cc, const u_char *iv, u_int ivlen) 178blowfish_setiv(CipherContext *cc, const u_char *iv, u_int ivlen)
180{ 179{
181 if (iv == NULL) 180 if (iv == NULL)
@@ -183,14 +182,14 @@ blowfish_setiv(CipherContext *cc, const u_char *iv, u_int ivlen)
183 else 182 else
184 memcpy(cc->u.bf.iv, (char *)iv, 8); 183 memcpy(cc->u.bf.iv, (char *)iv, 8);
185} 184}
186void 185static void
187blowfish_cbc_encrypt(CipherContext *cc, u_char *dest, const u_char *src, 186blowfish_cbc_encrypt(CipherContext *cc, u_char *dest, const u_char *src,
188 u_int len) 187 u_int len)
189{ 188{
190 BF_cbc_encrypt((void *)src, dest, len, &cc->u.bf.key, cc->u.bf.iv, 189 BF_cbc_encrypt((void *)src, dest, len, &cc->u.bf.key, cc->u.bf.iv,
191 BF_ENCRYPT); 190 BF_ENCRYPT);
192} 191}
193void 192static void
194blowfish_cbc_decrypt(CipherContext *cc, u_char *dest, const u_char *src, 193blowfish_cbc_decrypt(CipherContext *cc, u_char *dest, const u_char *src,
195 u_int len) 194 u_int len)
196{ 195{
@@ -221,7 +220,7 @@ swap_bytes(const u_char *src, u_char *dst, int n)
221 } 220 }
222} 221}
223 222
224void 223static void
225blowfish_ssh1_encrypt(CipherContext *cc, u_char *dest, const u_char *src, 224blowfish_ssh1_encrypt(CipherContext *cc, u_char *dest, const u_char *src,
226 u_int len) 225 u_int len)
227{ 226{
@@ -230,7 +229,7 @@ blowfish_ssh1_encrypt(CipherContext *cc, u_char *dest, const u_char *src,
230 BF_ENCRYPT); 229 BF_ENCRYPT);
231 swap_bytes(dest, dest, len); 230 swap_bytes(dest, dest, len);
232} 231}
233void 232static void
234blowfish_ssh1_decrypt(CipherContext *cc, u_char *dest, const u_char *src, 233blowfish_ssh1_decrypt(CipherContext *cc, u_char *dest, const u_char *src,
235 u_int len) 234 u_int len)
236{ 235{
@@ -241,37 +240,37 @@ blowfish_ssh1_decrypt(CipherContext *cc, u_char *dest, const u_char *src,
241} 240}
242 241
243/* alleged rc4 */ 242/* alleged rc4 */
244void 243static void
245arcfour_setkey(CipherContext *cc, const u_char *key, u_int keylen) 244arcfour_setkey(CipherContext *cc, const u_char *key, u_int keylen)
246{ 245{
247 RC4_set_key(&cc->u.rc4, keylen, (u_char *)key); 246 RC4_set_key(&cc->u.rc4, keylen, (u_char *)key);
248} 247}
249void 248static void
250arcfour_crypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len) 249arcfour_crypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len)
251{ 250{
252 RC4(&cc->u.rc4, len, (u_char *)src, dest); 251 RC4(&cc->u.rc4, len, (u_char *)src, dest);
253} 252}
254 253
255/* CAST */ 254/* CAST */
256void 255static void
257cast_setkey(CipherContext *cc, const u_char *key, u_int keylen) 256cast_setkey(CipherContext *cc, const u_char *key, u_int keylen)
258{ 257{
259 CAST_set_key(&cc->u.cast.key, keylen, (u_char *) key); 258 CAST_set_key(&cc->u.cast.key, keylen, (u_char *) key);
260} 259}
261void 260static void
262cast_setiv(CipherContext *cc, const u_char *iv, u_int ivlen) 261cast_setiv(CipherContext *cc, const u_char *iv, u_int ivlen)
263{ 262{
264 if (iv == NULL) 263 if (iv == NULL)
265 fatal("no IV for %s.", cc->cipher->name); 264 fatal("no IV for %s.", cc->cipher->name);
266 memcpy(cc->u.cast.iv, (char *)iv, 8); 265 memcpy(cc->u.cast.iv, (char *)iv, 8);
267} 266}
268void 267static void
269cast_cbc_encrypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len) 268cast_cbc_encrypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len)
270{ 269{
271 CAST_cbc_encrypt(src, dest, len, &cc->u.cast.key, cc->u.cast.iv, 270 CAST_cbc_encrypt(src, dest, len, &cc->u.cast.key, cc->u.cast.iv,
272 CAST_ENCRYPT); 271 CAST_ENCRYPT);
273} 272}
274void 273static void
275cast_cbc_decrypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len) 274cast_cbc_decrypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len)
276{ 275{
277 CAST_cbc_encrypt(src, dest, len, &cc->u.cast.key, cc->u.cast.iv, 276 CAST_cbc_encrypt(src, dest, len, &cc->u.cast.key, cc->u.cast.iv,
@@ -281,20 +280,20 @@ cast_cbc_decrypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len)
281/* RIJNDAEL */ 280/* RIJNDAEL */
282 281
283#define RIJNDAEL_BLOCKSIZE 16 282#define RIJNDAEL_BLOCKSIZE 16
284void 283static void
285rijndael_setkey(CipherContext *cc, const u_char *key, u_int keylen) 284rijndael_setkey(CipherContext *cc, const u_char *key, u_int keylen)
286{ 285{
287 rijndael_set_key(&cc->u.rijndael.enc, (u4byte *)key, 8*keylen, 1); 286 rijndael_set_key(&cc->u.rijndael.enc, (u4byte *)key, 8*keylen, 1);
288 rijndael_set_key(&cc->u.rijndael.dec, (u4byte *)key, 8*keylen, 0); 287 rijndael_set_key(&cc->u.rijndael.dec, (u4byte *)key, 8*keylen, 0);
289} 288}
290void 289static void
291rijndael_setiv(CipherContext *cc, const u_char *iv, u_int ivlen) 290rijndael_setiv(CipherContext *cc, const u_char *iv, u_int ivlen)
292{ 291{
293 if (iv == NULL) 292 if (iv == NULL)
294 fatal("no IV for %s.", cc->cipher->name); 293 fatal("no IV for %s.", cc->cipher->name);
295 memcpy((u_char *)cc->u.rijndael.iv, iv, RIJNDAEL_BLOCKSIZE); 294 memcpy((u_char *)cc->u.rijndael.iv, iv, RIJNDAEL_BLOCKSIZE);
296} 295}
297void 296static void
298rijndael_cbc_encrypt(CipherContext *cc, u_char *dest, const u_char *src, 297rijndael_cbc_encrypt(CipherContext *cc, u_char *dest, const u_char *src,
299 u_int len) 298 u_int len)
300{ 299{
@@ -321,7 +320,7 @@ rijndael_cbc_encrypt(CipherContext *cc, u_char *dest, const u_char *src,
321 memcpy(iv, cprev, RIJNDAEL_BLOCKSIZE); 320 memcpy(iv, cprev, RIJNDAEL_BLOCKSIZE);
322} 321}
323 322
324void 323static void
325rijndael_cbc_decrypt(CipherContext *cc, u_char *dest, const u_char *src, 324rijndael_cbc_decrypt(CipherContext *cc, u_char *dest, const u_char *src,
326 u_int len) 325 u_int len)
327{ 326{