diff options
Diffstat (limited to 'src/lib/libcrypto/evp/e_idea.c')
| -rw-r--r-- | src/lib/libcrypto/evp/e_idea.c | 162 |
1 files changed, 154 insertions, 8 deletions
diff --git a/src/lib/libcrypto/evp/e_idea.c b/src/lib/libcrypto/evp/e_idea.c index b2240b3043..d69f200423 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.11 2022/09/03 20:12:24 jsing Exp $ */ | 1 | /* $OpenBSD: e_idea.c,v 1.12 2022/09/04 08:57:32 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 | * |
| @@ -80,7 +80,16 @@ static int | |||
| 80 | idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 80 | idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
| 81 | const unsigned char *in, size_t inl) | 81 | const unsigned char *in, size_t inl) |
| 82 | { | 82 | { |
| 83 | BLOCK_CIPHER_ecb_loop() | 83 | size_t i, bl; |
| 84 | |||
| 85 | bl = ctx->cipher->block_size; | ||
| 86 | |||
| 87 | if (inl < bl) | ||
| 88 | return 1; | ||
| 89 | |||
| 90 | inl -= bl; | ||
| 91 | |||
| 92 | for (i = 0; i <= inl; i += bl) | ||
| 84 | idea_ecb_encrypt(in + i, out + i, ctx->cipher_data); | 93 | idea_ecb_encrypt(in + i, out + i, ctx->cipher_data); |
| 85 | return 1; | 94 | return 1; |
| 86 | } | 95 | } |
| @@ -89,13 +98,150 @@ typedef struct { | |||
| 89 | IDEA_KEY_SCHEDULE ks; | 98 | IDEA_KEY_SCHEDULE ks; |
| 90 | } EVP_IDEA_KEY; | 99 | } EVP_IDEA_KEY; |
| 91 | 100 | ||
| 92 | BLOCK_CIPHER_func_cbc(idea, idea, EVP_IDEA_KEY, ks) | 101 | static int |
| 93 | BLOCK_CIPHER_func_ofb(idea, idea, 64, EVP_IDEA_KEY, ks) | 102 | idea_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) |
| 94 | BLOCK_CIPHER_func_cfb(idea, idea, 64, EVP_IDEA_KEY, ks) | 103 | { |
| 104 | while (inl >= EVP_MAXCHUNK) { | ||
| 105 | idea_cbc_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_IDEA_KEY *)ctx->cipher_data)->ks, ctx->iv, ctx->encrypt); | ||
| 106 | inl -= EVP_MAXCHUNK; | ||
| 107 | in += EVP_MAXCHUNK; | ||
| 108 | out += EVP_MAXCHUNK; | ||
| 109 | } | ||
| 110 | |||
| 111 | if (inl) | ||
| 112 | idea_cbc_encrypt(in, out, (long)inl, &((EVP_IDEA_KEY *)ctx->cipher_data)->ks, ctx->iv, ctx->encrypt); | ||
| 113 | |||
| 114 | return 1; | ||
| 115 | } | ||
| 116 | |||
| 117 | static int | ||
| 118 | idea_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | ||
| 119 | { | ||
| 120 | while (inl >= EVP_MAXCHUNK) { | ||
| 121 | idea_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK, &((EVP_IDEA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num); | ||
| 122 | inl -= EVP_MAXCHUNK; | ||
| 123 | in += EVP_MAXCHUNK; | ||
| 124 | out += EVP_MAXCHUNK; | ||
| 125 | } | ||
| 126 | |||
| 127 | if (inl) | ||
| 128 | idea_ofb64_encrypt(in, out, (long)inl, &((EVP_IDEA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num); | ||
| 129 | |||
| 130 | return 1; | ||
| 131 | } | ||
| 132 | |||
| 133 | static int | ||
| 134 | idea_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) | ||
| 135 | { | ||
| 136 | size_t chunk = EVP_MAXCHUNK; | ||
| 137 | |||
| 138 | if (64 == 1) | ||
| 139 | chunk >>= 3; | ||
| 140 | |||
| 141 | if (inl < chunk) | ||
| 142 | chunk = inl; | ||
| 143 | |||
| 144 | while (inl && inl >= chunk) { | ||
| 145 | idea_cfb64_encrypt(in, out, (long)((64 == 1) && !(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS) ? inl * 8 : inl), &((EVP_IDEA_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt); | ||
| 146 | inl -= chunk; | ||
| 147 | in += chunk; | ||
| 148 | out += chunk; | ||
| 149 | if (inl < chunk) | ||
| 150 | chunk = inl; | ||
| 151 | } | ||
| 152 | |||
| 153 | return 1; | ||
| 154 | } | ||
| 155 | |||
| 156 | |||
| 157 | static const EVP_CIPHER idea_cbc = { | ||
| 158 | .nid = NID_idea_cbc, | ||
| 159 | .block_size = 8, | ||
| 160 | .key_len = 16, | ||
| 161 | .iv_len = 8, | ||
| 162 | .flags = 0 | EVP_CIPH_CBC_MODE, | ||
| 163 | .init = idea_init_key, | ||
| 164 | .do_cipher = idea_cbc_cipher, | ||
| 165 | .cleanup = NULL, | ||
| 166 | .ctx_size = sizeof(IDEA_KEY_SCHEDULE), | ||
| 167 | .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, | ||
| 168 | .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, | ||
| 169 | .ctrl = NULL, | ||
| 170 | .app_data = NULL, | ||
| 171 | }; | ||
| 172 | |||
| 173 | const EVP_CIPHER * | ||
| 174 | EVP_idea_cbc(void) | ||
| 175 | { | ||
| 176 | return &idea_cbc; | ||
| 177 | } | ||
| 178 | |||
| 179 | static const EVP_CIPHER idea_cfb64 = { | ||
| 180 | .nid = NID_idea_cfb64, | ||
| 181 | .block_size = 1, | ||
| 182 | .key_len = 16, | ||
| 183 | .iv_len = 8, | ||
| 184 | .flags = 0 | EVP_CIPH_CFB_MODE, | ||
| 185 | .init = idea_init_key, | ||
| 186 | .do_cipher = idea_cfb64_cipher, | ||
| 187 | .cleanup = NULL, | ||
| 188 | .ctx_size = sizeof(IDEA_KEY_SCHEDULE), | ||
| 189 | .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, | ||
| 190 | .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, | ||
| 191 | .ctrl = NULL, | ||
| 192 | .app_data = NULL, | ||
| 193 | }; | ||
| 194 | |||
| 195 | const EVP_CIPHER * | ||
| 196 | EVP_idea_cfb64(void) | ||
| 197 | { | ||
| 198 | return &idea_cfb64; | ||
| 199 | } | ||
| 200 | |||
| 201 | static const EVP_CIPHER idea_ofb = { | ||
| 202 | .nid = NID_idea_ofb64, | ||
| 203 | .block_size = 1, | ||
| 204 | .key_len = 16, | ||
| 205 | .iv_len = 8, | ||
| 206 | .flags = 0 | EVP_CIPH_OFB_MODE, | ||
| 207 | .init = idea_init_key, | ||
| 208 | .do_cipher = idea_ofb_cipher, | ||
| 209 | .cleanup = NULL, | ||
| 210 | .ctx_size = sizeof(IDEA_KEY_SCHEDULE), | ||
| 211 | .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, | ||
| 212 | .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, | ||
| 213 | .ctrl = NULL, | ||
| 214 | .app_data = NULL, | ||
| 215 | }; | ||
| 216 | |||
| 217 | const EVP_CIPHER * | ||
| 218 | EVP_idea_ofb(void) | ||
| 219 | { | ||
| 220 | return &idea_ofb; | ||
| 221 | } | ||
| 222 | |||
| 223 | static const EVP_CIPHER idea_ecb = { | ||
| 224 | .nid = NID_idea_ecb, | ||
| 225 | .block_size = 8, | ||
| 226 | .key_len = 16, | ||
| 227 | .iv_len = 0, | ||
| 228 | .flags = 0 | EVP_CIPH_ECB_MODE, | ||
| 229 | .init = idea_init_key, | ||
| 230 | .do_cipher = idea_ecb_cipher, | ||
| 231 | .cleanup = NULL, | ||
| 232 | .ctx_size = sizeof(IDEA_KEY_SCHEDULE), | ||
| 233 | .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, | ||
| 234 | .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, | ||
| 235 | .ctrl = NULL, | ||
| 236 | .app_data = NULL, | ||
| 237 | }; | ||
| 238 | |||
| 239 | const EVP_CIPHER * | ||
| 240 | EVP_idea_ecb(void) | ||
| 241 | { | ||
| 242 | return &idea_ecb; | ||
| 243 | } | ||
| 95 | 244 | ||
| 96 | BLOCK_CIPHER_defs(idea, IDEA_KEY_SCHEDULE, NID_idea, 8, 16, 8, 64, | ||
| 97 | 0, idea_init_key, NULL, | ||
| 98 | EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, NULL) | ||
| 99 | 245 | ||
| 100 | static int | 246 | static int |
| 101 | idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | 247 | idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
