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 | |
| 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 '')
| -rw-r--r-- | src/lib/libcrypto/evp/e_bf.c | 22 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/e_camellia.c | 38 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/e_cast.c | 21 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/e_des.c | 56 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/e_des3.c | 103 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/e_gost2814789.c | 22 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/e_idea.c | 53 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/e_sm4.c | 3 |
8 files changed, 141 insertions, 177 deletions
diff --git a/src/lib/libcrypto/evp/e_bf.c b/src/lib/libcrypto/evp/e_bf.c index f4e0c4c093..745c4d3201 100644 --- a/src/lib/libcrypto/evp/e_bf.c +++ b/src/lib/libcrypto/evp/e_bf.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: e_bf.c,v 1.9 2022/09/03 19:43:16 jsing Exp $ */ | 1 | /* $OpenBSD: e_bf.c,v 1.10 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 | * |
| @@ -68,9 +68,6 @@ | |||
| 68 | 68 | ||
| 69 | #include "evp_locl.h" | 69 | #include "evp_locl.h" |
| 70 | 70 | ||
| 71 | static int bf_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 72 | const unsigned char *iv, int enc); | ||
| 73 | |||
| 74 | typedef struct { | 71 | typedef struct { |
| 75 | BF_KEY ks; | 72 | BF_KEY ks; |
| 76 | } EVP_BF_KEY; | 73 | } EVP_BF_KEY; |
| @@ -78,6 +75,14 @@ typedef struct { | |||
| 78 | #define data(ctx) ((EVP_BF_KEY *)(ctx)->cipher_data) | 75 | #define data(ctx) ((EVP_BF_KEY *)(ctx)->cipher_data) |
| 79 | 76 | ||
| 80 | static int | 77 | static int |
| 78 | bf_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 79 | const unsigned char *iv, int enc) | ||
| 80 | { | ||
| 81 | BF_set_key(&data(ctx)->ks, EVP_CIPHER_CTX_key_length(ctx), key); | ||
| 82 | return 1; | ||
| 83 | } | ||
| 84 | |||
| 85 | static int | ||
| 81 | bf_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | 86 | bf_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) |
| 82 | { | 87 | { |
| 83 | while (inl >= EVP_MAXCHUNK) { | 88 | while (inl >= EVP_MAXCHUNK) { |
| @@ -237,13 +242,4 @@ EVP_bf_ecb(void) | |||
| 237 | { | 242 | { |
| 238 | return &bf_ecb; | 243 | return &bf_ecb; |
| 239 | } | 244 | } |
| 240 | |||
| 241 | |||
| 242 | static int | ||
| 243 | bf_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 244 | const unsigned char *iv, int enc) | ||
| 245 | { | ||
| 246 | BF_set_key(&data(ctx)->ks, EVP_CIPHER_CTX_key_length(ctx), key); | ||
| 247 | return 1; | ||
| 248 | } | ||
| 249 | #endif | 245 | #endif |
diff --git a/src/lib/libcrypto/evp/e_camellia.c b/src/lib/libcrypto/evp/e_camellia.c index 42c036a7ab..2d7ab73627 100644 --- a/src/lib/libcrypto/evp/e_camellia.c +++ b/src/lib/libcrypto/evp/e_camellia.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: e_camellia.c,v 1.11 2022/09/04 07:54:59 jsing Exp $ */ | 1 | /* $OpenBSD: e_camellia.c,v 1.12 2022/09/04 13:17:18 jsing Exp $ */ |
| 2 | /* ==================================================================== | 2 | /* ==================================================================== |
| 3 | * Copyright (c) 2006 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 2006 The OpenSSL Project. All rights reserved. |
| 4 | * | 4 | * |
| @@ -64,9 +64,6 @@ | |||
| 64 | 64 | ||
| 65 | #include "evp_locl.h" | 65 | #include "evp_locl.h" |
| 66 | 66 | ||
| 67 | static int camellia_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 68 | const unsigned char *iv, int enc); | ||
| 69 | |||
| 70 | /* Camellia subkey Structure */ | 67 | /* Camellia subkey Structure */ |
| 71 | typedef struct { | 68 | typedef struct { |
| 72 | CAMELLIA_KEY ks; | 69 | CAMELLIA_KEY ks; |
| @@ -76,6 +73,22 @@ typedef struct { | |||
| 76 | #define data(ctx) ((EVP_CAMELLIA_KEY *)(ctx)->cipher_data) | 73 | #define data(ctx) ((EVP_CAMELLIA_KEY *)(ctx)->cipher_data) |
| 77 | 74 | ||
| 78 | static int | 75 | static int |
| 76 | camellia_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 77 | const unsigned char *iv, int enc) | ||
| 78 | { | ||
| 79 | int ret; | ||
| 80 | |||
| 81 | ret = Camellia_set_key(key, ctx->key_len * 8, ctx->cipher_data); | ||
| 82 | |||
| 83 | if (ret < 0) { | ||
| 84 | EVPerror(EVP_R_CAMELLIA_KEY_SETUP_FAILED); | ||
| 85 | return 0; | ||
| 86 | } | ||
| 87 | |||
| 88 | return 1; | ||
| 89 | } | ||
| 90 | |||
| 91 | static int | ||
| 79 | camellia_128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | 92 | camellia_128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) |
| 80 | { | 93 | { |
| 81 | while (inl >= EVP_MAXCHUNK) { | 94 | while (inl >= EVP_MAXCHUNK) { |
| @@ -828,21 +841,4 @@ EVP_camellia_256_cfb8(void) | |||
| 828 | { | 841 | { |
| 829 | return &camellia_256_cfb8; | 842 | return &camellia_256_cfb8; |
| 830 | } | 843 | } |
| 831 | |||
| 832 | /* The subkey for Camellia is generated. */ | ||
| 833 | static int | ||
| 834 | camellia_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 835 | const unsigned char *iv, int enc) | ||
| 836 | { | ||
| 837 | int ret; | ||
| 838 | |||
| 839 | ret = Camellia_set_key(key, ctx->key_len * 8, ctx->cipher_data); | ||
| 840 | |||
| 841 | if (ret < 0) { | ||
| 842 | EVPerror(EVP_R_CAMELLIA_KEY_SETUP_FAILED); | ||
| 843 | return 0; | ||
| 844 | } | ||
| 845 | |||
| 846 | return 1; | ||
| 847 | } | ||
| 848 | #endif | 844 | #endif |
diff --git a/src/lib/libcrypto/evp/e_cast.c b/src/lib/libcrypto/evp/e_cast.c index b23dfeef1c..32f86d86af 100644 --- a/src/lib/libcrypto/evp/e_cast.c +++ b/src/lib/libcrypto/evp/e_cast.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: e_cast.c,v 1.8 2022/09/03 19:51:53 jsing Exp $ */ | 1 | /* $OpenBSD: e_cast.c,v 1.9 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 | * |
| @@ -68,9 +68,6 @@ | |||
| 68 | 68 | ||
| 69 | #include "evp_locl.h" | 69 | #include "evp_locl.h" |
| 70 | 70 | ||
| 71 | static int cast_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 72 | const unsigned char *iv, int enc); | ||
| 73 | |||
| 74 | typedef struct { | 71 | typedef struct { |
| 75 | CAST_KEY ks; | 72 | CAST_KEY ks; |
| 76 | } EVP_CAST_KEY; | 73 | } EVP_CAST_KEY; |
| @@ -78,6 +75,14 @@ typedef struct { | |||
| 78 | #define data(ctx) ((EVP_CAST_KEY *)(ctx)->cipher_data) | 75 | #define data(ctx) ((EVP_CAST_KEY *)(ctx)->cipher_data) |
| 79 | 76 | ||
| 80 | static int | 77 | static int |
| 78 | cast_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 79 | const unsigned char *iv, int enc) | ||
| 80 | { | ||
| 81 | CAST_set_key(&data(ctx)->ks, EVP_CIPHER_CTX_key_length(ctx), key); | ||
| 82 | return 1; | ||
| 83 | } | ||
| 84 | |||
| 85 | static int | ||
| 81 | cast5_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | 86 | cast5_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) |
| 82 | { | 87 | { |
| 83 | while (inl >= EVP_MAXCHUNK) { | 88 | while (inl >= EVP_MAXCHUNK) { |
| @@ -237,12 +242,4 @@ EVP_cast5_ecb(void) | |||
| 237 | { | 242 | { |
| 238 | return &cast5_ecb; | 243 | return &cast5_ecb; |
| 239 | } | 244 | } |
| 240 | |||
| 241 | static int | ||
| 242 | cast_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 243 | const unsigned char *iv, int enc) | ||
| 244 | { | ||
| 245 | CAST_set_key(&data(ctx)->ks, EVP_CIPHER_CTX_key_length(ctx), key); | ||
| 246 | return 1; | ||
| 247 | } | ||
| 248 | #endif | 245 | #endif |
diff --git a/src/lib/libcrypto/evp/e_des.c b/src/lib/libcrypto/evp/e_des.c index 1064c0b7cc..bf037591be 100644 --- a/src/lib/libcrypto/evp/e_des.c +++ b/src/lib/libcrypto/evp/e_des.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: e_des.c,v 1.16 2022/09/04 08:18:07 jsing Exp $ */ | 1 | /* $OpenBSD: e_des.c,v 1.17 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 | * |
| @@ -68,9 +68,29 @@ | |||
| 68 | 68 | ||
| 69 | #include "evp_locl.h" | 69 | #include "evp_locl.h" |
| 70 | 70 | ||
| 71 | static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | 71 | static int |
| 72 | const unsigned char *iv, int enc); | 72 | des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
| 73 | static int des_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr); | 73 | const unsigned char *iv, int enc) |
| 74 | { | ||
| 75 | DES_cblock *deskey = (DES_cblock *)key; | ||
| 76 | |||
| 77 | DES_set_key_unchecked(deskey, ctx->cipher_data); | ||
| 78 | return 1; | ||
| 79 | } | ||
| 80 | |||
| 81 | static int | ||
| 82 | des_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) | ||
| 83 | { | ||
| 84 | switch (type) { | ||
| 85 | case EVP_CTRL_RAND_KEY: | ||
| 86 | if (DES_random_key((DES_cblock *)ptr) == 0) | ||
| 87 | return 0; | ||
| 88 | return 1; | ||
| 89 | |||
| 90 | default: | ||
| 91 | return -1; | ||
| 92 | } | ||
| 93 | } | ||
| 74 | 94 | ||
| 75 | static int | 95 | static int |
| 76 | des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 96 | des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
| @@ -278,7 +298,6 @@ EVP_des_ecb(void) | |||
| 278 | return &des_ecb; | 298 | return &des_ecb; |
| 279 | } | 299 | } |
| 280 | 300 | ||
| 281 | |||
| 282 | static const EVP_CIPHER des_cfb1 = { | 301 | static const EVP_CIPHER des_cfb1 = { |
| 283 | .nid = NID_des_cfb1, | 302 | .nid = NID_des_cfb1, |
| 284 | .block_size = 1, | 303 | .block_size = 1, |
| @@ -301,7 +320,6 @@ EVP_des_cfb1(void) | |||
| 301 | return &des_cfb1; | 320 | return &des_cfb1; |
| 302 | } | 321 | } |
| 303 | 322 | ||
| 304 | |||
| 305 | static const EVP_CIPHER des_cfb8 = { | 323 | static const EVP_CIPHER des_cfb8 = { |
| 306 | .nid = NID_des_cfb8, | 324 | .nid = NID_des_cfb8, |
| 307 | .block_size = 1, | 325 | .block_size = 1, |
| @@ -323,30 +341,4 @@ EVP_des_cfb8(void) | |||
| 323 | { | 341 | { |
| 324 | return &des_cfb8; | 342 | return &des_cfb8; |
| 325 | } | 343 | } |
| 326 | |||
| 327 | |||
| 328 | static int | ||
| 329 | des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 330 | const unsigned char *iv, int enc) | ||
| 331 | { | ||
| 332 | DES_cblock *deskey = (DES_cblock *)key; | ||
| 333 | |||
| 334 | DES_set_key_unchecked(deskey, ctx->cipher_data); | ||
| 335 | return 1; | ||
| 336 | } | ||
| 337 | |||
| 338 | static int | ||
| 339 | des_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) | ||
| 340 | { | ||
| 341 | switch (type) { | ||
| 342 | case EVP_CTRL_RAND_KEY: | ||
| 343 | if (DES_random_key((DES_cblock *)ptr) == 0) | ||
| 344 | return 0; | ||
| 345 | return 1; | ||
| 346 | |||
| 347 | default: | ||
| 348 | return -1; | ||
| 349 | } | ||
| 350 | } | ||
| 351 | |||
| 352 | #endif | 344 | #endif |
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 | { |
diff --git a/src/lib/libcrypto/evp/e_gost2814789.c b/src/lib/libcrypto/evp/e_gost2814789.c index 11379be547..959610f16d 100644 --- a/src/lib/libcrypto/evp/e_gost2814789.c +++ b/src/lib/libcrypto/evp/e_gost2814789.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: e_gost2814789.c,v 1.6 2022/09/04 09:48:23 jsing Exp $ */ | 1 | /* $OpenBSD: e_gost2814789.c,v 1.7 2022/09/04 13:17:18 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | 3 | * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> |
| 4 | * Copyright (c) 2005-2006 Cryptocom LTD | 4 | * Copyright (c) 2005-2006 Cryptocom LTD |
| @@ -66,6 +66,15 @@ typedef struct { | |||
| 66 | } EVP_GOST2814789_CTX; | 66 | } EVP_GOST2814789_CTX; |
| 67 | 67 | ||
| 68 | static int | 68 | static int |
| 69 | gost2814789_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 70 | const unsigned char *iv, int enc) | ||
| 71 | { | ||
| 72 | EVP_GOST2814789_CTX *c = ctx->cipher_data; | ||
| 73 | |||
| 74 | return Gost2814789_set_key(&c->ks, key, ctx->key_len * 8); | ||
| 75 | } | ||
| 76 | |||
| 77 | static int | ||
| 69 | gost2814789_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) | 78 | gost2814789_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) |
| 70 | { | 79 | { |
| 71 | EVP_GOST2814789_CTX *c = ctx->cipher_data; | 80 | EVP_GOST2814789_CTX *c = ctx->cipher_data; |
| @@ -89,15 +98,6 @@ gost2814789_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) | |||
| 89 | } | 98 | } |
| 90 | } | 99 | } |
| 91 | 100 | ||
| 92 | static int | ||
| 93 | gost2814789_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 94 | const unsigned char *iv, int enc) | ||
| 95 | { | ||
| 96 | EVP_GOST2814789_CTX *c = ctx->cipher_data; | ||
| 97 | |||
| 98 | return Gost2814789_set_key(&c->ks, key, ctx->key_len * 8); | ||
| 99 | } | ||
| 100 | |||
| 101 | int | 101 | int |
| 102 | gost2814789_set_asn1_params(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params) | 102 | gost2814789_set_asn1_params(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params) |
| 103 | { | 103 | { |
| @@ -227,7 +227,6 @@ gost2814789_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned | |||
| 227 | return 1; | 227 | return 1; |
| 228 | } | 228 | } |
| 229 | 229 | ||
| 230 | |||
| 231 | static int | 230 | static int |
| 232 | gost2814789_cnt_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 231 | gost2814789_cnt_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
| 233 | const unsigned char *in, size_t inl) | 232 | const unsigned char *in, size_t inl) |
| @@ -316,5 +315,4 @@ EVP_gost2814789_cnt(void) | |||
| 316 | { | 315 | { |
| 317 | return &gost2814789_cnt; | 316 | return &gost2814789_cnt; |
| 318 | } | 317 | } |
| 319 | |||
| 320 | #endif | 318 | #endif |
diff --git a/src/lib/libcrypto/evp/e_idea.c b/src/lib/libcrypto/evp/e_idea.c index d69f200423..819f52ba23 100644 --- a/src/lib/libcrypto/evp/e_idea.c +++ b/src/lib/libcrypto/evp/e_idea.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: e_idea.c,v 1.12 2022/09/04 08:57:32 jsing Exp $ */ | 1 | /* $OpenBSD: e_idea.c,v 1.13 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,34 @@ | |||
| 69 | 69 | ||
| 70 | #include "evp_locl.h" | 70 | #include "evp_locl.h" |
| 71 | 71 | ||
| 72 | static int idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 73 | const unsigned char *iv, int enc); | ||
| 74 | |||
| 75 | /* NB idea_ecb_encrypt doesn't take an 'encrypt' argument so we treat it as a special | 72 | /* NB idea_ecb_encrypt doesn't take an 'encrypt' argument so we treat it as a special |
| 76 | * case | 73 | * case |
| 77 | */ | 74 | */ |
| 78 | 75 | ||
| 79 | static int | 76 | static int |
| 77 | idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 78 | const unsigned char *iv, int enc) | ||
| 79 | { | ||
| 80 | if (!enc) { | ||
| 81 | if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_OFB_MODE) | ||
| 82 | enc = 1; | ||
| 83 | else if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_CFB_MODE) | ||
| 84 | enc = 1; | ||
| 85 | } | ||
| 86 | if (enc) | ||
| 87 | idea_set_encrypt_key(key, ctx->cipher_data); | ||
| 88 | else { | ||
| 89 | IDEA_KEY_SCHEDULE tmp; | ||
| 90 | |||
| 91 | idea_set_encrypt_key(key, &tmp); | ||
| 92 | idea_set_decrypt_key(&tmp, ctx->cipher_data); | ||
| 93 | explicit_bzero((unsigned char *)&tmp, | ||
| 94 | sizeof(IDEA_KEY_SCHEDULE)); | ||
| 95 | } | ||
| 96 | return 1; | ||
| 97 | } | ||
| 98 | |||
| 99 | static int | ||
| 80 | idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 100 | idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
| 81 | const unsigned char *in, size_t inl) | 101 | const unsigned char *in, size_t inl) |
| 82 | { | 102 | { |
| @@ -241,29 +261,4 @@ EVP_idea_ecb(void) | |||
| 241 | { | 261 | { |
| 242 | return &idea_ecb; | 262 | return &idea_ecb; |
| 243 | } | 263 | } |
| 244 | |||
| 245 | |||
| 246 | static int | ||
| 247 | idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
| 248 | const unsigned char *iv, int enc) | ||
| 249 | { | ||
| 250 | if (!enc) { | ||
| 251 | if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_OFB_MODE) | ||
| 252 | enc = 1; | ||
| 253 | else if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_CFB_MODE) | ||
| 254 | enc = 1; | ||
| 255 | } | ||
| 256 | if (enc) | ||
| 257 | idea_set_encrypt_key(key, ctx->cipher_data); | ||
| 258 | else { | ||
| 259 | IDEA_KEY_SCHEDULE tmp; | ||
| 260 | |||
| 261 | idea_set_encrypt_key(key, &tmp); | ||
| 262 | idea_set_decrypt_key(&tmp, ctx->cipher_data); | ||
| 263 | explicit_bzero((unsigned char *)&tmp, | ||
| 264 | sizeof(IDEA_KEY_SCHEDULE)); | ||
| 265 | } | ||
| 266 | return 1; | ||
| 267 | } | ||
| 268 | |||
| 269 | #endif | 264 | #endif |
diff --git a/src/lib/libcrypto/evp/e_sm4.c b/src/lib/libcrypto/evp/e_sm4.c index 9003abccc3..fd9a9d04f7 100644 --- a/src/lib/libcrypto/evp/e_sm4.c +++ b/src/lib/libcrypto/evp/e_sm4.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: e_sm4.c,v 1.2 2022/09/03 20:02:17 jsing Exp $ */ | 1 | /* $OpenBSD: e_sm4.c,v 1.3 2022/09/04 13:17:18 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2017, 2019 Ribose Inc | 3 | * Copyright (c) 2017, 2019 Ribose Inc |
| 4 | * | 4 | * |
| @@ -267,5 +267,4 @@ EVP_sm4_ctr(void) | |||
| 267 | { | 267 | { |
| 268 | return &sm4_ctr_mode; | 268 | return &sm4_ctr_mode; |
| 269 | } | 269 | } |
| 270 | |||
| 271 | #endif | 270 | #endif |
