summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/evp')
-rw-r--r--src/lib/libcrypto/evp/e_aes.c1169
-rw-r--r--src/lib/libcrypto/evp/e_bf.c30
-rw-r--r--src/lib/libcrypto/evp/e_camellia.c112
-rw-r--r--src/lib/libcrypto/evp/e_cast.c30
-rw-r--r--src/lib/libcrypto/evp/e_chacha20poly1305.c4
-rw-r--r--src/lib/libcrypto/evp/e_des.c44
-rw-r--r--src/lib/libcrypto/evp/e_des3.c69
-rw-r--r--src/lib/libcrypto/evp/e_idea.c26
-rw-r--r--src/lib/libcrypto/evp/e_rc2.c4
-rw-r--r--src/lib/libcrypto/evp/e_xcbc_d.c8
-rw-r--r--src/lib/libcrypto/evp/evp.h30
-rw-r--r--src/lib/libcrypto/evp/evp_aead.c4
-rw-r--r--src/lib/libcrypto/evp/evp_cipher.c46
-rw-r--r--src/lib/libcrypto/evp/evp_digest.c4
-rw-r--r--src/lib/libcrypto/evp/evp_key.c4
-rw-r--r--src/lib/libcrypto/evp/evp_local.h4
-rw-r--r--src/lib/libcrypto/evp/evp_names.c3
-rw-r--r--src/lib/libcrypto/evp/evp_pbe.c4
-rw-r--r--src/lib/libcrypto/evp/evp_pkey.c4
-rw-r--r--src/lib/libcrypto/evp/m_sigver.c4
-rw-r--r--src/lib/libcrypto/evp/p_legacy.c4
-rw-r--r--src/lib/libcrypto/evp/p_lib.c20
-rw-r--r--src/lib/libcrypto/evp/p_sign.c3
-rw-r--r--src/lib/libcrypto/evp/p_verify.c3
-rw-r--r--src/lib/libcrypto/evp/pmeth_fn.c4
-rw-r--r--src/lib/libcrypto/evp/pmeth_gn.c4
-rw-r--r--src/lib/libcrypto/evp/pmeth_lib.c4
27 files changed, 362 insertions, 1283 deletions
diff --git a/src/lib/libcrypto/evp/e_aes.c b/src/lib/libcrypto/evp/e_aes.c
index 7753c18c15..e1ae1e9a5b 100644
--- a/src/lib/libcrypto/evp/e_aes.c
+++ b/src/lib/libcrypto/evp/e_aes.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_aes.c,v 1.59 2024/09/06 09:57:32 tb Exp $ */ 1/* $OpenBSD: e_aes.c,v 1.83 2025/07/22 09:31:09 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2001-2011 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2001-2011 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -59,19 +59,15 @@
59 59
60#ifndef OPENSSL_NO_AES 60#ifndef OPENSSL_NO_AES
61#include <openssl/aes.h> 61#include <openssl/aes.h>
62#include <openssl/err.h>
63#include <openssl/evp.h> 62#include <openssl/evp.h>
64 63
64#include "aes_local.h"
65#include "err_local.h"
65#include "evp_local.h" 66#include "evp_local.h"
66#include "modes_local.h" 67#include "modes_local.h"
67 68
68typedef struct { 69typedef struct {
69 AES_KEY ks; 70 AES_KEY ks;
70 block128_f block;
71 union {
72 cbc128_f cbc;
73 ctr128_f ctr;
74 } stream;
75} EVP_AES_KEY; 71} EVP_AES_KEY;
76 72
77typedef struct { 73typedef struct {
@@ -84,15 +80,11 @@ typedef struct {
84 int taglen; 80 int taglen;
85 int iv_gen; /* It is OK to generate IVs */ 81 int iv_gen; /* It is OK to generate IVs */
86 int tls_aad_len; /* TLS AAD length */ 82 int tls_aad_len; /* TLS AAD length */
87 ctr128_f ctr;
88} EVP_AES_GCM_CTX; 83} EVP_AES_GCM_CTX;
89 84
90typedef struct { 85typedef struct {
91 AES_KEY ks1, ks2; /* AES key schedules to use */ 86 AES_KEY ks1, ks2; /* AES key schedules to use */
92 XTS128_CONTEXT xts; 87 XTS128_CONTEXT xts; /* XXX - replace with flags. */
93 void (*stream)(const unsigned char *in, unsigned char *out,
94 size_t length, const AES_KEY *key1, const AES_KEY *key2,
95 const unsigned char iv[16]);
96} EVP_AES_XTS_CTX; 88} EVP_AES_XTS_CTX;
97 89
98typedef struct { 90typedef struct {
@@ -103,131 +95,17 @@ typedef struct {
103 int len_set; /* Set if message length set */ 95 int len_set; /* Set if message length set */
104 int L, M; /* L and M parameters from RFC3610 */ 96 int L, M; /* L and M parameters from RFC3610 */
105 CCM128_CONTEXT ccm; 97 CCM128_CONTEXT ccm;
106 ccm128_f str;
107} EVP_AES_CCM_CTX; 98} EVP_AES_CCM_CTX;
108 99
109#define MAXBITCHUNK ((size_t)1<<(sizeof(size_t)*8-4)) 100#define MAXBITCHUNK ((size_t)1<<(sizeof(size_t)*8-4))
110 101
111#ifdef VPAES_ASM
112int vpaes_set_encrypt_key(const unsigned char *userKey, int bits,
113 AES_KEY *key);
114int vpaes_set_decrypt_key(const unsigned char *userKey, int bits,
115 AES_KEY *key);
116
117void vpaes_encrypt(const unsigned char *in, unsigned char *out,
118 const AES_KEY *key);
119void vpaes_decrypt(const unsigned char *in, unsigned char *out,
120 const AES_KEY *key);
121
122void vpaes_cbc_encrypt(const unsigned char *in, unsigned char *out,
123 size_t length, const AES_KEY *key, unsigned char *ivec, int enc);
124#endif
125#ifdef BSAES_ASM
126void bsaes_cbc_encrypt(const unsigned char *in, unsigned char *out,
127 size_t length, const AES_KEY *key, unsigned char ivec[16], int enc);
128void bsaes_ctr32_encrypt_blocks(const unsigned char *in, unsigned char *out,
129 size_t len, const AES_KEY *key, const unsigned char ivec[16]);
130void bsaes_xts_encrypt(const unsigned char *inp, unsigned char *out,
131 size_t len, const AES_KEY *key1, const AES_KEY *key2,
132 const unsigned char iv[16]);
133void bsaes_xts_decrypt(const unsigned char *inp, unsigned char *out,
134 size_t len, const AES_KEY *key1, const AES_KEY *key2,
135 const unsigned char iv[16]);
136#endif
137#ifdef AES_CTR_ASM
138void AES_ctr32_encrypt(const unsigned char *in, unsigned char *out,
139 size_t blocks, const AES_KEY *key,
140 const unsigned char ivec[AES_BLOCK_SIZE]);
141#endif
142#ifdef AES_XTS_ASM
143void AES_xts_encrypt(const char *inp, char *out, size_t len,
144 const AES_KEY *key1, const AES_KEY *key2, const unsigned char iv[16]);
145void AES_xts_decrypt(const char *inp, char *out, size_t len,
146 const AES_KEY *key1, const AES_KEY *key2, const unsigned char iv[16]);
147#endif
148
149#if defined(AES_ASM) && ( \
150 ((defined(__i386) || defined(__i386__) || \
151 defined(_M_IX86)) && defined(OPENSSL_IA32_SSE2))|| \
152 defined(__x86_64) || defined(__x86_64__) || \
153 defined(_M_AMD64) || defined(_M_X64) || \
154 defined(__INTEL__) )
155
156#include "x86_arch.h"
157
158#ifdef VPAES_ASM
159#define VPAES_CAPABLE (crypto_cpu_caps_ia32() & CPUCAP_MASK_SSSE3)
160#endif
161#ifdef BSAES_ASM
162#define BSAES_CAPABLE VPAES_CAPABLE
163#endif
164/*
165 * AES-NI section
166 */
167#define AESNI_CAPABLE (crypto_cpu_caps_ia32() & CPUCAP_MASK_AESNI)
168
169int aesni_set_encrypt_key(const unsigned char *userKey, int bits,
170 AES_KEY *key);
171int aesni_set_decrypt_key(const unsigned char *userKey, int bits,
172 AES_KEY *key);
173
174void aesni_encrypt(const unsigned char *in, unsigned char *out,
175 const AES_KEY *key);
176void aesni_decrypt(const unsigned char *in, unsigned char *out,
177 const AES_KEY *key);
178
179void aesni_ecb_encrypt(const unsigned char *in, unsigned char *out,
180 size_t length, const AES_KEY *key, int enc);
181void aesni_cbc_encrypt(const unsigned char *in, unsigned char *out,
182 size_t length, const AES_KEY *key, unsigned char *ivec, int enc);
183
184void aesni_ctr32_encrypt_blocks(const unsigned char *in, unsigned char *out,
185 size_t blocks, const void *key, const unsigned char *ivec);
186
187void aesni_xts_encrypt(const unsigned char *in, unsigned char *out,
188 size_t length, const AES_KEY *key1, const AES_KEY *key2,
189 const unsigned char iv[16]);
190
191void aesni_xts_decrypt(const unsigned char *in, unsigned char *out,
192 size_t length, const AES_KEY *key1, const AES_KEY *key2,
193 const unsigned char iv[16]);
194
195void aesni_ccm64_encrypt_blocks (const unsigned char *in, unsigned char *out,
196 size_t blocks, const void *key, const unsigned char ivec[16],
197 unsigned char cmac[16]);
198
199void aesni_ccm64_decrypt_blocks (const unsigned char *in, unsigned char *out,
200 size_t blocks, const void *key, const unsigned char ivec[16],
201 unsigned char cmac[16]);
202
203static int 102static int
204aesni_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, 103aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
205 const unsigned char *iv, int enc) 104 const unsigned char *iv, int enc)
206{ 105{
207 int ret, mode; 106 EVP_AES_KEY *eak = ctx->cipher_data;
208 EVP_AES_KEY *dat = (EVP_AES_KEY *)ctx->cipher_data;
209
210 mode = ctx->cipher->flags & EVP_CIPH_MODE;
211 if ((mode == EVP_CIPH_ECB_MODE || mode == EVP_CIPH_CBC_MODE) &&
212 !enc) {
213 ret = aesni_set_decrypt_key(key, ctx->key_len * 8,
214 ctx->cipher_data);
215 dat->block = (block128_f)aesni_decrypt;
216 dat->stream.cbc = mode == EVP_CIPH_CBC_MODE ?
217 (cbc128_f)aesni_cbc_encrypt : NULL;
218 } else {
219 ret = aesni_set_encrypt_key(key, ctx->key_len * 8,
220 ctx->cipher_data);
221 dat->block = (block128_f)aesni_encrypt;
222 if (mode == EVP_CIPH_CBC_MODE)
223 dat->stream.cbc = (cbc128_f)aesni_cbc_encrypt;
224 else if (mode == EVP_CIPH_CTR_MODE)
225 dat->stream.ctr = (ctr128_f)aesni_ctr32_encrypt_blocks;
226 else
227 dat->stream.cbc = NULL;
228 }
229 107
230 if (ret < 0) { 108 if (AES_set_encrypt_key(key, ctx->key_len * 8, &eak->ks) < 0) {
231 EVPerror(EVP_R_AES_KEY_SETUP_FAILED); 109 EVPerror(EVP_R_AES_KEY_SETUP_FAILED);
232 return 0; 110 return 0;
233 } 111 }
@@ -236,213 +114,54 @@ aesni_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
236} 114}
237 115
238static int 116static int
239aesni_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 117aes_cbc_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
240 const unsigned char *in, size_t len) 118 const unsigned char *iv, int encrypt)
241{
242 aesni_cbc_encrypt(in, out, len, ctx->cipher_data, ctx->iv,
243 ctx->encrypt);
244
245 return 1;
246}
247
248static int
249aesni_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
250 const unsigned char *in, size_t len)
251{ 119{
252 size_t bl = ctx->cipher->block_size; 120 EVP_AES_KEY *eak = ctx->cipher_data;
253 121
254 if (len < bl) 122 if (encrypt) {
255 return 1; 123 if (AES_set_encrypt_key(key, ctx->key_len * 8, &eak->ks) < 0) {
256 124 EVPerror(EVP_R_AES_KEY_SETUP_FAILED);
257 aesni_ecb_encrypt(in, out, len, ctx->cipher_data, ctx->encrypt); 125 return 0;
258
259 return 1;
260}
261
262static int
263aesni_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
264 const unsigned char *iv, int enc)
265{
266 EVP_AES_GCM_CTX *gctx = ctx->cipher_data;
267
268 if (!iv && !key)
269 return 1;
270 if (key) {
271 aesni_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks);
272 CRYPTO_gcm128_init(&gctx->gcm, &gctx->ks,
273 (block128_f)aesni_encrypt);
274 gctx->ctr = (ctr128_f)aesni_ctr32_encrypt_blocks;
275 /* If we have an iv can set it directly, otherwise use
276 * saved IV.
277 */
278 if (iv == NULL && gctx->iv_set)
279 iv = gctx->iv;
280 if (iv) {
281 CRYPTO_gcm128_setiv(&gctx->gcm, iv, gctx->ivlen);
282 gctx->iv_set = 1;
283 } 126 }
284 gctx->key_set = 1;
285 } else { 127 } else {
286 /* If key set use IV, otherwise copy */ 128 if (AES_set_decrypt_key(key, ctx->key_len * 8, &eak->ks) < 0) {
287 if (gctx->key_set) 129 EVPerror(EVP_R_AES_KEY_SETUP_FAILED);
288 CRYPTO_gcm128_setiv(&gctx->gcm, iv, gctx->ivlen); 130 return 0;
289 else
290 memcpy(gctx->iv, iv, gctx->ivlen);
291 gctx->iv_set = 1;
292 gctx->iv_gen = 0;
293 }
294 return 1;
295}
296
297static int
298aesni_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
299 const unsigned char *iv, int enc)
300{
301 EVP_AES_XTS_CTX *xctx = ctx->cipher_data;
302
303 if (!iv && !key)
304 return 1;
305
306 if (key) {
307 /* key_len is two AES keys */
308 if (enc) {
309 aesni_set_encrypt_key(key, ctx->key_len * 4,
310 &xctx->ks1);
311 xctx->xts.block1 = (block128_f)aesni_encrypt;
312 xctx->stream = aesni_xts_encrypt;
313 } else {
314 aesni_set_decrypt_key(key, ctx->key_len * 4,
315 &xctx->ks1);
316 xctx->xts.block1 = (block128_f)aesni_decrypt;
317 xctx->stream = aesni_xts_decrypt;
318 } 131 }
319
320 aesni_set_encrypt_key(key + ctx->key_len / 2,
321 ctx->key_len * 4, &xctx->ks2);
322 xctx->xts.block2 = (block128_f)aesni_encrypt;
323
324 xctx->xts.key1 = &xctx->ks1;
325 }
326
327 if (iv) {
328 xctx->xts.key2 = &xctx->ks2;
329 memcpy(ctx->iv, iv, 16);
330 } 132 }
331 133
332 return 1; 134 return 1;
333} 135}
334 136
335static int 137static int
336aesni_ccm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, 138aes_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
337 const unsigned char *iv, int enc) 139 const unsigned char *in, size_t len)
338{
339 EVP_AES_CCM_CTX *cctx = ctx->cipher_data;
340
341 if (!iv && !key)
342 return 1;
343 if (key) {
344 aesni_set_encrypt_key(key, ctx->key_len * 8, &cctx->ks);
345 CRYPTO_ccm128_init(&cctx->ccm, cctx->M, cctx->L,
346 &cctx->ks, (block128_f)aesni_encrypt);
347 cctx->str = enc ? (ccm128_f)aesni_ccm64_encrypt_blocks :
348 (ccm128_f)aesni_ccm64_decrypt_blocks;
349 cctx->key_set = 1;
350 }
351 if (iv) {
352 memcpy(ctx->iv, iv, 15 - cctx->L);
353 cctx->iv_set = 1;
354 }
355 return 1;
356}
357
358#endif
359
360static int
361aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
362 const unsigned char *iv, int enc)
363{ 140{
364 int ret, mode; 141 EVP_AES_KEY *eak = ctx->cipher_data;
365 EVP_AES_KEY *dat = (EVP_AES_KEY *)ctx->cipher_data;
366
367 mode = ctx->cipher->flags & EVP_CIPH_MODE;
368 if ((mode == EVP_CIPH_ECB_MODE || mode == EVP_CIPH_CBC_MODE) &&
369 !enc)
370#ifdef BSAES_CAPABLE
371 if (BSAES_CAPABLE && mode == EVP_CIPH_CBC_MODE) {
372 ret = AES_set_decrypt_key(key, ctx->key_len * 8,
373 &dat->ks);
374 dat->block = (block128_f)AES_decrypt;
375 dat->stream.cbc = (cbc128_f)bsaes_cbc_encrypt;
376 } else
377#endif
378#ifdef VPAES_CAPABLE
379 if (VPAES_CAPABLE) {
380 ret = vpaes_set_decrypt_key(key, ctx->key_len * 8,
381 &dat->ks);
382 dat->block = (block128_f)vpaes_decrypt;
383 dat->stream.cbc = mode == EVP_CIPH_CBC_MODE ?
384 (cbc128_f)vpaes_cbc_encrypt : NULL;
385 } else
386#endif
387 {
388 ret = AES_set_decrypt_key(key, ctx->key_len * 8,
389 &dat->ks);
390 dat->block = (block128_f)AES_decrypt;
391 dat->stream.cbc = mode == EVP_CIPH_CBC_MODE ?
392 (cbc128_f)AES_cbc_encrypt : NULL;
393 } else
394#ifdef BSAES_CAPABLE
395 if (BSAES_CAPABLE && mode == EVP_CIPH_CTR_MODE) {
396 ret = AES_set_encrypt_key(key, ctx->key_len * 8,
397 &dat->ks);
398 dat->block = (block128_f)AES_encrypt;
399 dat->stream.ctr = (ctr128_f)bsaes_ctr32_encrypt_blocks;
400 } else
401#endif
402#ifdef VPAES_CAPABLE
403 if (VPAES_CAPABLE) {
404 ret = vpaes_set_encrypt_key(key, ctx->key_len * 8,
405 &dat->ks);
406 dat->block = (block128_f)vpaes_encrypt;
407 dat->stream.cbc = mode == EVP_CIPH_CBC_MODE ?
408 (cbc128_f)vpaes_cbc_encrypt : NULL;
409 } else
410#endif
411 {
412 ret = AES_set_encrypt_key(key, ctx->key_len * 8,
413 &dat->ks);
414 dat->block = (block128_f)AES_encrypt;
415 dat->stream.cbc = mode == EVP_CIPH_CBC_MODE ?
416 (cbc128_f)AES_cbc_encrypt : NULL;
417#ifdef AES_CTR_ASM
418 if (mode == EVP_CIPH_CTR_MODE)
419 dat->stream.ctr = (ctr128_f)AES_ctr32_encrypt;
420#endif
421 }
422 142
423 if (ret < 0) { 143 AES_cbc_encrypt(in, out, len, &eak->ks, ctx->iv, ctx->encrypt);
424 EVPerror(EVP_R_AES_KEY_SETUP_FAILED);
425 return 0;
426 }
427 144
428 return 1; 145 return 1;
429} 146}
430 147
431static int 148static int
432aes_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 149aes_ecb_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
433 const unsigned char *in, size_t len) 150 const unsigned char *iv, int encrypt)
434{ 151{
435 EVP_AES_KEY *dat = (EVP_AES_KEY *)ctx->cipher_data; 152 EVP_AES_KEY *eak = ctx->cipher_data;
436 153
437 if (dat->stream.cbc) 154 if (encrypt) {
438 (*dat->stream.cbc)(in, out, len, &dat->ks, ctx->iv, 155 if (AES_set_encrypt_key(key, ctx->key_len * 8, &eak->ks) < 0) {
439 ctx->encrypt); 156 EVPerror(EVP_R_AES_KEY_SETUP_FAILED);
440 else if (ctx->encrypt) 157 return 0;
441 CRYPTO_cbc128_encrypt(in, out, len, &dat->ks, ctx->iv, 158 }
442 dat->block); 159 } else {
443 else 160 if (AES_set_decrypt_key(key, ctx->key_len * 8, &eak->ks) < 0) {
444 CRYPTO_cbc128_decrypt(in, out, len, &dat->ks, ctx->iv, 161 EVPerror(EVP_R_AES_KEY_SETUP_FAILED);
445 dat->block); 162 return 0;
163 }
164 }
446 165
447 return 1; 166 return 1;
448} 167}
@@ -451,15 +170,9 @@ static int
451aes_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 170aes_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
452 const unsigned char *in, size_t len) 171 const unsigned char *in, size_t len)
453{ 172{
454 size_t bl = ctx->cipher->block_size; 173 EVP_AES_KEY *eak = ctx->cipher_data;
455 size_t i;
456 EVP_AES_KEY *dat = (EVP_AES_KEY *)ctx->cipher_data;
457
458 if (len < bl)
459 return 1;
460 174
461 for (i = 0, len -= bl; i <= len; i += bl) 175 aes_ecb_encrypt_internal(in, out, len, &eak->ks, ctx->encrypt);
462 (*dat->block)(in + i, out + i, &dat->ks);
463 176
464 return 1; 177 return 1;
465} 178}
@@ -468,10 +181,10 @@ static int
468aes_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 181aes_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
469 const unsigned char *in, size_t len) 182 const unsigned char *in, size_t len)
470{ 183{
471 EVP_AES_KEY *dat = (EVP_AES_KEY *)ctx->cipher_data; 184 EVP_AES_KEY *eak = ctx->cipher_data;
185
186 AES_ofb128_encrypt(in, out, len, &eak->ks, ctx->iv, &ctx->num);
472 187
473 CRYPTO_ofb128_encrypt(in, out, len, &dat->ks, ctx->iv, &ctx->num,
474 dat->block);
475 return 1; 188 return 1;
476} 189}
477 190
@@ -479,10 +192,11 @@ static int
479aes_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 192aes_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
480 const unsigned char *in, size_t len) 193 const unsigned char *in, size_t len)
481{ 194{
482 EVP_AES_KEY *dat = (EVP_AES_KEY *)ctx->cipher_data; 195 EVP_AES_KEY *eak = ctx->cipher_data;
196
197 AES_cfb128_encrypt(in, out, len, &eak->ks, ctx->iv, &ctx->num,
198 ctx->encrypt);
483 199
484 CRYPTO_cfb128_encrypt(in, out, len, &dat->ks, ctx->iv, &ctx->num,
485 ctx->encrypt, dat->block);
486 return 1; 200 return 1;
487} 201}
488 202
@@ -490,10 +204,11 @@ static int
490aes_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 204aes_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
491 const unsigned char *in, size_t len) 205 const unsigned char *in, size_t len)
492{ 206{
493 EVP_AES_KEY *dat = (EVP_AES_KEY *)ctx->cipher_data; 207 EVP_AES_KEY *eak = ctx->cipher_data;
208
209 AES_cfb8_encrypt(in, out, len, &eak->ks, ctx->iv, &ctx->num,
210 ctx->encrypt);
494 211
495 CRYPTO_cfb128_8_encrypt(in, out, len, &dat->ks, ctx->iv, &ctx->num,
496 ctx->encrypt, dat->block);
497 return 1; 212 return 1;
498} 213}
499 214
@@ -501,24 +216,25 @@ static int
501aes_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 216aes_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
502 const unsigned char *in, size_t len) 217 const unsigned char *in, size_t len)
503{ 218{
504 EVP_AES_KEY *dat = (EVP_AES_KEY *)ctx->cipher_data; 219 EVP_AES_KEY *eak = ctx->cipher_data;
505 220
506 if (ctx->flags&EVP_CIPH_FLAG_LENGTH_BITS) { 221 if ((ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS) != 0) {
507 CRYPTO_cfb128_1_encrypt(in, out, len, &dat->ks, ctx->iv, 222 AES_cfb1_encrypt(in, out, len, &eak->ks, ctx->iv, &ctx->num,
508 &ctx->num, ctx->encrypt, dat->block); 223 ctx->encrypt);
509 return 1; 224 return 1;
510 } 225 }
511 226
512 while (len >= MAXBITCHUNK) { 227 while (len >= MAXBITCHUNK) {
513 CRYPTO_cfb128_1_encrypt(in, out, MAXBITCHUNK*8, &dat->ks, 228 AES_cfb1_encrypt(in, out, MAXBITCHUNK * 8, &eak->ks, ctx->iv,
514 ctx->iv, &ctx->num, ctx->encrypt, dat->block); 229 &ctx->num, ctx->encrypt);
515 len -= MAXBITCHUNK; 230 len -= MAXBITCHUNK;
516 in += MAXBITCHUNK; 231 in += MAXBITCHUNK;
517 out += MAXBITCHUNK; 232 out += MAXBITCHUNK;
518 } 233 }
519 if (len) 234 if (len > 0) {
520 CRYPTO_cfb128_1_encrypt(in, out, len*8, &dat->ks, 235 AES_cfb1_encrypt(in, out, len * 8, &eak->ks, ctx->iv, &ctx->num,
521 ctx->iv, &ctx->num, ctx->encrypt, dat->block); 236 ctx->encrypt);
237 }
522 238
523 return 1; 239 return 1;
524} 240}
@@ -527,40 +243,23 @@ static int
527aes_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 243aes_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
528 const unsigned char *in, size_t len) 244 const unsigned char *in, size_t len)
529{ 245{
246 EVP_AES_KEY *eak = ctx->cipher_data;
530 unsigned int num = ctx->num; 247 unsigned int num = ctx->num;
531 EVP_AES_KEY *dat = (EVP_AES_KEY *)ctx->cipher_data;
532 248
533 if (dat->stream.ctr) 249 AES_ctr128_encrypt(in, out, len, &eak->ks, ctx->iv, ctx->buf, &num);
534 CRYPTO_ctr128_encrypt_ctr32(in, out, len, &dat->ks, 250
535 ctx->iv, ctx->buf, &num, dat->stream.ctr);
536 else
537 CRYPTO_ctr128_encrypt(in, out, len, &dat->ks,
538 ctx->iv, ctx->buf, &num, dat->block);
539 ctx->num = (size_t)num; 251 ctx->num = (size_t)num;
252
540 return 1; 253 return 1;
541} 254}
542 255
543
544#ifdef AESNI_CAPABLE
545static const EVP_CIPHER aesni_128_cbc = {
546 .nid = NID_aes_128_cbc,
547 .block_size = 16,
548 .key_len = 16,
549 .iv_len = 16,
550 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_CBC_MODE,
551 .init = aesni_init_key,
552 .do_cipher = aesni_cbc_cipher,
553 .ctx_size = sizeof(EVP_AES_KEY),
554};
555#endif
556
557static const EVP_CIPHER aes_128_cbc = { 256static const EVP_CIPHER aes_128_cbc = {
558 .nid = NID_aes_128_cbc, 257 .nid = NID_aes_128_cbc,
559 .block_size = 16, 258 .block_size = 16,
560 .key_len = 16, 259 .key_len = 16,
561 .iv_len = 16, 260 .iv_len = 16,
562 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_CBC_MODE, 261 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_CBC_MODE,
563 .init = aes_init_key, 262 .init = aes_cbc_init_key,
564 .do_cipher = aes_cbc_cipher, 263 .do_cipher = aes_cbc_cipher,
565 .ctx_size = sizeof(EVP_AES_KEY), 264 .ctx_size = sizeof(EVP_AES_KEY),
566}; 265};
@@ -568,34 +267,17 @@ static const EVP_CIPHER aes_128_cbc = {
568const EVP_CIPHER * 267const EVP_CIPHER *
569EVP_aes_128_cbc(void) 268EVP_aes_128_cbc(void)
570{ 269{
571#ifdef AESNI_CAPABLE
572 return AESNI_CAPABLE ? &aesni_128_cbc : &aes_128_cbc;
573#else
574 return &aes_128_cbc; 270 return &aes_128_cbc;
575#endif
576} 271}
577LCRYPTO_ALIAS(EVP_aes_128_cbc); 272LCRYPTO_ALIAS(EVP_aes_128_cbc);
578 273
579#ifdef AESNI_CAPABLE
580static const EVP_CIPHER aesni_128_ecb = {
581 .nid = NID_aes_128_ecb,
582 .block_size = 16,
583 .key_len = 16,
584 .iv_len = 0,
585 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_ECB_MODE,
586 .init = aesni_init_key,
587 .do_cipher = aesni_ecb_cipher,
588 .ctx_size = sizeof(EVP_AES_KEY),
589};
590#endif
591
592static const EVP_CIPHER aes_128_ecb = { 274static const EVP_CIPHER aes_128_ecb = {
593 .nid = NID_aes_128_ecb, 275 .nid = NID_aes_128_ecb,
594 .block_size = 16, 276 .block_size = 16,
595 .key_len = 16, 277 .key_len = 16,
596 .iv_len = 0, 278 .iv_len = 0,
597 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_ECB_MODE, 279 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_ECB_MODE,
598 .init = aes_init_key, 280 .init = aes_ecb_init_key,
599 .do_cipher = aes_ecb_cipher, 281 .do_cipher = aes_ecb_cipher,
600 .ctx_size = sizeof(EVP_AES_KEY), 282 .ctx_size = sizeof(EVP_AES_KEY),
601}; 283};
@@ -603,27 +285,10 @@ static const EVP_CIPHER aes_128_ecb = {
603const EVP_CIPHER * 285const EVP_CIPHER *
604EVP_aes_128_ecb(void) 286EVP_aes_128_ecb(void)
605{ 287{
606#ifdef AESNI_CAPABLE
607 return AESNI_CAPABLE ? &aesni_128_ecb : &aes_128_ecb;
608#else
609 return &aes_128_ecb; 288 return &aes_128_ecb;
610#endif
611} 289}
612LCRYPTO_ALIAS(EVP_aes_128_ecb); 290LCRYPTO_ALIAS(EVP_aes_128_ecb);
613 291
614#ifdef AESNI_CAPABLE
615static const EVP_CIPHER aesni_128_ofb = {
616 .nid = NID_aes_128_ofb128,
617 .block_size = 1,
618 .key_len = 16,
619 .iv_len = 16,
620 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_OFB_MODE,
621 .init = aesni_init_key,
622 .do_cipher = aes_ofb_cipher,
623 .ctx_size = sizeof(EVP_AES_KEY),
624};
625#endif
626
627static const EVP_CIPHER aes_128_ofb = { 292static const EVP_CIPHER aes_128_ofb = {
628 .nid = NID_aes_128_ofb128, 293 .nid = NID_aes_128_ofb128,
629 .block_size = 1, 294 .block_size = 1,
@@ -638,27 +303,10 @@ static const EVP_CIPHER aes_128_ofb = {
638const EVP_CIPHER * 303const EVP_CIPHER *
639EVP_aes_128_ofb(void) 304EVP_aes_128_ofb(void)
640{ 305{
641#ifdef AESNI_CAPABLE
642 return AESNI_CAPABLE ? &aesni_128_ofb : &aes_128_ofb;
643#else
644 return &aes_128_ofb; 306 return &aes_128_ofb;
645#endif
646} 307}
647LCRYPTO_ALIAS(EVP_aes_128_ofb); 308LCRYPTO_ALIAS(EVP_aes_128_ofb);
648 309
649#ifdef AESNI_CAPABLE
650static const EVP_CIPHER aesni_128_cfb = {
651 .nid = NID_aes_128_cfb128,
652 .block_size = 1,
653 .key_len = 16,
654 .iv_len = 16,
655 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_CFB_MODE,
656 .init = aesni_init_key,
657 .do_cipher = aes_cfb_cipher,
658 .ctx_size = sizeof(EVP_AES_KEY),
659};
660#endif
661
662static const EVP_CIPHER aes_128_cfb = { 310static const EVP_CIPHER aes_128_cfb = {
663 .nid = NID_aes_128_cfb128, 311 .nid = NID_aes_128_cfb128,
664 .block_size = 1, 312 .block_size = 1,
@@ -673,27 +321,10 @@ static const EVP_CIPHER aes_128_cfb = {
673const EVP_CIPHER * 321const EVP_CIPHER *
674EVP_aes_128_cfb128(void) 322EVP_aes_128_cfb128(void)
675{ 323{
676#ifdef AESNI_CAPABLE
677 return AESNI_CAPABLE ? &aesni_128_cfb : &aes_128_cfb;
678#else
679 return &aes_128_cfb; 324 return &aes_128_cfb;
680#endif
681} 325}
682LCRYPTO_ALIAS(EVP_aes_128_cfb128); 326LCRYPTO_ALIAS(EVP_aes_128_cfb128);
683 327
684#ifdef AESNI_CAPABLE
685static const EVP_CIPHER aesni_128_cfb1 = {
686 .nid = NID_aes_128_cfb1,
687 .block_size = 1,
688 .key_len = 16,
689 .iv_len = 16,
690 .flags = EVP_CIPH_CFB_MODE,
691 .init = aesni_init_key,
692 .do_cipher = aes_cfb1_cipher,
693 .ctx_size = sizeof(EVP_AES_KEY),
694};
695#endif
696
697static const EVP_CIPHER aes_128_cfb1 = { 328static const EVP_CIPHER aes_128_cfb1 = {
698 .nid = NID_aes_128_cfb1, 329 .nid = NID_aes_128_cfb1,
699 .block_size = 1, 330 .block_size = 1,
@@ -708,27 +339,10 @@ static const EVP_CIPHER aes_128_cfb1 = {
708const EVP_CIPHER * 339const EVP_CIPHER *
709EVP_aes_128_cfb1(void) 340EVP_aes_128_cfb1(void)
710{ 341{
711#ifdef AESNI_CAPABLE
712 return AESNI_CAPABLE ? &aesni_128_cfb1 : &aes_128_cfb1;
713#else
714 return &aes_128_cfb1; 342 return &aes_128_cfb1;
715#endif
716} 343}
717LCRYPTO_ALIAS(EVP_aes_128_cfb1); 344LCRYPTO_ALIAS(EVP_aes_128_cfb1);
718 345
719#ifdef AESNI_CAPABLE
720static const EVP_CIPHER aesni_128_cfb8 = {
721 .nid = NID_aes_128_cfb8,
722 .block_size = 1,
723 .key_len = 16,
724 .iv_len = 16,
725 .flags = EVP_CIPH_CFB_MODE,
726 .init = aesni_init_key,
727 .do_cipher = aes_cfb8_cipher,
728 .ctx_size = sizeof(EVP_AES_KEY),
729};
730#endif
731
732static const EVP_CIPHER aes_128_cfb8 = { 346static const EVP_CIPHER aes_128_cfb8 = {
733 .nid = NID_aes_128_cfb8, 347 .nid = NID_aes_128_cfb8,
734 .block_size = 1, 348 .block_size = 1,
@@ -743,27 +357,10 @@ static const EVP_CIPHER aes_128_cfb8 = {
743const EVP_CIPHER * 357const EVP_CIPHER *
744EVP_aes_128_cfb8(void) 358EVP_aes_128_cfb8(void)
745{ 359{
746#ifdef AESNI_CAPABLE
747 return AESNI_CAPABLE ? &aesni_128_cfb8 : &aes_128_cfb8;
748#else
749 return &aes_128_cfb8; 360 return &aes_128_cfb8;
750#endif
751} 361}
752LCRYPTO_ALIAS(EVP_aes_128_cfb8); 362LCRYPTO_ALIAS(EVP_aes_128_cfb8);
753 363
754#ifdef AESNI_CAPABLE
755static const EVP_CIPHER aesni_128_ctr = {
756 .nid = NID_aes_128_ctr,
757 .block_size = 1,
758 .key_len = 16,
759 .iv_len = 16,
760 .flags = EVP_CIPH_CTR_MODE,
761 .init = aesni_init_key,
762 .do_cipher = aes_ctr_cipher,
763 .ctx_size = sizeof(EVP_AES_KEY),
764};
765#endif
766
767static const EVP_CIPHER aes_128_ctr = { 364static const EVP_CIPHER aes_128_ctr = {
768 .nid = NID_aes_128_ctr, 365 .nid = NID_aes_128_ctr,
769 .block_size = 1, 366 .block_size = 1,
@@ -778,35 +375,17 @@ static const EVP_CIPHER aes_128_ctr = {
778const EVP_CIPHER * 375const EVP_CIPHER *
779EVP_aes_128_ctr(void) 376EVP_aes_128_ctr(void)
780{ 377{
781#ifdef AESNI_CAPABLE
782 return AESNI_CAPABLE ? &aesni_128_ctr : &aes_128_ctr;
783#else
784 return &aes_128_ctr; 378 return &aes_128_ctr;
785#endif
786} 379}
787LCRYPTO_ALIAS(EVP_aes_128_ctr); 380LCRYPTO_ALIAS(EVP_aes_128_ctr);
788 381
789
790#ifdef AESNI_CAPABLE
791static const EVP_CIPHER aesni_192_cbc = {
792 .nid = NID_aes_192_cbc,
793 .block_size = 16,
794 .key_len = 24,
795 .iv_len = 16,
796 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_CBC_MODE,
797 .init = aesni_init_key,
798 .do_cipher = aesni_cbc_cipher,
799 .ctx_size = sizeof(EVP_AES_KEY),
800};
801#endif
802
803static const EVP_CIPHER aes_192_cbc = { 382static const EVP_CIPHER aes_192_cbc = {
804 .nid = NID_aes_192_cbc, 383 .nid = NID_aes_192_cbc,
805 .block_size = 16, 384 .block_size = 16,
806 .key_len = 24, 385 .key_len = 24,
807 .iv_len = 16, 386 .iv_len = 16,
808 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_CBC_MODE, 387 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_CBC_MODE,
809 .init = aes_init_key, 388 .init = aes_cbc_init_key,
810 .do_cipher = aes_cbc_cipher, 389 .do_cipher = aes_cbc_cipher,
811 .ctx_size = sizeof(EVP_AES_KEY), 390 .ctx_size = sizeof(EVP_AES_KEY),
812}; 391};
@@ -814,34 +393,17 @@ static const EVP_CIPHER aes_192_cbc = {
814const EVP_CIPHER * 393const EVP_CIPHER *
815EVP_aes_192_cbc(void) 394EVP_aes_192_cbc(void)
816{ 395{
817#ifdef AESNI_CAPABLE
818 return AESNI_CAPABLE ? &aesni_192_cbc : &aes_192_cbc;
819#else
820 return &aes_192_cbc; 396 return &aes_192_cbc;
821#endif
822} 397}
823LCRYPTO_ALIAS(EVP_aes_192_cbc); 398LCRYPTO_ALIAS(EVP_aes_192_cbc);
824 399
825#ifdef AESNI_CAPABLE
826static const EVP_CIPHER aesni_192_ecb = {
827 .nid = NID_aes_192_ecb,
828 .block_size = 16,
829 .key_len = 24,
830 .iv_len = 0,
831 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_ECB_MODE,
832 .init = aesni_init_key,
833 .do_cipher = aesni_ecb_cipher,
834 .ctx_size = sizeof(EVP_AES_KEY),
835};
836#endif
837
838static const EVP_CIPHER aes_192_ecb = { 400static const EVP_CIPHER aes_192_ecb = {
839 .nid = NID_aes_192_ecb, 401 .nid = NID_aes_192_ecb,
840 .block_size = 16, 402 .block_size = 16,
841 .key_len = 24, 403 .key_len = 24,
842 .iv_len = 0, 404 .iv_len = 0,
843 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_ECB_MODE, 405 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_ECB_MODE,
844 .init = aes_init_key, 406 .init = aes_ecb_init_key,
845 .do_cipher = aes_ecb_cipher, 407 .do_cipher = aes_ecb_cipher,
846 .ctx_size = sizeof(EVP_AES_KEY), 408 .ctx_size = sizeof(EVP_AES_KEY),
847}; 409};
@@ -849,27 +411,10 @@ static const EVP_CIPHER aes_192_ecb = {
849const EVP_CIPHER * 411const EVP_CIPHER *
850EVP_aes_192_ecb(void) 412EVP_aes_192_ecb(void)
851{ 413{
852#ifdef AESNI_CAPABLE
853 return AESNI_CAPABLE ? &aesni_192_ecb : &aes_192_ecb;
854#else
855 return &aes_192_ecb; 414 return &aes_192_ecb;
856#endif
857} 415}
858LCRYPTO_ALIAS(EVP_aes_192_ecb); 416LCRYPTO_ALIAS(EVP_aes_192_ecb);
859 417
860#ifdef AESNI_CAPABLE
861static const EVP_CIPHER aesni_192_ofb = {
862 .nid = NID_aes_192_ofb128,
863 .block_size = 1,
864 .key_len = 24,
865 .iv_len = 16,
866 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_OFB_MODE,
867 .init = aesni_init_key,
868 .do_cipher = aes_ofb_cipher,
869 .ctx_size = sizeof(EVP_AES_KEY),
870};
871#endif
872
873static const EVP_CIPHER aes_192_ofb = { 418static const EVP_CIPHER aes_192_ofb = {
874 .nid = NID_aes_192_ofb128, 419 .nid = NID_aes_192_ofb128,
875 .block_size = 1, 420 .block_size = 1,
@@ -884,27 +429,10 @@ static const EVP_CIPHER aes_192_ofb = {
884const EVP_CIPHER * 429const EVP_CIPHER *
885EVP_aes_192_ofb(void) 430EVP_aes_192_ofb(void)
886{ 431{
887#ifdef AESNI_CAPABLE
888 return AESNI_CAPABLE ? &aesni_192_ofb : &aes_192_ofb;
889#else
890 return &aes_192_ofb; 432 return &aes_192_ofb;
891#endif
892} 433}
893LCRYPTO_ALIAS(EVP_aes_192_ofb); 434LCRYPTO_ALIAS(EVP_aes_192_ofb);
894 435
895#ifdef AESNI_CAPABLE
896static const EVP_CIPHER aesni_192_cfb = {
897 .nid = NID_aes_192_cfb128,
898 .block_size = 1,
899 .key_len = 24,
900 .iv_len = 16,
901 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_CFB_MODE,
902 .init = aesni_init_key,
903 .do_cipher = aes_cfb_cipher,
904 .ctx_size = sizeof(EVP_AES_KEY),
905};
906#endif
907
908static const EVP_CIPHER aes_192_cfb = { 436static const EVP_CIPHER aes_192_cfb = {
909 .nid = NID_aes_192_cfb128, 437 .nid = NID_aes_192_cfb128,
910 .block_size = 1, 438 .block_size = 1,
@@ -919,27 +447,10 @@ static const EVP_CIPHER aes_192_cfb = {
919const EVP_CIPHER * 447const EVP_CIPHER *
920EVP_aes_192_cfb128(void) 448EVP_aes_192_cfb128(void)
921{ 449{
922#ifdef AESNI_CAPABLE
923 return AESNI_CAPABLE ? &aesni_192_cfb : &aes_192_cfb;
924#else
925 return &aes_192_cfb; 450 return &aes_192_cfb;
926#endif
927} 451}
928LCRYPTO_ALIAS(EVP_aes_192_cfb128); 452LCRYPTO_ALIAS(EVP_aes_192_cfb128);
929 453
930#ifdef AESNI_CAPABLE
931static const EVP_CIPHER aesni_192_cfb1 = {
932 .nid = NID_aes_192_cfb1,
933 .block_size = 1,
934 .key_len = 24,
935 .iv_len = 16,
936 .flags = EVP_CIPH_CFB_MODE,
937 .init = aesni_init_key,
938 .do_cipher = aes_cfb1_cipher,
939 .ctx_size = sizeof(EVP_AES_KEY),
940};
941#endif
942
943static const EVP_CIPHER aes_192_cfb1 = { 454static const EVP_CIPHER aes_192_cfb1 = {
944 .nid = NID_aes_192_cfb1, 455 .nid = NID_aes_192_cfb1,
945 .block_size = 1, 456 .block_size = 1,
@@ -954,27 +465,10 @@ static const EVP_CIPHER aes_192_cfb1 = {
954const EVP_CIPHER * 465const EVP_CIPHER *
955EVP_aes_192_cfb1(void) 466EVP_aes_192_cfb1(void)
956{ 467{
957#ifdef AESNI_CAPABLE
958 return AESNI_CAPABLE ? &aesni_192_cfb1 : &aes_192_cfb1;
959#else
960 return &aes_192_cfb1; 468 return &aes_192_cfb1;
961#endif
962} 469}
963LCRYPTO_ALIAS(EVP_aes_192_cfb1); 470LCRYPTO_ALIAS(EVP_aes_192_cfb1);
964 471
965#ifdef AESNI_CAPABLE
966static const EVP_CIPHER aesni_192_cfb8 = {
967 .nid = NID_aes_192_cfb8,
968 .block_size = 1,
969 .key_len = 24,
970 .iv_len = 16,
971 .flags = EVP_CIPH_CFB_MODE,
972 .init = aesni_init_key,
973 .do_cipher = aes_cfb8_cipher,
974 .ctx_size = sizeof(EVP_AES_KEY),
975};
976#endif
977
978static const EVP_CIPHER aes_192_cfb8 = { 472static const EVP_CIPHER aes_192_cfb8 = {
979 .nid = NID_aes_192_cfb8, 473 .nid = NID_aes_192_cfb8,
980 .block_size = 1, 474 .block_size = 1,
@@ -989,27 +483,10 @@ static const EVP_CIPHER aes_192_cfb8 = {
989const EVP_CIPHER * 483const EVP_CIPHER *
990EVP_aes_192_cfb8(void) 484EVP_aes_192_cfb8(void)
991{ 485{
992#ifdef AESNI_CAPABLE
993 return AESNI_CAPABLE ? &aesni_192_cfb8 : &aes_192_cfb8;
994#else
995 return &aes_192_cfb8; 486 return &aes_192_cfb8;
996#endif
997} 487}
998LCRYPTO_ALIAS(EVP_aes_192_cfb8); 488LCRYPTO_ALIAS(EVP_aes_192_cfb8);
999 489
1000#ifdef AESNI_CAPABLE
1001static const EVP_CIPHER aesni_192_ctr = {
1002 .nid = NID_aes_192_ctr,
1003 .block_size = 1,
1004 .key_len = 24,
1005 .iv_len = 16,
1006 .flags = EVP_CIPH_CTR_MODE,
1007 .init = aesni_init_key,
1008 .do_cipher = aes_ctr_cipher,
1009 .ctx_size = sizeof(EVP_AES_KEY),
1010};
1011#endif
1012
1013static const EVP_CIPHER aes_192_ctr = { 490static const EVP_CIPHER aes_192_ctr = {
1014 .nid = NID_aes_192_ctr, 491 .nid = NID_aes_192_ctr,
1015 .block_size = 1, 492 .block_size = 1,
@@ -1024,35 +501,17 @@ static const EVP_CIPHER aes_192_ctr = {
1024const EVP_CIPHER * 501const EVP_CIPHER *
1025EVP_aes_192_ctr(void) 502EVP_aes_192_ctr(void)
1026{ 503{
1027#ifdef AESNI_CAPABLE
1028 return AESNI_CAPABLE ? &aesni_192_ctr : &aes_192_ctr;
1029#else
1030 return &aes_192_ctr; 504 return &aes_192_ctr;
1031#endif
1032} 505}
1033LCRYPTO_ALIAS(EVP_aes_192_ctr); 506LCRYPTO_ALIAS(EVP_aes_192_ctr);
1034 507
1035
1036#ifdef AESNI_CAPABLE
1037static const EVP_CIPHER aesni_256_cbc = {
1038 .nid = NID_aes_256_cbc,
1039 .block_size = 16,
1040 .key_len = 32,
1041 .iv_len = 16,
1042 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_CBC_MODE,
1043 .init = aesni_init_key,
1044 .do_cipher = aesni_cbc_cipher,
1045 .ctx_size = sizeof(EVP_AES_KEY),
1046};
1047#endif
1048
1049static const EVP_CIPHER aes_256_cbc = { 508static const EVP_CIPHER aes_256_cbc = {
1050 .nid = NID_aes_256_cbc, 509 .nid = NID_aes_256_cbc,
1051 .block_size = 16, 510 .block_size = 16,
1052 .key_len = 32, 511 .key_len = 32,
1053 .iv_len = 16, 512 .iv_len = 16,
1054 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_CBC_MODE, 513 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_CBC_MODE,
1055 .init = aes_init_key, 514 .init = aes_cbc_init_key,
1056 .do_cipher = aes_cbc_cipher, 515 .do_cipher = aes_cbc_cipher,
1057 .ctx_size = sizeof(EVP_AES_KEY), 516 .ctx_size = sizeof(EVP_AES_KEY),
1058}; 517};
@@ -1060,34 +519,17 @@ static const EVP_CIPHER aes_256_cbc = {
1060const EVP_CIPHER * 519const EVP_CIPHER *
1061EVP_aes_256_cbc(void) 520EVP_aes_256_cbc(void)
1062{ 521{
1063#ifdef AESNI_CAPABLE
1064 return AESNI_CAPABLE ? &aesni_256_cbc : &aes_256_cbc;
1065#else
1066 return &aes_256_cbc; 522 return &aes_256_cbc;
1067#endif
1068} 523}
1069LCRYPTO_ALIAS(EVP_aes_256_cbc); 524LCRYPTO_ALIAS(EVP_aes_256_cbc);
1070 525
1071#ifdef AESNI_CAPABLE
1072static const EVP_CIPHER aesni_256_ecb = {
1073 .nid = NID_aes_256_ecb,
1074 .block_size = 16,
1075 .key_len = 32,
1076 .iv_len = 0,
1077 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_ECB_MODE,
1078 .init = aesni_init_key,
1079 .do_cipher = aesni_ecb_cipher,
1080 .ctx_size = sizeof(EVP_AES_KEY),
1081};
1082#endif
1083
1084static const EVP_CIPHER aes_256_ecb = { 526static const EVP_CIPHER aes_256_ecb = {
1085 .nid = NID_aes_256_ecb, 527 .nid = NID_aes_256_ecb,
1086 .block_size = 16, 528 .block_size = 16,
1087 .key_len = 32, 529 .key_len = 32,
1088 .iv_len = 0, 530 .iv_len = 0,
1089 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_ECB_MODE, 531 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_ECB_MODE,
1090 .init = aes_init_key, 532 .init = aes_ecb_init_key,
1091 .do_cipher = aes_ecb_cipher, 533 .do_cipher = aes_ecb_cipher,
1092 .ctx_size = sizeof(EVP_AES_KEY), 534 .ctx_size = sizeof(EVP_AES_KEY),
1093}; 535};
@@ -1095,27 +537,10 @@ static const EVP_CIPHER aes_256_ecb = {
1095const EVP_CIPHER * 537const EVP_CIPHER *
1096EVP_aes_256_ecb(void) 538EVP_aes_256_ecb(void)
1097{ 539{
1098#ifdef AESNI_CAPABLE
1099 return AESNI_CAPABLE ? &aesni_256_ecb : &aes_256_ecb;
1100#else
1101 return &aes_256_ecb; 540 return &aes_256_ecb;
1102#endif
1103} 541}
1104LCRYPTO_ALIAS(EVP_aes_256_ecb); 542LCRYPTO_ALIAS(EVP_aes_256_ecb);
1105 543
1106#ifdef AESNI_CAPABLE
1107static const EVP_CIPHER aesni_256_ofb = {
1108 .nid = NID_aes_256_ofb128,
1109 .block_size = 1,
1110 .key_len = 32,
1111 .iv_len = 16,
1112 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_OFB_MODE,
1113 .init = aesni_init_key,
1114 .do_cipher = aes_ofb_cipher,
1115 .ctx_size = sizeof(EVP_AES_KEY),
1116};
1117#endif
1118
1119static const EVP_CIPHER aes_256_ofb = { 544static const EVP_CIPHER aes_256_ofb = {
1120 .nid = NID_aes_256_ofb128, 545 .nid = NID_aes_256_ofb128,
1121 .block_size = 1, 546 .block_size = 1,
@@ -1130,27 +555,10 @@ static const EVP_CIPHER aes_256_ofb = {
1130const EVP_CIPHER * 555const EVP_CIPHER *
1131EVP_aes_256_ofb(void) 556EVP_aes_256_ofb(void)
1132{ 557{
1133#ifdef AESNI_CAPABLE
1134 return AESNI_CAPABLE ? &aesni_256_ofb : &aes_256_ofb;
1135#else
1136 return &aes_256_ofb; 558 return &aes_256_ofb;
1137#endif
1138} 559}
1139LCRYPTO_ALIAS(EVP_aes_256_ofb); 560LCRYPTO_ALIAS(EVP_aes_256_ofb);
1140 561
1141#ifdef AESNI_CAPABLE
1142static const EVP_CIPHER aesni_256_cfb = {
1143 .nid = NID_aes_256_cfb128,
1144 .block_size = 1,
1145 .key_len = 32,
1146 .iv_len = 16,
1147 .flags = EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_CFB_MODE,
1148 .init = aesni_init_key,
1149 .do_cipher = aes_cfb_cipher,
1150 .ctx_size = sizeof(EVP_AES_KEY),
1151};
1152#endif
1153
1154static const EVP_CIPHER aes_256_cfb = { 562static const EVP_CIPHER aes_256_cfb = {
1155 .nid = NID_aes_256_cfb128, 563 .nid = NID_aes_256_cfb128,
1156 .block_size = 1, 564 .block_size = 1,
@@ -1165,27 +573,10 @@ static const EVP_CIPHER aes_256_cfb = {
1165const EVP_CIPHER * 573const EVP_CIPHER *
1166EVP_aes_256_cfb128(void) 574EVP_aes_256_cfb128(void)
1167{ 575{
1168#ifdef AESNI_CAPABLE
1169 return AESNI_CAPABLE ? &aesni_256_cfb : &aes_256_cfb;
1170#else
1171 return &aes_256_cfb; 576 return &aes_256_cfb;
1172#endif
1173} 577}
1174LCRYPTO_ALIAS(EVP_aes_256_cfb128); 578LCRYPTO_ALIAS(EVP_aes_256_cfb128);
1175 579
1176#ifdef AESNI_CAPABLE
1177static const EVP_CIPHER aesni_256_cfb1 = {
1178 .nid = NID_aes_256_cfb1,
1179 .block_size = 1,
1180 .key_len = 32,
1181 .iv_len = 16,
1182 .flags = EVP_CIPH_CFB_MODE,
1183 .init = aesni_init_key,
1184 .do_cipher = aes_cfb1_cipher,
1185 .ctx_size = sizeof(EVP_AES_KEY),
1186};
1187#endif
1188
1189static const EVP_CIPHER aes_256_cfb1 = { 580static const EVP_CIPHER aes_256_cfb1 = {
1190 .nid = NID_aes_256_cfb1, 581 .nid = NID_aes_256_cfb1,
1191 .block_size = 1, 582 .block_size = 1,
@@ -1200,27 +591,10 @@ static const EVP_CIPHER aes_256_cfb1 = {
1200const EVP_CIPHER * 591const EVP_CIPHER *
1201EVP_aes_256_cfb1(void) 592EVP_aes_256_cfb1(void)
1202{ 593{
1203#ifdef AESNI_CAPABLE
1204 return AESNI_CAPABLE ? &aesni_256_cfb1 : &aes_256_cfb1;
1205#else
1206 return &aes_256_cfb1; 594 return &aes_256_cfb1;
1207#endif
1208} 595}
1209LCRYPTO_ALIAS(EVP_aes_256_cfb1); 596LCRYPTO_ALIAS(EVP_aes_256_cfb1);
1210 597
1211#ifdef AESNI_CAPABLE
1212static const EVP_CIPHER aesni_256_cfb8 = {
1213 .nid = NID_aes_256_cfb8,
1214 .block_size = 1,
1215 .key_len = 32,
1216 .iv_len = 16,
1217 .flags = EVP_CIPH_CFB_MODE,
1218 .init = aesni_init_key,
1219 .do_cipher = aes_cfb8_cipher,
1220 .ctx_size = sizeof(EVP_AES_KEY),
1221};
1222#endif
1223
1224static const EVP_CIPHER aes_256_cfb8 = { 598static const EVP_CIPHER aes_256_cfb8 = {
1225 .nid = NID_aes_256_cfb8, 599 .nid = NID_aes_256_cfb8,
1226 .block_size = 1, 600 .block_size = 1,
@@ -1235,27 +609,10 @@ static const EVP_CIPHER aes_256_cfb8 = {
1235const EVP_CIPHER * 609const EVP_CIPHER *
1236EVP_aes_256_cfb8(void) 610EVP_aes_256_cfb8(void)
1237{ 611{
1238#ifdef AESNI_CAPABLE
1239 return AESNI_CAPABLE ? &aesni_256_cfb8 : &aes_256_cfb8;
1240#else
1241 return &aes_256_cfb8; 612 return &aes_256_cfb8;
1242#endif
1243} 613}
1244LCRYPTO_ALIAS(EVP_aes_256_cfb8); 614LCRYPTO_ALIAS(EVP_aes_256_cfb8);
1245 615
1246#ifdef AESNI_CAPABLE
1247static const EVP_CIPHER aesni_256_ctr = {
1248 .nid = NID_aes_256_ctr,
1249 .block_size = 1,
1250 .key_len = 32,
1251 .iv_len = 16,
1252 .flags = EVP_CIPH_CTR_MODE,
1253 .init = aesni_init_key,
1254 .do_cipher = aes_ctr_cipher,
1255 .ctx_size = sizeof(EVP_AES_KEY),
1256};
1257#endif
1258
1259static const EVP_CIPHER aes_256_ctr = { 616static const EVP_CIPHER aes_256_ctr = {
1260 .nid = NID_aes_256_ctr, 617 .nid = NID_aes_256_ctr,
1261 .block_size = 1, 618 .block_size = 1,
@@ -1270,11 +627,7 @@ static const EVP_CIPHER aes_256_ctr = {
1270const EVP_CIPHER * 627const EVP_CIPHER *
1271EVP_aes_256_ctr(void) 628EVP_aes_256_ctr(void)
1272{ 629{
1273#ifdef AESNI_CAPABLE
1274 return AESNI_CAPABLE ? &aesni_256_ctr : &aes_256_ctr;
1275#else
1276 return &aes_256_ctr; 630 return &aes_256_ctr;
1277#endif
1278} 631}
1279LCRYPTO_ALIAS(EVP_aes_256_ctr); 632LCRYPTO_ALIAS(EVP_aes_256_ctr);
1280 633
@@ -1455,35 +808,6 @@ aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
1455 } 808 }
1456} 809}
1457 810
1458static ctr128_f
1459aes_gcm_set_key(AES_KEY *aes_key, GCM128_CONTEXT *gcm_ctx,
1460 const unsigned char *key, size_t key_len)
1461{
1462#ifdef BSAES_CAPABLE
1463 if (BSAES_CAPABLE) {
1464 AES_set_encrypt_key(key, key_len * 8, aes_key);
1465 CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)AES_encrypt);
1466 return (ctr128_f)bsaes_ctr32_encrypt_blocks;
1467 } else
1468#endif
1469#ifdef VPAES_CAPABLE
1470 if (VPAES_CAPABLE) {
1471 vpaes_set_encrypt_key(key, key_len * 8, aes_key);
1472 CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)vpaes_encrypt);
1473 return NULL;
1474 } else
1475#endif
1476 (void)0; /* terminate potentially open 'else' */
1477
1478 AES_set_encrypt_key(key, key_len * 8, aes_key);
1479 CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)AES_encrypt);
1480#ifdef AES_CTR_ASM
1481 return (ctr128_f)AES_ctr32_encrypt;
1482#else
1483 return NULL;
1484#endif
1485}
1486
1487static int 811static int
1488aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, 812aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
1489 const unsigned char *iv, int enc) 813 const unsigned char *iv, int enc)
@@ -1493,8 +817,8 @@ aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
1493 if (!iv && !key) 817 if (!iv && !key)
1494 return 1; 818 return 1;
1495 if (key) { 819 if (key) {
1496 gctx->ctr = aes_gcm_set_key(&gctx->ks, &gctx->gcm, 820 AES_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks);
1497 key, ctx->key_len); 821 CRYPTO_gcm128_init(&gctx->gcm, &gctx->ks, aes_encrypt_block128);
1498 822
1499 /* If we have an iv can set it directly, otherwise use 823 /* If we have an iv can set it directly, otherwise use
1500 * saved IV. 824 * saved IV.
@@ -1554,14 +878,9 @@ aes_gcm_tls_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
1554 len -= EVP_GCM_TLS_EXPLICIT_IV_LEN + EVP_GCM_TLS_TAG_LEN; 878 len -= EVP_GCM_TLS_EXPLICIT_IV_LEN + EVP_GCM_TLS_TAG_LEN;
1555 if (ctx->encrypt) { 879 if (ctx->encrypt) {
1556 /* Encrypt payload */ 880 /* Encrypt payload */
1557 if (gctx->ctr) { 881 if (CRYPTO_gcm128_encrypt_ctr32(&gctx->gcm, in, out, len,
1558 if (CRYPTO_gcm128_encrypt_ctr32(&gctx->gcm, in, out, 882 aes_ctr32_encrypt_ctr128f))
1559 len, gctx->ctr)) 883 goto err;
1560 goto err;
1561 } else {
1562 if (CRYPTO_gcm128_encrypt(&gctx->gcm, in, out, len))
1563 goto err;
1564 }
1565 out += len; 884 out += len;
1566 885
1567 /* Finally write tag */ 886 /* Finally write tag */
@@ -1569,19 +888,15 @@ aes_gcm_tls_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
1569 rv = len + EVP_GCM_TLS_EXPLICIT_IV_LEN + EVP_GCM_TLS_TAG_LEN; 888 rv = len + EVP_GCM_TLS_EXPLICIT_IV_LEN + EVP_GCM_TLS_TAG_LEN;
1570 } else { 889 } else {
1571 /* Decrypt */ 890 /* Decrypt */
1572 if (gctx->ctr) { 891 if (CRYPTO_gcm128_decrypt_ctr32(&gctx->gcm, in, out, len,
1573 if (CRYPTO_gcm128_decrypt_ctr32(&gctx->gcm, in, out, 892 aes_ctr32_encrypt_ctr128f))
1574 len, gctx->ctr)) 893 goto err;
1575 goto err; 894
1576 } else {
1577 if (CRYPTO_gcm128_decrypt(&gctx->gcm, in, out, len))
1578 goto err;
1579 }
1580 /* Retrieve tag */ 895 /* Retrieve tag */
1581 CRYPTO_gcm128_tag(&gctx->gcm, ctx->buf, EVP_GCM_TLS_TAG_LEN); 896 CRYPTO_gcm128_tag(&gctx->gcm, ctx->buf, EVP_GCM_TLS_TAG_LEN);
1582 897
1583 /* If tag mismatch wipe buffer */ 898 /* If tag mismatch wipe buffer */
1584 if (memcmp(ctx->buf, in + len, EVP_GCM_TLS_TAG_LEN)) { 899 if (timingsafe_memcmp(ctx->buf, in + len, EVP_GCM_TLS_TAG_LEN) != 0) {
1585 explicit_bzero(out, len); 900 explicit_bzero(out, len);
1586 goto err; 901 goto err;
1587 } 902 }
@@ -1615,25 +930,13 @@ aes_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
1615 if (CRYPTO_gcm128_aad(&gctx->gcm, in, len)) 930 if (CRYPTO_gcm128_aad(&gctx->gcm, in, len))
1616 return -1; 931 return -1;
1617 } else if (ctx->encrypt) { 932 } else if (ctx->encrypt) {
1618 if (gctx->ctr) { 933 if (CRYPTO_gcm128_encrypt_ctr32(&gctx->gcm,
1619 if (CRYPTO_gcm128_encrypt_ctr32(&gctx->gcm, 934 in, out, len, aes_ctr32_encrypt_ctr128f))
1620 in, out, len, gctx->ctr)) 935 return -1;
1621 return -1;
1622 } else {
1623 if (CRYPTO_gcm128_encrypt(&gctx->gcm,
1624 in, out, len))
1625 return -1;
1626 }
1627 } else { 936 } else {
1628 if (gctx->ctr) { 937 if (CRYPTO_gcm128_decrypt_ctr32(&gctx->gcm,
1629 if (CRYPTO_gcm128_decrypt_ctr32(&gctx->gcm, 938 in, out, len, aes_ctr32_encrypt_ctr128f))
1630 in, out, len, gctx->ctr)) 939 return -1;
1631 return -1;
1632 } else {
1633 if (CRYPTO_gcm128_decrypt(&gctx->gcm,
1634 in, out, len))
1635 return -1;
1636 }
1637 } 940 }
1638 return len; 941 return len;
1639 } else { 942 } else {
@@ -1662,22 +965,6 @@ aes_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
1662 EVP_CIPH_FLAG_CUSTOM_CIPHER | EVP_CIPH_ALWAYS_CALL_INIT | \ 965 EVP_CIPH_FLAG_CUSTOM_CIPHER | EVP_CIPH_ALWAYS_CALL_INIT | \
1663 EVP_CIPH_CTRL_INIT | EVP_CIPH_CUSTOM_COPY ) 966 EVP_CIPH_CTRL_INIT | EVP_CIPH_CUSTOM_COPY )
1664 967
1665
1666#ifdef AESNI_CAPABLE
1667static const EVP_CIPHER aesni_128_gcm = {
1668 .nid = NID_aes_128_gcm,
1669 .block_size = 1,
1670 .key_len = 16,
1671 .iv_len = 12,
1672 .flags = EVP_CIPH_FLAG_AEAD_CIPHER|CUSTOM_FLAGS | EVP_CIPH_GCM_MODE,
1673 .init = aesni_gcm_init_key,
1674 .do_cipher = aes_gcm_cipher,
1675 .cleanup = aes_gcm_cleanup,
1676 .ctx_size = sizeof(EVP_AES_GCM_CTX),
1677 .ctrl = aes_gcm_ctrl,
1678};
1679#endif
1680
1681static const EVP_CIPHER aes_128_gcm = { 968static const EVP_CIPHER aes_128_gcm = {
1682 .nid = NID_aes_128_gcm, 969 .nid = NID_aes_128_gcm,
1683 .block_size = 1, 970 .block_size = 1,
@@ -1694,29 +981,10 @@ static const EVP_CIPHER aes_128_gcm = {
1694const EVP_CIPHER * 981const EVP_CIPHER *
1695EVP_aes_128_gcm(void) 982EVP_aes_128_gcm(void)
1696{ 983{
1697#ifdef AESNI_CAPABLE
1698 return AESNI_CAPABLE ? &aesni_128_gcm : &aes_128_gcm;
1699#else
1700 return &aes_128_gcm; 984 return &aes_128_gcm;
1701#endif
1702} 985}
1703LCRYPTO_ALIAS(EVP_aes_128_gcm); 986LCRYPTO_ALIAS(EVP_aes_128_gcm);
1704 987
1705#ifdef AESNI_CAPABLE
1706static const EVP_CIPHER aesni_192_gcm = {
1707 .nid = NID_aes_192_gcm,
1708 .block_size = 1,
1709 .key_len = 24,
1710 .iv_len = 12,
1711 .flags = EVP_CIPH_FLAG_AEAD_CIPHER|CUSTOM_FLAGS | EVP_CIPH_GCM_MODE,
1712 .init = aesni_gcm_init_key,
1713 .do_cipher = aes_gcm_cipher,
1714 .cleanup = aes_gcm_cleanup,
1715 .ctx_size = sizeof(EVP_AES_GCM_CTX),
1716 .ctrl = aes_gcm_ctrl,
1717};
1718#endif
1719
1720static const EVP_CIPHER aes_192_gcm = { 988static const EVP_CIPHER aes_192_gcm = {
1721 .nid = NID_aes_192_gcm, 989 .nid = NID_aes_192_gcm,
1722 .block_size = 1, 990 .block_size = 1,
@@ -1733,29 +1001,10 @@ static const EVP_CIPHER aes_192_gcm = {
1733const EVP_CIPHER * 1001const EVP_CIPHER *
1734EVP_aes_192_gcm(void) 1002EVP_aes_192_gcm(void)
1735{ 1003{
1736#ifdef AESNI_CAPABLE
1737 return AESNI_CAPABLE ? &aesni_192_gcm : &aes_192_gcm;
1738#else
1739 return &aes_192_gcm; 1004 return &aes_192_gcm;
1740#endif
1741} 1005}
1742LCRYPTO_ALIAS(EVP_aes_192_gcm); 1006LCRYPTO_ALIAS(EVP_aes_192_gcm);
1743 1007
1744#ifdef AESNI_CAPABLE
1745static const EVP_CIPHER aesni_256_gcm = {
1746 .nid = NID_aes_256_gcm,
1747 .block_size = 1,
1748 .key_len = 32,
1749 .iv_len = 12,
1750 .flags = EVP_CIPH_FLAG_AEAD_CIPHER|CUSTOM_FLAGS | EVP_CIPH_GCM_MODE,
1751 .init = aesni_gcm_init_key,
1752 .do_cipher = aes_gcm_cipher,
1753 .cleanup = aes_gcm_cleanup,
1754 .ctx_size = sizeof(EVP_AES_GCM_CTX),
1755 .ctrl = aes_gcm_ctrl,
1756};
1757#endif
1758
1759static const EVP_CIPHER aes_256_gcm = { 1008static const EVP_CIPHER aes_256_gcm = {
1760 .nid = NID_aes_256_gcm, 1009 .nid = NID_aes_256_gcm,
1761 .block_size = 1, 1010 .block_size = 1,
@@ -1772,11 +1021,7 @@ static const EVP_CIPHER aes_256_gcm = {
1772const EVP_CIPHER * 1021const EVP_CIPHER *
1773EVP_aes_256_gcm(void) 1022EVP_aes_256_gcm(void)
1774{ 1023{
1775#ifdef AESNI_CAPABLE
1776 return AESNI_CAPABLE ? &aesni_256_gcm : &aes_256_gcm;
1777#else
1778 return &aes_256_gcm; 1024 return &aes_256_gcm;
1779#endif
1780} 1025}
1781LCRYPTO_ALIAS(EVP_aes_256_gcm); 1026LCRYPTO_ALIAS(EVP_aes_256_gcm);
1782 1027
@@ -1818,64 +1063,24 @@ aes_xts_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
1818 1063
1819static int 1064static int
1820aes_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, 1065aes_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
1821 const unsigned char *iv, int enc) 1066 const unsigned char *iv, int encrypt)
1822{ 1067{
1823 EVP_AES_XTS_CTX *xctx = ctx->cipher_data; 1068 EVP_AES_XTS_CTX *xctx = ctx->cipher_data;
1824 1069
1825 if (!iv && !key) 1070 if (key != NULL) {
1826 return 1;
1827
1828 if (key) do {
1829#ifdef AES_XTS_ASM
1830 xctx->stream = enc ? AES_xts_encrypt : AES_xts_decrypt;
1831#else
1832 xctx->stream = NULL;
1833#endif
1834 /* key_len is two AES keys */ 1071 /* key_len is two AES keys */
1835#ifdef BSAES_CAPABLE 1072 if (encrypt)
1836 if (BSAES_CAPABLE)
1837 xctx->stream = enc ? bsaes_xts_encrypt :
1838 bsaes_xts_decrypt;
1839 else
1840#endif
1841#ifdef VPAES_CAPABLE
1842 if (VPAES_CAPABLE) {
1843 if (enc) {
1844 vpaes_set_encrypt_key(key, ctx->key_len * 4,
1845 &xctx->ks1);
1846 xctx->xts.block1 = (block128_f)vpaes_encrypt;
1847 } else {
1848 vpaes_set_decrypt_key(key, ctx->key_len * 4,
1849 &xctx->ks1);
1850 xctx->xts.block1 = (block128_f)vpaes_decrypt;
1851 }
1852
1853 vpaes_set_encrypt_key(key + ctx->key_len / 2,
1854 ctx->key_len * 4, &xctx->ks2);
1855 xctx->xts.block2 = (block128_f)vpaes_encrypt;
1856
1857 xctx->xts.key1 = &xctx->ks1;
1858 break;
1859 } else
1860#endif
1861 (void)0; /* terminate potentially open 'else' */
1862
1863 if (enc) {
1864 AES_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1); 1073 AES_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1);
1865 xctx->xts.block1 = (block128_f)AES_encrypt; 1074 else
1866 } else {
1867 AES_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1); 1075 AES_set_decrypt_key(key, ctx->key_len * 4, &xctx->ks1);
1868 xctx->xts.block1 = (block128_f)AES_decrypt;
1869 }
1870 1076
1871 AES_set_encrypt_key(key + ctx->key_len / 2, 1077 AES_set_encrypt_key(key + ctx->key_len / 2, ctx->key_len * 4,
1872 ctx->key_len * 4, &xctx->ks2); 1078 &xctx->ks2);
1873 xctx->xts.block2 = (block128_f)AES_encrypt;
1874 1079
1875 xctx->xts.key1 = &xctx->ks1; 1080 xctx->xts.key1 = &xctx->ks1;
1876 } while (0); 1081 }
1877 1082
1878 if (iv) { 1083 if (iv != NULL) {
1879 xctx->xts.key2 = &xctx->ks2; 1084 xctx->xts.key2 = &xctx->ks2;
1880 memcpy(ctx->iv, iv, 16); 1085 memcpy(ctx->iv, iv, 16);
1881 } 1086 }
@@ -1889,17 +1094,15 @@ aes_xts_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
1889{ 1094{
1890 EVP_AES_XTS_CTX *xctx = ctx->cipher_data; 1095 EVP_AES_XTS_CTX *xctx = ctx->cipher_data;
1891 1096
1892 if (!xctx->xts.key1 || !xctx->xts.key2) 1097 if (xctx->xts.key1 == NULL || xctx->xts.key2 == NULL)
1893 return 0;
1894 if (!out || !in || len < AES_BLOCK_SIZE)
1895 return 0; 1098 return 0;
1896 1099
1897 if (xctx->stream) 1100 if (out == NULL || in == NULL || len < AES_BLOCK_SIZE)
1898 (*xctx->stream)(in, out, len, xctx->xts.key1, xctx->xts.key2,
1899 ctx->iv);
1900 else if (CRYPTO_xts128_encrypt(&xctx->xts, ctx->iv, in, out, len,
1901 ctx->encrypt))
1902 return 0; 1101 return 0;
1102
1103 aes_xts_encrypt_internal(in, out, len, xctx->xts.key1, xctx->xts.key2,
1104 ctx->iv, ctx->encrypt);
1105
1903 return 1; 1106 return 1;
1904} 1107}
1905 1108
@@ -1907,22 +1110,6 @@ aes_xts_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
1907 ( EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_CUSTOM_IV | \ 1110 ( EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_CUSTOM_IV | \
1908 EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CTRL_INIT | EVP_CIPH_CUSTOM_COPY ) 1111 EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CTRL_INIT | EVP_CIPH_CUSTOM_COPY )
1909 1112
1910
1911#ifdef AESNI_CAPABLE
1912static const EVP_CIPHER aesni_128_xts = {
1913 .nid = NID_aes_128_xts,
1914 .block_size = 1,
1915 .key_len = 2 * 16,
1916 .iv_len = 16,
1917 .flags = XTS_FLAGS | EVP_CIPH_XTS_MODE,
1918 .init = aesni_xts_init_key,
1919 .do_cipher = aes_xts_cipher,
1920 .cleanup = NULL,
1921 .ctx_size = sizeof(EVP_AES_XTS_CTX),
1922 .ctrl = aes_xts_ctrl,
1923};
1924#endif
1925
1926static const EVP_CIPHER aes_128_xts = { 1113static const EVP_CIPHER aes_128_xts = {
1927 .nid = NID_aes_128_xts, 1114 .nid = NID_aes_128_xts,
1928 .block_size = 1, 1115 .block_size = 1,
@@ -1939,29 +1126,10 @@ static const EVP_CIPHER aes_128_xts = {
1939const EVP_CIPHER * 1126const EVP_CIPHER *
1940EVP_aes_128_xts(void) 1127EVP_aes_128_xts(void)
1941{ 1128{
1942#ifdef AESNI_CAPABLE
1943 return AESNI_CAPABLE ? &aesni_128_xts : &aes_128_xts;
1944#else
1945 return &aes_128_xts; 1129 return &aes_128_xts;
1946#endif
1947} 1130}
1948LCRYPTO_ALIAS(EVP_aes_128_xts); 1131LCRYPTO_ALIAS(EVP_aes_128_xts);
1949 1132
1950#ifdef AESNI_CAPABLE
1951static const EVP_CIPHER aesni_256_xts = {
1952 .nid = NID_aes_256_xts,
1953 .block_size = 1,
1954 .key_len = 2 * 32,
1955 .iv_len = 16,
1956 .flags = XTS_FLAGS | EVP_CIPH_XTS_MODE,
1957 .init = aesni_xts_init_key,
1958 .do_cipher = aes_xts_cipher,
1959 .cleanup = NULL,
1960 .ctx_size = sizeof(EVP_AES_XTS_CTX),
1961 .ctrl = aes_xts_ctrl,
1962};
1963#endif
1964
1965static const EVP_CIPHER aes_256_xts = { 1133static const EVP_CIPHER aes_256_xts = {
1966 .nid = NID_aes_256_xts, 1134 .nid = NID_aes_256_xts,
1967 .block_size = 1, 1135 .block_size = 1,
@@ -1978,11 +1146,7 @@ static const EVP_CIPHER aes_256_xts = {
1978const EVP_CIPHER * 1146const EVP_CIPHER *
1979EVP_aes_256_xts(void) 1147EVP_aes_256_xts(void)
1980{ 1148{
1981#ifdef AESNI_CAPABLE
1982 return AESNI_CAPABLE ? &aesni_256_xts : &aes_256_xts;
1983#else
1984 return &aes_256_xts; 1149 return &aes_256_xts;
1985#endif
1986} 1150}
1987LCRYPTO_ALIAS(EVP_aes_256_xts); 1151LCRYPTO_ALIAS(EVP_aes_256_xts);
1988 1152
@@ -2062,23 +1226,12 @@ aes_ccm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
2062 1226
2063 if (!iv && !key) 1227 if (!iv && !key)
2064 return 1; 1228 return 1;
2065 if (key) do { 1229 if (key) {
2066#ifdef VPAES_CAPABLE
2067 if (VPAES_CAPABLE) {
2068 vpaes_set_encrypt_key(key, ctx->key_len*8, &cctx->ks);
2069 CRYPTO_ccm128_init(&cctx->ccm, cctx->M, cctx->L,
2070 &cctx->ks, (block128_f)vpaes_encrypt);
2071 cctx->str = NULL;
2072 cctx->key_set = 1;
2073 break;
2074 }
2075#endif
2076 AES_set_encrypt_key(key, ctx->key_len * 8, &cctx->ks); 1230 AES_set_encrypt_key(key, ctx->key_len * 8, &cctx->ks);
2077 CRYPTO_ccm128_init(&cctx->ccm, cctx->M, cctx->L, 1231 CRYPTO_ccm128_init(&cctx->ccm, cctx->M, cctx->L,
2078 &cctx->ks, (block128_f)AES_encrypt); 1232 &cctx->ks, aes_encrypt_block128);
2079 cctx->str = NULL;
2080 cctx->key_set = 1; 1233 cctx->key_set = 1;
2081 } while (0); 1234 }
2082 if (iv) { 1235 if (iv) {
2083 memcpy(ctx->iv, iv, 15 - cctx->L); 1236 memcpy(ctx->iv, iv, 15 - cctx->L);
2084 cctx->iv_set = 1; 1237 cctx->iv_set = 1;
@@ -2094,7 +1247,14 @@ aes_ccm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
2094 CCM128_CONTEXT *ccm = &cctx->ccm; 1247 CCM128_CONTEXT *ccm = &cctx->ccm;
2095 1248
2096 /* If not set up, return error */ 1249 /* If not set up, return error */
2097 if (!cctx->iv_set && !cctx->key_set) 1250 if (!cctx->key_set)
1251 return -1;
1252
1253 /* EVP_*Final() doesn't return any data */
1254 if (in == NULL && out != NULL)
1255 return 0;
1256
1257 if (!cctx->iv_set)
2098 return -1; 1258 return -1;
2099 if (!ctx->encrypt && !cctx->tag_set) 1259 if (!ctx->encrypt && !cctx->tag_set)
2100 return -1; 1260 return -1;
@@ -2113,9 +1273,7 @@ aes_ccm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
2113 CRYPTO_ccm128_aad(ccm, in, len); 1273 CRYPTO_ccm128_aad(ccm, in, len);
2114 return len; 1274 return len;
2115 } 1275 }
2116 /* EVP_*Final() doesn't return any data */ 1276
2117 if (!in)
2118 return 0;
2119 /* If not set length yet do it */ 1277 /* If not set length yet do it */
2120 if (!cctx->len_set) { 1278 if (!cctx->len_set) {
2121 if (CRYPTO_ccm128_setiv(ccm, ctx->iv, 15 - cctx->L, len)) 1279 if (CRYPTO_ccm128_setiv(ccm, ctx->iv, 15 - cctx->L, len))
@@ -2123,18 +1281,18 @@ aes_ccm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
2123 cctx->len_set = 1; 1281 cctx->len_set = 1;
2124 } 1282 }
2125 if (ctx->encrypt) { 1283 if (ctx->encrypt) {
2126 if (cctx->str ? CRYPTO_ccm128_encrypt_ccm64(ccm, in, out, len, 1284 if (CRYPTO_ccm128_encrypt_ccm64(ccm, in, out, len,
2127 cctx->str) : CRYPTO_ccm128_encrypt(ccm, in, out, len)) 1285 aes_ccm64_encrypt_ccm128f) != 0)
2128 return -1; 1286 return -1;
2129 cctx->tag_set = 1; 1287 cctx->tag_set = 1;
2130 return len; 1288 return len;
2131 } else { 1289 } else {
2132 int rv = -1; 1290 int rv = -1;
2133 if (cctx->str ? !CRYPTO_ccm128_decrypt_ccm64(ccm, in, out, len, 1291 if (CRYPTO_ccm128_decrypt_ccm64(ccm, in, out, len,
2134 cctx->str) : !CRYPTO_ccm128_decrypt(ccm, in, out, len)) { 1292 aes_ccm64_decrypt_ccm128f) == 0) {
2135 unsigned char tag[16]; 1293 unsigned char tag[16];
2136 if (CRYPTO_ccm128_tag(ccm, tag, cctx->M)) { 1294 if (CRYPTO_ccm128_tag(ccm, tag, cctx->M)) {
2137 if (!memcmp(tag, ctx->buf, cctx->M)) 1295 if (timingsafe_memcmp(tag, ctx->buf, cctx->M) == 0)
2138 rv = len; 1296 rv = len;
2139 } 1297 }
2140 } 1298 }
@@ -2145,24 +1303,8 @@ aes_ccm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
2145 cctx->len_set = 0; 1303 cctx->len_set = 0;
2146 return rv; 1304 return rv;
2147 } 1305 }
2148
2149} 1306}
2150 1307
2151#ifdef AESNI_CAPABLE
2152static const EVP_CIPHER aesni_128_ccm = {
2153 .nid = NID_aes_128_ccm,
2154 .block_size = 1,
2155 .key_len = 16,
2156 .iv_len = 12,
2157 .flags = CUSTOM_FLAGS | EVP_CIPH_CCM_MODE,
2158 .init = aesni_ccm_init_key,
2159 .do_cipher = aes_ccm_cipher,
2160 .cleanup = NULL,
2161 .ctx_size = sizeof(EVP_AES_CCM_CTX),
2162 .ctrl = aes_ccm_ctrl,
2163};
2164#endif
2165
2166static const EVP_CIPHER aes_128_ccm = { 1308static const EVP_CIPHER aes_128_ccm = {
2167 .nid = NID_aes_128_ccm, 1309 .nid = NID_aes_128_ccm,
2168 .block_size = 1, 1310 .block_size = 1,
@@ -2179,29 +1321,10 @@ static const EVP_CIPHER aes_128_ccm = {
2179const EVP_CIPHER * 1321const EVP_CIPHER *
2180EVP_aes_128_ccm(void) 1322EVP_aes_128_ccm(void)
2181{ 1323{
2182#ifdef AESNI_CAPABLE
2183 return AESNI_CAPABLE ? &aesni_128_ccm : &aes_128_ccm;
2184#else
2185 return &aes_128_ccm; 1324 return &aes_128_ccm;
2186#endif
2187} 1325}
2188LCRYPTO_ALIAS(EVP_aes_128_ccm); 1326LCRYPTO_ALIAS(EVP_aes_128_ccm);
2189 1327
2190#ifdef AESNI_CAPABLE
2191static const EVP_CIPHER aesni_192_ccm = {
2192 .nid = NID_aes_192_ccm,
2193 .block_size = 1,
2194 .key_len = 24,
2195 .iv_len = 12,
2196 .flags = CUSTOM_FLAGS | EVP_CIPH_CCM_MODE,
2197 .init = aesni_ccm_init_key,
2198 .do_cipher = aes_ccm_cipher,
2199 .cleanup = NULL,
2200 .ctx_size = sizeof(EVP_AES_CCM_CTX),
2201 .ctrl = aes_ccm_ctrl,
2202};
2203#endif
2204
2205static const EVP_CIPHER aes_192_ccm = { 1328static const EVP_CIPHER aes_192_ccm = {
2206 .nid = NID_aes_192_ccm, 1329 .nid = NID_aes_192_ccm,
2207 .block_size = 1, 1330 .block_size = 1,
@@ -2218,29 +1341,10 @@ static const EVP_CIPHER aes_192_ccm = {
2218const EVP_CIPHER * 1341const EVP_CIPHER *
2219EVP_aes_192_ccm(void) 1342EVP_aes_192_ccm(void)
2220{ 1343{
2221#ifdef AESNI_CAPABLE
2222 return AESNI_CAPABLE ? &aesni_192_ccm : &aes_192_ccm;
2223#else
2224 return &aes_192_ccm; 1344 return &aes_192_ccm;
2225#endif
2226} 1345}
2227LCRYPTO_ALIAS(EVP_aes_192_ccm); 1346LCRYPTO_ALIAS(EVP_aes_192_ccm);
2228 1347
2229#ifdef AESNI_CAPABLE
2230static const EVP_CIPHER aesni_256_ccm = {
2231 .nid = NID_aes_256_ccm,
2232 .block_size = 1,
2233 .key_len = 32,
2234 .iv_len = 12,
2235 .flags = CUSTOM_FLAGS | EVP_CIPH_CCM_MODE,
2236 .init = aesni_ccm_init_key,
2237 .do_cipher = aes_ccm_cipher,
2238 .cleanup = NULL,
2239 .ctx_size = sizeof(EVP_AES_CCM_CTX),
2240 .ctrl = aes_ccm_ctrl,
2241};
2242#endif
2243
2244static const EVP_CIPHER aes_256_ccm = { 1348static const EVP_CIPHER aes_256_ccm = {
2245 .nid = NID_aes_256_ccm, 1349 .nid = NID_aes_256_ccm,
2246 .block_size = 1, 1350 .block_size = 1,
@@ -2257,11 +1361,7 @@ static const EVP_CIPHER aes_256_ccm = {
2257const EVP_CIPHER * 1361const EVP_CIPHER *
2258EVP_aes_256_ccm(void) 1362EVP_aes_256_ccm(void)
2259{ 1363{
2260#ifdef AESNI_CAPABLE
2261 return AESNI_CAPABLE ? &aesni_256_ccm : &aes_256_ccm;
2262#else
2263 return &aes_256_ccm; 1364 return &aes_256_ccm;
2264#endif
2265} 1365}
2266LCRYPTO_ALIAS(EVP_aes_256_ccm); 1366LCRYPTO_ALIAS(EVP_aes_256_ccm);
2267 1367
@@ -2273,7 +1373,6 @@ struct aead_aes_gcm_ctx {
2273 AES_KEY ks; 1373 AES_KEY ks;
2274 } ks; 1374 } ks;
2275 GCM128_CONTEXT gcm; 1375 GCM128_CONTEXT gcm;
2276 ctr128_f ctr;
2277 unsigned char tag_len; 1376 unsigned char tag_len;
2278}; 1377};
2279 1378
@@ -2301,18 +1400,8 @@ aead_aes_gcm_init(EVP_AEAD_CTX *ctx, const unsigned char *key, size_t key_len,
2301 if ((gcm_ctx = calloc(1, sizeof(struct aead_aes_gcm_ctx))) == NULL) 1400 if ((gcm_ctx = calloc(1, sizeof(struct aead_aes_gcm_ctx))) == NULL)
2302 return 0; 1401 return 0;
2303 1402
2304#ifdef AESNI_CAPABLE 1403 AES_set_encrypt_key(key, key_bits, &gcm_ctx->ks.ks);
2305 if (AESNI_CAPABLE) { 1404 CRYPTO_gcm128_init(&gcm_ctx->gcm, &gcm_ctx->ks.ks, aes_encrypt_block128);
2306 aesni_set_encrypt_key(key, key_bits, &gcm_ctx->ks.ks);
2307 CRYPTO_gcm128_init(&gcm_ctx->gcm, &gcm_ctx->ks.ks,
2308 (block128_f)aesni_encrypt);
2309 gcm_ctx->ctr = (ctr128_f) aesni_ctr32_encrypt_blocks;
2310 } else
2311#endif
2312 {
2313 gcm_ctx->ctr = aes_gcm_set_key(&gcm_ctx->ks.ks, &gcm_ctx->gcm,
2314 key, key_len);
2315 }
2316 gcm_ctx->tag_len = tag_len; 1405 gcm_ctx->tag_len = tag_len;
2317 ctx->aead_state = gcm_ctx; 1406 ctx->aead_state = gcm_ctx;
2318 1407
@@ -2353,15 +1442,9 @@ aead_aes_gcm_seal(const EVP_AEAD_CTX *ctx, unsigned char *out, size_t *out_len,
2353 if (ad_len > 0 && CRYPTO_gcm128_aad(&gcm, ad, ad_len)) 1442 if (ad_len > 0 && CRYPTO_gcm128_aad(&gcm, ad, ad_len))
2354 return 0; 1443 return 0;
2355 1444
2356 if (gcm_ctx->ctr) { 1445 if (CRYPTO_gcm128_encrypt_ctr32(&gcm, in + bulk, out + bulk,
2357 if (CRYPTO_gcm128_encrypt_ctr32(&gcm, in + bulk, out + bulk, 1446 in_len - bulk, aes_ctr32_encrypt_ctr128f))
2358 in_len - bulk, gcm_ctx->ctr)) 1447 return 0;
2359 return 0;
2360 } else {
2361 if (CRYPTO_gcm128_encrypt(&gcm, in + bulk, out + bulk,
2362 in_len - bulk))
2363 return 0;
2364 }
2365 1448
2366 CRYPTO_gcm128_tag(&gcm, out + in_len, gcm_ctx->tag_len); 1449 CRYPTO_gcm128_tag(&gcm, out + in_len, gcm_ctx->tag_len);
2367 *out_len = in_len + gcm_ctx->tag_len; 1450 *out_len = in_len + gcm_ctx->tag_len;
@@ -2404,15 +1487,9 @@ aead_aes_gcm_open(const EVP_AEAD_CTX *ctx, unsigned char *out, size_t *out_len,
2404 if (CRYPTO_gcm128_aad(&gcm, ad, ad_len)) 1487 if (CRYPTO_gcm128_aad(&gcm, ad, ad_len))
2405 return 0; 1488 return 0;
2406 1489
2407 if (gcm_ctx->ctr) { 1490 if (CRYPTO_gcm128_decrypt_ctr32(&gcm, in + bulk, out + bulk,
2408 if (CRYPTO_gcm128_decrypt_ctr32(&gcm, in + bulk, out + bulk, 1491 in_len - bulk - gcm_ctx->tag_len, aes_ctr32_encrypt_ctr128f))
2409 in_len - bulk - gcm_ctx->tag_len, gcm_ctx->ctr)) 1492 return 0;
2410 return 0;
2411 } else {
2412 if (CRYPTO_gcm128_decrypt(&gcm, in + bulk, out + bulk,
2413 in_len - bulk - gcm_ctx->tag_len))
2414 return 0;
2415 }
2416 1493
2417 CRYPTO_gcm128_tag(&gcm, tag, gcm_ctx->tag_len); 1494 CRYPTO_gcm128_tag(&gcm, tag, gcm_ctx->tag_len);
2418 if (timingsafe_memcmp(tag, in + plaintext_len, gcm_ctx->tag_len) != 0) { 1495 if (timingsafe_memcmp(tag, in + plaintext_len, gcm_ctx->tag_len) != 0) {
diff --git a/src/lib/libcrypto/evp/e_bf.c b/src/lib/libcrypto/evp/e_bf.c
index 4f3799975b..8c32a5658e 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.19 2024/04/09 13:52:41 beck Exp $ */ 1/* $OpenBSD: e_bf.c,v 1.20 2025/05/27 03:58:12 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 *
@@ -162,13 +162,14 @@ static const EVP_CIPHER bf_cbc = {
162 .block_size = 8, 162 .block_size = 8,
163 .key_len = 16, 163 .key_len = 16,
164 .iv_len = 8, 164 .iv_len = 8,
165 .flags = EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CBC_MODE, 165 .flags = EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CBC_MODE |
166 EVP_CIPH_FLAG_DEFAULT_ASN1,
166 .init = bf_init_key, 167 .init = bf_init_key,
167 .do_cipher = bf_cbc_cipher, 168 .do_cipher = bf_cbc_cipher,
168 .cleanup = NULL, 169 .cleanup = NULL,
169 .ctx_size = sizeof(EVP_BF_KEY), 170 .ctx_size = sizeof(EVP_BF_KEY),
170 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 171 .set_asn1_parameters = NULL,
171 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 172 .get_asn1_parameters = NULL,
172 .ctrl = NULL, 173 .ctrl = NULL,
173}; 174};
174 175
@@ -184,13 +185,14 @@ static const EVP_CIPHER bf_cfb64 = {
184 .block_size = 1, 185 .block_size = 1,
185 .key_len = 16, 186 .key_len = 16,
186 .iv_len = 8, 187 .iv_len = 8,
187 .flags = EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CFB_MODE, 188 .flags = EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CFB_MODE |
189 EVP_CIPH_FLAG_DEFAULT_ASN1,
188 .init = bf_init_key, 190 .init = bf_init_key,
189 .do_cipher = bf_cfb64_cipher, 191 .do_cipher = bf_cfb64_cipher,
190 .cleanup = NULL, 192 .cleanup = NULL,
191 .ctx_size = sizeof(EVP_BF_KEY), 193 .ctx_size = sizeof(EVP_BF_KEY),
192 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 194 .set_asn1_parameters = NULL,
193 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 195 .get_asn1_parameters = NULL,
194 .ctrl = NULL, 196 .ctrl = NULL,
195}; 197};
196 198
@@ -206,13 +208,14 @@ static const EVP_CIPHER bf_ofb = {
206 .block_size = 1, 208 .block_size = 1,
207 .key_len = 16, 209 .key_len = 16,
208 .iv_len = 8, 210 .iv_len = 8,
209 .flags = EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_OFB_MODE, 211 .flags = EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_OFB_MODE |
212 EVP_CIPH_FLAG_DEFAULT_ASN1,
210 .init = bf_init_key, 213 .init = bf_init_key,
211 .do_cipher = bf_ofb_cipher, 214 .do_cipher = bf_ofb_cipher,
212 .cleanup = NULL, 215 .cleanup = NULL,
213 .ctx_size = sizeof(EVP_BF_KEY), 216 .ctx_size = sizeof(EVP_BF_KEY),
214 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 217 .set_asn1_parameters = NULL,
215 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 218 .get_asn1_parameters = NULL,
216 .ctrl = NULL, 219 .ctrl = NULL,
217}; 220};
218 221
@@ -228,13 +231,14 @@ static const EVP_CIPHER bf_ecb = {
228 .block_size = 8, 231 .block_size = 8,
229 .key_len = 16, 232 .key_len = 16,
230 .iv_len = 0, 233 .iv_len = 0,
231 .flags = EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_ECB_MODE, 234 .flags = EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_ECB_MODE |
235 EVP_CIPH_FLAG_DEFAULT_ASN1,
232 .init = bf_init_key, 236 .init = bf_init_key,
233 .do_cipher = bf_ecb_cipher, 237 .do_cipher = bf_ecb_cipher,
234 .cleanup = NULL, 238 .cleanup = NULL,
235 .ctx_size = sizeof(EVP_BF_KEY), 239 .ctx_size = sizeof(EVP_BF_KEY),
236 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 240 .set_asn1_parameters = NULL,
237 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 241 .get_asn1_parameters = NULL,
238 .ctrl = NULL, 242 .ctrl = NULL,
239}; 243};
240 244
diff --git a/src/lib/libcrypto/evp/e_camellia.c b/src/lib/libcrypto/evp/e_camellia.c
index 55dcc79922..8da46275a3 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.20 2024/04/09 13:52:41 beck Exp $ */ 1/* $OpenBSD: e_camellia.c,v 1.22 2025/05/27 03:58:12 tb 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 *
@@ -59,9 +59,9 @@
59 59
60#ifndef OPENSSL_NO_CAMELLIA 60#ifndef OPENSSL_NO_CAMELLIA
61#include <openssl/evp.h> 61#include <openssl/evp.h>
62#include <openssl/err.h>
63#include <openssl/camellia.h> 62#include <openssl/camellia.h>
64 63
64#include "err_local.h"
65#include "evp_local.h" 65#include "evp_local.h"
66 66
67/* Camellia subkey Structure */ 67/* Camellia subkey Structure */
@@ -163,13 +163,13 @@ static const EVP_CIPHER camellia_128_cbc = {
163 .block_size = 16, 163 .block_size = 16,
164 .key_len = 16, 164 .key_len = 16,
165 .iv_len = 16, 165 .iv_len = 16,
166 .flags = 0 | EVP_CIPH_CBC_MODE, 166 .flags = EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1,
167 .init = camellia_init_key, 167 .init = camellia_init_key,
168 .do_cipher = camellia_128_cbc_cipher, 168 .do_cipher = camellia_128_cbc_cipher,
169 .cleanup = NULL, 169 .cleanup = NULL,
170 .ctx_size = sizeof(EVP_CAMELLIA_KEY), 170 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
171 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 171 .set_asn1_parameters = NULL,
172 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 172 .get_asn1_parameters = NULL,
173 .ctrl = NULL, 173 .ctrl = NULL,
174}; 174};
175 175
@@ -185,13 +185,13 @@ static const EVP_CIPHER camellia_128_cfb128 = {
185 .block_size = 1, 185 .block_size = 1,
186 .key_len = 16, 186 .key_len = 16,
187 .iv_len = 16, 187 .iv_len = 16,
188 .flags = 0 | EVP_CIPH_CFB_MODE, 188 .flags = EVP_CIPH_CFB_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1,
189 .init = camellia_init_key, 189 .init = camellia_init_key,
190 .do_cipher = camellia_128_cfb128_cipher, 190 .do_cipher = camellia_128_cfb128_cipher,
191 .cleanup = NULL, 191 .cleanup = NULL,
192 .ctx_size = sizeof(EVP_CAMELLIA_KEY), 192 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
193 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 193 .set_asn1_parameters = NULL,
194 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 194 .get_asn1_parameters = NULL,
195 .ctrl = NULL, 195 .ctrl = NULL,
196}; 196};
197 197
@@ -207,13 +207,13 @@ static const EVP_CIPHER camellia_128_ofb = {
207 .block_size = 1, 207 .block_size = 1,
208 .key_len = 16, 208 .key_len = 16,
209 .iv_len = 16, 209 .iv_len = 16,
210 .flags = 0 | EVP_CIPH_OFB_MODE, 210 .flags = EVP_CIPH_OFB_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1,
211 .init = camellia_init_key, 211 .init = camellia_init_key,
212 .do_cipher = camellia_128_ofb_cipher, 212 .do_cipher = camellia_128_ofb_cipher,
213 .cleanup = NULL, 213 .cleanup = NULL,
214 .ctx_size = sizeof(EVP_CAMELLIA_KEY), 214 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
215 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 215 .set_asn1_parameters = NULL,
216 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 216 .get_asn1_parameters = NULL,
217 .ctrl = NULL, 217 .ctrl = NULL,
218}; 218};
219 219
@@ -229,13 +229,13 @@ static const EVP_CIPHER camellia_128_ecb = {
229 .block_size = 16, 229 .block_size = 16,
230 .key_len = 16, 230 .key_len = 16,
231 .iv_len = 0, 231 .iv_len = 0,
232 .flags = 0 | EVP_CIPH_ECB_MODE, 232 .flags = EVP_CIPH_ECB_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1,
233 .init = camellia_init_key, 233 .init = camellia_init_key,
234 .do_cipher = camellia_128_ecb_cipher, 234 .do_cipher = camellia_128_ecb_cipher,
235 .cleanup = NULL, 235 .cleanup = NULL,
236 .ctx_size = sizeof(EVP_CAMELLIA_KEY), 236 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
237 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 237 .set_asn1_parameters = NULL,
238 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 238 .get_asn1_parameters = NULL,
239 .ctrl = NULL, 239 .ctrl = NULL,
240}; 240};
241 241
@@ -321,13 +321,13 @@ static const EVP_CIPHER camellia_192_cbc = {
321 .block_size = 16, 321 .block_size = 16,
322 .key_len = 24, 322 .key_len = 24,
323 .iv_len = 16, 323 .iv_len = 16,
324 .flags = 0 | EVP_CIPH_CBC_MODE, 324 .flags = EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1,
325 .init = camellia_init_key, 325 .init = camellia_init_key,
326 .do_cipher = camellia_192_cbc_cipher, 326 .do_cipher = camellia_192_cbc_cipher,
327 .cleanup = NULL, 327 .cleanup = NULL,
328 .ctx_size = sizeof(EVP_CAMELLIA_KEY), 328 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
329 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 329 .set_asn1_parameters = NULL,
330 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 330 .get_asn1_parameters = NULL,
331 .ctrl = NULL, 331 .ctrl = NULL,
332}; 332};
333 333
@@ -343,13 +343,13 @@ static const EVP_CIPHER camellia_192_cfb128 = {
343 .block_size = 1, 343 .block_size = 1,
344 .key_len = 24, 344 .key_len = 24,
345 .iv_len = 16, 345 .iv_len = 16,
346 .flags = 0 | EVP_CIPH_CFB_MODE, 346 .flags = EVP_CIPH_CFB_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1,
347 .init = camellia_init_key, 347 .init = camellia_init_key,
348 .do_cipher = camellia_192_cfb128_cipher, 348 .do_cipher = camellia_192_cfb128_cipher,
349 .cleanup = NULL, 349 .cleanup = NULL,
350 .ctx_size = sizeof(EVP_CAMELLIA_KEY), 350 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
351 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 351 .set_asn1_parameters = NULL,
352 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 352 .get_asn1_parameters = NULL,
353 .ctrl = NULL, 353 .ctrl = NULL,
354}; 354};
355 355
@@ -365,13 +365,13 @@ static const EVP_CIPHER camellia_192_ofb = {
365 .block_size = 1, 365 .block_size = 1,
366 .key_len = 24, 366 .key_len = 24,
367 .iv_len = 16, 367 .iv_len = 16,
368 .flags = 0 | EVP_CIPH_OFB_MODE, 368 .flags = EVP_CIPH_OFB_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1,
369 .init = camellia_init_key, 369 .init = camellia_init_key,
370 .do_cipher = camellia_192_ofb_cipher, 370 .do_cipher = camellia_192_ofb_cipher,
371 .cleanup = NULL, 371 .cleanup = NULL,
372 .ctx_size = sizeof(EVP_CAMELLIA_KEY), 372 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
373 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 373 .set_asn1_parameters = NULL,
374 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 374 .get_asn1_parameters = NULL,
375 .ctrl = NULL, 375 .ctrl = NULL,
376}; 376};
377 377
@@ -387,13 +387,13 @@ static const EVP_CIPHER camellia_192_ecb = {
387 .block_size = 16, 387 .block_size = 16,
388 .key_len = 24, 388 .key_len = 24,
389 .iv_len = 0, 389 .iv_len = 0,
390 .flags = 0 | EVP_CIPH_ECB_MODE, 390 .flags = EVP_CIPH_ECB_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1,
391 .init = camellia_init_key, 391 .init = camellia_init_key,
392 .do_cipher = camellia_192_ecb_cipher, 392 .do_cipher = camellia_192_ecb_cipher,
393 .cleanup = NULL, 393 .cleanup = NULL,
394 .ctx_size = sizeof(EVP_CAMELLIA_KEY), 394 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
395 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 395 .set_asn1_parameters = NULL,
396 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 396 .get_asn1_parameters = NULL,
397 .ctrl = NULL, 397 .ctrl = NULL,
398}; 398};
399 399
@@ -479,13 +479,13 @@ static const EVP_CIPHER camellia_256_cbc = {
479 .block_size = 16, 479 .block_size = 16,
480 .key_len = 32, 480 .key_len = 32,
481 .iv_len = 16, 481 .iv_len = 16,
482 .flags = 0 | EVP_CIPH_CBC_MODE, 482 .flags = EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1,
483 .init = camellia_init_key, 483 .init = camellia_init_key,
484 .do_cipher = camellia_256_cbc_cipher, 484 .do_cipher = camellia_256_cbc_cipher,
485 .cleanup = NULL, 485 .cleanup = NULL,
486 .ctx_size = sizeof(EVP_CAMELLIA_KEY), 486 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
487 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 487 .set_asn1_parameters = NULL,
488 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 488 .get_asn1_parameters = NULL,
489 .ctrl = NULL, 489 .ctrl = NULL,
490}; 490};
491 491
@@ -501,13 +501,13 @@ static const EVP_CIPHER camellia_256_cfb128 = {
501 .block_size = 1, 501 .block_size = 1,
502 .key_len = 32, 502 .key_len = 32,
503 .iv_len = 16, 503 .iv_len = 16,
504 .flags = 0 | EVP_CIPH_CFB_MODE, 504 .flags = EVP_CIPH_CFB_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1,
505 .init = camellia_init_key, 505 .init = camellia_init_key,
506 .do_cipher = camellia_256_cfb128_cipher, 506 .do_cipher = camellia_256_cfb128_cipher,
507 .cleanup = NULL, 507 .cleanup = NULL,
508 .ctx_size = sizeof(EVP_CAMELLIA_KEY), 508 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
509 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 509 .set_asn1_parameters = NULL,
510 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 510 .get_asn1_parameters = NULL,
511 .ctrl = NULL, 511 .ctrl = NULL,
512}; 512};
513 513
@@ -523,13 +523,13 @@ static const EVP_CIPHER camellia_256_ofb = {
523 .block_size = 1, 523 .block_size = 1,
524 .key_len = 32, 524 .key_len = 32,
525 .iv_len = 16, 525 .iv_len = 16,
526 .flags = 0 | EVP_CIPH_OFB_MODE, 526 .flags = EVP_CIPH_OFB_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1,
527 .init = camellia_init_key, 527 .init = camellia_init_key,
528 .do_cipher = camellia_256_ofb_cipher, 528 .do_cipher = camellia_256_ofb_cipher,
529 .cleanup = NULL, 529 .cleanup = NULL,
530 .ctx_size = sizeof(EVP_CAMELLIA_KEY), 530 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
531 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 531 .set_asn1_parameters = NULL,
532 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 532 .get_asn1_parameters = NULL,
533 .ctrl = NULL, 533 .ctrl = NULL,
534}; 534};
535 535
@@ -545,13 +545,13 @@ static const EVP_CIPHER camellia_256_ecb = {
545 .block_size = 16, 545 .block_size = 16,
546 .key_len = 32, 546 .key_len = 32,
547 .iv_len = 0, 547 .iv_len = 0,
548 .flags = 0 | EVP_CIPH_ECB_MODE, 548 .flags = EVP_CIPH_ECB_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1,
549 .init = camellia_init_key, 549 .init = camellia_init_key,
550 .do_cipher = camellia_256_ecb_cipher, 550 .do_cipher = camellia_256_ecb_cipher,
551 .cleanup = NULL, 551 .cleanup = NULL,
552 .ctx_size = sizeof(EVP_CAMELLIA_KEY), 552 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
553 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 553 .set_asn1_parameters = NULL,
554 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 554 .get_asn1_parameters = NULL,
555 .ctrl = NULL, 555 .ctrl = NULL,
556}; 556};
557 557
@@ -589,13 +589,13 @@ static const EVP_CIPHER camellia_128_cfb1 = {
589 .block_size = 1, 589 .block_size = 1,
590 .key_len = 128/8, 590 .key_len = 128/8,
591 .iv_len = 16, 591 .iv_len = 16,
592 .flags = 0 | EVP_CIPH_CFB_MODE, 592 .flags = EVP_CIPH_CFB_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1,
593 .init = camellia_init_key, 593 .init = camellia_init_key,
594 .do_cipher = camellia_128_cfb1_cipher, 594 .do_cipher = camellia_128_cfb1_cipher,
595 .cleanup = NULL, 595 .cleanup = NULL,
596 .ctx_size = sizeof(EVP_CAMELLIA_KEY), 596 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
597 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 597 .set_asn1_parameters = NULL,
598 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 598 .get_asn1_parameters = NULL,
599 .ctrl = NULL, 599 .ctrl = NULL,
600}; 600};
601 601
@@ -633,13 +633,13 @@ static const EVP_CIPHER camellia_192_cfb1 = {
633 .block_size = 1, 633 .block_size = 1,
634 .key_len = 192/8, 634 .key_len = 192/8,
635 .iv_len = 16, 635 .iv_len = 16,
636 .flags = 0 | EVP_CIPH_CFB_MODE, 636 .flags = EVP_CIPH_CFB_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1,
637 .init = camellia_init_key, 637 .init = camellia_init_key,
638 .do_cipher = camellia_192_cfb1_cipher, 638 .do_cipher = camellia_192_cfb1_cipher,
639 .cleanup = NULL, 639 .cleanup = NULL,
640 .ctx_size = sizeof(EVP_CAMELLIA_KEY), 640 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
641 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 641 .set_asn1_parameters = NULL,
642 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 642 .get_asn1_parameters = NULL,
643 .ctrl = NULL, 643 .ctrl = NULL,
644}; 644};
645 645
@@ -677,13 +677,13 @@ static const EVP_CIPHER camellia_256_cfb1 = {
677 .block_size = 1, 677 .block_size = 1,
678 .key_len = 256/8, 678 .key_len = 256/8,
679 .iv_len = 16, 679 .iv_len = 16,
680 .flags = 0 | EVP_CIPH_CFB_MODE, 680 .flags = EVP_CIPH_CFB_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1,
681 .init = camellia_init_key, 681 .init = camellia_init_key,
682 .do_cipher = camellia_256_cfb1_cipher, 682 .do_cipher = camellia_256_cfb1_cipher,
683 .cleanup = NULL, 683 .cleanup = NULL,
684 .ctx_size = sizeof(EVP_CAMELLIA_KEY), 684 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
685 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 685 .set_asn1_parameters = NULL,
686 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 686 .get_asn1_parameters = NULL,
687 .ctrl = NULL, 687 .ctrl = NULL,
688}; 688};
689 689
@@ -720,13 +720,13 @@ static const EVP_CIPHER camellia_128_cfb8 = {
720 .block_size = 1, 720 .block_size = 1,
721 .key_len = 128/8, 721 .key_len = 128/8,
722 .iv_len = 16, 722 .iv_len = 16,
723 .flags = 0 | EVP_CIPH_CFB_MODE, 723 .flags = EVP_CIPH_CFB_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1,
724 .init = camellia_init_key, 724 .init = camellia_init_key,
725 .do_cipher = camellia_128_cfb8_cipher, 725 .do_cipher = camellia_128_cfb8_cipher,
726 .cleanup = NULL, 726 .cleanup = NULL,
727 .ctx_size = sizeof(EVP_CAMELLIA_KEY), 727 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
728 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 728 .set_asn1_parameters = NULL,
729 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 729 .get_asn1_parameters = NULL,
730 .ctrl = NULL, 730 .ctrl = NULL,
731}; 731};
732 732
@@ -762,13 +762,13 @@ static const EVP_CIPHER camellia_192_cfb8 = {
762 .block_size = 1, 762 .block_size = 1,
763 .key_len = 192/8, 763 .key_len = 192/8,
764 .iv_len = 16, 764 .iv_len = 16,
765 .flags = 0 | EVP_CIPH_CFB_MODE, 765 .flags = EVP_CIPH_CFB_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1,
766 .init = camellia_init_key, 766 .init = camellia_init_key,
767 .do_cipher = camellia_192_cfb8_cipher, 767 .do_cipher = camellia_192_cfb8_cipher,
768 .cleanup = NULL, 768 .cleanup = NULL,
769 .ctx_size = sizeof(EVP_CAMELLIA_KEY), 769 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
770 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 770 .set_asn1_parameters = NULL,
771 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 771 .get_asn1_parameters = NULL,
772 .ctrl = NULL, 772 .ctrl = NULL,
773}; 773};
774 774
@@ -804,13 +804,13 @@ static const EVP_CIPHER camellia_256_cfb8 = {
804 .block_size = 1, 804 .block_size = 1,
805 .key_len = 256/8, 805 .key_len = 256/8,
806 .iv_len = 16, 806 .iv_len = 16,
807 .flags = 0 | EVP_CIPH_CFB_MODE, 807 .flags = EVP_CIPH_CFB_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1,
808 .init = camellia_init_key, 808 .init = camellia_init_key,
809 .do_cipher = camellia_256_cfb8_cipher, 809 .do_cipher = camellia_256_cfb8_cipher,
810 .cleanup = NULL, 810 .cleanup = NULL,
811 .ctx_size = sizeof(EVP_CAMELLIA_KEY), 811 .ctx_size = sizeof(EVP_CAMELLIA_KEY),
812 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 812 .set_asn1_parameters = NULL,
813 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 813 .get_asn1_parameters = NULL,
814 .ctrl = NULL, 814 .ctrl = NULL,
815}; 815};
816 816
diff --git a/src/lib/libcrypto/evp/e_cast.c b/src/lib/libcrypto/evp/e_cast.c
index 1575a7a5bb..283cb8cf63 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.18 2024/04/09 13:52:41 beck Exp $ */ 1/* $OpenBSD: e_cast.c,v 1.19 2025/05/27 03:58:12 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 *
@@ -162,13 +162,14 @@ static const EVP_CIPHER cast5_cbc = {
162 .block_size = 8, 162 .block_size = 8,
163 .key_len = CAST_KEY_LENGTH, 163 .key_len = CAST_KEY_LENGTH,
164 .iv_len = 8, 164 .iv_len = 8,
165 .flags = EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CBC_MODE, 165 .flags = EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CBC_MODE |
166 EVP_CIPH_FLAG_DEFAULT_ASN1,
166 .init = cast_init_key, 167 .init = cast_init_key,
167 .do_cipher = cast5_cbc_cipher, 168 .do_cipher = cast5_cbc_cipher,
168 .cleanup = NULL, 169 .cleanup = NULL,
169 .ctx_size = sizeof(EVP_CAST_KEY), 170 .ctx_size = sizeof(EVP_CAST_KEY),
170 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 171 .set_asn1_parameters = NULL,
171 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 172 .get_asn1_parameters = NULL,
172 .ctrl = NULL, 173 .ctrl = NULL,
173}; 174};
174 175
@@ -184,13 +185,14 @@ static const EVP_CIPHER cast5_cfb64 = {
184 .block_size = 1, 185 .block_size = 1,
185 .key_len = CAST_KEY_LENGTH, 186 .key_len = CAST_KEY_LENGTH,
186 .iv_len = 8, 187 .iv_len = 8,
187 .flags = EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CFB_MODE, 188 .flags = EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CFB_MODE |
189 EVP_CIPH_FLAG_DEFAULT_ASN1,
188 .init = cast_init_key, 190 .init = cast_init_key,
189 .do_cipher = cast5_cfb64_cipher, 191 .do_cipher = cast5_cfb64_cipher,
190 .cleanup = NULL, 192 .cleanup = NULL,
191 .ctx_size = sizeof(EVP_CAST_KEY), 193 .ctx_size = sizeof(EVP_CAST_KEY),
192 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 194 .set_asn1_parameters = NULL,
193 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 195 .get_asn1_parameters = NULL,
194 .ctrl = NULL, 196 .ctrl = NULL,
195}; 197};
196 198
@@ -206,13 +208,14 @@ static const EVP_CIPHER cast5_ofb = {
206 .block_size = 1, 208 .block_size = 1,
207 .key_len = CAST_KEY_LENGTH, 209 .key_len = CAST_KEY_LENGTH,
208 .iv_len = 8, 210 .iv_len = 8,
209 .flags = EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_OFB_MODE, 211 .flags = EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_OFB_MODE |
212 EVP_CIPH_FLAG_DEFAULT_ASN1,
210 .init = cast_init_key, 213 .init = cast_init_key,
211 .do_cipher = cast5_ofb_cipher, 214 .do_cipher = cast5_ofb_cipher,
212 .cleanup = NULL, 215 .cleanup = NULL,
213 .ctx_size = sizeof(EVP_CAST_KEY), 216 .ctx_size = sizeof(EVP_CAST_KEY),
214 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 217 .set_asn1_parameters = NULL,
215 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 218 .get_asn1_parameters = NULL,
216 .ctrl = NULL, 219 .ctrl = NULL,
217}; 220};
218 221
@@ -228,13 +231,14 @@ static const EVP_CIPHER cast5_ecb = {
228 .block_size = 8, 231 .block_size = 8,
229 .key_len = CAST_KEY_LENGTH, 232 .key_len = CAST_KEY_LENGTH,
230 .iv_len = 0, 233 .iv_len = 0,
231 .flags = EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_ECB_MODE, 234 .flags = EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_ECB_MODE |
235 EVP_CIPH_FLAG_DEFAULT_ASN1,
232 .init = cast_init_key, 236 .init = cast_init_key,
233 .do_cipher = cast5_ecb_cipher, 237 .do_cipher = cast5_ecb_cipher,
234 .cleanup = NULL, 238 .cleanup = NULL,
235 .ctx_size = sizeof(EVP_CAST_KEY), 239 .ctx_size = sizeof(EVP_CAST_KEY),
236 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 240 .set_asn1_parameters = NULL,
237 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 241 .get_asn1_parameters = NULL,
238 .ctrl = NULL, 242 .ctrl = NULL,
239}; 243};
240 244
diff --git a/src/lib/libcrypto/evp/e_chacha20poly1305.c b/src/lib/libcrypto/evp/e_chacha20poly1305.c
index d176569f90..d3a1e44875 100644
--- a/src/lib/libcrypto/evp/e_chacha20poly1305.c
+++ b/src/lib/libcrypto/evp/e_chacha20poly1305.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_chacha20poly1305.c,v 1.37 2024/12/20 20:05:29 schwarze Exp $ */ 1/* $OpenBSD: e_chacha20poly1305.c,v 1.38 2025/05/10 05:54:38 tb Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2022 Joel Sing <jsing@openbsd.org> 4 * Copyright (c) 2022 Joel Sing <jsing@openbsd.org>
@@ -26,12 +26,12 @@
26 26
27#if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305) 27#if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
28 28
29#include <openssl/err.h>
30#include <openssl/evp.h> 29#include <openssl/evp.h>
31#include <openssl/chacha.h> 30#include <openssl/chacha.h>
32#include <openssl/poly1305.h> 31#include <openssl/poly1305.h>
33 32
34#include "bytestring.h" 33#include "bytestring.h"
34#include "err_local.h"
35#include "evp_local.h" 35#include "evp_local.h"
36 36
37#define POLY1305_TAG_LEN 16 37#define POLY1305_TAG_LEN 16
diff --git a/src/lib/libcrypto/evp/e_des.c b/src/lib/libcrypto/evp/e_des.c
index fb335e95b1..680f77a723 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.24 2024/04/09 13:52:41 beck Exp $ */ 1/* $OpenBSD: e_des.c,v 1.25 2025/05/27 03:58:12 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 *
@@ -226,13 +226,14 @@ static const EVP_CIPHER des_cbc = {
226 .block_size = 8, 226 .block_size = 8,
227 .key_len = 8, 227 .key_len = 8,
228 .iv_len = 8, 228 .iv_len = 8,
229 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_CBC_MODE, 229 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_CBC_MODE |
230 EVP_CIPH_FLAG_DEFAULT_ASN1,
230 .init = des_init_key, 231 .init = des_init_key,
231 .do_cipher = des_cbc_cipher, 232 .do_cipher = des_cbc_cipher,
232 .cleanup = NULL, 233 .cleanup = NULL,
233 .ctx_size = sizeof(DES_key_schedule), 234 .ctx_size = sizeof(DES_key_schedule),
234 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 235 .set_asn1_parameters = NULL,
235 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 236 .get_asn1_parameters = NULL,
236 .ctrl = des_ctrl, 237 .ctrl = des_ctrl,
237}; 238};
238 239
@@ -248,13 +249,14 @@ static const EVP_CIPHER des_cfb64 = {
248 .block_size = 1, 249 .block_size = 1,
249 .key_len = 8, 250 .key_len = 8,
250 .iv_len = 8, 251 .iv_len = 8,
251 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_CFB_MODE, 252 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_CFB_MODE |
253 EVP_CIPH_FLAG_DEFAULT_ASN1,
252 .init = des_init_key, 254 .init = des_init_key,
253 .do_cipher = des_cfb64_cipher, 255 .do_cipher = des_cfb64_cipher,
254 .cleanup = NULL, 256 .cleanup = NULL,
255 .ctx_size = sizeof(DES_key_schedule), 257 .ctx_size = sizeof(DES_key_schedule),
256 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 258 .set_asn1_parameters = NULL,
257 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 259 .get_asn1_parameters = NULL,
258 .ctrl = des_ctrl, 260 .ctrl = des_ctrl,
259}; 261};
260 262
@@ -270,13 +272,14 @@ static const EVP_CIPHER des_ofb = {
270 .block_size = 1, 272 .block_size = 1,
271 .key_len = 8, 273 .key_len = 8,
272 .iv_len = 8, 274 .iv_len = 8,
273 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_OFB_MODE, 275 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_OFB_MODE |
276 EVP_CIPH_FLAG_DEFAULT_ASN1,
274 .init = des_init_key, 277 .init = des_init_key,
275 .do_cipher = des_ofb_cipher, 278 .do_cipher = des_ofb_cipher,
276 .cleanup = NULL, 279 .cleanup = NULL,
277 .ctx_size = sizeof(DES_key_schedule), 280 .ctx_size = sizeof(DES_key_schedule),
278 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 281 .set_asn1_parameters = NULL,
279 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 282 .get_asn1_parameters = NULL,
280 .ctrl = des_ctrl, 283 .ctrl = des_ctrl,
281}; 284};
282 285
@@ -292,13 +295,14 @@ static const EVP_CIPHER des_ecb = {
292 .block_size = 8, 295 .block_size = 8,
293 .key_len = 8, 296 .key_len = 8,
294 .iv_len = 0, 297 .iv_len = 0,
295 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_ECB_MODE, 298 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_ECB_MODE |
299 EVP_CIPH_FLAG_DEFAULT_ASN1,
296 .init = des_init_key, 300 .init = des_init_key,
297 .do_cipher = des_ecb_cipher, 301 .do_cipher = des_ecb_cipher,
298 .cleanup = NULL, 302 .cleanup = NULL,
299 .ctx_size = sizeof(DES_key_schedule), 303 .ctx_size = sizeof(DES_key_schedule),
300 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 304 .set_asn1_parameters = NULL,
301 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 305 .get_asn1_parameters = NULL,
302 .ctrl = des_ctrl, 306 .ctrl = des_ctrl,
303}; 307};
304 308
@@ -314,13 +318,14 @@ static const EVP_CIPHER des_cfb1 = {
314 .block_size = 1, 318 .block_size = 1,
315 .key_len = 8, 319 .key_len = 8,
316 .iv_len = 8, 320 .iv_len = 8,
317 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_CFB_MODE, 321 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_CFB_MODE |
322 EVP_CIPH_FLAG_DEFAULT_ASN1,
318 .init = des_init_key, 323 .init = des_init_key,
319 .do_cipher = des_cfb1_cipher, 324 .do_cipher = des_cfb1_cipher,
320 .cleanup = NULL, 325 .cleanup = NULL,
321 .ctx_size = sizeof(DES_key_schedule), 326 .ctx_size = sizeof(DES_key_schedule),
322 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 327 .set_asn1_parameters = NULL,
323 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 328 .get_asn1_parameters = NULL,
324 .ctrl = des_ctrl, 329 .ctrl = des_ctrl,
325}; 330};
326 331
@@ -336,13 +341,14 @@ static const EVP_CIPHER des_cfb8 = {
336 .block_size = 1, 341 .block_size = 1,
337 .key_len = 8, 342 .key_len = 8,
338 .iv_len = 8, 343 .iv_len = 8,
339 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_CFB_MODE, 344 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_CFB_MODE |
345 EVP_CIPH_FLAG_DEFAULT_ASN1,
340 .init = des_init_key, 346 .init = des_init_key,
341 .do_cipher = des_cfb8_cipher, 347 .do_cipher = des_cfb8_cipher,
342 .cleanup = NULL, 348 .cleanup = NULL,
343 .ctx_size = sizeof(DES_key_schedule), 349 .ctx_size = sizeof(DES_key_schedule),
344 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 350 .set_asn1_parameters = NULL,
345 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 351 .get_asn1_parameters = NULL,
346 .ctrl = des_ctrl, 352 .ctrl = des_ctrl,
347}; 353};
348 354
diff --git a/src/lib/libcrypto/evp/e_des3.c b/src/lib/libcrypto/evp/e_des3.c
index 48fbcdb366..f3eb4cce1b 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.30 2024/04/09 13:52:41 beck Exp $ */ 1/* $OpenBSD: e_des3.c,v 1.31 2025/05/27 03:58:12 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 *
@@ -258,13 +258,14 @@ static const EVP_CIPHER des_ede_cbc = {
258 .block_size = 8, 258 .block_size = 8,
259 .key_len = 16, 259 .key_len = 16,
260 .iv_len = 8, 260 .iv_len = 8,
261 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_CBC_MODE, 261 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_CBC_MODE |
262 EVP_CIPH_FLAG_DEFAULT_ASN1,
262 .init = des_ede_init_key, 263 .init = des_ede_init_key,
263 .do_cipher = des_ede_cbc_cipher, 264 .do_cipher = des_ede_cbc_cipher,
264 .cleanup = NULL, 265 .cleanup = NULL,
265 .ctx_size = sizeof(DES_EDE_KEY), 266 .ctx_size = sizeof(DES_EDE_KEY),
266 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 267 .set_asn1_parameters = NULL,
267 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 268 .get_asn1_parameters = NULL,
268 .ctrl = des3_ctrl, 269 .ctrl = des3_ctrl,
269}; 270};
270 271
@@ -280,13 +281,14 @@ static const EVP_CIPHER des_ede_cfb64 = {
280 .block_size = 1, 281 .block_size = 1,
281 .key_len = 16, 282 .key_len = 16,
282 .iv_len = 8, 283 .iv_len = 8,
283 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_CFB_MODE, 284 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_CFB_MODE |
285 EVP_CIPH_FLAG_DEFAULT_ASN1,
284 .init = des_ede_init_key, 286 .init = des_ede_init_key,
285 .do_cipher = des_ede_cfb64_cipher, 287 .do_cipher = des_ede_cfb64_cipher,
286 .cleanup = NULL, 288 .cleanup = NULL,
287 .ctx_size = sizeof(DES_EDE_KEY), 289 .ctx_size = sizeof(DES_EDE_KEY),
288 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 290 .set_asn1_parameters = NULL,
289 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 291 .get_asn1_parameters = NULL,
290 .ctrl = des3_ctrl, 292 .ctrl = des3_ctrl,
291}; 293};
292 294
@@ -307,8 +309,8 @@ static const EVP_CIPHER des_ede_ofb = {
307 .do_cipher = des_ede_ofb_cipher, 309 .do_cipher = des_ede_ofb_cipher,
308 .cleanup = NULL, 310 .cleanup = NULL,
309 .ctx_size = sizeof(DES_EDE_KEY), 311 .ctx_size = sizeof(DES_EDE_KEY),
310 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 312 .set_asn1_parameters = NULL,
311 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 313 .get_asn1_parameters = NULL,
312 .ctrl = des3_ctrl, 314 .ctrl = des3_ctrl,
313}; 315};
314 316
@@ -324,13 +326,14 @@ static const EVP_CIPHER des_ede_ecb = {
324 .block_size = 8, 326 .block_size = 8,
325 .key_len = 16, 327 .key_len = 16,
326 .iv_len = 0, 328 .iv_len = 0,
327 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_ECB_MODE, 329 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_ECB_MODE |
330 EVP_CIPH_FLAG_DEFAULT_ASN1,
328 .init = des_ede_init_key, 331 .init = des_ede_init_key,
329 .do_cipher = des_ede_ecb_cipher, 332 .do_cipher = des_ede_ecb_cipher,
330 .cleanup = NULL, 333 .cleanup = NULL,
331 .ctx_size = sizeof(DES_EDE_KEY), 334 .ctx_size = sizeof(DES_EDE_KEY),
332 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 335 .set_asn1_parameters = NULL,
333 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 336 .get_asn1_parameters = NULL,
334 .ctrl = des3_ctrl, 337 .ctrl = des3_ctrl,
335}; 338};
336 339
@@ -352,13 +355,14 @@ static const EVP_CIPHER des_ede3_cbc = {
352 .block_size = 8, 355 .block_size = 8,
353 .key_len = 24, 356 .key_len = 24,
354 .iv_len = 8, 357 .iv_len = 8,
355 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_CBC_MODE, 358 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_CBC_MODE |
359 EVP_CIPH_FLAG_DEFAULT_ASN1,
356 .init = des_ede3_init_key, 360 .init = des_ede3_init_key,
357 .do_cipher = des_ede3_cbc_cipher, 361 .do_cipher = des_ede3_cbc_cipher,
358 .cleanup = NULL, 362 .cleanup = NULL,
359 .ctx_size = sizeof(DES_EDE_KEY), 363 .ctx_size = sizeof(DES_EDE_KEY),
360 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 364 .set_asn1_parameters = NULL,
361 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 365 .get_asn1_parameters = NULL,
362 .ctrl = des3_ctrl, 366 .ctrl = des3_ctrl,
363}; 367};
364 368
@@ -374,13 +378,14 @@ static const EVP_CIPHER des_ede3_cfb64 = {
374 .block_size = 1, 378 .block_size = 1,
375 .key_len = 24, 379 .key_len = 24,
376 .iv_len = 8, 380 .iv_len = 8,
377 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_CFB_MODE, 381 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_CFB_MODE |
382 EVP_CIPH_FLAG_DEFAULT_ASN1,
378 .init = des_ede3_init_key, 383 .init = des_ede3_init_key,
379 .do_cipher = des_ede3_cfb64_cipher, 384 .do_cipher = des_ede3_cfb64_cipher,
380 .cleanup = NULL, 385 .cleanup = NULL,
381 .ctx_size = sizeof(DES_EDE_KEY), 386 .ctx_size = sizeof(DES_EDE_KEY),
382 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 387 .set_asn1_parameters = NULL,
383 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 388 .get_asn1_parameters = NULL,
384 .ctrl = des3_ctrl, 389 .ctrl = des3_ctrl,
385}; 390};
386 391
@@ -396,13 +401,14 @@ static const EVP_CIPHER des_ede3_ofb = {
396 .block_size = 1, 401 .block_size = 1,
397 .key_len = 24, 402 .key_len = 24,
398 .iv_len = 8, 403 .iv_len = 8,
399 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_OFB_MODE, 404 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_OFB_MODE |
405 EVP_CIPH_FLAG_DEFAULT_ASN1,
400 .init = des_ede3_init_key, 406 .init = des_ede3_init_key,
401 .do_cipher = des_ede3_ofb_cipher, 407 .do_cipher = des_ede3_ofb_cipher,
402 .cleanup = NULL, 408 .cleanup = NULL,
403 .ctx_size = sizeof(DES_EDE_KEY), 409 .ctx_size = sizeof(DES_EDE_KEY),
404 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 410 .set_asn1_parameters = NULL,
405 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 411 .get_asn1_parameters = NULL,
406 .ctrl = des3_ctrl, 412 .ctrl = des3_ctrl,
407}; 413};
408 414
@@ -418,13 +424,14 @@ static const EVP_CIPHER des_ede3_ecb = {
418 .block_size = 8, 424 .block_size = 8,
419 .key_len = 24, 425 .key_len = 24,
420 .iv_len = 0, 426 .iv_len = 0,
421 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_ECB_MODE, 427 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_ECB_MODE |
428 EVP_CIPH_FLAG_DEFAULT_ASN1,
422 .init = des_ede3_init_key, 429 .init = des_ede3_init_key,
423 .do_cipher = des_ede3_ecb_cipher, 430 .do_cipher = des_ede3_ecb_cipher,
424 .cleanup = NULL, 431 .cleanup = NULL,
425 .ctx_size = sizeof(DES_EDE_KEY), 432 .ctx_size = sizeof(DES_EDE_KEY),
426 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 433 .set_asn1_parameters = NULL,
427 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 434 .get_asn1_parameters = NULL,
428 .ctrl = des3_ctrl, 435 .ctrl = des3_ctrl,
429}; 436};
430 437
@@ -441,13 +448,14 @@ static const EVP_CIPHER des_ede3_cfb1 = {
441 .block_size = 1, 448 .block_size = 1,
442 .key_len = 24, 449 .key_len = 24,
443 .iv_len = 8, 450 .iv_len = 8,
444 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_CFB_MODE, 451 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_CFB_MODE |
452 EVP_CIPH_FLAG_DEFAULT_ASN1,
445 .init = des_ede3_init_key, 453 .init = des_ede3_init_key,
446 .do_cipher = des_ede3_cfb1_cipher, 454 .do_cipher = des_ede3_cfb1_cipher,
447 .cleanup = NULL, 455 .cleanup = NULL,
448 .ctx_size = sizeof(DES_EDE_KEY), 456 .ctx_size = sizeof(DES_EDE_KEY),
449 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 457 .set_asn1_parameters = NULL,
450 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 458 .get_asn1_parameters = NULL,
451 .ctrl = des3_ctrl, 459 .ctrl = des3_ctrl,
452}; 460};
453 461
@@ -464,13 +472,14 @@ static const EVP_CIPHER des_ede3_cfb8 = {
464 .block_size = 1, 472 .block_size = 1,
465 .key_len = 24, 473 .key_len = 24,
466 .iv_len = 8, 474 .iv_len = 8,
467 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_CFB_MODE, 475 .flags = EVP_CIPH_RAND_KEY | EVP_CIPH_CFB_MODE |
476 EVP_CIPH_FLAG_DEFAULT_ASN1,
468 .init = des_ede3_init_key, 477 .init = des_ede3_init_key,
469 .do_cipher = des_ede3_cfb8_cipher, 478 .do_cipher = des_ede3_cfb8_cipher,
470 .cleanup = NULL, 479 .cleanup = NULL,
471 .ctx_size = sizeof(DES_EDE_KEY), 480 .ctx_size = sizeof(DES_EDE_KEY),
472 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 481 .set_asn1_parameters = NULL,
473 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 482 .get_asn1_parameters = NULL,
474 .ctrl = des3_ctrl, 483 .ctrl = des3_ctrl,
475}; 484};
476 485
diff --git a/src/lib/libcrypto/evp/e_idea.c b/src/lib/libcrypto/evp/e_idea.c
index 86cf77602a..5d33a110fd 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.22 2024/04/09 13:52:41 beck Exp $ */ 1/* $OpenBSD: e_idea.c,v 1.23 2025/05/27 03:58:12 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 *
@@ -181,13 +181,13 @@ static const EVP_CIPHER idea_cbc = {
181 .block_size = 8, 181 .block_size = 8,
182 .key_len = 16, 182 .key_len = 16,
183 .iv_len = 8, 183 .iv_len = 8,
184 .flags = 0 | EVP_CIPH_CBC_MODE, 184 .flags = EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1,
185 .init = idea_init_key, 185 .init = idea_init_key,
186 .do_cipher = idea_cbc_cipher, 186 .do_cipher = idea_cbc_cipher,
187 .cleanup = NULL, 187 .cleanup = NULL,
188 .ctx_size = sizeof(IDEA_KEY_SCHEDULE), 188 .ctx_size = sizeof(IDEA_KEY_SCHEDULE),
189 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 189 .set_asn1_parameters = NULL,
190 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 190 .get_asn1_parameters = NULL,
191 .ctrl = NULL, 191 .ctrl = NULL,
192}; 192};
193 193
@@ -203,13 +203,13 @@ static const EVP_CIPHER idea_cfb64 = {
203 .block_size = 1, 203 .block_size = 1,
204 .key_len = 16, 204 .key_len = 16,
205 .iv_len = 8, 205 .iv_len = 8,
206 .flags = 0 | EVP_CIPH_CFB_MODE, 206 .flags = EVP_CIPH_CFB_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1,
207 .init = idea_init_key, 207 .init = idea_init_key,
208 .do_cipher = idea_cfb64_cipher, 208 .do_cipher = idea_cfb64_cipher,
209 .cleanup = NULL, 209 .cleanup = NULL,
210 .ctx_size = sizeof(IDEA_KEY_SCHEDULE), 210 .ctx_size = sizeof(IDEA_KEY_SCHEDULE),
211 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 211 .set_asn1_parameters = NULL,
212 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 212 .get_asn1_parameters = NULL,
213 .ctrl = NULL, 213 .ctrl = NULL,
214}; 214};
215 215
@@ -225,13 +225,13 @@ static const EVP_CIPHER idea_ofb = {
225 .block_size = 1, 225 .block_size = 1,
226 .key_len = 16, 226 .key_len = 16,
227 .iv_len = 8, 227 .iv_len = 8,
228 .flags = 0 | EVP_CIPH_OFB_MODE, 228 .flags = EVP_CIPH_OFB_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1,
229 .init = idea_init_key, 229 .init = idea_init_key,
230 .do_cipher = idea_ofb_cipher, 230 .do_cipher = idea_ofb_cipher,
231 .cleanup = NULL, 231 .cleanup = NULL,
232 .ctx_size = sizeof(IDEA_KEY_SCHEDULE), 232 .ctx_size = sizeof(IDEA_KEY_SCHEDULE),
233 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 233 .set_asn1_parameters = NULL,
234 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 234 .get_asn1_parameters = NULL,
235 .ctrl = NULL, 235 .ctrl = NULL,
236}; 236};
237 237
@@ -247,13 +247,13 @@ static const EVP_CIPHER idea_ecb = {
247 .block_size = 8, 247 .block_size = 8,
248 .key_len = 16, 248 .key_len = 16,
249 .iv_len = 0, 249 .iv_len = 0,
250 .flags = 0 | EVP_CIPH_ECB_MODE, 250 .flags = EVP_CIPH_ECB_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1,
251 .init = idea_init_key, 251 .init = idea_init_key,
252 .do_cipher = idea_ecb_cipher, 252 .do_cipher = idea_ecb_cipher,
253 .cleanup = NULL, 253 .cleanup = NULL,
254 .ctx_size = sizeof(IDEA_KEY_SCHEDULE), 254 .ctx_size = sizeof(IDEA_KEY_SCHEDULE),
255 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 255 .set_asn1_parameters = NULL,
256 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 256 .get_asn1_parameters = NULL,
257 .ctrl = NULL, 257 .ctrl = NULL,
258}; 258};
259 259
diff --git a/src/lib/libcrypto/evp/e_rc2.c b/src/lib/libcrypto/evp/e_rc2.c
index dc404cff20..b7ba60297a 100644
--- a/src/lib/libcrypto/evp/e_rc2.c
+++ b/src/lib/libcrypto/evp/e_rc2.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_rc2.c,v 1.29 2024/04/09 13:52:41 beck Exp $ */ 1/* $OpenBSD: e_rc2.c,v 1.30 2025/05/10 05:54:38 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 *
@@ -63,11 +63,11 @@
63 63
64#ifndef OPENSSL_NO_RC2 64#ifndef OPENSSL_NO_RC2
65 65
66#include <openssl/err.h>
67#include <openssl/evp.h> 66#include <openssl/evp.h>
68#include <openssl/objects.h> 67#include <openssl/objects.h>
69#include <openssl/rc2.h> 68#include <openssl/rc2.h>
70 69
70#include "err_local.h"
71#include "evp_local.h" 71#include "evp_local.h"
72 72
73static int rc2_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, 73static int rc2_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
diff --git a/src/lib/libcrypto/evp/e_xcbc_d.c b/src/lib/libcrypto/evp/e_xcbc_d.c
index 1e3bee0791..1c5e6c32b2 100644
--- a/src/lib/libcrypto/evp/e_xcbc_d.c
+++ b/src/lib/libcrypto/evp/e_xcbc_d.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_xcbc_d.c,v 1.18 2024/04/09 13:52:41 beck Exp $ */ 1/* $OpenBSD: e_xcbc_d.c,v 1.19 2025/05/27 03:58:12 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 *
@@ -88,13 +88,13 @@ static const EVP_CIPHER d_xcbc_cipher = {
88 .block_size = 8, 88 .block_size = 8,
89 .key_len = 24, 89 .key_len = 24,
90 .iv_len = 8, 90 .iv_len = 8,
91 .flags = EVP_CIPH_CBC_MODE, 91 .flags = EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1,
92 .init = desx_cbc_init_key, 92 .init = desx_cbc_init_key,
93 .do_cipher = desx_cbc_cipher, 93 .do_cipher = desx_cbc_cipher,
94 .cleanup = NULL, 94 .cleanup = NULL,
95 .ctx_size = sizeof(DESX_CBC_KEY), 95 .ctx_size = sizeof(DESX_CBC_KEY),
96 .set_asn1_parameters = EVP_CIPHER_set_asn1_iv, 96 .set_asn1_parameters = NULL,
97 .get_asn1_parameters = EVP_CIPHER_get_asn1_iv, 97 .get_asn1_parameters = NULL,
98 .ctrl = NULL, 98 .ctrl = NULL,
99}; 99};
100 100
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h
index c2b81d0576..94295e1262 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.137 2024/08/31 10:38:49 tb Exp $ */ 1/* $OpenBSD: evp.h,v 1.138 2025/07/02 06:36:52 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 *
@@ -778,28 +778,24 @@ void *EVP_PKEY_get0(const EVP_PKEY *pkey);
778const unsigned char *EVP_PKEY_get0_hmac(const EVP_PKEY *pkey, size_t *len); 778const unsigned char *EVP_PKEY_get0_hmac(const EVP_PKEY *pkey, size_t *len);
779 779
780#ifndef OPENSSL_NO_RSA 780#ifndef OPENSSL_NO_RSA
781struct rsa_st; 781RSA *EVP_PKEY_get0_RSA(const EVP_PKEY *pkey);
782struct rsa_st *EVP_PKEY_get0_RSA(EVP_PKEY *pkey); 782RSA *EVP_PKEY_get1_RSA(const EVP_PKEY *pkey);
783struct rsa_st *EVP_PKEY_get1_RSA(EVP_PKEY *pkey); 783int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key);
784int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, struct rsa_st *key);
785#endif 784#endif
786#ifndef OPENSSL_NO_DSA 785#ifndef OPENSSL_NO_DSA
787struct dsa_st; 786DSA *EVP_PKEY_get0_DSA(const EVP_PKEY *pkey);
788struct dsa_st *EVP_PKEY_get0_DSA(EVP_PKEY *pkey); 787DSA *EVP_PKEY_get1_DSA(const EVP_PKEY *pkey);
789struct dsa_st *EVP_PKEY_get1_DSA(EVP_PKEY *pkey); 788int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key);
790int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, struct dsa_st *key);
791#endif 789#endif
792#ifndef OPENSSL_NO_DH 790#ifndef OPENSSL_NO_DH
793struct dh_st; 791DH *EVP_PKEY_get0_DH(const EVP_PKEY *pkey);
794struct dh_st *EVP_PKEY_get0_DH(EVP_PKEY *pkey); 792DH *EVP_PKEY_get1_DH(const EVP_PKEY *pkey);
795struct dh_st *EVP_PKEY_get1_DH(EVP_PKEY *pkey); 793int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key);
796int EVP_PKEY_set1_DH(EVP_PKEY *pkey, struct dh_st *key);
797#endif 794#endif
798#ifndef OPENSSL_NO_EC 795#ifndef OPENSSL_NO_EC
799struct ec_key_st; 796EC_KEY *EVP_PKEY_get0_EC_KEY(const EVP_PKEY *pkey);
800struct ec_key_st *EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey); 797EC_KEY *EVP_PKEY_get1_EC_KEY(const EVP_PKEY *pkey);
801struct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey); 798int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key);
802int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, struct ec_key_st *key);
803#endif 799#endif
804 800
805EVP_PKEY *EVP_PKEY_new(void); 801EVP_PKEY *EVP_PKEY_new(void);
diff --git a/src/lib/libcrypto/evp/evp_aead.c b/src/lib/libcrypto/evp/evp_aead.c
index b35f5157ed..fdac082217 100644
--- a/src/lib/libcrypto/evp/evp_aead.c
+++ b/src/lib/libcrypto/evp/evp_aead.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_aead.c,v 1.11 2024/04/09 13:52:41 beck Exp $ */ 1/* $OpenBSD: evp_aead.c,v 1.12 2025/05/10 05:54:38 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2014, Google Inc. 3 * Copyright (c) 2014, Google Inc.
4 * 4 *
@@ -19,8 +19,8 @@
19#include <string.h> 19#include <string.h>
20 20
21#include <openssl/evp.h> 21#include <openssl/evp.h>
22#include <openssl/err.h>
23 22
23#include "err_local.h"
24#include "evp_local.h" 24#include "evp_local.h"
25 25
26size_t 26size_t
diff --git a/src/lib/libcrypto/evp/evp_cipher.c b/src/lib/libcrypto/evp/evp_cipher.c
index e9c266d1b9..04e0e1c0b0 100644
--- a/src/lib/libcrypto/evp/evp_cipher.c
+++ b/src/lib/libcrypto/evp/evp_cipher.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_cipher.c,v 1.23 2024/04/10 15:00:38 beck Exp $ */ 1/* $OpenBSD: evp_cipher.c,v 1.28 2025/07/02 06:19:46 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 *
@@ -115,10 +115,10 @@
115#include <string.h> 115#include <string.h>
116 116
117#include <openssl/asn1.h> 117#include <openssl/asn1.h>
118#include <openssl/err.h>
119#include <openssl/evp.h> 118#include <openssl/evp.h>
120 119
121#include "asn1_local.h" 120#include "asn1_local.h"
121#include "err_local.h"
122#include "evp_local.h" 122#include "evp_local.h"
123 123
124int 124int
@@ -167,7 +167,7 @@ EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *engine,
167 } 167 }
168 168
169 if ((ctx->cipher->flags & EVP_CIPH_CTRL_INIT) != 0) { 169 if ((ctx->cipher->flags & EVP_CIPH_CTRL_INIT) != 0) {
170 if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_INIT, 0, NULL)) { 170 if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_INIT, 0, NULL) <= 0) {
171 EVPerror(EVP_R_INITIALIZATION_ERROR); 171 EVPerror(EVP_R_INITIALIZATION_ERROR);
172 return 0; 172 return 0;
173 } 173 }
@@ -944,14 +944,20 @@ EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *ctx)
944LCRYPTO_ALIAS(EVP_CIPHER_CTX_flags); 944LCRYPTO_ALIAS(EVP_CIPHER_CTX_flags);
945 945
946/* 946/*
947 * Used by CMS and its predecessors. Only GOST and RC2 have a custom method. 947 * Used by CMS and its predecessors. Only RC2 has a custom method.
948 */ 948 */
949 949
950int 950int
951EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *ctx, ASN1_TYPE *type) 951EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *ctx, ASN1_TYPE *type)
952{ 952{
953 int iv_len; 953 int iv_len;
954 954
955 if (ctx->cipher->get_asn1_parameters != NULL)
956 return ctx->cipher->get_asn1_parameters(ctx, type);
957
958 if ((ctx->cipher->flags & EVP_CIPH_FLAG_DEFAULT_ASN1) == 0)
959 return -1;
960
955 if (type == NULL) 961 if (type == NULL)
956 return 0; 962 return 0;
957 963
@@ -970,21 +976,15 @@ EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *ctx, ASN1_TYPE *type)
970} 976}
971 977
972int 978int
973EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *ctx, ASN1_TYPE *type) 979EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *ctx, ASN1_TYPE *type)
974{ 980{
975 if (ctx->cipher->get_asn1_parameters != NULL) 981 int iv_len;
976 return ctx->cipher->get_asn1_parameters(ctx, type);
977
978 if ((ctx->cipher->flags & EVP_CIPH_FLAG_DEFAULT_ASN1) != 0)
979 return EVP_CIPHER_get_asn1_iv(ctx, type);
980 982
981 return -1; 983 if (ctx->cipher->set_asn1_parameters != NULL)
982} 984 return ctx->cipher->set_asn1_parameters(ctx, type);
983 985
984int 986 if ((ctx->cipher->flags & EVP_CIPH_FLAG_DEFAULT_ASN1) == 0)
985EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *ctx, ASN1_TYPE *type) 987 return -1;
986{
987 int iv_len;
988 988
989 if (type == NULL) 989 if (type == NULL)
990 return 0; 990 return 0;
@@ -998,18 +998,6 @@ EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *ctx, ASN1_TYPE *type)
998 return ASN1_TYPE_set_octetstring(type, ctx->oiv, iv_len); 998 return ASN1_TYPE_set_octetstring(type, ctx->oiv, iv_len);
999} 999}
1000 1000
1001int
1002EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *ctx, ASN1_TYPE *type)
1003{
1004 if (ctx->cipher->set_asn1_parameters != NULL)
1005 return ctx->cipher->set_asn1_parameters(ctx, type);
1006
1007 if ((ctx->cipher->flags & EVP_CIPH_FLAG_DEFAULT_ASN1) != 0)
1008 return EVP_CIPHER_set_asn1_iv(ctx, type);
1009
1010 return -1;
1011}
1012
1013/* Convert the various cipher NIDs and dummies to a proper OID NID */ 1001/* Convert the various cipher NIDs and dummies to a proper OID NID */
1014int 1002int
1015EVP_CIPHER_type(const EVP_CIPHER *cipher) 1003EVP_CIPHER_type(const EVP_CIPHER *cipher)
diff --git a/src/lib/libcrypto/evp/evp_digest.c b/src/lib/libcrypto/evp/evp_digest.c
index 0a97d25c7d..8bd6691fbf 100644
--- a/src/lib/libcrypto/evp/evp_digest.c
+++ b/src/lib/libcrypto/evp/evp_digest.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_digest.c,v 1.14 2024/04/10 15:00:38 beck Exp $ */ 1/* $OpenBSD: evp_digest.c,v 1.15 2025/05/10 05:54:38 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 *
@@ -114,10 +114,10 @@
114 114
115#include <openssl/opensslconf.h> 115#include <openssl/opensslconf.h>
116 116
117#include <openssl/err.h>
118#include <openssl/evp.h> 117#include <openssl/evp.h>
119#include <openssl/objects.h> 118#include <openssl/objects.h>
120 119
120#include "err_local.h"
121#include "evp_local.h" 121#include "evp_local.h"
122 122
123int 123int
diff --git a/src/lib/libcrypto/evp/evp_key.c b/src/lib/libcrypto/evp/evp_key.c
index e7c7ec3294..128bec0ac3 100644
--- a/src/lib/libcrypto/evp/evp_key.c
+++ b/src/lib/libcrypto/evp/evp_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_key.c,v 1.36 2024/04/09 13:52:41 beck Exp $ */ 1/* $OpenBSD: evp_key.c,v 1.37 2025/05/10 05:54:38 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 *
@@ -59,12 +59,12 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h> 60#include <string.h>
61 61
62#include <openssl/err.h>
63#include <openssl/evp.h> 62#include <openssl/evp.h>
64#include <openssl/objects.h> 63#include <openssl/objects.h>
65#include <openssl/ui.h> 64#include <openssl/ui.h>
66#include <openssl/x509.h> 65#include <openssl/x509.h>
67 66
67#include "err_local.h"
68#include "evp_local.h" 68#include "evp_local.h"
69 69
70/* should be init to zeros. */ 70/* should be init to zeros. */
diff --git a/src/lib/libcrypto/evp/evp_local.h b/src/lib/libcrypto/evp/evp_local.h
index 54cd65d0af..76465643c6 100644
--- a/src/lib/libcrypto/evp/evp_local.h
+++ b/src/lib/libcrypto/evp/evp_local.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_local.h,v 1.25 2024/08/29 16:58:19 tb Exp $ */ 1/* $OpenBSD: evp_local.h,v 1.26 2025/05/27 03:58:12 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -353,9 +353,7 @@ struct evp_aead_ctx_st {
353}; 353};
354 354
355/* Legacy EVP_CIPHER methods used by CMS and its predecessors. */ 355/* Legacy EVP_CIPHER methods used by CMS and its predecessors. */
356int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *cipher, ASN1_TYPE *type);
357int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *cipher, ASN1_TYPE *type); 356int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *cipher, ASN1_TYPE *type);
358int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *cipher, ASN1_TYPE *type);
359int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *cipher, ASN1_TYPE *type); 357int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *cipher, ASN1_TYPE *type);
360 358
361int EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen, 359int EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
diff --git a/src/lib/libcrypto/evp/evp_names.c b/src/lib/libcrypto/evp/evp_names.c
index 817d33602c..8757d191dd 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.18 2024/08/31 10:38:49 tb Exp $ */ 1/* $OpenBSD: evp_names.c,v 1.19 2025/05/10 05:54:38 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2023 Theo Buehler <tb@openbsd.org> 3 * Copyright (c) 2023 Theo Buehler <tb@openbsd.org>
4 * 4 *
@@ -15,7 +15,6 @@
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */ 16 */
17 17
18#include <openssl/err.h>
19#include <openssl/evp.h> 18#include <openssl/evp.h>
20#include <openssl/objects.h> 19#include <openssl/objects.h>
21 20
diff --git a/src/lib/libcrypto/evp/evp_pbe.c b/src/lib/libcrypto/evp/evp_pbe.c
index 88ceb14033..cb2ace1fd0 100644
--- a/src/lib/libcrypto/evp/evp_pbe.c
+++ b/src/lib/libcrypto/evp/evp_pbe.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_pbe.c,v 1.50 2024/04/09 13:52:41 beck Exp $ */ 1/* $OpenBSD: evp_pbe.c,v 1.51 2025/05/10 05:54:38 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -60,13 +60,13 @@
60#include <string.h> 60#include <string.h>
61 61
62#include <openssl/asn1.h> 62#include <openssl/asn1.h>
63#include <openssl/err.h>
64#include <openssl/evp.h> 63#include <openssl/evp.h>
65#include <openssl/hmac.h> 64#include <openssl/hmac.h>
66#include <openssl/objects.h> 65#include <openssl/objects.h>
67#include <openssl/pkcs12.h> 66#include <openssl/pkcs12.h>
68#include <openssl/x509.h> 67#include <openssl/x509.h>
69 68
69#include "err_local.h"
70#include "evp_local.h" 70#include "evp_local.h"
71#include "hmac_local.h" 71#include "hmac_local.h"
72#include "pkcs12_local.h" 72#include "pkcs12_local.h"
diff --git a/src/lib/libcrypto/evp/evp_pkey.c b/src/lib/libcrypto/evp/evp_pkey.c
index a1e127352a..1c0b8b41e9 100644
--- a/src/lib/libcrypto/evp/evp_pkey.c
+++ b/src/lib/libcrypto/evp/evp_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_pkey.c,v 1.33 2025/02/04 04:51:34 tb Exp $ */ 1/* $OpenBSD: evp_pkey.c,v 1.34 2025/05/10 05:54:38 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -60,10 +60,10 @@
60#include <stdlib.h> 60#include <stdlib.h>
61#include <string.h> 61#include <string.h>
62 62
63#include <openssl/err.h>
64#include <openssl/x509.h> 63#include <openssl/x509.h>
65 64
66#include "asn1_local.h" 65#include "asn1_local.h"
66#include "err_local.h"
67#include "evp_local.h" 67#include "evp_local.h"
68 68
69/* Extract a private key from a PKCS8 structure */ 69/* Extract a private key from a PKCS8 structure */
diff --git a/src/lib/libcrypto/evp/m_sigver.c b/src/lib/libcrypto/evp/m_sigver.c
index a3353854f1..66e4752242 100644
--- a/src/lib/libcrypto/evp/m_sigver.c
+++ b/src/lib/libcrypto/evp/m_sigver.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: m_sigver.c,v 1.27 2024/04/09 13:52:41 beck Exp $ */ 1/* $OpenBSD: m_sigver.c,v 1.28 2025/05/10 05:54:38 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -58,11 +58,11 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60 60
61#include <openssl/err.h>
62#include <openssl/evp.h> 61#include <openssl/evp.h>
63#include <openssl/objects.h> 62#include <openssl/objects.h>
64#include <openssl/x509.h> 63#include <openssl/x509.h>
65 64
65#include "err_local.h"
66#include "evp_local.h" 66#include "evp_local.h"
67 67
68static int 68static int
diff --git a/src/lib/libcrypto/evp/p_legacy.c b/src/lib/libcrypto/evp/p_legacy.c
index 01cfdbcd6a..7c958a16e3 100644
--- a/src/lib/libcrypto/evp/p_legacy.c
+++ b/src/lib/libcrypto/evp/p_legacy.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p_legacy.c,v 1.6 2024/04/09 13:52:41 beck Exp $ */ 1/* $OpenBSD: p_legacy.c,v 1.7 2025/05/10 05:54:38 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 *
@@ -59,10 +59,10 @@
59#include <stdlib.h> 59#include <stdlib.h>
60 60
61#include <openssl/evp.h> 61#include <openssl/evp.h>
62#include <openssl/err.h>
63 62
64#include <openssl/rsa.h> 63#include <openssl/rsa.h>
65 64
65#include "err_local.h"
66#include "evp_local.h" 66#include "evp_local.h"
67 67
68int 68int
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c
index 95c7721303..3f88185737 100644
--- a/src/lib/libcrypto/evp/p_lib.c
+++ b/src/lib/libcrypto/evp/p_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p_lib.c,v 1.61 2024/08/22 12:24:24 tb Exp $ */ 1/* $OpenBSD: p_lib.c,v 1.63 2025/07/02 06:36:52 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 *
@@ -111,7 +111,6 @@
111#include <openssl/bio.h> 111#include <openssl/bio.h>
112#include <openssl/cmac.h> 112#include <openssl/cmac.h>
113#include <openssl/crypto.h> 113#include <openssl/crypto.h>
114#include <openssl/err.h>
115#include <openssl/evp.h> 114#include <openssl/evp.h>
116#include <openssl/objects.h> 115#include <openssl/objects.h>
117#include <openssl/x509.h> 116#include <openssl/x509.h>
@@ -129,6 +128,7 @@
129#include <openssl/rsa.h> 128#include <openssl/rsa.h>
130#endif 129#endif
131 130
131#include "err_local.h"
132#include "evp_local.h" 132#include "evp_local.h"
133 133
134extern const EVP_PKEY_ASN1_METHOD cmac_asn1_meth; 134extern const EVP_PKEY_ASN1_METHOD cmac_asn1_meth;
@@ -628,7 +628,7 @@ LCRYPTO_ALIAS(EVP_PKEY_get0_hmac);
628 628
629#ifndef OPENSSL_NO_RSA 629#ifndef OPENSSL_NO_RSA
630RSA * 630RSA *
631EVP_PKEY_get0_RSA(EVP_PKEY *pkey) 631EVP_PKEY_get0_RSA(const EVP_PKEY *pkey)
632{ 632{
633 if (pkey->type == EVP_PKEY_RSA || pkey->type == EVP_PKEY_RSA_PSS) 633 if (pkey->type == EVP_PKEY_RSA || pkey->type == EVP_PKEY_RSA_PSS)
634 return pkey->pkey.rsa; 634 return pkey->pkey.rsa;
@@ -639,7 +639,7 @@ EVP_PKEY_get0_RSA(EVP_PKEY *pkey)
639LCRYPTO_ALIAS(EVP_PKEY_get0_RSA); 639LCRYPTO_ALIAS(EVP_PKEY_get0_RSA);
640 640
641RSA * 641RSA *
642EVP_PKEY_get1_RSA(EVP_PKEY *pkey) 642EVP_PKEY_get1_RSA(const EVP_PKEY *pkey)
643{ 643{
644 RSA *rsa; 644 RSA *rsa;
645 645
@@ -665,7 +665,7 @@ LCRYPTO_ALIAS(EVP_PKEY_set1_RSA);
665 665
666#ifndef OPENSSL_NO_DSA 666#ifndef OPENSSL_NO_DSA
667DSA * 667DSA *
668EVP_PKEY_get0_DSA(EVP_PKEY *pkey) 668EVP_PKEY_get0_DSA(const EVP_PKEY *pkey)
669{ 669{
670 if (pkey->type != EVP_PKEY_DSA) { 670 if (pkey->type != EVP_PKEY_DSA) {
671 EVPerror(EVP_R_EXPECTING_A_DSA_KEY); 671 EVPerror(EVP_R_EXPECTING_A_DSA_KEY);
@@ -676,7 +676,7 @@ EVP_PKEY_get0_DSA(EVP_PKEY *pkey)
676LCRYPTO_ALIAS(EVP_PKEY_get0_DSA); 676LCRYPTO_ALIAS(EVP_PKEY_get0_DSA);
677 677
678DSA * 678DSA *
679EVP_PKEY_get1_DSA(EVP_PKEY *pkey) 679EVP_PKEY_get1_DSA(const EVP_PKEY *pkey)
680{ 680{
681 DSA *dsa; 681 DSA *dsa;
682 682
@@ -702,7 +702,7 @@ LCRYPTO_ALIAS(EVP_PKEY_set1_DSA);
702 702
703#ifndef OPENSSL_NO_EC 703#ifndef OPENSSL_NO_EC
704EC_KEY * 704EC_KEY *
705EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey) 705EVP_PKEY_get0_EC_KEY(const EVP_PKEY *pkey)
706{ 706{
707 if (pkey->type != EVP_PKEY_EC) { 707 if (pkey->type != EVP_PKEY_EC) {
708 EVPerror(EVP_R_EXPECTING_A_EC_KEY); 708 EVPerror(EVP_R_EXPECTING_A_EC_KEY);
@@ -713,7 +713,7 @@ EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey)
713LCRYPTO_ALIAS(EVP_PKEY_get0_EC_KEY); 713LCRYPTO_ALIAS(EVP_PKEY_get0_EC_KEY);
714 714
715EC_KEY * 715EC_KEY *
716EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey) 716EVP_PKEY_get1_EC_KEY(const EVP_PKEY *pkey)
717{ 717{
718 EC_KEY *key; 718 EC_KEY *key;
719 719
@@ -740,7 +740,7 @@ LCRYPTO_ALIAS(EVP_PKEY_set1_EC_KEY);
740 740
741#ifndef OPENSSL_NO_DH 741#ifndef OPENSSL_NO_DH
742DH * 742DH *
743EVP_PKEY_get0_DH(EVP_PKEY *pkey) 743EVP_PKEY_get0_DH(const EVP_PKEY *pkey)
744{ 744{
745 if (pkey->type != EVP_PKEY_DH) { 745 if (pkey->type != EVP_PKEY_DH) {
746 EVPerror(EVP_R_EXPECTING_A_DH_KEY); 746 EVPerror(EVP_R_EXPECTING_A_DH_KEY);
@@ -751,7 +751,7 @@ EVP_PKEY_get0_DH(EVP_PKEY *pkey)
751LCRYPTO_ALIAS(EVP_PKEY_get0_DH); 751LCRYPTO_ALIAS(EVP_PKEY_get0_DH);
752 752
753DH * 753DH *
754EVP_PKEY_get1_DH(EVP_PKEY *pkey) 754EVP_PKEY_get1_DH(const EVP_PKEY *pkey)
755{ 755{
756 DH *dh; 756 DH *dh;
757 757
diff --git a/src/lib/libcrypto/evp/p_sign.c b/src/lib/libcrypto/evp/p_sign.c
index 7f472ea716..775cf78d62 100644
--- a/src/lib/libcrypto/evp/p_sign.c
+++ b/src/lib/libcrypto/evp/p_sign.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p_sign.c,v 1.22 2024/04/09 13:52:41 beck Exp $ */ 1/* $OpenBSD: p_sign.c,v 1.23 2025/05/10 05:54:38 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 *
@@ -58,7 +58,6 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60 60
61#include <openssl/err.h>
62#include <openssl/evp.h> 61#include <openssl/evp.h>
63#include <openssl/objects.h> 62#include <openssl/objects.h>
64#include <openssl/x509.h> 63#include <openssl/x509.h>
diff --git a/src/lib/libcrypto/evp/p_verify.c b/src/lib/libcrypto/evp/p_verify.c
index 02132e2c38..cd7482df55 100644
--- a/src/lib/libcrypto/evp/p_verify.c
+++ b/src/lib/libcrypto/evp/p_verify.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p_verify.c,v 1.21 2024/04/09 13:52:41 beck Exp $ */ 1/* $OpenBSD: p_verify.c,v 1.22 2025/05/10 05:54:38 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 *
@@ -58,7 +58,6 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60 60
61#include <openssl/err.h>
62#include <openssl/evp.h> 61#include <openssl/evp.h>
63#include <openssl/objects.h> 62#include <openssl/objects.h>
64#include <openssl/x509.h> 63#include <openssl/x509.h>
diff --git a/src/lib/libcrypto/evp/pmeth_fn.c b/src/lib/libcrypto/evp/pmeth_fn.c
index 308c434f0d..ad6c04dabb 100644
--- a/src/lib/libcrypto/evp/pmeth_fn.c
+++ b/src/lib/libcrypto/evp/pmeth_fn.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pmeth_fn.c,v 1.11 2024/04/12 09:41:39 tb Exp $ */ 1/* $OpenBSD: pmeth_fn.c,v 1.12 2025/05/10 05:54:38 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -59,10 +59,10 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61 61
62#include <openssl/err.h>
63#include <openssl/evp.h> 62#include <openssl/evp.h>
64#include <openssl/objects.h> 63#include <openssl/objects.h>
65 64
65#include "err_local.h"
66#include "evp_local.h" 66#include "evp_local.h"
67 67
68#define M_check_autoarg(ctx, arg, arglen, err) \ 68#define M_check_autoarg(ctx, arg, arglen, err) \
diff --git a/src/lib/libcrypto/evp/pmeth_gn.c b/src/lib/libcrypto/evp/pmeth_gn.c
index bc1c5bd7d2..fa5b446124 100644
--- a/src/lib/libcrypto/evp/pmeth_gn.c
+++ b/src/lib/libcrypto/evp/pmeth_gn.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pmeth_gn.c,v 1.21 2024/08/31 09:14:21 tb Exp $ */ 1/* $OpenBSD: pmeth_gn.c,v 1.22 2025/05/10 05:54:38 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -60,12 +60,12 @@
60#include <stdlib.h> 60#include <stdlib.h>
61 61
62#include <openssl/bn.h> 62#include <openssl/bn.h>
63#include <openssl/err.h>
64#include <openssl/evp.h> 63#include <openssl/evp.h>
65#include <openssl/objects.h> 64#include <openssl/objects.h>
66 65
67#include "asn1_local.h" 66#include "asn1_local.h"
68#include "bn_local.h" 67#include "bn_local.h"
68#include "err_local.h"
69#include "evp_local.h" 69#include "evp_local.h"
70 70
71int 71int
diff --git a/src/lib/libcrypto/evp/pmeth_lib.c b/src/lib/libcrypto/evp/pmeth_lib.c
index fbf4057c38..ce6beecad6 100644
--- a/src/lib/libcrypto/evp/pmeth_lib.c
+++ b/src/lib/libcrypto/evp/pmeth_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pmeth_lib.c,v 1.42 2025/01/20 12:57:28 tb Exp $ */ 1/* $OpenBSD: pmeth_lib.c,v 1.43 2025/05/10 05:54:38 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -63,12 +63,12 @@
63 63
64#include <openssl/opensslconf.h> 64#include <openssl/opensslconf.h>
65 65
66#include <openssl/err.h>
67#include <openssl/evp.h> 66#include <openssl/evp.h>
68#include <openssl/objects.h> 67#include <openssl/objects.h>
69#include <openssl/x509v3.h> 68#include <openssl/x509v3.h>
70 69
71#include "asn1_local.h" 70#include "asn1_local.h"
71#include "err_local.h"
72#include "evp_local.h" 72#include "evp_local.h"
73 73
74extern const EVP_PKEY_METHOD cmac_pkey_meth; 74extern const EVP_PKEY_METHOD cmac_pkey_meth;