diff options
| author | jsing <> | 2022-09-04 13:17:18 +0000 |
|---|---|---|
| committer | jsing <> | 2022-09-04 13:17:18 +0000 |
| commit | f453032a082679ee008caf1733daa90d71890cee (patch) | |
| tree | cb92f37869e1b342783302b265164463a74d0a99 /src/lib/libcrypto/evp/e_des3.c | |
| parent | ec5b7288624517a9f05504f95f89b25996d63a22 (diff) | |
| download | openbsd-f453032a082679ee008caf1733daa90d71890cee.tar.gz openbsd-f453032a082679ee008caf1733daa90d71890cee.tar.bz2 openbsd-f453032a082679ee008caf1733daa90d71890cee.zip | |
Rearrange some functions.
Pull the init_key and ctrl (if present) functions up to the top. This
improves readability and allows for the removal of function prototypes.
No functional change.
Diffstat (limited to 'src/lib/libcrypto/evp/e_des3.c')
| -rw-r--r-- | src/lib/libcrypto/evp/e_des3.c | 103 |
1 files changed, 47 insertions, 56 deletions
diff --git a/src/lib/libcrypto/evp/e_des3.c b/src/lib/libcrypto/evp/e_des3.c index 1d843d9c84..e9d7f56809 100644 --- a/src/lib/libcrypto/evp/e_des3.c +++ b/src/lib/libcrypto/evp/e_des3.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: e_des3.c,v 1.22 2022/09/04 08:54:16 jsing Exp $ */ | 1 | /* $OpenBSD: e_des3.c,v 1.23 2022/09/04 13:17:18 jsing Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -69,14 +69,6 @@ | |||
| 69 | 69 | ||
| 70 | #include "evp_locl.h" | 70 | #include "evp_locl.h" |
| 71 | 71 | ||
| 72 | static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 73 | const unsigned char *iv, int enc); | ||
| 74 | |||
| 75 | static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 76 | const unsigned char *iv, int enc); | ||
| 77 | |||
| 78 | static int des3_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr); | ||
| 79 | |||
| 80 | typedef struct { | 72 | typedef struct { |
| 81 | DES_key_schedule ks1;/* key schedule */ | 73 | DES_key_schedule ks1;/* key schedule */ |
| 82 | DES_key_schedule ks2;/* key schedule (for ede) */ | 74 | DES_key_schedule ks2;/* key schedule (for ede) */ |
| @@ -86,6 +78,52 @@ typedef struct { | |||
| 86 | #define data(ctx) ((DES_EDE_KEY *)(ctx)->cipher_data) | 78 | #define data(ctx) ((DES_EDE_KEY *)(ctx)->cipher_data) |
| 87 | 79 | ||
| 88 | static int | 80 | static int |
| 81 | des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 82 | const unsigned char *iv, int enc) | ||
| 83 | { | ||
| 84 | DES_cblock *deskey = (DES_cblock *)key; | ||
| 85 | |||
| 86 | DES_set_key_unchecked(&deskey[0], &data(ctx)->ks1); | ||
| 87 | DES_set_key_unchecked(&deskey[1], &data(ctx)->ks2); | ||
| 88 | memcpy(&data(ctx)->ks3, &data(ctx)->ks1, | ||
| 89 | sizeof(data(ctx)->ks1)); | ||
| 90 | return 1; | ||
| 91 | } | ||
| 92 | |||
| 93 | static int | ||
| 94 | des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 95 | const unsigned char *iv, int enc) | ||
| 96 | { | ||
| 97 | DES_cblock *deskey = (DES_cblock *)key; | ||
| 98 | |||
| 99 | |||
| 100 | DES_set_key_unchecked(&deskey[0], &data(ctx)->ks1); | ||
| 101 | DES_set_key_unchecked(&deskey[1], &data(ctx)->ks2); | ||
| 102 | DES_set_key_unchecked(&deskey[2], &data(ctx)->ks3); | ||
| 103 | return 1; | ||
| 104 | } | ||
| 105 | |||
| 106 | static int | ||
| 107 | des3_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) | ||
| 108 | { | ||
| 109 | DES_cblock *deskey = ptr; | ||
| 110 | |||
| 111 | switch (type) { | ||
| 112 | case EVP_CTRL_RAND_KEY: | ||
| 113 | if (DES_random_key(deskey) == 0) | ||
| 114 | return 0; | ||
| 115 | if (c->key_len >= 16 && DES_random_key(deskey + 1) == 0) | ||
| 116 | return 0; | ||
| 117 | if (c->key_len >= 24 && DES_random_key(deskey + 2) == 0) | ||
| 118 | return 0; | ||
| 119 | return 1; | ||
| 120 | |||
| 121 | default: | ||
| 122 | return -1; | ||
| 123 | } | ||
| 124 | } | ||
| 125 | |||
| 126 | static int | ||
| 89 | des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 127 | des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
| 90 | const unsigned char *in, size_t inl) | 128 | const unsigned char *in, size_t inl) |
| 91 | { | 129 | { |
| @@ -432,53 +470,6 @@ EVP_des_ede3_cfb8(void) | |||
| 432 | return &des_ede3_cfb8; | 470 | return &des_ede3_cfb8; |
| 433 | } | 471 | } |
| 434 | 472 | ||
| 435 | |||
| 436 | static int | ||
| 437 | des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 438 | const unsigned char *iv, int enc) | ||
| 439 | { | ||
| 440 | DES_cblock *deskey = (DES_cblock *)key; | ||
| 441 | |||
| 442 | DES_set_key_unchecked(&deskey[0], &data(ctx)->ks1); | ||
| 443 | DES_set_key_unchecked(&deskey[1], &data(ctx)->ks2); | ||
| 444 | memcpy(&data(ctx)->ks3, &data(ctx)->ks1, | ||
| 445 | sizeof(data(ctx)->ks1)); | ||
| 446 | return 1; | ||
| 447 | } | ||
| 448 | |||
| 449 | static int | ||
| 450 | des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 451 | const unsigned char *iv, int enc) | ||
| 452 | { | ||
| 453 | DES_cblock *deskey = (DES_cblock *)key; | ||
| 454 | |||
| 455 | |||
| 456 | DES_set_key_unchecked(&deskey[0], &data(ctx)->ks1); | ||
| 457 | DES_set_key_unchecked(&deskey[1], &data(ctx)->ks2); | ||
| 458 | DES_set_key_unchecked(&deskey[2], &data(ctx)->ks3); | ||
| 459 | return 1; | ||
| 460 | } | ||
| 461 | |||
| 462 | static int | ||
| 463 | des3_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) | ||
| 464 | { | ||
| 465 | DES_cblock *deskey = ptr; | ||
| 466 | |||
| 467 | switch (type) { | ||
| 468 | case EVP_CTRL_RAND_KEY: | ||
| 469 | if (DES_random_key(deskey) == 0) | ||
| 470 | return 0; | ||
| 471 | if (c->key_len >= 16 && DES_random_key(deskey + 1) == 0) | ||
| 472 | return 0; | ||
| 473 | if (c->key_len >= 24 && DES_random_key(deskey + 2) == 0) | ||
| 474 | return 0; | ||
| 475 | return 1; | ||
| 476 | |||
| 477 | default: | ||
| 478 | return -1; | ||
| 479 | } | ||
| 480 | } | ||
| 481 | |||
| 482 | const EVP_CIPHER * | 473 | const EVP_CIPHER * |
| 483 | EVP_des_ede(void) | 474 | EVP_des_ede(void) |
| 484 | { | 475 | { |
