diff options
author | tb <> | 2024-03-02 10:13:13 +0000 |
---|---|---|
committer | tb <> | 2024-03-02 10:13:13 +0000 |
commit | d7a8734f3bc8f273ccc2d8c7425ebf2f744118af (patch) | |
tree | 7c88586c01b489d8d1d146f3e29fe0056bdd8436 /src | |
parent | bb2222e671a46a72a1bbbf44ad27a1183debd4a0 (diff) | |
download | openbsd-d7a8734f3bc8f273ccc2d8c7425ebf2f744118af.tar.gz openbsd-d7a8734f3bc8f273ccc2d8c7425ebf2f744118af.tar.bz2 openbsd-d7a8734f3bc8f273ccc2d8c7425ebf2f744118af.zip |
Remove RC4-HMAC-MD5 and AES-{128,256}-CBC-HMAC-SHA-1
"Stitched" mode AEADs were removed from libssl a long time ago. Nothing
uses these CIPHERs anymore.
ok jsing
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/Makefile | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/Symbols.list | 3 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/e_aes_cbc_hmac_sha1.c | 604 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/e_rc4_hmac_md5.c | 308 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/evp.h | 9 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/evp_names.c | 26 |
6 files changed, 3 insertions, 951 deletions
diff --git a/src/lib/libcrypto/Makefile b/src/lib/libcrypto/Makefile index b7fb2d0ff7..457ff381c4 100644 --- a/src/lib/libcrypto/Makefile +++ b/src/lib/libcrypto/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | # $OpenBSD: Makefile,v 1.169 2024/03/02 10:03:12 tb Exp $ | 1 | # $OpenBSD: Makefile,v 1.170 2024/03/02 10:13:12 tb Exp $ |
2 | 2 | ||
3 | LIB= crypto | 3 | LIB= crypto |
4 | LIBREBUILD=y | 4 | LIBREBUILD=y |
@@ -348,7 +348,6 @@ SRCS+= bio_b64.c | |||
348 | SRCS+= bio_enc.c | 348 | SRCS+= bio_enc.c |
349 | SRCS+= bio_md.c | 349 | SRCS+= bio_md.c |
350 | SRCS+= e_aes.c | 350 | SRCS+= e_aes.c |
351 | SRCS+= e_aes_cbc_hmac_sha1.c | ||
352 | SRCS+= e_bf.c | 351 | SRCS+= e_bf.c |
353 | SRCS+= e_camellia.c | 352 | SRCS+= e_camellia.c |
354 | SRCS+= e_cast.c | 353 | SRCS+= e_cast.c |
@@ -361,7 +360,6 @@ SRCS+= e_idea.c | |||
361 | SRCS+= e_null.c | 360 | SRCS+= e_null.c |
362 | SRCS+= e_rc2.c | 361 | SRCS+= e_rc2.c |
363 | SRCS+= e_rc4.c | 362 | SRCS+= e_rc4.c |
364 | SRCS+= e_rc4_hmac_md5.c | ||
365 | SRCS+= e_sm4.c | 363 | SRCS+= e_sm4.c |
366 | SRCS+= e_xcbc_d.c | 364 | SRCS+= e_xcbc_d.c |
367 | SRCS+= evp_aead.c | 365 | SRCS+= evp_aead.c |
diff --git a/src/lib/libcrypto/Symbols.list b/src/lib/libcrypto/Symbols.list index 3d8f456389..84a38a342d 100644 --- a/src/lib/libcrypto/Symbols.list +++ b/src/lib/libcrypto/Symbols.list | |||
@@ -1371,7 +1371,6 @@ EVP_aead_aes_256_gcm | |||
1371 | EVP_aead_chacha20_poly1305 | 1371 | EVP_aead_chacha20_poly1305 |
1372 | EVP_aead_xchacha20_poly1305 | 1372 | EVP_aead_xchacha20_poly1305 |
1373 | EVP_aes_128_cbc | 1373 | EVP_aes_128_cbc |
1374 | EVP_aes_128_cbc_hmac_sha1 | ||
1375 | EVP_aes_128_ccm | 1374 | EVP_aes_128_ccm |
1376 | EVP_aes_128_cfb1 | 1375 | EVP_aes_128_cfb1 |
1377 | EVP_aes_128_cfb128 | 1376 | EVP_aes_128_cfb128 |
@@ -1393,7 +1392,6 @@ EVP_aes_192_gcm | |||
1393 | EVP_aes_192_ofb | 1392 | EVP_aes_192_ofb |
1394 | EVP_aes_192_wrap | 1393 | EVP_aes_192_wrap |
1395 | EVP_aes_256_cbc | 1394 | EVP_aes_256_cbc |
1396 | EVP_aes_256_cbc_hmac_sha1 | ||
1397 | EVP_aes_256_ccm | 1395 | EVP_aes_256_ccm |
1398 | EVP_aes_256_cfb1 | 1396 | EVP_aes_256_cfb1 |
1399 | EVP_aes_256_cfb128 | 1397 | EVP_aes_256_cfb128 |
@@ -1477,7 +1475,6 @@ EVP_rc2_ecb | |||
1477 | EVP_rc2_ofb | 1475 | EVP_rc2_ofb |
1478 | EVP_rc4 | 1476 | EVP_rc4 |
1479 | EVP_rc4_40 | 1477 | EVP_rc4_40 |
1480 | EVP_rc4_hmac_md5 | ||
1481 | EVP_read_pw_string | 1478 | EVP_read_pw_string |
1482 | EVP_read_pw_string_min | 1479 | EVP_read_pw_string_min |
1483 | EVP_ripemd160 | 1480 | EVP_ripemd160 |
diff --git a/src/lib/libcrypto/evp/e_aes_cbc_hmac_sha1.c b/src/lib/libcrypto/evp/e_aes_cbc_hmac_sha1.c deleted file mode 100644 index 4241436451..0000000000 --- a/src/lib/libcrypto/evp/e_aes_cbc_hmac_sha1.c +++ /dev/null | |||
@@ -1,604 +0,0 @@ | |||
1 | /* $OpenBSD: e_aes_cbc_hmac_sha1.c,v 1.20 2024/01/08 09:31:09 tb Exp $ */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 2011-2013 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * licensing@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | */ | ||
50 | |||
51 | #include <stdio.h> | ||
52 | #include <string.h> | ||
53 | |||
54 | #include <openssl/opensslconf.h> | ||
55 | |||
56 | #if !defined(OPENSSL_NO_AES) && !defined(OPENSSL_NO_SHA1) | ||
57 | |||
58 | #include <openssl/evp.h> | ||
59 | #include <openssl/objects.h> | ||
60 | #include <openssl/aes.h> | ||
61 | #include <openssl/sha.h> | ||
62 | |||
63 | #include "constant_time.h" | ||
64 | #include "evp_local.h" | ||
65 | |||
66 | #define TLS1_1_VERSION 0x0302 | ||
67 | |||
68 | typedef struct { | ||
69 | AES_KEY ks; | ||
70 | SHA_CTX head, tail, md; | ||
71 | size_t payload_length; /* AAD length in decrypt case */ | ||
72 | union { | ||
73 | unsigned int tls_ver; | ||
74 | unsigned char tls_aad[16]; /* 13 used */ | ||
75 | } aux; | ||
76 | } EVP_AES_HMAC_SHA1; | ||
77 | |||
78 | #define NO_PAYLOAD_LENGTH ((size_t)-1) | ||
79 | |||
80 | #if defined(AES_ASM) && ( \ | ||
81 | defined(__x86_64) || defined(__x86_64__) || \ | ||
82 | defined(_M_AMD64) || defined(_M_X64) || \ | ||
83 | defined(__INTEL__) ) | ||
84 | |||
85 | #include "x86_arch.h" | ||
86 | |||
87 | #if defined(__GNUC__) && __GNUC__>=2 | ||
88 | # define BSWAP(x) ({ unsigned int r=(x); asm ("bswapl %0":"=r"(r):"0"(r)); r; }) | ||
89 | #endif | ||
90 | |||
91 | int aesni_set_encrypt_key(const unsigned char *userKey, int bits, AES_KEY *key); | ||
92 | int aesni_set_decrypt_key(const unsigned char *userKey, int bits, AES_KEY *key); | ||
93 | |||
94 | void aesni_cbc_encrypt(const unsigned char *in, unsigned char *out, | ||
95 | size_t length, const AES_KEY *key, unsigned char *ivec, int enc); | ||
96 | |||
97 | void aesni_cbc_sha1_enc (const void *inp, void *out, size_t blocks, | ||
98 | const AES_KEY *key, unsigned char iv[16], SHA_CTX *ctx, const void *in0); | ||
99 | |||
100 | #define data(ctx) ((EVP_AES_HMAC_SHA1 *)(ctx)->cipher_data) | ||
101 | |||
102 | static int | ||
103 | aesni_cbc_hmac_sha1_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *inkey, | ||
104 | const unsigned char *iv, int enc) | ||
105 | { | ||
106 | EVP_AES_HMAC_SHA1 *key = data(ctx); | ||
107 | int ret; | ||
108 | |||
109 | if (enc) | ||
110 | ret = aesni_set_encrypt_key(inkey, ctx->key_len * 8, &key->ks); | ||
111 | else | ||
112 | ret = aesni_set_decrypt_key(inkey, ctx->key_len * 8, &key->ks); | ||
113 | |||
114 | SHA1_Init(&key->head); /* handy when benchmarking */ | ||
115 | key->tail = key->head; | ||
116 | key->md = key->head; | ||
117 | |||
118 | key->payload_length = NO_PAYLOAD_LENGTH; | ||
119 | |||
120 | return ret < 0 ? 0 : 1; | ||
121 | } | ||
122 | |||
123 | #define STITCHED_CALL | ||
124 | |||
125 | #if !defined(STITCHED_CALL) | ||
126 | #define aes_off 0 | ||
127 | #endif | ||
128 | |||
129 | void sha1_block_data_order (void *c, const void *p, size_t len); | ||
130 | |||
131 | static void | ||
132 | sha1_update(SHA_CTX *c, const void *data, size_t len) | ||
133 | { | ||
134 | const unsigned char *ptr = data; | ||
135 | size_t res; | ||
136 | |||
137 | if ((res = c->num)) { | ||
138 | res = SHA_CBLOCK - res; | ||
139 | if (len < res) | ||
140 | res = len; | ||
141 | SHA1_Update(c, ptr, res); | ||
142 | ptr += res; | ||
143 | len -= res; | ||
144 | } | ||
145 | |||
146 | res = len % SHA_CBLOCK; | ||
147 | len -= res; | ||
148 | |||
149 | if (len) { | ||
150 | sha1_block_data_order(c, ptr, len / SHA_CBLOCK); | ||
151 | |||
152 | ptr += len; | ||
153 | c->Nh += len >> 29; | ||
154 | c->Nl += len <<= 3; | ||
155 | if (c->Nl < (unsigned int)len) | ||
156 | c->Nh++; | ||
157 | } | ||
158 | |||
159 | if (res) | ||
160 | SHA1_Update(c, ptr, res); | ||
161 | } | ||
162 | |||
163 | #ifdef SHA1_Update | ||
164 | #undef SHA1_Update | ||
165 | #endif | ||
166 | #define SHA1_Update sha1_update | ||
167 | |||
168 | static int | ||
169 | aesni_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
170 | const unsigned char *in, size_t len) | ||
171 | { | ||
172 | EVP_AES_HMAC_SHA1 *key = data(ctx); | ||
173 | unsigned int l; | ||
174 | size_t plen = key->payload_length, | ||
175 | iv = 0, /* explicit IV in TLS 1.1 and later */ | ||
176 | sha_off = 0; | ||
177 | #if defined(STITCHED_CALL) | ||
178 | size_t aes_off = 0, blocks; | ||
179 | |||
180 | sha_off = SHA_CBLOCK - key->md.num; | ||
181 | #endif | ||
182 | |||
183 | key->payload_length = NO_PAYLOAD_LENGTH; | ||
184 | |||
185 | if (len % AES_BLOCK_SIZE) | ||
186 | return 0; | ||
187 | |||
188 | if (ctx->encrypt) { | ||
189 | if (plen == NO_PAYLOAD_LENGTH) | ||
190 | plen = len; | ||
191 | else if (len != ((plen + SHA_DIGEST_LENGTH + AES_BLOCK_SIZE) & | ||
192 | -AES_BLOCK_SIZE)) | ||
193 | return 0; | ||
194 | else if (key->aux.tls_ver >= TLS1_1_VERSION) | ||
195 | iv = AES_BLOCK_SIZE; | ||
196 | |||
197 | #if defined(STITCHED_CALL) | ||
198 | if (plen > (sha_off + iv) && | ||
199 | (blocks = (plen - (sha_off + iv)) / SHA_CBLOCK)) { | ||
200 | SHA1_Update(&key->md, in + iv, sha_off); | ||
201 | |||
202 | aesni_cbc_sha1_enc(in, out, blocks, &key->ks, | ||
203 | ctx->iv, &key->md, in + iv + sha_off); | ||
204 | blocks *= SHA_CBLOCK; | ||
205 | aes_off += blocks; | ||
206 | sha_off += blocks; | ||
207 | key->md.Nh += blocks >> 29; | ||
208 | key->md.Nl += blocks <<= 3; | ||
209 | if (key->md.Nl < (unsigned int)blocks) | ||
210 | key->md.Nh++; | ||
211 | } else { | ||
212 | sha_off = 0; | ||
213 | } | ||
214 | #endif | ||
215 | sha_off += iv; | ||
216 | SHA1_Update(&key->md, in + sha_off, plen - sha_off); | ||
217 | |||
218 | if (plen != len) { /* "TLS" mode of operation */ | ||
219 | if (in != out) | ||
220 | memcpy(out + aes_off, in + aes_off, | ||
221 | plen - aes_off); | ||
222 | |||
223 | /* calculate HMAC and append it to payload */ | ||
224 | SHA1_Final(out + plen, &key->md); | ||
225 | key->md = key->tail; | ||
226 | SHA1_Update(&key->md, out + plen, SHA_DIGEST_LENGTH); | ||
227 | SHA1_Final(out + plen, &key->md); | ||
228 | |||
229 | /* pad the payload|hmac */ | ||
230 | plen += SHA_DIGEST_LENGTH; | ||
231 | for (l = len - plen - 1; plen < len; plen++) | ||
232 | out[plen] = l; | ||
233 | |||
234 | /* encrypt HMAC|padding at once */ | ||
235 | aesni_cbc_encrypt(out + aes_off, out + aes_off, | ||
236 | len - aes_off, &key->ks, ctx->iv, 1); | ||
237 | } else { | ||
238 | aesni_cbc_encrypt(in + aes_off, out + aes_off, | ||
239 | len - aes_off, &key->ks, ctx->iv, 1); | ||
240 | } | ||
241 | } else { | ||
242 | union { | ||
243 | unsigned int u[SHA_DIGEST_LENGTH/sizeof(unsigned int)]; | ||
244 | unsigned char c[32 + SHA_DIGEST_LENGTH]; | ||
245 | } mac, *pmac; | ||
246 | |||
247 | /* arrange cache line alignment */ | ||
248 | pmac = (void *)(((size_t)mac.c + 31) & ((size_t)0 - 32)); | ||
249 | |||
250 | /* decrypt HMAC|padding at once */ | ||
251 | aesni_cbc_encrypt(in, out, len, &key->ks, ctx->iv, 0); | ||
252 | |||
253 | if (plen == 0 || plen == NO_PAYLOAD_LENGTH) { | ||
254 | SHA1_Update(&key->md, out, len); | ||
255 | } else if (plen < 4) { | ||
256 | return 0; | ||
257 | } else { /* "TLS" mode of operation */ | ||
258 | size_t inp_len, mask, j, i; | ||
259 | unsigned int res, maxpad, pad, bitlen; | ||
260 | int ret = 1; | ||
261 | union { | ||
262 | unsigned int u[SHA_LBLOCK]; | ||
263 | unsigned char c[SHA_CBLOCK]; | ||
264 | } | ||
265 | *data = (void *)key->md.data; | ||
266 | |||
267 | if ((key->aux.tls_aad[plen - 4] << 8 | | ||
268 | key->aux.tls_aad[plen - 3]) >= TLS1_1_VERSION) | ||
269 | iv = AES_BLOCK_SIZE; | ||
270 | |||
271 | if (len < (iv + SHA_DIGEST_LENGTH + 1)) | ||
272 | return 0; | ||
273 | |||
274 | /* omit explicit iv */ | ||
275 | out += iv; | ||
276 | len -= iv; | ||
277 | |||
278 | /* figure out payload length */ | ||
279 | pad = out[len - 1]; | ||
280 | maxpad = len - (SHA_DIGEST_LENGTH + 1); | ||
281 | maxpad |= (255 - maxpad) >> (sizeof(maxpad) * 8 - 8); | ||
282 | maxpad &= 255; | ||
283 | |||
284 | ret &= constant_time_ge(maxpad, pad); | ||
285 | |||
286 | inp_len = len - (SHA_DIGEST_LENGTH + pad + 1); | ||
287 | mask = (0 - ((inp_len - len) >> | ||
288 | (sizeof(inp_len) * 8 - 1))); | ||
289 | inp_len &= mask; | ||
290 | ret &= (int)mask; | ||
291 | |||
292 | key->aux.tls_aad[plen - 2] = inp_len >> 8; | ||
293 | key->aux.tls_aad[plen - 1] = inp_len; | ||
294 | |||
295 | /* calculate HMAC */ | ||
296 | key->md = key->head; | ||
297 | SHA1_Update(&key->md, key->aux.tls_aad, plen); | ||
298 | |||
299 | #if 1 | ||
300 | len -= SHA_DIGEST_LENGTH; /* amend mac */ | ||
301 | if (len >= (256 + SHA_CBLOCK)) { | ||
302 | j = (len - (256 + SHA_CBLOCK)) & | ||
303 | (0 - SHA_CBLOCK); | ||
304 | j += SHA_CBLOCK - key->md.num; | ||
305 | SHA1_Update(&key->md, out, j); | ||
306 | out += j; | ||
307 | len -= j; | ||
308 | inp_len -= j; | ||
309 | } | ||
310 | |||
311 | /* but pretend as if we hashed padded payload */ | ||
312 | bitlen = key->md.Nl + (inp_len << 3); /* at most 18 bits */ | ||
313 | #ifdef BSWAP | ||
314 | bitlen = BSWAP(bitlen); | ||
315 | #else | ||
316 | mac.c[0] = 0; | ||
317 | mac.c[1] = (unsigned char)(bitlen >> 16); | ||
318 | mac.c[2] = (unsigned char)(bitlen >> 8); | ||
319 | mac.c[3] = (unsigned char)bitlen; | ||
320 | bitlen = mac.u[0]; | ||
321 | #endif | ||
322 | |||
323 | pmac->u[0] = 0; | ||
324 | pmac->u[1] = 0; | ||
325 | pmac->u[2] = 0; | ||
326 | pmac->u[3] = 0; | ||
327 | pmac->u[4] = 0; | ||
328 | |||
329 | for (res = key->md.num, j = 0; j < len; j++) { | ||
330 | size_t c = out[j]; | ||
331 | mask = (j - inp_len) >> (sizeof(j) * 8 - 8); | ||
332 | c &= mask; | ||
333 | c |= 0x80 & ~mask & | ||
334 | ~((inp_len - j) >> (sizeof(j) * 8 - 8)); | ||
335 | data->c[res++] = (unsigned char)c; | ||
336 | |||
337 | if (res != SHA_CBLOCK) | ||
338 | continue; | ||
339 | |||
340 | /* j is not incremented yet */ | ||
341 | mask = 0 - ((inp_len + 7 - j) >> | ||
342 | (sizeof(j) * 8 - 1)); | ||
343 | data->u[SHA_LBLOCK - 1] |= bitlen&mask; | ||
344 | sha1_block_data_order(&key->md, data, 1); | ||
345 | mask &= 0 - ((j - inp_len - 72) >> | ||
346 | (sizeof(j) * 8 - 1)); | ||
347 | pmac->u[0] |= key->md.h0 & mask; | ||
348 | pmac->u[1] |= key->md.h1 & mask; | ||
349 | pmac->u[2] |= key->md.h2 & mask; | ||
350 | pmac->u[3] |= key->md.h3 & mask; | ||
351 | pmac->u[4] |= key->md.h4 & mask; | ||
352 | res = 0; | ||
353 | } | ||
354 | |||
355 | for (i = res; i < SHA_CBLOCK; i++, j++) | ||
356 | data->c[i] = 0; | ||
357 | |||
358 | if (res > SHA_CBLOCK - 8) { | ||
359 | mask = 0 - ((inp_len + 8 - j) >> | ||
360 | (sizeof(j) * 8 - 1)); | ||
361 | data->u[SHA_LBLOCK - 1] |= bitlen & mask; | ||
362 | sha1_block_data_order(&key->md, data, 1); | ||
363 | mask &= 0 - ((j - inp_len - 73) >> | ||
364 | (sizeof(j) * 8 - 1)); | ||
365 | pmac->u[0] |= key->md.h0 & mask; | ||
366 | pmac->u[1] |= key->md.h1 & mask; | ||
367 | pmac->u[2] |= key->md.h2 & mask; | ||
368 | pmac->u[3] |= key->md.h3 & mask; | ||
369 | pmac->u[4] |= key->md.h4 & mask; | ||
370 | |||
371 | memset(data, 0, SHA_CBLOCK); | ||
372 | j += 64; | ||
373 | } | ||
374 | data->u[SHA_LBLOCK - 1] = bitlen; | ||
375 | sha1_block_data_order(&key->md, data, 1); | ||
376 | mask = 0 - ((j - inp_len - 73) >> (sizeof(j) * 8 - 1)); | ||
377 | pmac->u[0] |= key->md.h0 & mask; | ||
378 | pmac->u[1] |= key->md.h1 & mask; | ||
379 | pmac->u[2] |= key->md.h2 & mask; | ||
380 | pmac->u[3] |= key->md.h3 & mask; | ||
381 | pmac->u[4] |= key->md.h4 & mask; | ||
382 | |||
383 | #ifdef BSWAP | ||
384 | pmac->u[0] = BSWAP(pmac->u[0]); | ||
385 | pmac->u[1] = BSWAP(pmac->u[1]); | ||
386 | pmac->u[2] = BSWAP(pmac->u[2]); | ||
387 | pmac->u[3] = BSWAP(pmac->u[3]); | ||
388 | pmac->u[4] = BSWAP(pmac->u[4]); | ||
389 | #else | ||
390 | for (i = 0; i < 5; i++) { | ||
391 | res = pmac->u[i]; | ||
392 | pmac->c[4 * i + 0] = (unsigned char)(res >> 24); | ||
393 | pmac->c[4 * i + 1] = (unsigned char)(res >> 16); | ||
394 | pmac->c[4 * i + 2] = (unsigned char)(res >> 8); | ||
395 | pmac->c[4 * i + 3] = (unsigned char)res; | ||
396 | } | ||
397 | #endif | ||
398 | len += SHA_DIGEST_LENGTH; | ||
399 | #else | ||
400 | SHA1_Update(&key->md, out, inp_len); | ||
401 | res = key->md.num; | ||
402 | SHA1_Final(pmac->c, &key->md); | ||
403 | |||
404 | { | ||
405 | unsigned int inp_blocks, pad_blocks; | ||
406 | |||
407 | /* but pretend as if we hashed padded payload */ | ||
408 | inp_blocks = 1 + ((SHA_CBLOCK - 9 - res) >> | ||
409 | (sizeof(res) * 8 - 1)); | ||
410 | res += (unsigned int)(len - inp_len); | ||
411 | pad_blocks = res / SHA_CBLOCK; | ||
412 | res %= SHA_CBLOCK; | ||
413 | pad_blocks += 1 + ((SHA_CBLOCK - 9 - res) >> | ||
414 | (sizeof(res) * 8 - 1)); | ||
415 | for (; inp_blocks < pad_blocks; inp_blocks++) | ||
416 | sha1_block_data_order(&key->md, | ||
417 | data, 1); | ||
418 | } | ||
419 | #endif | ||
420 | key->md = key->tail; | ||
421 | SHA1_Update(&key->md, pmac->c, SHA_DIGEST_LENGTH); | ||
422 | SHA1_Final(pmac->c, &key->md); | ||
423 | |||
424 | /* verify HMAC */ | ||
425 | out += inp_len; | ||
426 | len -= inp_len; | ||
427 | #if 1 | ||
428 | { | ||
429 | unsigned char *p = | ||
430 | out + len - 1 - maxpad - SHA_DIGEST_LENGTH; | ||
431 | size_t off = out - p; | ||
432 | unsigned int c, cmask; | ||
433 | |||
434 | maxpad += SHA_DIGEST_LENGTH; | ||
435 | for (res = 0, i = 0, j = 0; j < maxpad; j++) { | ||
436 | c = p[j]; | ||
437 | cmask = ((int)(j - off - | ||
438 | SHA_DIGEST_LENGTH)) >> | ||
439 | (sizeof(int) * 8 - 1); | ||
440 | res |= (c ^ pad) & ~cmask; /* ... and padding */ | ||
441 | cmask &= ((int)(off - 1 - j)) >> | ||
442 | (sizeof(int) * 8 - 1); | ||
443 | res |= (c ^ pmac->c[i]) & cmask; | ||
444 | i += 1 & cmask; | ||
445 | } | ||
446 | maxpad -= SHA_DIGEST_LENGTH; | ||
447 | |||
448 | res = 0 - ((0 - res) >> (sizeof(res) * 8 - 1)); | ||
449 | ret &= (int)~res; | ||
450 | } | ||
451 | #else | ||
452 | for (res = 0, i = 0; i < SHA_DIGEST_LENGTH; i++) | ||
453 | res |= out[i] ^ pmac->c[i]; | ||
454 | res = 0 - ((0 - res) >> (sizeof(res) * 8 - 1)); | ||
455 | ret &= (int)~res; | ||
456 | |||
457 | /* verify padding */ | ||
458 | pad = (pad & ~res) | (maxpad & res); | ||
459 | out = out + len - 1 - pad; | ||
460 | for (res = 0, i = 0; i < pad; i++) | ||
461 | res |= out[i] ^ pad; | ||
462 | |||
463 | res = (0 - res) >> (sizeof(res) * 8 - 1); | ||
464 | ret &= (int)~res; | ||
465 | #endif | ||
466 | return ret; | ||
467 | } | ||
468 | } | ||
469 | |||
470 | return 1; | ||
471 | } | ||
472 | |||
473 | static int | ||
474 | aesni_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) | ||
475 | { | ||
476 | EVP_AES_HMAC_SHA1 *key = data(ctx); | ||
477 | |||
478 | switch (type) { | ||
479 | case EVP_CTRL_AEAD_SET_MAC_KEY: | ||
480 | { | ||
481 | unsigned int i; | ||
482 | unsigned char hmac_key[64]; | ||
483 | |||
484 | memset(hmac_key, 0, sizeof(hmac_key)); | ||
485 | |||
486 | if (arg > (int)sizeof(hmac_key)) { | ||
487 | SHA1_Init(&key->head); | ||
488 | SHA1_Update(&key->head, ptr, arg); | ||
489 | SHA1_Final(hmac_key, &key->head); | ||
490 | } else { | ||
491 | memcpy(hmac_key, ptr, arg); | ||
492 | } | ||
493 | |||
494 | for (i = 0; i < sizeof(hmac_key); i++) | ||
495 | hmac_key[i] ^= 0x36; /* ipad */ | ||
496 | SHA1_Init(&key->head); | ||
497 | SHA1_Update(&key->head, hmac_key, sizeof(hmac_key)); | ||
498 | |||
499 | for (i = 0; i < sizeof(hmac_key); i++) | ||
500 | hmac_key[i] ^= 0x36 ^ 0x5c; /* opad */ | ||
501 | SHA1_Init(&key->tail); | ||
502 | SHA1_Update(&key->tail, hmac_key, sizeof(hmac_key)); | ||
503 | |||
504 | explicit_bzero(hmac_key, sizeof(hmac_key)); | ||
505 | |||
506 | return 1; | ||
507 | } | ||
508 | case EVP_CTRL_AEAD_TLS1_AAD: | ||
509 | { | ||
510 | unsigned char *p = ptr; | ||
511 | unsigned int len; | ||
512 | |||
513 | /* RFC 5246, 6.2.3.3: additional data has length 13 */ | ||
514 | if (arg != 13) | ||
515 | return -1; | ||
516 | |||
517 | len = p[arg - 2] << 8 | p[arg - 1]; | ||
518 | |||
519 | if (ctx->encrypt) { | ||
520 | key->payload_length = len; | ||
521 | if ((key->aux.tls_ver = p[arg - 4] << 8 | | ||
522 | p[arg - 3]) >= TLS1_1_VERSION) { | ||
523 | len -= AES_BLOCK_SIZE; | ||
524 | p[arg - 2] = len >> 8; | ||
525 | p[arg - 1] = len; | ||
526 | } | ||
527 | key->md = key->head; | ||
528 | SHA1_Update(&key->md, p, arg); | ||
529 | |||
530 | return (int)(((len + SHA_DIGEST_LENGTH + | ||
531 | AES_BLOCK_SIZE) & -AES_BLOCK_SIZE) - len); | ||
532 | } else { | ||
533 | memcpy(key->aux.tls_aad, ptr, arg); | ||
534 | key->payload_length = arg; | ||
535 | |||
536 | return SHA_DIGEST_LENGTH; | ||
537 | } | ||
538 | } | ||
539 | default: | ||
540 | return -1; | ||
541 | } | ||
542 | } | ||
543 | |||
544 | static const EVP_CIPHER aesni_128_cbc_hmac_sha1_cipher = { | ||
545 | #ifdef NID_aes_128_cbc_hmac_sha1 | ||
546 | .nid = NID_aes_128_cbc_hmac_sha1, | ||
547 | #else | ||
548 | .nid = NID_undef, | ||
549 | #endif | ||
550 | .block_size = 16, | ||
551 | .key_len = 16, | ||
552 | .iv_len = 16, | ||
553 | .flags = EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1 | | ||
554 | EVP_CIPH_FLAG_AEAD_CIPHER, | ||
555 | .init = aesni_cbc_hmac_sha1_init_key, | ||
556 | .do_cipher = aesni_cbc_hmac_sha1_cipher, | ||
557 | .ctx_size = sizeof(EVP_AES_HMAC_SHA1), | ||
558 | .ctrl = aesni_cbc_hmac_sha1_ctrl | ||
559 | }; | ||
560 | |||
561 | static const EVP_CIPHER aesni_256_cbc_hmac_sha1_cipher = { | ||
562 | #ifdef NID_aes_256_cbc_hmac_sha1 | ||
563 | .nid = NID_aes_256_cbc_hmac_sha1, | ||
564 | #else | ||
565 | .nid = NID_undef, | ||
566 | #endif | ||
567 | .block_size = 16, | ||
568 | .key_len = 32, | ||
569 | .iv_len = 16, | ||
570 | .flags = EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1 | | ||
571 | EVP_CIPH_FLAG_AEAD_CIPHER, | ||
572 | .init = aesni_cbc_hmac_sha1_init_key, | ||
573 | .do_cipher = aesni_cbc_hmac_sha1_cipher, | ||
574 | .ctx_size = sizeof(EVP_AES_HMAC_SHA1), | ||
575 | .ctrl = aesni_cbc_hmac_sha1_ctrl | ||
576 | }; | ||
577 | |||
578 | const EVP_CIPHER * | ||
579 | EVP_aes_128_cbc_hmac_sha1(void) | ||
580 | { | ||
581 | return (OPENSSL_cpu_caps() & CPUCAP_MASK_AESNI) ? | ||
582 | &aesni_128_cbc_hmac_sha1_cipher : NULL; | ||
583 | } | ||
584 | |||
585 | const EVP_CIPHER * | ||
586 | EVP_aes_256_cbc_hmac_sha1(void) | ||
587 | { | ||
588 | return (OPENSSL_cpu_caps() & CPUCAP_MASK_AESNI) ? | ||
589 | &aesni_256_cbc_hmac_sha1_cipher : NULL; | ||
590 | } | ||
591 | #else | ||
592 | const EVP_CIPHER * | ||
593 | EVP_aes_128_cbc_hmac_sha1(void) | ||
594 | { | ||
595 | return NULL; | ||
596 | } | ||
597 | |||
598 | const EVP_CIPHER * | ||
599 | EVP_aes_256_cbc_hmac_sha1(void) | ||
600 | { | ||
601 | return NULL; | ||
602 | } | ||
603 | #endif | ||
604 | #endif | ||
diff --git a/src/lib/libcrypto/evp/e_rc4_hmac_md5.c b/src/lib/libcrypto/evp/e_rc4_hmac_md5.c deleted file mode 100644 index 420b945a80..0000000000 --- a/src/lib/libcrypto/evp/e_rc4_hmac_md5.c +++ /dev/null | |||
@@ -1,308 +0,0 @@ | |||
1 | /* $OpenBSD: e_rc4_hmac_md5.c,v 1.15 2024/01/07 16:18:18 tb Exp $ */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 2011 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * licensing@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | */ | ||
50 | |||
51 | #include <stdio.h> | ||
52 | #include <string.h> | ||
53 | |||
54 | #include <openssl/opensslconf.h> | ||
55 | |||
56 | #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_MD5) | ||
57 | |||
58 | #include <openssl/evp.h> | ||
59 | #include <openssl/objects.h> | ||
60 | #include <openssl/rc4.h> | ||
61 | #include <openssl/md5.h> | ||
62 | |||
63 | #include "evp_local.h" | ||
64 | |||
65 | /* FIXME: surely this is available elsewhere? */ | ||
66 | #define EVP_RC4_KEY_SIZE 16 | ||
67 | |||
68 | typedef struct { | ||
69 | RC4_KEY ks; | ||
70 | MD5_CTX head, tail, md; | ||
71 | size_t payload_length; | ||
72 | } EVP_RC4_HMAC_MD5; | ||
73 | |||
74 | #define NO_PAYLOAD_LENGTH ((size_t)-1) | ||
75 | |||
76 | void rc4_md5_enc (RC4_KEY *key, const void *in0, void *out, | ||
77 | MD5_CTX *ctx, const void *inp, size_t blocks); | ||
78 | |||
79 | #define data(ctx) ((EVP_RC4_HMAC_MD5 *)(ctx)->cipher_data) | ||
80 | |||
81 | static int | ||
82 | rc4_hmac_md5_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *inkey, | ||
83 | const unsigned char *iv, int enc) | ||
84 | { | ||
85 | EVP_RC4_HMAC_MD5 *key = data(ctx); | ||
86 | |||
87 | RC4_set_key(&key->ks, EVP_CIPHER_CTX_key_length(ctx), inkey); | ||
88 | |||
89 | MD5_Init(&key->head); /* handy when benchmarking */ | ||
90 | key->tail = key->head; | ||
91 | key->md = key->head; | ||
92 | |||
93 | key->payload_length = NO_PAYLOAD_LENGTH; | ||
94 | |||
95 | return 1; | ||
96 | } | ||
97 | |||
98 | #if !defined(OPENSSL_NO_ASM) && defined(RC4_MD5_ASM) && ( \ | ||
99 | defined(__x86_64) || defined(__x86_64__) || \ | ||
100 | defined(_M_AMD64) || defined(_M_X64) || \ | ||
101 | defined(__INTEL__) ) && \ | ||
102 | !(defined(__APPLE__) && defined(__MACH__)) | ||
103 | #define STITCHED_CALL | ||
104 | #include "x86_arch.h" | ||
105 | #endif | ||
106 | |||
107 | #if !defined(STITCHED_CALL) | ||
108 | #define rc4_off 0 | ||
109 | #define md5_off 0 | ||
110 | #endif | ||
111 | |||
112 | static int | ||
113 | rc4_hmac_md5_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
114 | const unsigned char *in, size_t len) | ||
115 | { | ||
116 | EVP_RC4_HMAC_MD5 *key = data(ctx); | ||
117 | #if defined(STITCHED_CALL) | ||
118 | size_t rc4_off = 32-1-(key->ks.x&(32-1)), /* 32 is $MOD from rc4_md5-x86_64.pl */ | ||
119 | md5_off = MD5_CBLOCK - key->md.num, | ||
120 | blocks; | ||
121 | unsigned int l; | ||
122 | #endif | ||
123 | size_t plen = key->payload_length; | ||
124 | |||
125 | if (plen != NO_PAYLOAD_LENGTH && len != (plen + MD5_DIGEST_LENGTH)) | ||
126 | return 0; | ||
127 | |||
128 | if (ctx->encrypt) { | ||
129 | if (plen == NO_PAYLOAD_LENGTH) | ||
130 | plen = len; | ||
131 | #if defined(STITCHED_CALL) | ||
132 | /* cipher has to "fall behind" */ | ||
133 | if (rc4_off > md5_off) | ||
134 | md5_off += MD5_CBLOCK; | ||
135 | |||
136 | if (plen > md5_off && | ||
137 | (blocks = (plen - md5_off) / MD5_CBLOCK) && | ||
138 | (OPENSSL_cpu_caps() & CPUCAP_MASK_INTELP4) == 0) { | ||
139 | MD5_Update(&key->md, in, md5_off); | ||
140 | RC4(&key->ks, rc4_off, in, out); | ||
141 | |||
142 | rc4_md5_enc(&key->ks, in + rc4_off, out + rc4_off, | ||
143 | &key->md, in + md5_off, blocks); | ||
144 | blocks *= MD5_CBLOCK; | ||
145 | rc4_off += blocks; | ||
146 | md5_off += blocks; | ||
147 | key->md.Nh += blocks >> 29; | ||
148 | key->md.Nl += blocks <<= 3; | ||
149 | if (key->md.Nl < (unsigned int)blocks) | ||
150 | key->md.Nh++; | ||
151 | } else { | ||
152 | rc4_off = 0; | ||
153 | md5_off = 0; | ||
154 | } | ||
155 | #endif | ||
156 | MD5_Update(&key->md, in + md5_off, plen - md5_off); | ||
157 | |||
158 | if (plen!=len) { /* "TLS" mode of operation */ | ||
159 | if (in != out) | ||
160 | memcpy(out + rc4_off, in + rc4_off, | ||
161 | plen - rc4_off); | ||
162 | |||
163 | /* calculate HMAC and append it to payload */ | ||
164 | MD5_Final(out + plen, &key->md); | ||
165 | key->md = key->tail; | ||
166 | MD5_Update(&key->md, out + plen, MD5_DIGEST_LENGTH); | ||
167 | MD5_Final(out + plen, &key->md); | ||
168 | |||
169 | /* encrypt HMAC at once */ | ||
170 | RC4(&key->ks, len - rc4_off, out + rc4_off, | ||
171 | out + rc4_off); | ||
172 | } else { | ||
173 | RC4(&key->ks, len - rc4_off, in + rc4_off, | ||
174 | out + rc4_off); | ||
175 | } | ||
176 | } else { | ||
177 | unsigned char mac[MD5_DIGEST_LENGTH]; | ||
178 | #if defined(STITCHED_CALL) | ||
179 | /* digest has to "fall behind" */ | ||
180 | if (md5_off > rc4_off) | ||
181 | rc4_off += 2*MD5_CBLOCK; | ||
182 | else | ||
183 | rc4_off += MD5_CBLOCK; | ||
184 | |||
185 | if (len > rc4_off && (blocks = (len - rc4_off) / MD5_CBLOCK) && | ||
186 | (OPENSSL_cpu_caps() & CPUCAP_MASK_INTELP4) == 0) { | ||
187 | RC4(&key->ks, rc4_off, in, out); | ||
188 | MD5_Update(&key->md, out, md5_off); | ||
189 | |||
190 | rc4_md5_enc(&key->ks, in + rc4_off, out + rc4_off, | ||
191 | &key->md, out + md5_off, blocks); | ||
192 | blocks *= MD5_CBLOCK; | ||
193 | rc4_off += blocks; | ||
194 | md5_off += blocks; | ||
195 | l = (key->md.Nl + (blocks << 3)) & 0xffffffffU; | ||
196 | if (l < key->md.Nl) | ||
197 | key->md.Nh++; | ||
198 | key->md.Nl = l; | ||
199 | key->md.Nh += blocks >> 29; | ||
200 | } else { | ||
201 | md5_off = 0; | ||
202 | rc4_off = 0; | ||
203 | } | ||
204 | #endif | ||
205 | /* decrypt HMAC at once */ | ||
206 | RC4(&key->ks, len - rc4_off, in + rc4_off, out + rc4_off); | ||
207 | if (plen!=NO_PAYLOAD_LENGTH) { /* "TLS" mode of operation */ | ||
208 | MD5_Update(&key->md, out + md5_off, plen - md5_off); | ||
209 | |||
210 | /* calculate HMAC and verify it */ | ||
211 | MD5_Final(mac, &key->md); | ||
212 | key->md = key->tail; | ||
213 | MD5_Update(&key->md, mac, MD5_DIGEST_LENGTH); | ||
214 | MD5_Final(mac, &key->md); | ||
215 | |||
216 | if (memcmp(out + plen, mac, MD5_DIGEST_LENGTH)) | ||
217 | return 0; | ||
218 | } else { | ||
219 | MD5_Update(&key->md, out + md5_off, len - md5_off); | ||
220 | } | ||
221 | } | ||
222 | |||
223 | key->payload_length = NO_PAYLOAD_LENGTH; | ||
224 | |||
225 | return 1; | ||
226 | } | ||
227 | |||
228 | static int | ||
229 | rc4_hmac_md5_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) | ||
230 | { | ||
231 | EVP_RC4_HMAC_MD5 *key = data(ctx); | ||
232 | |||
233 | switch (type) { | ||
234 | case EVP_CTRL_AEAD_SET_MAC_KEY: | ||
235 | { | ||
236 | unsigned int i; | ||
237 | unsigned char hmac_key[64]; | ||
238 | |||
239 | memset (hmac_key, 0, sizeof(hmac_key)); | ||
240 | |||
241 | if (arg > (int)sizeof(hmac_key)) { | ||
242 | MD5_Init(&key->head); | ||
243 | MD5_Update(&key->head, ptr, arg); | ||
244 | MD5_Final(hmac_key, &key->head); | ||
245 | } else { | ||
246 | memcpy(hmac_key, ptr, arg); | ||
247 | } | ||
248 | |||
249 | for (i = 0; i < sizeof(hmac_key); i++) | ||
250 | hmac_key[i] ^= 0x36; /* ipad */ | ||
251 | MD5_Init(&key->head); | ||
252 | MD5_Update(&key->head, hmac_key, sizeof(hmac_key)); | ||
253 | |||
254 | for (i = 0; i < sizeof(hmac_key); i++) | ||
255 | hmac_key[i] ^= 0x36 ^ 0x5c; /* opad */ | ||
256 | MD5_Init(&key->tail); | ||
257 | MD5_Update(&key->tail, hmac_key, sizeof(hmac_key)); | ||
258 | |||
259 | return 1; | ||
260 | } | ||
261 | case EVP_CTRL_AEAD_TLS1_AAD: | ||
262 | { | ||
263 | unsigned char *p = ptr; | ||
264 | unsigned int len = p[arg - 2] << 8 | p[arg - 1]; | ||
265 | |||
266 | if (!ctx->encrypt) { | ||
267 | if (len < MD5_DIGEST_LENGTH) | ||
268 | return -1; | ||
269 | len -= MD5_DIGEST_LENGTH; | ||
270 | p[arg - 2] = len >> 8; | ||
271 | p[arg - 1] = len; | ||
272 | } | ||
273 | key->payload_length = len; | ||
274 | key->md = key->head; | ||
275 | MD5_Update(&key->md, p, arg); | ||
276 | |||
277 | return MD5_DIGEST_LENGTH; | ||
278 | } | ||
279 | default: | ||
280 | return -1; | ||
281 | } | ||
282 | } | ||
283 | |||
284 | static const EVP_CIPHER r4_hmac_md5_cipher = { | ||
285 | #ifdef NID_rc4_hmac_md5 | ||
286 | .nid = NID_rc4_hmac_md5, | ||
287 | #else | ||
288 | .nid = NID_undef, | ||
289 | #endif | ||
290 | .block_size = 1, | ||
291 | .key_len = EVP_RC4_KEY_SIZE, | ||
292 | .iv_len = 0, | ||
293 | .flags = EVP_CIPH_STREAM_CIPHER|EVP_CIPH_VARIABLE_LENGTH|EVP_CIPH_FLAG_AEAD_CIPHER, | ||
294 | .init = rc4_hmac_md5_init_key, | ||
295 | .do_cipher = rc4_hmac_md5_cipher, | ||
296 | .cleanup = NULL, | ||
297 | .ctx_size = sizeof(EVP_RC4_HMAC_MD5), | ||
298 | .set_asn1_parameters = NULL, | ||
299 | .get_asn1_parameters = NULL, | ||
300 | .ctrl = rc4_hmac_md5_ctrl, | ||
301 | }; | ||
302 | |||
303 | const EVP_CIPHER * | ||
304 | EVP_rc4_hmac_md5(void) | ||
305 | { | ||
306 | return (&r4_hmac_md5_cipher); | ||
307 | } | ||
308 | #endif | ||
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h index f7026e2cea..28b095ffd4 100644 --- a/src/lib/libcrypto/evp/evp.h +++ b/src/lib/libcrypto/evp/evp.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: evp.h,v 1.129 2024/03/02 10:08:29 tb Exp $ */ | 1 | /* $OpenBSD: evp.h,v 1.130 2024/03/02 10:13:13 tb 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 | * |
@@ -649,9 +649,6 @@ const EVP_CIPHER *EVP_desx_cbc(void); | |||
649 | #ifndef OPENSSL_NO_RC4 | 649 | #ifndef OPENSSL_NO_RC4 |
650 | const EVP_CIPHER *EVP_rc4(void); | 650 | const EVP_CIPHER *EVP_rc4(void); |
651 | const EVP_CIPHER *EVP_rc4_40(void); | 651 | const EVP_CIPHER *EVP_rc4_40(void); |
652 | #ifndef OPENSSL_NO_MD5 | ||
653 | const EVP_CIPHER *EVP_rc4_hmac_md5(void); | ||
654 | #endif | ||
655 | #endif | 652 | #endif |
656 | #ifndef OPENSSL_NO_IDEA | 653 | #ifndef OPENSSL_NO_IDEA |
657 | const EVP_CIPHER *EVP_idea_ecb(void); | 654 | const EVP_CIPHER *EVP_idea_ecb(void); |
@@ -722,10 +719,6 @@ const EVP_CIPHER *EVP_aes_256_xts(void); | |||
722 | #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305) | 719 | #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305) |
723 | const EVP_CIPHER *EVP_chacha20_poly1305(void); | 720 | const EVP_CIPHER *EVP_chacha20_poly1305(void); |
724 | #endif | 721 | #endif |
725 | #if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA1) | ||
726 | const EVP_CIPHER *EVP_aes_128_cbc_hmac_sha1(void); | ||
727 | const EVP_CIPHER *EVP_aes_256_cbc_hmac_sha1(void); | ||
728 | #endif | ||
729 | #endif | 722 | #endif |
730 | #ifndef OPENSSL_NO_CAMELLIA | 723 | #ifndef OPENSSL_NO_CAMELLIA |
731 | const EVP_CIPHER *EVP_camellia_128_ecb(void); | 724 | const EVP_CIPHER *EVP_camellia_128_ecb(void); |
diff --git a/src/lib/libcrypto/evp/evp_names.c b/src/lib/libcrypto/evp/evp_names.c index ec66c12082..2936c36622 100644 --- a/src/lib/libcrypto/evp/evp_names.c +++ b/src/lib/libcrypto/evp/evp_names.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: evp_names.c,v 1.11 2024/03/02 09:43:10 tb Exp $ */ | 1 | /* $OpenBSD: evp_names.c,v 1.12 2024/03/02 10:13:13 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Theo Buehler <tb@openbsd.org> | 3 | * Copyright (c) 2023 Theo Buehler <tb@openbsd.org> |
4 | * | 4 | * |
@@ -52,10 +52,6 @@ static const struct cipher_name cipher_names[] = { | |||
52 | .cipher = EVP_aes_128_cbc, | 52 | .cipher = EVP_aes_128_cbc, |
53 | }, | 53 | }, |
54 | { | 54 | { |
55 | .name = SN_aes_128_cbc_hmac_sha1, | ||
56 | .cipher = EVP_aes_128_cbc_hmac_sha1, | ||
57 | }, | ||
58 | { | ||
59 | .name = SN_aes_128_cfb128, | 55 | .name = SN_aes_128_cfb128, |
60 | .cipher = EVP_aes_128_cfb128, | 56 | .cipher = EVP_aes_128_cfb128, |
61 | }, | 57 | }, |
@@ -118,10 +114,6 @@ static const struct cipher_name cipher_names[] = { | |||
118 | .cipher = EVP_aes_256_cbc, | 114 | .cipher = EVP_aes_256_cbc, |
119 | }, | 115 | }, |
120 | { | 116 | { |
121 | .name = SN_aes_256_cbc_hmac_sha1, | ||
122 | .cipher = EVP_aes_256_cbc_hmac_sha1, | ||
123 | }, | ||
124 | { | ||
125 | .name = SN_aes_256_cfb128, | 117 | .name = SN_aes_256_cfb128, |
126 | .cipher = EVP_aes_256_cfb128, | 118 | .cipher = EVP_aes_256_cfb128, |
127 | }, | 119 | }, |
@@ -497,10 +489,6 @@ static const struct cipher_name cipher_names[] = { | |||
497 | .name = SN_rc4_40, | 489 | .name = SN_rc4_40, |
498 | .cipher = EVP_rc4_40, | 490 | .cipher = EVP_rc4_40, |
499 | }, | 491 | }, |
500 | { | ||
501 | .name = SN_rc4_hmac_md5, | ||
502 | .cipher = EVP_rc4_hmac_md5, | ||
503 | }, | ||
504 | #endif /* OPENSSL_NO_RC4 */ | 492 | #endif /* OPENSSL_NO_RC4 */ |
505 | 493 | ||
506 | #ifndef OPENSSL_NO_SM4 | 494 | #ifndef OPENSSL_NO_SM4 |
@@ -538,10 +526,6 @@ static const struct cipher_name cipher_names[] = { | |||
538 | .cipher = EVP_aes_128_cbc, | 526 | .cipher = EVP_aes_128_cbc, |
539 | }, | 527 | }, |
540 | { | 528 | { |
541 | .name = LN_aes_128_cbc_hmac_sha1, | ||
542 | .cipher = EVP_aes_128_cbc_hmac_sha1, | ||
543 | }, | ||
544 | { | ||
545 | .name = LN_aes_128_ccm, | 529 | .name = LN_aes_128_ccm, |
546 | .cipher = EVP_aes_128_ccm, | 530 | .cipher = EVP_aes_128_ccm, |
547 | }, | 531 | }, |
@@ -620,10 +604,6 @@ static const struct cipher_name cipher_names[] = { | |||
620 | .cipher = EVP_aes_256_cbc, | 604 | .cipher = EVP_aes_256_cbc, |
621 | }, | 605 | }, |
622 | { | 606 | { |
623 | .name = LN_aes_256_cbc_hmac_sha1, | ||
624 | .cipher = EVP_aes_256_cbc_hmac_sha1, | ||
625 | }, | ||
626 | { | ||
627 | .name = LN_aes_256_ccm, | 607 | .name = LN_aes_256_ccm, |
628 | .cipher = EVP_aes_256_ccm, | 608 | .cipher = EVP_aes_256_ccm, |
629 | }, | 609 | }, |
@@ -1060,10 +1040,6 @@ static const struct cipher_name cipher_names[] = { | |||
1060 | .name = LN_rc4_40, | 1040 | .name = LN_rc4_40, |
1061 | .cipher = EVP_rc4_40, | 1041 | .cipher = EVP_rc4_40, |
1062 | }, | 1042 | }, |
1063 | { | ||
1064 | .name = LN_rc4_hmac_md5, | ||
1065 | .cipher = EVP_rc4_hmac_md5, | ||
1066 | }, | ||
1067 | #endif /* OPENSSL_NO_RC4 */ | 1043 | #endif /* OPENSSL_NO_RC4 */ |
1068 | 1044 | ||
1069 | #ifndef OPENSSL_NO_SM4 | 1045 | #ifndef OPENSSL_NO_SM4 |