diff options
author | Ben Lindstrom <mouring@eviladmin.org> | 2001-06-25 05:01:22 +0000 |
---|---|---|
committer | Ben Lindstrom <mouring@eviladmin.org> | 2001-06-25 05:01:22 +0000 |
commit | bba81213b972ce15fbbaca60b9ffabb42371ce8f (patch) | |
tree | e6bd40752969f2b93d179cfb9aaae9074ca45956 /cipher.c | |
parent | 34f91883a6f3123656b0a8017d68b658f7cf2403 (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.c | 63 |
1 files changed, 31 insertions, 32 deletions
@@ -35,7 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #include "includes.h" | 37 | #include "includes.h" |
38 | RCSID("$OpenBSD: cipher.c,v 1.44 2001/05/28 22:51:10 markus Exp $"); | 38 | RCSID("$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 */ |
48 | void | 47 | static void |
49 | none_setkey(CipherContext *cc, const u_char *key, u_int keylen) | 48 | none_setkey(CipherContext *cc, const u_char *key, u_int keylen) |
50 | { | 49 | { |
51 | } | 50 | } |
52 | void | 51 | static void |
53 | none_setiv(CipherContext *cc, const u_char *iv, u_int ivlen) | 52 | none_setiv(CipherContext *cc, const u_char *iv, u_int ivlen) |
54 | { | 53 | { |
55 | } | 54 | } |
56 | void | 55 | static void |
57 | none_crypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len) | 56 | none_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 */ |
63 | void | 62 | static void |
64 | des_ssh1_setkey(CipherContext *cc, const u_char *key, u_int keylen) | 63 | des_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 | } |
74 | void | 73 | static void |
75 | des_ssh1_setiv(CipherContext *cc, const u_char *iv, u_int ivlen) | 74 | des_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 | } |
79 | void | 78 | static void |
80 | des_ssh1_encrypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len) | 79 | des_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 | } |
85 | void | 84 | static void |
86 | des_ssh1_decrypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len) | 85 | des_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 */ |
93 | void | 92 | static void |
94 | des3_setkey(CipherContext *cc, const u_char *key, u_int keylen) | 93 | des3_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 | } |
100 | void | 99 | static void |
101 | des3_setiv(CipherContext *cc, const u_char *iv, u_int ivlen) | 100 | des3_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 | } |
110 | void | 109 | static void |
111 | des3_cbc_encrypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len) | 110 | des3_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 | } |
117 | void | 116 | static void |
118 | des3_cbc_decrypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len) | 117 | des3_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 | */ |
139 | void | 138 | static void |
140 | des3_ssh1_setkey(CipherContext *cc, const u_char *key, u_int keylen) | 139 | des3_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 | } |
149 | void | 148 | static void |
150 | des3_ssh1_encrypt(CipherContext *cc, u_char *dest, const u_char *src, | 149 | des3_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 | } |
160 | void | 159 | static void |
161 | des3_ssh1_decrypt(CipherContext *cc, u_char *dest, const u_char *src, | 160 | des3_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 */ |
173 | void | 172 | static void |
174 | blowfish_setkey(CipherContext *cc, const u_char *key, u_int keylen) | 173 | blowfish_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 | } |
178 | void | 177 | static void |
179 | blowfish_setiv(CipherContext *cc, const u_char *iv, u_int ivlen) | 178 | blowfish_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 | } |
186 | void | 185 | static void |
187 | blowfish_cbc_encrypt(CipherContext *cc, u_char *dest, const u_char *src, | 186 | blowfish_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 | } |
193 | void | 192 | static void |
194 | blowfish_cbc_decrypt(CipherContext *cc, u_char *dest, const u_char *src, | 193 | blowfish_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 | ||
224 | void | 223 | static void |
225 | blowfish_ssh1_encrypt(CipherContext *cc, u_char *dest, const u_char *src, | 224 | blowfish_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 | } |
233 | void | 232 | static void |
234 | blowfish_ssh1_decrypt(CipherContext *cc, u_char *dest, const u_char *src, | 233 | blowfish_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 */ |
244 | void | 243 | static void |
245 | arcfour_setkey(CipherContext *cc, const u_char *key, u_int keylen) | 244 | arcfour_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 | } |
249 | void | 248 | static void |
250 | arcfour_crypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len) | 249 | arcfour_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 */ |
256 | void | 255 | static void |
257 | cast_setkey(CipherContext *cc, const u_char *key, u_int keylen) | 256 | cast_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 | } |
261 | void | 260 | static void |
262 | cast_setiv(CipherContext *cc, const u_char *iv, u_int ivlen) | 261 | cast_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 | } |
268 | void | 267 | static void |
269 | cast_cbc_encrypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len) | 268 | cast_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 | } |
274 | void | 273 | static void |
275 | cast_cbc_decrypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len) | 274 | cast_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 |
284 | void | 283 | static void |
285 | rijndael_setkey(CipherContext *cc, const u_char *key, u_int keylen) | 284 | rijndael_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 | } |
290 | void | 289 | static void |
291 | rijndael_setiv(CipherContext *cc, const u_char *iv, u_int ivlen) | 290 | rijndael_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 | } |
297 | void | 296 | static void |
298 | rijndael_cbc_encrypt(CipherContext *cc, u_char *dest, const u_char *src, | 297 | rijndael_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 | ||
324 | void | 323 | static void |
325 | rijndael_cbc_decrypt(CipherContext *cc, u_char *dest, const u_char *src, | 324 | rijndael_cbc_decrypt(CipherContext *cc, u_char *dest, const u_char *src, |
326 | u_int len) | 325 | u_int len) |
327 | { | 326 | { |