summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/e_idea.c
diff options
context:
space:
mode:
authorjsing <>2022-09-04 13:17:18 +0000
committerjsing <>2022-09-04 13:17:18 +0000
commite0a6d27109c842f87e3f1f5c368f7eaf24cfd6f7 (patch)
treecb92f37869e1b342783302b265164463a74d0a99 /src/lib/libcrypto/evp/e_idea.c
parent6f74aedf29c64cca6f4963750a513b61049d06d8 (diff)
downloadopenbsd-e0a6d27109c842f87e3f1f5c368f7eaf24cfd6f7.tar.gz
openbsd-e0a6d27109c842f87e3f1f5c368f7eaf24cfd6f7.tar.bz2
openbsd-e0a6d27109c842f87e3f1f5c368f7eaf24cfd6f7.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_idea.c')
-rw-r--r--src/lib/libcrypto/evp/e_idea.c53
1 files changed, 24 insertions, 29 deletions
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
72static 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
79static int 76static int
77idea_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
99static int
80idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 100idea_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
246static int
247idea_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