|
Lines 41-46
Link Here
|
| 41 |
#include "log.h" |
41 |
#include "log.h" |
| 42 |
#include "cipher.h" |
42 |
#include "cipher.h" |
| 43 |
|
43 |
|
|
|
44 |
#define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) |
| 45 |
|
| 44 |
#include <openssl/md5.h> |
46 |
#include <openssl/md5.h> |
| 45 |
#include "rijndael.h" |
47 |
#include "rijndael.h" |
| 46 |
|
48 |
|
|
Lines 196-215
Link Here
|
| 196 |
type = (*cipher->evptype)(); |
198 |
type = (*cipher->evptype)(); |
| 197 |
|
199 |
|
| 198 |
EVP_CIPHER_CTX_init(&cc->evp); |
200 |
EVP_CIPHER_CTX_init(&cc->evp); |
| 199 |
if (EVP_CipherInit(&cc->evp, type, NULL, (u_char *)iv, |
201 |
EVP_CipherInit(&cc->evp, type, (u_char *)key, (u_char *)iv, |
| 200 |
(encrypt == CIPHER_ENCRYPT)) == 0) |
202 |
(encrypt == CIPHER_ENCRYPT)); |
| 201 |
fatal("cipher_init: EVP_CipherInit failed for %s", |
|
|
| 202 |
cipher->name); |
| 203 |
klen = EVP_CIPHER_CTX_key_length(&cc->evp); |
| 204 |
if (klen > 0 && keylen != klen) { |
| 205 |
debug("cipher_init: set keylen (%d -> %d)", klen, keylen); |
| 206 |
if (EVP_CIPHER_CTX_set_key_length(&cc->evp, keylen) == 0) |
| 207 |
fatal("cipher_init: set keylen failed (%d -> %d)", |
| 208 |
klen, keylen); |
| 209 |
} |
| 210 |
if (EVP_CipherInit(&cc->evp, NULL, (u_char *)key, NULL, -1) == 0) |
| 211 |
fatal("cipher_init: EVP_CipherInit: set key failed for %s", |
| 212 |
cipher->name); |
| 213 |
} |
203 |
} |
| 214 |
|
204 |
|
| 215 |
void |
205 |
void |
|
Lines 217-231
Link Here
|
| 217 |
{ |
207 |
{ |
| 218 |
if (len % cc->cipher->block_size) |
208 |
if (len % cc->cipher->block_size) |
| 219 |
fatal("cipher_encrypt: bad plaintext length %d", len); |
209 |
fatal("cipher_encrypt: bad plaintext length %d", len); |
| 220 |
if (EVP_Cipher(&cc->evp, dest, (u_char *)src, len) == 0) |
210 |
EVP_Cipher(&cc->evp, dest, (u_char *)src, len); |
| 221 |
fatal("evp_crypt: EVP_Cipher failed"); |
|
|
| 222 |
} |
211 |
} |
| 223 |
|
212 |
|
| 224 |
void |
213 |
void |
| 225 |
cipher_cleanup(CipherContext *cc) |
214 |
cipher_cleanup(CipherContext *cc) |
| 226 |
{ |
215 |
{ |
| 227 |
if (EVP_CIPHER_CTX_cleanup(&cc->evp) == 0) |
216 |
EVP_CIPHER_CTX_cleanup(&cc->evp); |
| 228 |
error("cipher_cleanup: EVP_CIPHER_CTX_cleanup failed"); |
|
|
| 229 |
} |
217 |
} |
| 230 |
|
218 |
|
| 231 |
/* |
219 |
/* |
|
Lines 296-309
Link Here
|
| 296 |
EVP_CIPHER_CTX_init(&c->k1); |
284 |
EVP_CIPHER_CTX_init(&c->k1); |
| 297 |
EVP_CIPHER_CTX_init(&c->k2); |
285 |
EVP_CIPHER_CTX_init(&c->k2); |
| 298 |
EVP_CIPHER_CTX_init(&c->k3); |
286 |
EVP_CIPHER_CTX_init(&c->k3); |
| 299 |
if (EVP_CipherInit(&c->k1, EVP_des_cbc(), k1, NULL, enc) == 0 || |
287 |
EVP_CipherInit(&c->k1, EVP_des_cbc(), k1, NULL, enc); |
| 300 |
EVP_CipherInit(&c->k2, EVP_des_cbc(), k2, NULL, !enc) == 0 || |
288 |
EVP_CipherInit(&c->k2, EVP_des_cbc(), k2, NULL, !enc); |
| 301 |
EVP_CipherInit(&c->k3, EVP_des_cbc(), k3, NULL, enc) == 0) { |
289 |
EVP_CipherInit(&c->k3, EVP_des_cbc(), k3, NULL, enc); |
| 302 |
memset(c, 0, sizeof(*c)); |
|
|
| 303 |
xfree(c); |
| 304 |
EVP_CIPHER_CTX_set_app_data(ctx, NULL); |
| 305 |
return (0); |
| 306 |
} |
| 307 |
return (1); |
290 |
return (1); |
| 308 |
} |
291 |
} |
| 309 |
static int |
292 |
static int |
|
Lines 315-324
Link Here
|
| 315 |
error("ssh1_3des_cbc: no context"); |
298 |
error("ssh1_3des_cbc: no context"); |
| 316 |
return (0); |
299 |
return (0); |
| 317 |
} |
300 |
} |
| 318 |
if (EVP_Cipher(&c->k1, dest, (u_char *)src, len) == 0 || |
301 |
EVP_Cipher(&c->k1, dest, (u_char *)src, len); |
| 319 |
EVP_Cipher(&c->k2, dest, dest, len) == 0 || |
302 |
EVP_Cipher(&c->k2, dest, dest, len); |
| 320 |
EVP_Cipher(&c->k3, dest, dest, len) == 0) |
303 |
EVP_Cipher(&c->k3, dest, dest, len); |
| 321 |
return (0); |
|
|
| 322 |
return (1); |
304 |
return (1); |
| 323 |
} |
305 |
} |
| 324 |
static int |
306 |
static int |
|
Lines 346-352
Link Here
|
| 346 |
ssh1_3des.init = ssh1_3des_init; |
328 |
ssh1_3des.init = ssh1_3des_init; |
| 347 |
ssh1_3des.cleanup = ssh1_3des_cleanup; |
329 |
ssh1_3des.cleanup = ssh1_3des_cleanup; |
| 348 |
ssh1_3des.do_cipher = ssh1_3des_cbc; |
330 |
ssh1_3des.do_cipher = ssh1_3des_cbc; |
| 349 |
ssh1_3des.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH; |
|
|
| 350 |
return (&ssh1_3des); |
331 |
return (&ssh1_3des); |
| 351 |
} |
332 |
} |
| 352 |
|
333 |
|
|
Lines 494-500
Link Here
|
| 494 |
rijndal_cbc.init = ssh_rijndael_init; |
475 |
rijndal_cbc.init = ssh_rijndael_init; |
| 495 |
rijndal_cbc.cleanup = ssh_rijndael_cleanup; |
476 |
rijndal_cbc.cleanup = ssh_rijndael_cleanup; |
| 496 |
rijndal_cbc.do_cipher = ssh_rijndael_cbc; |
477 |
rijndal_cbc.do_cipher = ssh_rijndael_cbc; |
| 497 |
rijndal_cbc.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | |
|
|
| 498 |
EVP_CIPH_ALWAYS_CALL_INIT; |
| 499 |
return (&rijndal_cbc); |
478 |
return (&rijndal_cbc); |
| 500 |
} |
479 |
} |