diff options
author | Ben Lindstrom <mouring@eviladmin.org> | 2002-03-08 03:50:57 +0000 |
---|---|---|
committer | Ben Lindstrom <mouring@eviladmin.org> | 2002-03-08 03:50:57 +0000 |
commit | 784e234c19fc474af3ac3b7f96fa2dcc9f6443be (patch) | |
tree | 73ee0f45ac2714865bd2cc4d6b59d1d2a8d643d5 /cipher.c | |
parent | 7577fd83c16ef3415b61ca1bea1b14e1ab8e4228 (diff) |
- (bal) Test for IRIX JOBS support at runtime. Patch provided
by David Kaelbling <drk@sgi.com>
Diffstat (limited to 'cipher.c')
-rw-r--r-- | cipher.c | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -41,6 +41,10 @@ RCSID("$OpenBSD: cipher.c,v 1.52 2002/02/18 13:05:32 markus Exp $"); | |||
41 | #include "log.h" | 41 | #include "log.h" |
42 | #include "cipher.h" | 42 | #include "cipher.h" |
43 | 43 | ||
44 | #if OPENSSL_VERSION_NUMBER <= 0x0090600fL | ||
45 | #define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) | ||
46 | #endif | ||
47 | |||
44 | #include <openssl/md5.h> | 48 | #include <openssl/md5.h> |
45 | #include "rijndael.h" | 49 | #include "rijndael.h" |
46 | 50 | ||
@@ -196,6 +200,7 @@ cipher_init(CipherContext *cc, Cipher *cipher, | |||
196 | type = (*cipher->evptype)(); | 200 | type = (*cipher->evptype)(); |
197 | 201 | ||
198 | EVP_CIPHER_CTX_init(&cc->evp); | 202 | EVP_CIPHER_CTX_init(&cc->evp); |
203 | #if OPENSSL_VERSION_NUMBER > 0x0090600fL | ||
199 | if (EVP_CipherInit(&cc->evp, type, NULL, (u_char *)iv, | 204 | if (EVP_CipherInit(&cc->evp, type, NULL, (u_char *)iv, |
200 | (encrypt == CIPHER_ENCRYPT)) == 0) | 205 | (encrypt == CIPHER_ENCRYPT)) == 0) |
201 | fatal("cipher_init: EVP_CipherInit failed for %s", | 206 | fatal("cipher_init: EVP_CipherInit failed for %s", |
@@ -210,6 +215,10 @@ cipher_init(CipherContext *cc, Cipher *cipher, | |||
210 | if (EVP_CipherInit(&cc->evp, NULL, (u_char *)key, NULL, -1) == 0) | 215 | if (EVP_CipherInit(&cc->evp, NULL, (u_char *)key, NULL, -1) == 0) |
211 | fatal("cipher_init: EVP_CipherInit: set key failed for %s", | 216 | fatal("cipher_init: EVP_CipherInit: set key failed for %s", |
212 | cipher->name); | 217 | cipher->name); |
218 | #else | ||
219 | EVP_CipherInit(&cc->evp, type, (u_char *)key, (u_char *)iv, | ||
220 | (encrypt == CIPHER_ENCRYPT)); | ||
221 | #endif | ||
213 | } | 222 | } |
214 | 223 | ||
215 | void | 224 | void |
@@ -217,15 +226,23 @@ cipher_crypt(CipherContext *cc, u_char *dest, const u_char *src, u_int len) | |||
217 | { | 226 | { |
218 | if (len % cc->cipher->block_size) | 227 | if (len % cc->cipher->block_size) |
219 | fatal("cipher_encrypt: bad plaintext length %d", len); | 228 | fatal("cipher_encrypt: bad plaintext length %d", len); |
229 | #if OPENSSL_VERSION_NUMBER > 0x0090600fL | ||
220 | if (EVP_Cipher(&cc->evp, dest, (u_char *)src, len) == 0) | 230 | if (EVP_Cipher(&cc->evp, dest, (u_char *)src, len) == 0) |
221 | fatal("evp_crypt: EVP_Cipher failed"); | 231 | fatal("evp_crypt: EVP_Cipher failed"); |
232 | #else | ||
233 | EVP_Cipher(&cc->evp, dest, (u_char *)src, len); | ||
234 | #endif | ||
222 | } | 235 | } |
223 | 236 | ||
224 | void | 237 | void |
225 | cipher_cleanup(CipherContext *cc) | 238 | cipher_cleanup(CipherContext *cc) |
226 | { | 239 | { |
240 | #if OPENSSL_VERSION_NUMBER > 0x0090600fL | ||
227 | if (EVP_CIPHER_CTX_cleanup(&cc->evp) == 0) | 241 | if (EVP_CIPHER_CTX_cleanup(&cc->evp) == 0) |
228 | error("cipher_cleanup: EVP_CIPHER_CTX_cleanup failed"); | 242 | error("cipher_cleanup: EVP_CIPHER_CTX_cleanup failed"); |
243 | #else | ||
244 | EVP_CIPHER_CTX_cleanup(&cc->evp); | ||
245 | #endif | ||
229 | } | 246 | } |
230 | 247 | ||
231 | /* | 248 | /* |
@@ -296,6 +313,7 @@ ssh1_3des_init(EVP_CIPHER_CTX *ctx, const u_char *key, const u_char *iv, | |||
296 | EVP_CIPHER_CTX_init(&c->k1); | 313 | EVP_CIPHER_CTX_init(&c->k1); |
297 | EVP_CIPHER_CTX_init(&c->k2); | 314 | EVP_CIPHER_CTX_init(&c->k2); |
298 | EVP_CIPHER_CTX_init(&c->k3); | 315 | EVP_CIPHER_CTX_init(&c->k3); |
316 | #if OPENSSL_VERSION_NUMBER > 0x0090600fL | ||
299 | if (EVP_CipherInit(&c->k1, EVP_des_cbc(), k1, NULL, enc) == 0 || | 317 | if (EVP_CipherInit(&c->k1, EVP_des_cbc(), k1, NULL, enc) == 0 || |
300 | EVP_CipherInit(&c->k2, EVP_des_cbc(), k2, NULL, !enc) == 0 || | 318 | EVP_CipherInit(&c->k2, EVP_des_cbc(), k2, NULL, !enc) == 0 || |
301 | EVP_CipherInit(&c->k3, EVP_des_cbc(), k3, NULL, enc) == 0) { | 319 | EVP_CipherInit(&c->k3, EVP_des_cbc(), k3, NULL, enc) == 0) { |
@@ -304,6 +322,11 @@ ssh1_3des_init(EVP_CIPHER_CTX *ctx, const u_char *key, const u_char *iv, | |||
304 | EVP_CIPHER_CTX_set_app_data(ctx, NULL); | 322 | EVP_CIPHER_CTX_set_app_data(ctx, NULL); |
305 | return (0); | 323 | return (0); |
306 | } | 324 | } |
325 | #else | ||
326 | EVP_CipherInit(&c->k1, EVP_des_cbc(), k1, NULL, enc); | ||
327 | EVP_CipherInit(&c->k2, EVP_des_cbc(), k2, NULL, !enc); | ||
328 | EVP_CipherInit(&c->k3, EVP_des_cbc(), k3, NULL, enc); | ||
329 | #endif | ||
307 | return (1); | 330 | return (1); |
308 | } | 331 | } |
309 | static int | 332 | static int |
@@ -315,10 +338,16 @@ ssh1_3des_cbc(EVP_CIPHER_CTX *ctx, u_char *dest, const u_char *src, u_int len) | |||
315 | error("ssh1_3des_cbc: no context"); | 338 | error("ssh1_3des_cbc: no context"); |
316 | return (0); | 339 | return (0); |
317 | } | 340 | } |
341 | #if OPENSSL_VERSION_NUMBER > 0x0090600fL | ||
318 | if (EVP_Cipher(&c->k1, dest, (u_char *)src, len) == 0 || | 342 | if (EVP_Cipher(&c->k1, dest, (u_char *)src, len) == 0 || |
319 | EVP_Cipher(&c->k2, dest, dest, len) == 0 || | 343 | EVP_Cipher(&c->k2, dest, dest, len) == 0 || |
320 | EVP_Cipher(&c->k3, dest, dest, len) == 0) | 344 | EVP_Cipher(&c->k3, dest, dest, len) == 0) |
321 | return (0); | 345 | return (0); |
346 | #else | ||
347 | EVP_Cipher(&c->k1, dest, (u_char *)src, len); | ||
348 | EVP_Cipher(&c->k2, dest, dest, len); | ||
349 | EVP_Cipher(&c->k3, dest, dest, len); | ||
350 | #endif | ||
322 | return (1); | 351 | return (1); |
323 | } | 352 | } |
324 | static int | 353 | static int |
@@ -346,7 +375,9 @@ evp_ssh1_3des(void) | |||
346 | ssh1_3des.init = ssh1_3des_init; | 375 | ssh1_3des.init = ssh1_3des_init; |
347 | ssh1_3des.cleanup = ssh1_3des_cleanup; | 376 | ssh1_3des.cleanup = ssh1_3des_cleanup; |
348 | ssh1_3des.do_cipher = ssh1_3des_cbc; | 377 | ssh1_3des.do_cipher = ssh1_3des_cbc; |
378 | #if OPENSSL_VERSION_NUMBER > 0x0090600fL | ||
349 | ssh1_3des.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH; | 379 | ssh1_3des.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH; |
380 | #endif | ||
350 | return (&ssh1_3des); | 381 | return (&ssh1_3des); |
351 | } | 382 | } |
352 | 383 | ||
@@ -494,7 +525,9 @@ evp_rijndael(void) | |||
494 | rijndal_cbc.init = ssh_rijndael_init; | 525 | rijndal_cbc.init = ssh_rijndael_init; |
495 | rijndal_cbc.cleanup = ssh_rijndael_cleanup; | 526 | rijndal_cbc.cleanup = ssh_rijndael_cleanup; |
496 | rijndal_cbc.do_cipher = ssh_rijndael_cbc; | 527 | rijndal_cbc.do_cipher = ssh_rijndael_cbc; |
528 | #if OPENSSL_VERSION_NUMBER > 0x0090600fL | ||
497 | rijndal_cbc.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | | 529 | rijndal_cbc.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | |
498 | EVP_CIPH_ALWAYS_CALL_INIT; | 530 | EVP_CIPH_ALWAYS_CALL_INIT; |
531 | #endif | ||
499 | return (&rijndal_cbc); | 532 | return (&rijndal_cbc); |
500 | } | 533 | } |