diff options
| author | Pierre Pronchery <khorben@FreeBSD.org> | 2025-07-11 23:17:50 +0200 |
|---|---|---|
| committer | Pierre Pronchery <khorben@FreeBSD.org> | 2025-08-07 13:54:09 +0200 |
| commit | 1095efe41feed8ea5a6fe5ca123c347ae0914801 (patch) | |
| tree | c67facfd21376f5dc2aa6d670070675857adbf9d /crypto | |
| parent | 09a25192275b21412a51e3a2d5d6ff0eb147425d (diff) | |
openssl: import 3.5.1
This change adds OpenSSL 3.5.1 from upstream [1].
The 3.5.1 artifact was been verified via PGP key [2] and by SHA256 checksum [3].
More information about the release (from a high level) can be found in
the release notes [4].
1. https://github.com/openssl/openssl/releases/download/openssl-3.5.1/openssl-3.5.1.tar.gz
2. https://github.com/openssl/openssl/releases/download/openssl-3.5.1/openssl-3.5.1.tar.gz.asc
3. https://github.com/openssl/openssl/releases/download/openssl-3.5.1/openssl-3.5.1.tar.gz.sha256
4. https://github.com/openssl/openssl/blob/openssl-3.5.1/NEWS.md
Reviewed by: ngie, philip
Approved by: philip (mentor)
Sponsored by: The FreeBSD Foundation
Diffstat (limited to 'crypto')
42 files changed, 1034 insertions, 533 deletions
diff --git a/crypto/aes/asm/aesv8-armx.pl b/crypto/aes/asm/aesv8-armx.pl index 4f503a31ca67..af501f8ff573 100755 --- a/crypto/aes/asm/aesv8-armx.pl +++ b/crypto/aes/asm/aesv8-armx.pl @@ -152,7 +152,7 @@ $code.=<<___ if ($flavour =~ /64/); adrp $ptr,.Lrcon add $ptr,$ptr,:lo12:.Lrcon ___ -$code.=<<___ if ($flavour =~ /32/); +$code.=<<___ if ($flavour !~ /64/); adr $ptr,.Lrcon ___ $code.=<<___; diff --git a/crypto/bio/bio_dump.c b/crypto/bio/bio_dump.c index 40c18410e4cf..cd489142bb70 100644 --- a/crypto/bio/bio_dump.c +++ b/crypto/bio/bio_dump.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2025 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -47,6 +47,8 @@ int BIO_dump_indent_cb(int (*cb) (const void *data, size_t len, void *u), for (i = 0; i < rows; i++) { n = BIO_snprintf(buf, sizeof(buf), "%*s%04x - ", indent, "", i * dump_width); + if (n < 0) + return -1; for (j = 0; j < dump_width; j++) { if (SPACE(buf, n, 3)) { if (((i * dump_width) + j) >= len) { diff --git a/crypto/bio/bio_print.c b/crypto/bio/bio_print.c index 5f2543030e54..55fb4877b4c5 100644 --- a/crypto/bio/bio_print.c +++ b/crypto/bio/bio_print.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2025 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -535,6 +535,10 @@ static LDOUBLE abs_val(LDOUBLE value) LDOUBLE result = value; if (value < 0) result = -value; + if (result > 0 && result / 2 == result) /* INF */ + result = 0; + else if (result != result) /* NAN */ + result = 0; return result; } @@ -590,6 +594,9 @@ fmtfp(char **sbuffer, signvalue = '+'; else if (flags & DP_F_SPACE) signvalue = ' '; + ufvalue = abs_val(fvalue); + if (ufvalue == 0 && fvalue != 0) /* INF or NAN? */ + signvalue = '?'; /* * G_FORMAT sometimes prints like E_FORMAT and sometimes like F_FORMAT @@ -597,12 +604,12 @@ fmtfp(char **sbuffer, * that from here on. */ if (style == G_FORMAT) { - if (fvalue == 0.0) { + if (ufvalue == 0.0) { realstyle = F_FORMAT; - } else if (fvalue < 0.0001) { + } else if (ufvalue < 0.0001) { realstyle = E_FORMAT; - } else if ((max == 0 && fvalue >= 10) - || (max > 0 && fvalue >= pow_10(max))) { + } else if ((max == 0 && ufvalue >= 10) + || (max > 0 && ufvalue >= pow_10(max))) { realstyle = E_FORMAT; } else { realstyle = F_FORMAT; @@ -612,9 +619,9 @@ fmtfp(char **sbuffer, } if (style != F_FORMAT) { - tmpvalue = fvalue; + tmpvalue = ufvalue; /* Calculate the exponent */ - if (fvalue != 0.0) { + if (ufvalue != 0.0) { while (tmpvalue < 1) { tmpvalue *= 10; exp--; @@ -651,9 +658,9 @@ fmtfp(char **sbuffer, } } if (realstyle == E_FORMAT) - fvalue = tmpvalue; + ufvalue = tmpvalue; } - ufvalue = abs_val(fvalue); + /* * By subtracting 65535 (2^16-1) we cancel the low order 15 bits * of ULONG_MAX to avoid using imprecise floating point values. diff --git a/crypto/bn/asm/rsaz-2k-avxifma.pl b/crypto/bn/asm/rsaz-2k-avxifma.pl index 65710eac3ec4..0c962f248dd9 100644 --- a/crypto/bn/asm/rsaz-2k-avxifma.pl +++ b/crypto/bn/asm/rsaz-2k-avxifma.pl @@ -27,7 +27,6 @@ $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; ( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or die "can't locate x86_64-xlate.pl"; -# TODO: Find out the version of NASM that supports VEX-encoded AVX-IFMA instructions if (`$ENV{CC} -Wa,-v -c -o /dev/null -x assembler /dev/null 2>&1` =~ /GNU assembler version ([2-9]\.[0-9]+)/) { $avxifma = ($1>=2.40); @@ -39,6 +38,11 @@ if (!$avxifma && `$ENV{CC} -v 2>&1` $avxifma = ($ver>=16.0); } +if ($win64 && ($flavour =~ /nasm/ || $ENV{ASM} =~ /nasm/) && + `nasm -v 2>&1` =~ /NASM version ([2-9]\.[0-9]+)(?:\.([0-9]+))?(rc[0-9]+)?/) { + $avxifma = ($1>2.16) + ($1==2.16 && ((!defined($2) && !defined($3)) || (defined($2)))); +} + open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\"" or die "can't call $xlate: $!"; *STDOUT=*OUT; @@ -296,34 +300,34 @@ $code.=<<___; and \$0xf, %r14 vpsubq .Lmask52x4(%rip), $_R0, $T0 shl \$5, %r14 - vmovapd (%rdx, %r14), $T1 + vmovapd (%rdx,%r14), $T1 vblendvpd $T1, $T0, $_R0, $_R0 shr \$4, %r13b and \$0xf, %r13 vpsubq .Lmask52x4(%rip), $_R0h, $T0 shl \$5, %r13 - vmovapd (%rdx, %r13), $T1 + vmovapd (%rdx,%r13), $T1 vblendvpd $T1, $T0, $_R0h, $_R0h mov %r12b, %r11b and \$0xf, %r12 vpsubq .Lmask52x4(%rip), $_R1, $T0 shl \$5, %r12 - vmovapd (%rdx, %r12), $T1 + vmovapd (%rdx,%r12), $T1 vblendvpd $T1, $T0, $_R1, $_R1 shr \$4, %r11b and \$0xf, %r11 vpsubq .Lmask52x4(%rip), $_R1h, $T0 shl \$5, %r11 - vmovapd (%rdx, %r11), $T1 + vmovapd (%rdx,%r11), $T1 vblendvpd $T1, $T0, $_R1h, $_R1h and \$0xf, %r10 vpsubq .Lmask52x4(%rip), $_R2, $T0 shl \$5, %r10 - vmovapd (%rdx, %r10), $T1 + vmovapd (%rdx,%r10), $T1 vblendvpd $T1, $T0, $_R2, $_R2 # Add carries according to the obtained mask diff --git a/crypto/bn/asm/rsaz-3k-avxifma.pl b/crypto/bn/asm/rsaz-3k-avxifma.pl index 64c00c10e325..a19cb5aaa309 100644 --- a/crypto/bn/asm/rsaz-3k-avxifma.pl +++ b/crypto/bn/asm/rsaz-3k-avxifma.pl @@ -27,7 +27,6 @@ $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; ( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or die "can't locate x86_64-xlate.pl"; -# TODO: Find out the version of NASM that supports VEX-encoded AVX-IFMA instructions if (`$ENV{CC} -Wa,-v -c -o /dev/null -x assembler /dev/null 2>&1` =~ /GNU assembler version ([2-9]\.[0-9]+)/) { $avxifma = ($1>=2.40); @@ -39,6 +38,11 @@ if (!$avxifma && `$ENV{CC} -v 2>&1` $avxifma = ($ver>=16.0); } +if ($win64 && ($flavour =~ /nasm/ || $ENV{ASM} =~ /nasm/) && + `nasm -v 2>&1` =~ /NASM version ([2-9]\.[0-9]+)(?:\.([0-9]+))?(rc[0-9]+)?/) { + $avxifma = ($1>2.16) + ($1==2.16 && ((!defined($2) && !defined($3)) || (defined($2)))); +} + open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\"" or die "can't call $xlate: $!"; *STDOUT=*OUT; @@ -355,56 +359,56 @@ $code.=<<___; and \$0xf, %r14 vpsubq .Lmask52x4(%rip), $_R0, $T0 shl \$5, %r14 - vmovapd (%rdx, %r14), $T1 + vmovapd (%rdx,%r14), $T1 vblendvpd $T1, $T0, $_R0, $_R0 shr \$4, %r10b and \$0xf, %r10 vpsubq .Lmask52x4(%rip), $_R0h, $T0 shl \$5, %r10 - vmovapd (%rdx, %r10), $T1 + vmovapd (%rdx,%r10), $T1 vblendvpd $T1, $T0, $_R0h, $_R0h mov %r13b, %r10b and \$0xf, %r13 vpsubq .Lmask52x4(%rip), $_R1, $T0 shl \$5, %r13 - vmovapd (%rdx, %r13), $T1 + vmovapd (%rdx,%r13), $T1 vblendvpd $T1, $T0, $_R1, $_R1 shr \$4, %r10b and \$0xf, %r10 vpsubq .Lmask52x4(%rip), $_R1h, $T0 shl \$5, %r10 - vmovapd (%rdx, %r10), $T1 + vmovapd (%rdx,%r10), $T1 vblendvpd $T1, $T0, $_R1h, $_R1h mov %r12b, %r10b and \$0xf, %r12 vpsubq .Lmask52x4(%rip), $_R2, $T0 shl \$5, %r12 - vmovapd (%rdx, %r12), $T1 + vmovapd (%rdx,%r12), $T1 vblendvpd $T1, $T0, $_R2, $_R2 shr \$4, %r10b and \$0xf, %r10 vpsubq .Lmask52x4(%rip), $_R2h, $T0 shl \$5, %r10 - vmovapd (%rdx, %r10), $T1 + vmovapd (%rdx,%r10), $T1 vblendvpd $T1, $T0, $_R2h, $_R2h mov %r11b, %r10b and \$0xf, %r11 vpsubq .Lmask52x4(%rip), $_R3, $T0 shl \$5, %r11 - vmovapd (%rdx, %r11), $T1 + vmovapd (%rdx,%r11), $T1 vblendvpd $T1, $T0, $_R3, $_R3 shr \$4, %r10b and \$0xf, %r10 vpsubq .Lmask52x4(%rip), $_R3h, $T0 shl \$5, %r10 - vmovapd (%rdx, %r10), $T1 + vmovapd (%rdx,%r10), $T1 vblendvpd $T1, $T0, $_R3h, $_R3h vpand .Lmask52x4(%rip), $_R0, $_R0 diff --git a/crypto/bn/asm/rsaz-4k-avxifma.pl b/crypto/bn/asm/rsaz-4k-avxifma.pl index 5de6a4c4c2b2..f15e2d74118c 100644 --- a/crypto/bn/asm/rsaz-4k-avxifma.pl +++ b/crypto/bn/asm/rsaz-4k-avxifma.pl @@ -27,7 +27,6 @@ $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; ( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or die "can't locate x86_64-xlate.pl"; -# TODO: Find out the version of NASM that supports VEX-encoded AVX-IFMA instructions if (`$ENV{CC} -Wa,-v -c -o /dev/null -x assembler /dev/null 2>&1` =~ /GNU assembler version ([2-9]\.[0-9]+)/) { $avxifma = ($1>=2.40); @@ -39,6 +38,11 @@ if (!$avxifma && `$ENV{CC} -v 2>&1` $avxifma = ($ver>=16.0); } +if ($win64 && ($flavour =~ /nasm/ || $ENV{ASM} =~ /nasm/) && + `nasm -v 2>&1` =~ /NASM version ([2-9]\.[0-9]+)(?:\.([0-9]+))?(rc[0-9]+)?/) { + $avxifma = ($1>2.16) + ($1==2.16 && ((!defined($2) && !defined($3)) || (defined($2)))); +} + open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\"" or die "can't call $xlate: $!"; *STDOUT=*OUT; @@ -424,70 +428,70 @@ $code.=<<___; and \$0xf, %r14 vpsubq .Lmask52x4(%rip), $_R0, $tmp shl \$5, %r14 - vmovapd (%r8, %r14), $tmp2 + vmovapd (%r8,%r14), $tmp2 vblendvpd $tmp2, $tmp, $_R0, $_R0 shr \$4, %r9b and \$0xf, %r9 vpsubq .Lmask52x4(%rip), $_R0h, $tmp shl \$5, %r9 - vmovapd (%r8, %r9), $tmp2 + vmovapd (%r8,%r9), $tmp2 vblendvpd $tmp2, $tmp, $_R0h, $_R0h movb %r13b,%r9b and \$0xf, %r13 vpsubq .Lmask52x4(%rip), $_R1, $tmp shl \$5, %r13 - vmovapd (%r8, %r13), $tmp2 + vmovapd (%r8,%r13), $tmp2 vblendvpd $tmp2, $tmp, $_R1, $_R1 shr \$4, %r9b and \$0xf, %r9 vpsubq .Lmask52x4(%rip), $_R1h, $tmp shl \$5, %r9 - vmovapd (%r8, %r9), $tmp2 + vmovapd (%r8,%r9), $tmp2 vblendvpd $tmp2, $tmp, $_R1h, $_R1h movb %r12b,%r9b and \$0xf, %r12 vpsubq .Lmask52x4(%rip), $_R2, $tmp shl \$5, %r12 - vmovapd (%r8, %r12), $tmp2 + vmovapd (%r8,%r12), $tmp2 vblendvpd $tmp2, $tmp, $_R2, $_R2 shr \$4, %r9b and \$0xf, %r9 vpsubq .Lmask52x4(%rip), $_R2h, $tmp shl \$5, %r9 - vmovapd (%r8, %r9), $tmp2 + vmovapd (%r8,%r9), $tmp2 vblendvpd $tmp2, $tmp, $_R2h, $_R2h movb %r11b,%r9b and \$0xf, %r11 vpsubq .Lmask52x4(%rip), $_R3, $tmp shl \$5, %r11 - vmovapd (%r8, %r11), $tmp2 + vmovapd (%r8,%r11), $tmp2 vblendvpd $tmp2, $tmp, $_R3, $_R3 shr \$4, %r9b and \$0xf, %r9 vpsubq .Lmask52x4(%rip), $_R3h, $tmp shl \$5, %r9 - vmovapd (%r8, %r9), $tmp2 + vmovapd (%r8,%r9), $tmp2 vblendvpd $tmp2, $tmp, $_R3h, $_R3h movb %r10b,%r9b and \$0xf, %r10 vpsubq .Lmask52x4(%rip), $_R4, $tmp shl \$5, %r10 - vmovapd (%r8, %r10), $tmp2 + vmovapd (%r8,%r10), $tmp2 vblendvpd $tmp2, $tmp, $_R4, $_R4 shr \$4, %r9b and \$0xf, %r9 vpsubq .Lmask52x4(%rip), $_R4h, $tmp shl \$5, %r9 - vmovapd (%r8, %r9), $tmp2 + vmovapd (%r8,%r9), $tmp2 vblendvpd $tmp2, $tmp, $_R4h, $_R4h pop %r8 diff --git a/crypto/chacha/asm/chacha-armv8-sve.pl b/crypto/chacha/asm/chacha-armv8-sve.pl index 705917fb52c5..62a8be6fe12c 100755 --- a/crypto/chacha/asm/chacha-armv8-sve.pl +++ b/crypto/chacha/asm/chacha-armv8-sve.pl @@ -248,9 +248,6 @@ sub load_regs() { my $next_offset = $offset + 1; $code.=<<___; ld1w {$reg.s},p0/z,[$inp,#$offset,MUL VL] -#ifdef __AARCH64EB__ - revb $reg.s,p0/m,$reg.s -#endif ___ if (@_) { &load_regs($next_offset, @_); @@ -272,9 +269,6 @@ sub store_regs() { my $reg = shift; my $next_offset = $offset + 1; $code.=<<___; -#ifdef __AARCH64EB__ - revb $reg.s,p0/m,$reg.s -#endif st1w {$reg.s},p0,[$outp,#$offset,MUL VL] ___ if (@_) { @@ -480,13 +474,29 @@ sub SVE_TRANSFORMS() { $code.=<<___; #ifdef __AARCH64EB__ rev @sxx[0],@sxx[0] + revb @mx[0].s,p0/m,@mx[0].s + revb @mx[1].s,p0/m,@mx[1].s rev @sxx[2],@sxx[2] + revb @mx[2].s,p0/m,@mx[2].s + revb @mx[3].s,p0/m,@mx[3].s rev @sxx[4],@sxx[4] + revb @mx[4].s,p0/m,@mx[4].s + revb @mx[5].s,p0/m,@mx[5].s rev @sxx[6],@sxx[6] + revb @mx[6].s,p0/m,@mx[6].s + revb @mx[7].s,p0/m,@mx[7].s rev @sxx[8],@sxx[8] + revb @mx[8].s,p0/m,@mx[8].s + revb @mx[9].s,p0/m,@mx[9].s rev @sxx[10],@sxx[10] + revb @mx[10].s,p0/m,@mx[10].s + revb @mx[11].s,p0/m,@mx[11].s rev @sxx[12],@sxx[12] + revb @mx[12].s,p0/m,@mx[12].s + revb @mx[13].s,p0/m,@mx[13].s rev @sxx[14],@sxx[14] + revb @mx[14].s,p0/m,@mx[14].s + revb @mx[15].s,p0/m,@mx[15].s #endif .if mixin == 1 add @K[6],@K[6],#1 diff --git a/crypto/cmp/cmp_http.c b/crypto/cmp/cmp_http.c index c0226e562a32..d20ea618d84f 100644 --- a/crypto/cmp/cmp_http.c +++ b/crypto/cmp/cmp_http.c @@ -81,11 +81,11 @@ OSSL_CMP_MSG *OSSL_CMP_MSG_http_perform(OSSL_CMP_CTX *ctx, path++; if (bios == NULL) ossl_cmp_log4(DEBUG, ctx, - "connecting to CMP server via http%s://%s:%s%s/%s", + "connecting to CMP server via http%s://%s:%s/%s", tls_used ? "s" : "", ctx->server, server_port, path); else ossl_cmp_log3(DEBUG, ctx, - "using existing connection with CMP server %s%s and HTTP path /%s", + "using existing connection with CMP server %s:%s and HTTP path /%s", ctx->server, server_port, path); } diff --git a/crypto/core_namemap.c b/crypto/core_namemap.c index f36f070fa2ab..4b1380a6f2dc 100644 --- a/crypto/core_namemap.c +++ b/crypto/core_namemap.c @@ -13,7 +13,7 @@ #include "internal/sizes.h" #include "crypto/context.h" -#define NAMEMAP_HT_BUCKETS 2048 +#define NAMEMAP_HT_BUCKETS 512 HT_START_KEY_DEFN(namenum_key) HT_DEF_KEY_FIELD_CHAR_ARRAY(name, 64) diff --git a/crypto/dh/dh_pmeth.c b/crypto/dh/dh_pmeth.c index c11ada98267c..3b75a537b3e0 100644 --- a/crypto/dh/dh_pmeth.c +++ b/crypto/dh/dh_pmeth.c @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2006-2025 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -422,7 +422,7 @@ static int pkey_dh_derive(EVP_PKEY_CTX *ctx, unsigned char *key, ret = DH_compute_key_padded(key, dhpubbn, dh); else ret = DH_compute_key(key, dhpubbn, dh); - if (ret < 0) + if (ret <= 0) return ret; *keylen = ret; return 1; diff --git a/crypto/ec/ecp_nistp384.c b/crypto/ec/ecp_nistp384.c index 2ceb94fe33b7..9d682f5a02cc 100644 --- a/crypto/ec/ecp_nistp384.c +++ b/crypto/ec/ecp_nistp384.c @@ -684,6 +684,22 @@ static void felem_reduce_ref(felem out, const widefelem in) out[i] = acc[i]; } +static ossl_inline void felem_square_reduce_ref(felem out, const felem in) +{ + widefelem tmp; + + felem_square_ref(tmp, in); + felem_reduce_ref(out, tmp); +} + +static ossl_inline void felem_mul_reduce_ref(felem out, const felem in1, const felem in2) +{ + widefelem tmp; + + felem_mul_ref(tmp, in1, in2); + felem_reduce_ref(out, tmp); +} + #if defined(ECP_NISTP384_ASM) static void felem_square_wrapper(widefelem out, const felem in); static void felem_mul_wrapper(widefelem out, const felem in1, const felem in2); @@ -695,10 +711,18 @@ static void (*felem_mul_p)(widefelem out, const felem in1, const felem in2) = static void (*felem_reduce_p)(felem out, const widefelem in) = felem_reduce_ref; +static void (*felem_square_reduce_p)(felem out, const felem in) = + felem_square_reduce_ref; +static void (*felem_mul_reduce_p)(felem out, const felem in1, const felem in2) = + felem_mul_reduce_ref; + void p384_felem_square(widefelem out, const felem in); void p384_felem_mul(widefelem out, const felem in1, const felem in2); void p384_felem_reduce(felem out, const widefelem in); +void p384_felem_square_reduce(felem out, const felem in); +void p384_felem_mul_reduce(felem out, const felem in1, const felem in2); + # if defined(_ARCH_PPC64) # include "crypto/ppc_arch.h" # endif @@ -710,6 +734,8 @@ static void felem_select(void) felem_square_p = p384_felem_square; felem_mul_p = p384_felem_mul; felem_reduce_p = p384_felem_reduce; + felem_square_reduce_p = p384_felem_square_reduce; + felem_mul_reduce_p = p384_felem_mul_reduce; return; } @@ -718,7 +744,9 @@ static void felem_select(void) /* Default */ felem_square_p = felem_square_ref; felem_mul_p = felem_mul_ref; - felem_reduce_p = p384_felem_reduce; + felem_reduce_p = felem_reduce_ref; + felem_square_reduce_p = felem_square_reduce_ref; + felem_mul_reduce_p = felem_mul_reduce_ref; } static void felem_square_wrapper(widefelem out, const felem in) @@ -737,31 +765,15 @@ static void felem_mul_wrapper(widefelem out, const felem in1, const felem in2) # define felem_mul felem_mul_p # define felem_reduce felem_reduce_p -void p384_felem_square_reduce(felem out, const felem in); -void p384_felem_mul_reduce(felem out, const felem in1, const felem in2); - -# define felem_square_reduce p384_felem_square_reduce -# define felem_mul_reduce p384_felem_mul_reduce +# define felem_square_reduce felem_square_reduce_p +# define felem_mul_reduce felem_mul_reduce_p #else # define felem_square felem_square_ref # define felem_mul felem_mul_ref # define felem_reduce felem_reduce_ref -static ossl_inline void felem_square_reduce(felem out, const felem in) -{ - widefelem tmp; - - felem_square(tmp, in); - felem_reduce(out, tmp); -} - -static ossl_inline void felem_mul_reduce(felem out, const felem in1, const felem in2) -{ - widefelem tmp; - - felem_mul(tmp, in1, in2); - felem_reduce(out, tmp); -} +# define felem_square_reduce felem_square_reduce_ref +# define felem_mul_reduce felem_mul_reduce_ref #endif /*- diff --git a/crypto/err/openssl.txt b/crypto/err/openssl.txt index 17981605c028..355b20d627db 100644 --- a/crypto/err/openssl.txt +++ b/crypto/err/openssl.txt @@ -803,6 +803,12 @@ EVP_R_PKEY_APPLICATION_ASN1_METHOD_ALREADY_REGISTERED:179:\ pkey application asn1 method already registered EVP_R_PRIVATE_KEY_DECODE_ERROR:145:private key decode error EVP_R_PRIVATE_KEY_ENCODE_ERROR:146:private key encode error +EVP_R_PROVIDER_ASYM_CIPHER_FAILURE:232:provider asym cipher failure +EVP_R_PROVIDER_ASYM_CIPHER_NOT_SUPPORTED:235:provider asym cipher not supported +EVP_R_PROVIDER_KEYMGMT_FAILURE:233:provider keymgmt failure +EVP_R_PROVIDER_KEYMGMT_NOT_SUPPORTED:236:provider keymgmt not supported +EVP_R_PROVIDER_SIGNATURE_FAILURE:234:provider signature failure +EVP_R_PROVIDER_SIGNATURE_NOT_SUPPORTED:237:provider signature not supported EVP_R_PUBLIC_KEY_NOT_RSA:106:public key not rsa EVP_R_SETTING_XOF_FAILED:227:setting xof failed EVP_R_SET_DEFAULT_PROPERTY_FAILURE:209:set default property failure diff --git a/crypto/evp/asymcipher.c b/crypto/evp/asymcipher.c index ded0a9245121..975170c0aa09 100644 --- a/crypto/evp/asymcipher.c +++ b/crypto/evp/asymcipher.c @@ -33,6 +33,7 @@ static int evp_pkey_asym_cipher_init(EVP_PKEY_CTX *ctx, int operation, int ret = 0; void *provkey = NULL; EVP_ASYM_CIPHER *cipher = NULL; + const char *desc; EVP_KEYMGMT *tmp_keymgmt = NULL; const OSSL_PROVIDER *tmp_prov = NULL; const char *supported_ciph = NULL; @@ -159,10 +160,12 @@ static int evp_pkey_asym_cipher_init(EVP_PKEY_CTX *ctx, int operation, goto err; } + desc = cipher->description != NULL ? cipher->description : ""; switch (operation) { case EVP_PKEY_OP_ENCRYPT: if (cipher->encrypt_init == NULL) { - ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_ASYM_CIPHER_NOT_SUPPORTED, + "%s encrypt_init:%s", cipher->type_name, desc); ret = -2; goto err; } @@ -170,7 +173,8 @@ static int evp_pkey_asym_cipher_init(EVP_PKEY_CTX *ctx, int operation, break; case EVP_PKEY_OP_DECRYPT: if (cipher->decrypt_init == NULL) { - ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_ASYM_CIPHER_NOT_SUPPORTED, + "%s decrypt_init:%s", cipher->type_name, desc); ret = -2; goto err; } @@ -238,6 +242,8 @@ int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, const unsigned char *in, size_t inlen) { + EVP_ASYM_CIPHER *cipher; + const char *desc; int ret; if (ctx == NULL) { @@ -253,8 +259,12 @@ int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx, if (ctx->op.ciph.algctx == NULL) goto legacy; - ret = ctx->op.ciph.cipher->encrypt(ctx->op.ciph.algctx, out, outlen, - (out == NULL ? 0 : *outlen), in, inlen); + cipher = ctx->op.ciph.cipher; + desc = cipher->description != NULL ? cipher->description : ""; + ret = cipher->encrypt(ctx->op.ciph.algctx, out, outlen, (out == NULL ? 0 : *outlen), in, inlen); + if (ret <= 0) + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_ASYM_CIPHER_FAILURE, + "%s encrypt:%s", cipher->type_name, desc); return ret; legacy: @@ -280,6 +290,8 @@ int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, const unsigned char *in, size_t inlen) { + EVP_ASYM_CIPHER *cipher; + const char *desc; int ret; if (ctx == NULL) { @@ -295,8 +307,13 @@ int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, if (ctx->op.ciph.algctx == NULL) goto legacy; - ret = ctx->op.ciph.cipher->decrypt(ctx->op.ciph.algctx, out, outlen, - (out == NULL ? 0 : *outlen), in, inlen); + cipher = ctx->op.ciph.cipher; + desc = cipher->description != NULL ? cipher->description : ""; + ret = cipher->decrypt(ctx->op.ciph.algctx, out, outlen, (out == NULL ? 0 : *outlen), in, inlen); + if (ret <= 0) + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_ASYM_CIPHER_FAILURE, + "%s decrypt:%s", cipher->type_name, desc); + return ret; legacy: diff --git a/crypto/evp/bio_enc.c b/crypto/evp/bio_enc.c index ffe4b5bb02e3..2f272deadd7b 100644 --- a/crypto/evp/bio_enc.c +++ b/crypto/evp/bio_enc.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2024 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2025 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -161,6 +161,7 @@ static int enc_read(BIO *b, char *out, int outl) /* Should be continue next time we are called? */ if (!BIO_should_retry(next)) { ctx->cont = i; + ctx->finished = 1; i = EVP_CipherFinal_ex(ctx->cipher, ctx->buf, &(ctx->buf_len)); ctx->ok = i; diff --git a/crypto/evp/ctrl_params_translate.c b/crypto/evp/ctrl_params_translate.c index 13240db611b3..ed73fc0fbb8d 100644 --- a/crypto/evp/ctrl_params_translate.c +++ b/crypto/evp/ctrl_params_translate.c @@ -78,11 +78,11 @@ struct translation_st; /* Forwarding */ * With the PRE_CTRL_TO_PARAMS state, the * fixup_args function is expected to modify * the passed |*params| in whatever way - * necessary, when |action_type == SET|. + * necessary, when |action_type == OSSL_ACTION_SET|. * With the POST_CTRL_TO_PARAMS state, the * fixup_args function is expected to modify * the passed |p2| in whatever way necessary, - * when |action_type == GET|. + * when |action_type == OSSL_ACTION_GET|. * * The return value from the fixup_args call * with the POST_CTRL_TO_PARAMS state becomes @@ -107,7 +107,7 @@ struct translation_st; /* Forwarding */ * With the PRE_CTRL_STR_TO_PARAMS state, * the fixup_args function is expected to * modify the passed |*params| in whatever - * way necessary, when |action_type == SET|. + * way necessary, when |action_type == OSSL_ACTION_SET|. * With the POST_CTRL_STR_TO_PARAMS state, * the fixup_args function is only expected * to return a value. @@ -132,11 +132,11 @@ struct translation_st; /* Forwarding */ * With the PRE_PARAMS_TO_CTRL state, the * fixup_args function is expected to modify * the passed |p1| and |p2| in whatever way - * necessary, when |action_type == SET|. + * necessary, when |action_type == OSSL_ACTION_SET|. * With the POST_PARAMS_TO_CTRL state, the * fixup_args function is expected to * modify the passed |*params| in whatever - * way necessary, when |action_type == GET|. + * way necessary, when |action_type == OSSL_ACTION_GET|. * * CLEANUP_PARAMS_TO_CTRL The cleanup_args functions has been called * from EVP_PKEY_CTX_get_params() or @@ -150,7 +150,7 @@ enum state { PRE_PARAMS_TO_CTRL, POST_PARAMS_TO_CTRL, CLEANUP_PARAMS_TO_CTRL }; enum action { - NONE = 0, GET = 1, SET = 2 + OSSL_ACTION_NONE = 0, OSSL_ACTION_GET = 1, OSSL_ACTION_SET = 2 }; typedef int fixup_args_fn(enum state state, const struct translation_st *translation, @@ -166,7 +166,7 @@ struct translation_ctx_st { */ EVP_PKEY_CTX *pctx; /* - * The action type (GET or SET). This may be 0 in some cases, and should + * The action type (OSSL_ACTION_GET or OSSL_ACTION_SET). This may be 0 in some cases, and should * be modified by the fixup_args function in the PRE states. It should * otherwise remain untouched once set. */ @@ -215,7 +215,7 @@ struct translation_st { /*- * What this table item does. * - * If the item has this set to 0, it means that both GET and SET are + * If the item has this set to 0, it means that both OSSL_ACTION_GET and OSSL_ACTION_SET are * supported, and |fixup_args| will determine which it is. This is to * support translations of ctrls where the action type depends on the * value of |p1| or |p2| (ctrls are really bi-directional, but are @@ -271,7 +271,7 @@ struct translation_st { /* * Fixer functions * - * |fixup_args| is always called before (for SET) or after (for GET) + * |fixup_args| is always called before (for OSSL_ACTION_SET) or after (for OSSL_ACTION_GET) * the actual ctrl / OSSL_PARAM function. */ fixup_args_fn *fixup_args; @@ -312,7 +312,7 @@ static int default_check(enum state state, * function will have to deal with it carefully. */ if (translation != NULL) { - if (!ossl_assert(translation->action_type != GET)) { + if (!ossl_assert(translation->action_type != OSSL_ACTION_GET)) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); return -2; } @@ -344,7 +344,7 @@ static int default_check(enum state state, * default_fixup_args fixes up all sorts of arguments, governed by the * diverse attributes in the translation item. It covers all "standard" * base ctrl functionality, meaning it can handle basic conversion of - * data between p1+p2 (SET) or return value+p2 (GET) as long as the values + * data between p1+p2 (OSSL_ACTION_SET) or return value+p2 (OSSL_ACTION_GET) as long as the values * don't have extra semantics (such as NIDs, OIDs, that sort of stuff). * Extra semantics must be handled via specific fixup_args functions. * @@ -353,33 +353,36 @@ static int default_check(enum state state, * * PRE_CTRL_TO_PARAMS, 0 - ERROR. action type must be * determined by a fixup function. - * PRE_CTRL_TO_PARAMS, SET | GET - |p1| and |p2| are converted to an + * PRE_CTRL_TO_PARAMS, OSSL_ACTION_SET + * | OSSL_ACTION_GET - |p1| and |p2| are converted to an * OSSL_PARAM according to the data * type given in |translattion|. * For OSSL_PARAM_UNSIGNED_INTEGER, * a BIGNUM passed as |p2| is accepted. - * POST_CTRL_TO_PARAMS, GET - If the OSSL_PARAM data type is a + * POST_CTRL_TO_PARAMS, OSSL_ACTION_GET - If the OSSL_PARAM data type is a * STRING or PTR type, |p1| is set * to the OSSL_PARAM return size, and * |p2| is set to the string. - * PRE_CTRL_STR_TO_PARAMS, !SET - ERROR. That combination is not + * PRE_CTRL_STR_TO_PARAMS, + * !OSSL_ACTION_SET - ERROR. That combination is not * supported. - * PRE_CTRL_STR_TO_PARAMS, SET - |p2| is taken as a string, and is + * PRE_CTRL_STR_TO_PARAMS, + * OSSL_ACTION_SET - |p2| is taken as a string, and is * converted to an OSSL_PARAM in a * standard manner, guided by the * param key and data type from * |translation|. - * PRE_PARAMS_TO_CTRL, SET - the OSSL_PARAM is converted to + * PRE_PARAMS_TO_CTRL, OSSL_ACTION_SET - the OSSL_PARAM is converted to * |p1| and |p2| according to the * data type given in |translation| * For OSSL_PARAM_UNSIGNED_INTEGER, * if |p2| is non-NULL, then |*p2| * is assigned a BIGNUM, otherwise * |p1| is assigned an unsigned int. - * POST_PARAMS_TO_CTRL, GET - |p1| and |p2| are converted to + * POST_PARAMS_TO_CTRL, OSSL_ACTION_GET - |p1| and |p2| are converted to * an OSSL_PARAM, in the same manner * as for the combination of - * PRE_CTRL_TO_PARAMS, SET. + * PRE_CTRL_TO_PARAMS, OSSL_ACTION_SET. */ static int default_fixup_args(enum state state, const struct translation_st *translation, @@ -405,7 +408,7 @@ static int default_fixup_args(enum state state, */ case PRE_CTRL_TO_PARAMS: /* This is ctrl to params translation, so we need an OSSL_PARAM key */ - if (ctx->action_type == NONE) { + if (ctx->action_type == OSSL_ACTION_NONE) { /* * No action type is an error here. That's a case for a * special fixup function. @@ -439,7 +442,7 @@ static int default_fixup_args(enum state state, } /* - * OSSL_PARAM_construct_TYPE() works equally well for both SET and GET. + * OSSL_PARAM_construct_TYPE() works equally well for OSSL_ACTION_SET and OSSL_ACTION_GET. */ switch (translation->param_data_type) { case OSSL_PARAM_INTEGER: @@ -456,7 +459,7 @@ static int default_fixup_args(enum state state, * must deallocate. */ if (ctx->p2 != NULL) { - if (ctx->action_type == SET) { + if (ctx->action_type == OSSL_ACTION_SET) { ctx->buflen = BN_num_bytes(ctx->p2); if ((ctx->allocated_buf = OPENSSL_malloc(ctx->buflen)) == NULL) @@ -516,7 +519,7 @@ static int default_fixup_args(enum state state, * as its return value, we need to ensure that we do it here as well, * for the OSSL_PARAM data types where this makes sense. */ - if (ctx->action_type == GET) { + if (ctx->action_type == OSSL_ACTION_GET) { switch (translation->param_data_type) { case OSSL_PARAM_UTF8_STRING: case OSSL_PARAM_UTF8_PTR: @@ -544,7 +547,7 @@ static int default_fixup_args(enum state state, int exists = 0; /* Only setting is supported here */ - if (ctx->action_type != SET) { + if (ctx->action_type != OSSL_ACTION_SET) { ERR_raise_data(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED, "[action:%d, state:%d] only setting allowed", ctx->action_type, state); @@ -610,7 +613,7 @@ static int default_fixup_args(enum state state, case PRE_PARAMS_TO_CTRL: { /* This is params to ctrl translation */ - if (state == PRE_PARAMS_TO_CTRL && ctx->action_type == SET) { + if (state == PRE_PARAMS_TO_CTRL && ctx->action_type == OSSL_ACTION_SET) { /* For the PRE state, only setting needs some work to be done */ /* When setting, we populate |p1| and |p2| from |*params| */ @@ -648,7 +651,7 @@ static int default_fixup_args(enum state state, return 0; } } else if ((state == POST_PARAMS_TO_CTRL || state == PKEY) - && ctx->action_type == GET) { + && ctx->action_type == OSSL_ACTION_GET) { /* For the POST state, only getting needs some work to be done */ unsigned int param_data_type = translation->param_data_type; size_t size = (size_t)ctx->p1; @@ -693,7 +696,7 @@ static int default_fixup_args(enum state state, translation->param_data_type); return 0; } - } else if (state == PRE_PARAMS_TO_CTRL && ctx->action_type == GET) { + } else if (state == PRE_PARAMS_TO_CTRL && ctx->action_type == OSSL_ACTION_GET) { if (translation->param_data_type == OSSL_PARAM_OCTET_PTR) ctx->p2 = &ctx->bufp; } @@ -716,8 +719,8 @@ cleanup_translation_ctx(enum state state, } /* - * fix_cipher_md fixes up an EVP_CIPHER / EVP_MD to its name on SET, - * and cipher / md name to EVP_MD on GET. + * fix_cipher_md fixes up an EVP_CIPHER / EVP_MD to its name on OSSL_ACTION_SET, + * and cipher / md name to EVP_MD on OSSL_ACTION_GET. */ static const char *get_cipher_name(void *cipher) { @@ -751,7 +754,7 @@ static int fix_cipher_md(enum state state, if ((ret = default_check(state, translation, ctx)) <= 0) return ret; - if (state == PRE_CTRL_TO_PARAMS && ctx->action_type == GET) { + if (state == PRE_CTRL_TO_PARAMS && ctx->action_type == OSSL_ACTION_GET) { /* * |ctx->p2| contains the address to an EVP_CIPHER or EVP_MD pointer * to be filled in. We need to remember it, then make |ctx->p2| @@ -762,7 +765,7 @@ static int fix_cipher_md(enum state state, ctx->orig_p2 = ctx->p2; ctx->p2 = ctx->name_buf; ctx->p1 = sizeof(ctx->name_buf); - } else if (state == PRE_CTRL_TO_PARAMS && ctx->action_type == SET) { + } else if (state == PRE_CTRL_TO_PARAMS && ctx->action_type == OSSL_ACTION_SET) { /* * In different parts of OpenSSL, this ctrl command is used * differently. Some calls pass a NID as p1, others pass an @@ -772,7 +775,7 @@ static int fix_cipher_md(enum state state, ? OBJ_nid2sn(ctx->p1) : get_name(ctx->p2)); ctx->p1 = strlen(ctx->p2); - } else if (state == POST_PARAMS_TO_CTRL && ctx->action_type == GET) { + } else if (state == POST_PARAMS_TO_CTRL && ctx->action_type == OSSL_ACTION_GET) { ctx->p2 = (ctx->p2 == NULL ? "" : (char *)get_name(ctx->p2)); ctx->p1 = strlen(ctx->p2); } @@ -780,7 +783,7 @@ static int fix_cipher_md(enum state state, if ((ret = default_fixup_args(state, translation, ctx)) <= 0) return ret; - if (state == POST_CTRL_TO_PARAMS && ctx->action_type == GET) { + if (state == POST_CTRL_TO_PARAMS && ctx->action_type == OSSL_ACTION_GET) { /* * Here's how we reuse |ctx->orig_p2| that was set in the * PRE_CTRL_TO_PARAMS state above. @@ -788,7 +791,7 @@ static int fix_cipher_md(enum state state, *(void **)ctx->orig_p2 = (void *)get_algo_by_name(ctx->pctx->libctx, ctx->p2); ctx->p1 = 1; - } else if (state == PRE_PARAMS_TO_CTRL && ctx->action_type == SET) { + } else if (state == PRE_PARAMS_TO_CTRL && ctx->action_type == OSSL_ACTION_SET) { ctx->p2 = (void *)get_algo_by_name(ctx->pctx->libctx, ctx->p2); ctx->p1 = 0; } @@ -821,7 +824,7 @@ static int fix_distid_len(enum state state, if (ret > 0) { ret = 0; if ((state == POST_CTRL_TO_PARAMS - || state == POST_CTRL_STR_TO_PARAMS) && ctx->action_type == GET) { + || state == POST_CTRL_STR_TO_PARAMS) && ctx->action_type == OSSL_ACTION_GET) { *(size_t *)ctx->p2 = ctx->sz; ret = 1; } @@ -854,9 +857,9 @@ static int fix_kdf_type(enum state state, if (state == PRE_CTRL_TO_PARAMS) { /* * In |translations|, the initial value for |ctx->action_type| must - * be NONE. + * be OSSL_ACTION_NONE. */ - if (!ossl_assert(ctx->action_type == NONE)) + if (!ossl_assert(ctx->action_type == OSSL_ACTION_NONE)) return 0; /* The action type depends on the value of *p1 */ @@ -871,17 +874,17 @@ static int fix_kdf_type(enum state state, */ ctx->p2 = ctx->name_buf; ctx->p1 = sizeof(ctx->name_buf); - ctx->action_type = GET; + ctx->action_type = OSSL_ACTION_GET; } else { - ctx->action_type = SET; + ctx->action_type = OSSL_ACTION_SET; } } if ((ret = default_check(state, translation, ctx)) <= 0) return ret; - if ((state == PRE_CTRL_TO_PARAMS && ctx->action_type == SET) - || (state == POST_PARAMS_TO_CTRL && ctx->action_type == GET)) { + if ((state == PRE_CTRL_TO_PARAMS && ctx->action_type == OSSL_ACTION_SET) + || (state == POST_PARAMS_TO_CTRL && ctx->action_type == OSSL_ACTION_GET)) { ret = -2; /* Convert KDF type numbers to strings */ for (; kdf_type_map->kdf_type_str != NULL; kdf_type_map++) @@ -898,8 +901,8 @@ static int fix_kdf_type(enum state state, if ((ret = default_fixup_args(state, translation, ctx)) <= 0) return ret; - if ((state == POST_CTRL_TO_PARAMS && ctx->action_type == GET) - || (state == PRE_PARAMS_TO_CTRL && ctx->action_type == SET)) { + if ((state == POST_CTRL_TO_PARAMS && ctx->action_type == OSSL_ACTION_GET) + || (state == PRE_PARAMS_TO_CTRL && ctx->action_type == OSSL_ACTION_SET)) { ctx->p1 = ret = -1; /* Convert KDF type strings to numbers */ @@ -910,7 +913,7 @@ static int fix_kdf_type(enum state state, break; } ctx->p2 = NULL; - } else if (state == PRE_PARAMS_TO_CTRL && ctx->action_type == GET) { + } else if (state == PRE_PARAMS_TO_CTRL && ctx->action_type == OSSL_ACTION_GET) { ctx->p1 = -2; } end: @@ -955,8 +958,8 @@ static int fix_oid(enum state state, if ((ret = default_check(state, translation, ctx)) <= 0) return ret; - if ((state == PRE_CTRL_TO_PARAMS && ctx->action_type == SET) - || (state == POST_PARAMS_TO_CTRL && ctx->action_type == GET)) { + if ((state == PRE_CTRL_TO_PARAMS && ctx->action_type == OSSL_ACTION_SET) + || (state == POST_PARAMS_TO_CTRL && ctx->action_type == OSSL_ACTION_GET)) { /* * We're translating from ctrl to params and setting the OID, or * we're translating from params to ctrl and getting the OID. @@ -973,8 +976,8 @@ static int fix_oid(enum state state, if ((ret = default_fixup_args(state, translation, ctx)) <= 0) return ret; - if ((state == PRE_PARAMS_TO_CTRL && ctx->action_type == SET) - || (state == POST_CTRL_TO_PARAMS && ctx->action_type == GET)) { + if ((state == PRE_PARAMS_TO_CTRL && ctx->action_type == OSSL_ACTION_SET) + || (state == POST_CTRL_TO_PARAMS && ctx->action_type == OSSL_ACTION_GET)) { /* * We're translating from ctrl to params and setting the OID name, * or we're translating from params to ctrl and getting the OID @@ -999,7 +1002,7 @@ static int fix_dh_nid(enum state state, return ret; /* This is only settable */ - if (ctx->action_type != SET) + if (ctx->action_type != OSSL_ACTION_SET) return 0; if (state == PRE_CTRL_TO_PARAMS) { @@ -1025,7 +1028,7 @@ static int fix_dh_nid5114(enum state state, return ret; /* This is only settable */ - if (ctx->action_type != SET) + if (ctx->action_type != OSSL_ACTION_SET) return 0; switch (state) { @@ -1069,7 +1072,7 @@ static int fix_dh_paramgen_type(enum state state, return ret; /* This is only settable */ - if (ctx->action_type != SET) + if (ctx->action_type != OSSL_ACTION_SET) return 0; if (state == PRE_CTRL_STR_TO_PARAMS) { @@ -1095,7 +1098,7 @@ static int fix_ec_param_enc(enum state state, return ret; /* This is currently only settable */ - if (ctx->action_type != SET) + if (ctx->action_type != OSSL_ACTION_SET) return 0; if (state == PRE_CTRL_TO_PARAMS) { @@ -1144,7 +1147,7 @@ static int fix_ec_paramgen_curve_nid(enum state state, return ret; /* This is currently only settable */ - if (ctx->action_type != SET) + if (ctx->action_type != OSSL_ACTION_SET) return 0; if (state == PRE_CTRL_TO_PARAMS) { @@ -1194,28 +1197,28 @@ static int fix_ecdh_cofactor(enum state state, * The initial value for |ctx->action_type| must be zero. * evp_pkey_ctrl_to_params() takes it from the translation item. */ - if (!ossl_assert(ctx->action_type == NONE)) + if (!ossl_assert(ctx->action_type == OSSL_ACTION_NONE)) return 0; /* The action type depends on the value of ctx->p1 */ if (ctx->p1 == -2) - ctx->action_type = GET; + ctx->action_type = OSSL_ACTION_GET; else - ctx->action_type = SET; + ctx->action_type = OSSL_ACTION_SET; } else if (state == PRE_CTRL_STR_TO_PARAMS) { - ctx->action_type = SET; + ctx->action_type = OSSL_ACTION_SET; } else if (state == PRE_PARAMS_TO_CTRL) { /* The initial value for |ctx->action_type| must not be zero. */ - if (!ossl_assert(ctx->action_type != NONE)) + if (!ossl_assert(ctx->action_type != OSSL_ACTION_NONE)) return 0; - } else if (state == POST_PARAMS_TO_CTRL && ctx->action_type == NONE) { - ctx->action_type = GET; + } else if (state == POST_PARAMS_TO_CTRL && ctx->action_type == OSSL_ACTION_NONE) { + ctx->action_type = OSSL_ACTION_GET; } if ((ret = default_check(state, translation, ctx)) <= 0) return ret; - if (state == PRE_CTRL_TO_PARAMS && ctx->action_type == SET) { + if (state == PRE_CTRL_TO_PARAMS && ctx->action_type == OSSL_ACTION_SET) { if (ctx->p1 < -1 || ctx->p1 > 1) { /* Uses the same return value of pkey_ec_ctrl() */ return -2; @@ -1225,7 +1228,7 @@ static int fix_ecdh_cofactor(enum state state, if ((ret = default_fixup_args(state, translation, ctx)) <= 0) return ret; - if (state == POST_CTRL_TO_PARAMS && ctx->action_type == GET) { + if (state == POST_CTRL_TO_PARAMS && ctx->action_type == OSSL_ACTION_GET) { if (ctx->p1 < 0 || ctx->p1 > 1) { /* * The provider should return either 0 or 1, any other value is a @@ -1233,9 +1236,9 @@ static int fix_ecdh_cofactor(enum state state, */ ctx->p1 = ret = -1; } - } else if (state == PRE_PARAMS_TO_CTRL && ctx->action_type == GET) { + } else if (state == PRE_PARAMS_TO_CTRL && ctx->action_type == OSSL_ACTION_GET) { ctx->p1 = -2; - } else if (state == POST_PARAMS_TO_CTRL && ctx->action_type == GET) { + } else if (state == POST_PARAMS_TO_CTRL && ctx->action_type == OSSL_ACTION_GET) { ctx->p1 = ret; } @@ -1262,7 +1265,7 @@ static int fix_rsa_padding_mode(enum state state, if ((ret = default_check(state, translation, ctx)) <= 0) return ret; - if (state == PRE_CTRL_TO_PARAMS && ctx->action_type == GET) { + if (state == PRE_CTRL_TO_PARAMS && ctx->action_type == OSSL_ACTION_GET) { /* * EVP_PKEY_CTRL_GET_RSA_PADDING returns the padding mode in the * weirdest way for a ctrl. Instead of doing like all other ctrls @@ -1271,13 +1274,13 @@ static int fix_rsa_padding_mode(enum state state, * returned. We must therefore remember |ctx->p2|, then make * |ctx->p2| point at a buffer to be filled in with the name, and * |ctx->p1| with its size. default_fixup_args() will take care - * of the rest for us, along with the POST_CTRL_TO_PARAMS && GET + * of the rest for us, along with the POST_CTRL_TO_PARAMS && OSSL_ACTION_GET * code section further down. */ ctx->orig_p2 = ctx->p2; ctx->p2 = ctx->name_buf; ctx->p1 = sizeof(ctx->name_buf); - } else if (state == PRE_CTRL_TO_PARAMS && ctx->action_type == SET) { + } else if (state == PRE_CTRL_TO_PARAMS && ctx->action_type == OSSL_ACTION_SET) { /* * Ideally, we should use utf8 strings for the diverse padding modes. * We only came here because someone called EVP_PKEY_CTX_ctrl(), @@ -1298,7 +1301,7 @@ static int fix_rsa_padding_mode(enum state state, ctx->params[0] = OSSL_PARAM_construct_int(translation->param_key, &ctx->p1); return 1; - } else if (state == POST_PARAMS_TO_CTRL && ctx->action_type == GET) { + } else if (state == POST_PARAMS_TO_CTRL && ctx->action_type == OSSL_ACTION_GET) { size_t i; /* @@ -1341,8 +1344,8 @@ static int fix_rsa_padding_mode(enum state state, if ((ret = default_fixup_args(state, translation, ctx)) <= 0) return ret; - if ((ctx->action_type == SET && state == PRE_PARAMS_TO_CTRL) - || (ctx->action_type == GET && state == POST_CTRL_TO_PARAMS)) { + if ((ctx->action_type == OSSL_ACTION_SET && state == PRE_PARAMS_TO_CTRL) + || (ctx->action_type == OSSL_ACTION_GET && state == POST_CTRL_TO_PARAMS)) { size_t i; for (i = 0; i < OSSL_NELEM(str_value_map); i++) { @@ -1382,7 +1385,7 @@ static int fix_rsa_pss_saltlen(enum state state, if ((ret = default_check(state, translation, ctx)) <= 0) return ret; - if (state == PRE_CTRL_TO_PARAMS && ctx->action_type == GET) { + if (state == PRE_CTRL_TO_PARAMS && ctx->action_type == OSSL_ACTION_GET) { /* * EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN returns the saltlen by filling * in the int pointed at by p2. This is potentially as weird as @@ -1392,14 +1395,14 @@ static int fix_rsa_pss_saltlen(enum state state, * In any case, we must therefore remember |ctx->p2|, then make * |ctx->p2| point at a buffer to be filled in with the name, and * |ctx->p1| with its size. default_fixup_args() will take care - * of the rest for us, along with the POST_CTRL_TO_PARAMS && GET + * of the rest for us, along with the POST_CTRL_TO_PARAMS && OSSL_ACTION_GET * code section further down. */ ctx->orig_p2 = ctx->p2; ctx->p2 = ctx->name_buf; ctx->p1 = sizeof(ctx->name_buf); - } else if ((ctx->action_type == SET && state == PRE_CTRL_TO_PARAMS) - || (ctx->action_type == GET && state == POST_PARAMS_TO_CTRL)) { + } else if ((ctx->action_type == OSSL_ACTION_SET && state == PRE_CTRL_TO_PARAMS) + || (ctx->action_type == OSSL_ACTION_GET && state == POST_PARAMS_TO_CTRL)) { size_t i; for (i = 0; i < OSSL_NELEM(str_value_map); i++) { @@ -1420,8 +1423,8 @@ static int fix_rsa_pss_saltlen(enum state state, if ((ret = default_fixup_args(state, translation, ctx)) <= 0) return ret; - if ((ctx->action_type == SET && state == PRE_PARAMS_TO_CTRL) - || (ctx->action_type == GET && state == POST_CTRL_TO_PARAMS)) { + if ((ctx->action_type == OSSL_ACTION_SET && state == PRE_PARAMS_TO_CTRL) + || (ctx->action_type == OSSL_ACTION_GET && state == POST_CTRL_TO_PARAMS)) { size_t i; int val; @@ -1462,8 +1465,8 @@ static int fix_hkdf_mode(enum state state, if ((ret = default_check(state, translation, ctx)) <= 0) return ret; - if ((ctx->action_type == SET && state == PRE_CTRL_TO_PARAMS) - || (ctx->action_type == GET && state == POST_PARAMS_TO_CTRL)) { + if ((ctx->action_type == OSSL_ACTION_SET && state == PRE_CTRL_TO_PARAMS) + || (ctx->action_type == OSSL_ACTION_GET && state == POST_PARAMS_TO_CTRL)) { size_t i; for (i = 0; i < OSSL_NELEM(str_value_map); i++) { @@ -1479,8 +1482,8 @@ static int fix_hkdf_mode(enum state state, if ((ret = default_fixup_args(state, translation, ctx)) <= 0) return ret; - if ((ctx->action_type == SET && state == PRE_PARAMS_TO_CTRL) - || (ctx->action_type == GET && state == POST_CTRL_TO_PARAMS)) { + if ((ctx->action_type == OSSL_ACTION_SET && state == PRE_PARAMS_TO_CTRL) + || (ctx->action_type == OSSL_ACTION_GET && state == POST_CTRL_TO_PARAMS)) { size_t i; for (i = 0; i < OSSL_NELEM(str_value_map); i++) { @@ -1504,7 +1507,7 @@ static int fix_hkdf_mode(enum state state, * =============== * * These all get the data they want, then call default_fixup_args() as - * a post-ctrl GET fixup. They all get NULL ctx, ctrl_cmd, ctrl_str, + * a post-ctrl OSSL_ACTION_GET fixup. They all get NULL ctx, ctrl_cmd, ctrl_str, * p1, sz */ @@ -2047,7 +2050,7 @@ static int fix_group_ecx(enum state state, case PRE_PARAMS_TO_CTRL: if (!EVP_PKEY_CTX_IS_GEN_OP(ctx->pctx)) return 0; - ctx->action_type = NONE; + ctx->action_type = OSSL_ACTION_NONE; return 1; case POST_PARAMS_TO_CTRL: if (OSSL_PARAM_get_utf8_string_ptr(ctx->params, &value) == 0 || @@ -2077,13 +2080,13 @@ static const struct translation_st evp_pkey_ctx_translations[] = { * that has no separate counterpart in OSSL_PARAM terms, since we get * the length of the DistID automatically when getting the DistID itself. */ - { SET, -1, -1, EVP_PKEY_OP_TYPE_SIG, + { OSSL_ACTION_SET, -1, -1, EVP_PKEY_OP_TYPE_SIG, EVP_PKEY_CTRL_SET1_ID, "distid", "hexdistid", OSSL_PKEY_PARAM_DIST_ID, OSSL_PARAM_OCTET_STRING, NULL }, - { GET, -1, -1, -1, + { OSSL_ACTION_GET, -1, -1, -1, EVP_PKEY_CTRL_GET1_ID, "distid", "hexdistid", OSSL_PKEY_PARAM_DIST_ID, OSSL_PARAM_OCTET_PTR, NULL }, - { GET, -1, -1, -1, + { OSSL_ACTION_GET, -1, -1, -1, EVP_PKEY_CTRL_GET1_ID_LEN, NULL, NULL, OSSL_PKEY_PARAM_DIST_ID, OSSL_PARAM_OCTET_PTR, fix_distid_len }, @@ -2096,74 +2099,74 @@ static const struct translation_st evp_pkey_ctx_translations[] = { * EVP_PKEY_CTRL_DH_KDF_TYPE is used both for setting and getting. The * fixup function has to handle this... */ - { NONE, EVP_PKEY_DHX, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_NONE, EVP_PKEY_DHX, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_DH_KDF_TYPE, NULL, NULL, OSSL_EXCHANGE_PARAM_KDF_TYPE, OSSL_PARAM_UTF8_STRING, fix_dh_kdf_type }, - { SET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_DH_KDF_MD, NULL, NULL, OSSL_EXCHANGE_PARAM_KDF_DIGEST, OSSL_PARAM_UTF8_STRING, fix_md }, - { GET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_GET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_GET_DH_KDF_MD, NULL, NULL, OSSL_EXCHANGE_PARAM_KDF_DIGEST, OSSL_PARAM_UTF8_STRING, fix_md }, - { SET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_DH_KDF_OUTLEN, NULL, NULL, OSSL_EXCHANGE_PARAM_KDF_OUTLEN, OSSL_PARAM_UNSIGNED_INTEGER, NULL }, - { GET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_GET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_GET_DH_KDF_OUTLEN, NULL, NULL, OSSL_EXCHANGE_PARAM_KDF_OUTLEN, OSSL_PARAM_UNSIGNED_INTEGER, NULL }, - { SET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_DH_KDF_UKM, NULL, NULL, OSSL_EXCHANGE_PARAM_KDF_UKM, OSSL_PARAM_OCTET_STRING, NULL }, - { GET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_GET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_GET_DH_KDF_UKM, NULL, NULL, OSSL_EXCHANGE_PARAM_KDF_UKM, OSSL_PARAM_OCTET_PTR, NULL }, - { SET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_DH_KDF_OID, NULL, NULL, OSSL_KDF_PARAM_CEK_ALG, OSSL_PARAM_UTF8_STRING, fix_oid }, - { GET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_GET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_GET_DH_KDF_OID, NULL, NULL, OSSL_KDF_PARAM_CEK_ALG, OSSL_PARAM_UTF8_STRING, fix_oid }, /* DHX Keygen Parameters that are shared with DH */ - { SET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_PARAMGEN, + { OSSL_ACTION_SET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_PARAMGEN, EVP_PKEY_CTRL_DH_PARAMGEN_TYPE, "dh_paramgen_type", NULL, OSSL_PKEY_PARAM_FFC_TYPE, OSSL_PARAM_UTF8_STRING, fix_dh_paramgen_type }, - { SET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_PARAMGEN, + { OSSL_ACTION_SET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_PARAMGEN, EVP_PKEY_CTRL_DH_PARAMGEN_PRIME_LEN, "dh_paramgen_prime_len", NULL, OSSL_PKEY_PARAM_FFC_PBITS, OSSL_PARAM_UNSIGNED_INTEGER, NULL }, - { SET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN, + { OSSL_ACTION_SET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN, EVP_PKEY_CTRL_DH_NID, "dh_param", NULL, OSSL_PKEY_PARAM_GROUP_NAME, OSSL_PARAM_UTF8_STRING, NULL }, - { SET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN, + { OSSL_ACTION_SET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN, EVP_PKEY_CTRL_DH_RFC5114, "dh_rfc5114", NULL, OSSL_PKEY_PARAM_GROUP_NAME, OSSL_PARAM_UTF8_STRING, fix_dh_nid5114 }, /* DH Keygen Parameters that are shared with DHX */ - { SET, EVP_PKEY_DH, 0, EVP_PKEY_OP_PARAMGEN, + { OSSL_ACTION_SET, EVP_PKEY_DH, 0, EVP_PKEY_OP_PARAMGEN, EVP_PKEY_CTRL_DH_PARAMGEN_TYPE, "dh_paramgen_type", NULL, OSSL_PKEY_PARAM_FFC_TYPE, OSSL_PARAM_UTF8_STRING, fix_dh_paramgen_type }, - { SET, EVP_PKEY_DH, 0, EVP_PKEY_OP_PARAMGEN, + { OSSL_ACTION_SET, EVP_PKEY_DH, 0, EVP_PKEY_OP_PARAMGEN, EVP_PKEY_CTRL_DH_PARAMGEN_PRIME_LEN, "dh_paramgen_prime_len", NULL, OSSL_PKEY_PARAM_FFC_PBITS, OSSL_PARAM_UNSIGNED_INTEGER, NULL }, - { SET, EVP_PKEY_DH, 0, EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN, + { OSSL_ACTION_SET, EVP_PKEY_DH, 0, EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN, EVP_PKEY_CTRL_DH_NID, "dh_param", NULL, OSSL_PKEY_PARAM_GROUP_NAME, OSSL_PARAM_UTF8_STRING, fix_dh_nid }, - { SET, EVP_PKEY_DH, 0, EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN, + { OSSL_ACTION_SET, EVP_PKEY_DH, 0, EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN, EVP_PKEY_CTRL_DH_RFC5114, "dh_rfc5114", NULL, OSSL_PKEY_PARAM_GROUP_NAME, OSSL_PARAM_UTF8_STRING, fix_dh_nid5114 }, /* DH specific Keygen Parameters */ - { SET, EVP_PKEY_DH, 0, EVP_PKEY_OP_PARAMGEN, + { OSSL_ACTION_SET, EVP_PKEY_DH, 0, EVP_PKEY_OP_PARAMGEN, EVP_PKEY_CTRL_DH_PARAMGEN_GENERATOR, "dh_paramgen_generator", NULL, OSSL_PKEY_PARAM_DH_GENERATOR, OSSL_PARAM_INTEGER, NULL }, /* DHX specific Keygen Parameters */ - { SET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_PARAMGEN, + { OSSL_ACTION_SET, EVP_PKEY_DHX, 0, EVP_PKEY_OP_PARAMGEN, EVP_PKEY_CTRL_DH_PARAMGEN_SUBPRIME_LEN, "dh_paramgen_subprime_len", NULL, OSSL_PKEY_PARAM_FFC_QBITS, OSSL_PARAM_UNSIGNED_INTEGER, NULL }, - { SET, EVP_PKEY_DH, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, EVP_PKEY_DH, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_DH_PAD, "dh_pad", NULL, OSSL_EXCHANGE_PARAM_PAD, OSSL_PARAM_UNSIGNED_INTEGER, NULL }, @@ -2171,13 +2174,13 @@ static const struct translation_st evp_pkey_ctx_translations[] = { * DSA * === */ - { SET, EVP_PKEY_DSA, 0, EVP_PKEY_OP_PARAMGEN, + { OSSL_ACTION_SET, EVP_PKEY_DSA, 0, EVP_PKEY_OP_PARAMGEN, EVP_PKEY_CTRL_DSA_PARAMGEN_BITS, "dsa_paramgen_bits", NULL, OSSL_PKEY_PARAM_FFC_PBITS, OSSL_PARAM_UNSIGNED_INTEGER, NULL }, - { SET, EVP_PKEY_DSA, 0, EVP_PKEY_OP_PARAMGEN, + { OSSL_ACTION_SET, EVP_PKEY_DSA, 0, EVP_PKEY_OP_PARAMGEN, EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS, "dsa_paramgen_q_bits", NULL, OSSL_PKEY_PARAM_FFC_QBITS, OSSL_PARAM_UNSIGNED_INTEGER, NULL }, - { SET, EVP_PKEY_DSA, 0, EVP_PKEY_OP_PARAMGEN, + { OSSL_ACTION_SET, EVP_PKEY_DSA, 0, EVP_PKEY_OP_PARAMGEN, EVP_PKEY_CTRL_DSA_PARAMGEN_MD, "dsa_paramgen_md", NULL, OSSL_PKEY_PARAM_FFC_DIGEST, OSSL_PARAM_UTF8_STRING, fix_md }, @@ -2185,10 +2188,10 @@ static const struct translation_st evp_pkey_ctx_translations[] = { * EC * == */ - { SET, EVP_PKEY_EC, 0, EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN, + { OSSL_ACTION_SET, EVP_PKEY_EC, 0, EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN, EVP_PKEY_CTRL_EC_PARAM_ENC, "ec_param_enc", NULL, OSSL_PKEY_PARAM_EC_ENCODING, OSSL_PARAM_UTF8_STRING, fix_ec_param_enc }, - { SET, EVP_PKEY_EC, 0, EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN, + { OSSL_ACTION_SET, EVP_PKEY_EC, 0, EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN, EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID, "ec_paramgen_curve", NULL, OSSL_PKEY_PARAM_GROUP_NAME, OSSL_PARAM_UTF8_STRING, fix_ec_paramgen_curve_nid }, @@ -2196,29 +2199,29 @@ static const struct translation_st evp_pkey_ctx_translations[] = { * EVP_PKEY_CTRL_EC_ECDH_COFACTOR and EVP_PKEY_CTRL_EC_KDF_TYPE are used * both for setting and getting. The fixup function has to handle this... */ - { NONE, EVP_PKEY_EC, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_NONE, EVP_PKEY_EC, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_EC_ECDH_COFACTOR, "ecdh_cofactor_mode", NULL, OSSL_EXCHANGE_PARAM_EC_ECDH_COFACTOR_MODE, OSSL_PARAM_INTEGER, fix_ecdh_cofactor }, - { NONE, EVP_PKEY_EC, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_NONE, EVP_PKEY_EC, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_EC_KDF_TYPE, NULL, NULL, OSSL_EXCHANGE_PARAM_KDF_TYPE, OSSL_PARAM_UTF8_STRING, fix_ec_kdf_type }, - { SET, EVP_PKEY_EC, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, EVP_PKEY_EC, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_EC_KDF_MD, "ecdh_kdf_md", NULL, OSSL_EXCHANGE_PARAM_KDF_DIGEST, OSSL_PARAM_UTF8_STRING, fix_md }, - { GET, EVP_PKEY_EC, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_GET, EVP_PKEY_EC, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_GET_EC_KDF_MD, NULL, NULL, OSSL_EXCHANGE_PARAM_KDF_DIGEST, OSSL_PARAM_UTF8_STRING, fix_md }, - { SET, EVP_PKEY_EC, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, EVP_PKEY_EC, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_EC_KDF_OUTLEN, NULL, NULL, OSSL_EXCHANGE_PARAM_KDF_OUTLEN, OSSL_PARAM_UNSIGNED_INTEGER, NULL }, - { GET, EVP_PKEY_EC, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_GET, EVP_PKEY_EC, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN, NULL, NULL, OSSL_EXCHANGE_PARAM_KDF_OUTLEN, OSSL_PARAM_UNSIGNED_INTEGER, NULL }, - { SET, EVP_PKEY_EC, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, EVP_PKEY_EC, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_EC_KDF_UKM, NULL, NULL, OSSL_EXCHANGE_PARAM_KDF_UKM, OSSL_PARAM_OCTET_STRING, NULL }, - { GET, EVP_PKEY_EC, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_GET, EVP_PKEY_EC, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_GET_EC_KDF_UKM, NULL, NULL, OSSL_EXCHANGE_PARAM_KDF_UKM, OSSL_PARAM_OCTET_PTR, NULL }, @@ -2226,10 +2229,10 @@ static const struct translation_st evp_pkey_ctx_translations[] = { * SM2 * == */ - { SET, EVP_PKEY_SM2, 0, EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN, + { OSSL_ACTION_SET, EVP_PKEY_SM2, 0, EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN, EVP_PKEY_CTRL_EC_PARAM_ENC, "ec_param_enc", NULL, OSSL_PKEY_PARAM_EC_ENCODING, OSSL_PARAM_UTF8_STRING, fix_ec_param_enc }, - { SET, EVP_PKEY_SM2, 0, EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN, + { OSSL_ACTION_SET, EVP_PKEY_SM2, 0, EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN, EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID, "ec_paramgen_curve", NULL, OSSL_PKEY_PARAM_GROUP_NAME, OSSL_PARAM_UTF8_STRING, fix_ec_paramgen_curve_nid }, @@ -2237,29 +2240,29 @@ static const struct translation_st evp_pkey_ctx_translations[] = { * EVP_PKEY_CTRL_EC_ECDH_COFACTOR and EVP_PKEY_CTRL_EC_KDF_TYPE are used * both for setting and getting. The fixup function has to handle this... */ - { NONE, EVP_PKEY_SM2, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_NONE, EVP_PKEY_SM2, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_EC_ECDH_COFACTOR, "ecdh_cofactor_mode", NULL, OSSL_EXCHANGE_PARAM_EC_ECDH_COFACTOR_MODE, OSSL_PARAM_INTEGER, fix_ecdh_cofactor }, - { NONE, EVP_PKEY_SM2, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_NONE, EVP_PKEY_SM2, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_EC_KDF_TYPE, NULL, NULL, OSSL_EXCHANGE_PARAM_KDF_TYPE, OSSL_PARAM_UTF8_STRING, fix_ec_kdf_type }, - { SET, EVP_PKEY_SM2, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, EVP_PKEY_SM2, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_EC_KDF_MD, "ecdh_kdf_md", NULL, OSSL_EXCHANGE_PARAM_KDF_DIGEST, OSSL_PARAM_UTF8_STRING, fix_md }, - { GET, EVP_PKEY_SM2, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_GET, EVP_PKEY_SM2, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_GET_EC_KDF_MD, NULL, NULL, OSSL_EXCHANGE_PARAM_KDF_DIGEST, OSSL_PARAM_UTF8_STRING, fix_md }, - { SET, EVP_PKEY_SM2, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, EVP_PKEY_SM2, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_EC_KDF_OUTLEN, NULL, NULL, OSSL_EXCHANGE_PARAM_KDF_OUTLEN, OSSL_PARAM_UNSIGNED_INTEGER, NULL }, - { GET, EVP_PKEY_SM2, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_GET, EVP_PKEY_SM2, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN, NULL, NULL, OSSL_EXCHANGE_PARAM_KDF_OUTLEN, OSSL_PARAM_UNSIGNED_INTEGER, NULL }, - { SET, EVP_PKEY_SM2, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, EVP_PKEY_SM2, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_EC_KDF_UKM, NULL, NULL, OSSL_EXCHANGE_PARAM_KDF_UKM, OSSL_PARAM_OCTET_STRING, NULL }, - { GET, EVP_PKEY_SM2, 0, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_GET, EVP_PKEY_SM2, 0, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_GET_EC_KDF_UKM, NULL, NULL, OSSL_EXCHANGE_PARAM_KDF_UKM, OSSL_PARAM_OCTET_PTR, NULL }, /*- @@ -2273,20 +2276,20 @@ static const struct translation_st evp_pkey_ctx_translations[] = { * fix_rsa_padding_mode() does the work when the caller has a different * idea. */ - { SET, EVP_PKEY_RSA, EVP_PKEY_RSA_PSS, + { OSSL_ACTION_SET, EVP_PKEY_RSA, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_TYPE_CRYPT | EVP_PKEY_OP_TYPE_SIG, EVP_PKEY_CTRL_RSA_PADDING, "rsa_padding_mode", NULL, OSSL_PKEY_PARAM_PAD_MODE, OSSL_PARAM_UTF8_STRING, fix_rsa_padding_mode }, - { GET, EVP_PKEY_RSA, EVP_PKEY_RSA_PSS, + { OSSL_ACTION_GET, EVP_PKEY_RSA, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_TYPE_CRYPT | EVP_PKEY_OP_TYPE_SIG, EVP_PKEY_CTRL_GET_RSA_PADDING, NULL, NULL, OSSL_PKEY_PARAM_PAD_MODE, OSSL_PARAM_UTF8_STRING, fix_rsa_padding_mode }, - { SET, EVP_PKEY_RSA, EVP_PKEY_RSA_PSS, + { OSSL_ACTION_SET, EVP_PKEY_RSA, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_TYPE_CRYPT | EVP_PKEY_OP_TYPE_SIG, EVP_PKEY_CTRL_RSA_MGF1_MD, "rsa_mgf1_md", NULL, OSSL_PKEY_PARAM_MGF1_DIGEST, OSSL_PARAM_UTF8_STRING, fix_md }, - { GET, EVP_PKEY_RSA, EVP_PKEY_RSA_PSS, + { OSSL_ACTION_GET, EVP_PKEY_RSA, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_TYPE_CRYPT | EVP_PKEY_OP_TYPE_SIG, EVP_PKEY_CTRL_GET_RSA_MGF1_MD, NULL, NULL, OSSL_PKEY_PARAM_MGF1_DIGEST, OSSL_PARAM_UTF8_STRING, fix_md }, @@ -2297,19 +2300,19 @@ static const struct translation_st evp_pkey_ctx_translations[] = { * OSSL_PARAM allows both forms. * fix_rsa_pss_saltlen() takes care of the distinction. */ - { SET, EVP_PKEY_RSA, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_TYPE_SIG, + { OSSL_ACTION_SET, EVP_PKEY_RSA, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_TYPE_SIG, EVP_PKEY_CTRL_RSA_PSS_SALTLEN, "rsa_pss_saltlen", NULL, OSSL_PKEY_PARAM_RSA_PSS_SALTLEN, OSSL_PARAM_UTF8_STRING, fix_rsa_pss_saltlen }, - { GET, EVP_PKEY_RSA, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_TYPE_SIG, + { OSSL_ACTION_GET, EVP_PKEY_RSA, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_TYPE_SIG, EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN, NULL, NULL, OSSL_PKEY_PARAM_RSA_PSS_SALTLEN, OSSL_PARAM_UTF8_STRING, fix_rsa_pss_saltlen }, - { SET, EVP_PKEY_RSA, 0, EVP_PKEY_OP_TYPE_CRYPT, + { OSSL_ACTION_SET, EVP_PKEY_RSA, 0, EVP_PKEY_OP_TYPE_CRYPT, EVP_PKEY_CTRL_RSA_OAEP_MD, "rsa_oaep_md", NULL, OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST, OSSL_PARAM_UTF8_STRING, fix_md }, - { GET, EVP_PKEY_RSA, 0, EVP_PKEY_OP_TYPE_CRYPT, + { OSSL_ACTION_GET, EVP_PKEY_RSA, 0, EVP_PKEY_OP_TYPE_CRYPT, EVP_PKEY_CTRL_GET_RSA_OAEP_MD, NULL, NULL, OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST, OSSL_PARAM_UTF8_STRING, fix_md }, /* @@ -2318,35 +2321,35 @@ static const struct translation_st evp_pkey_ctx_translations[] = { * expectation for any translation item where |ctrl_str| is NULL and * |ctrl_hexstr| is non-NULL. */ - { SET, EVP_PKEY_RSA, 0, EVP_PKEY_OP_TYPE_CRYPT, + { OSSL_ACTION_SET, EVP_PKEY_RSA, 0, EVP_PKEY_OP_TYPE_CRYPT, EVP_PKEY_CTRL_RSA_OAEP_LABEL, NULL, "rsa_oaep_label", OSSL_ASYM_CIPHER_PARAM_OAEP_LABEL, OSSL_PARAM_OCTET_STRING, NULL }, - { GET, EVP_PKEY_RSA, 0, EVP_PKEY_OP_TYPE_CRYPT, + { OSSL_ACTION_GET, EVP_PKEY_RSA, 0, EVP_PKEY_OP_TYPE_CRYPT, EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL, NULL, NULL, OSSL_ASYM_CIPHER_PARAM_OAEP_LABEL, OSSL_PARAM_OCTET_PTR, NULL }, - { SET, EVP_PKEY_RSA, 0, EVP_PKEY_OP_TYPE_CRYPT, + { OSSL_ACTION_SET, EVP_PKEY_RSA, 0, EVP_PKEY_OP_TYPE_CRYPT, EVP_PKEY_CTRL_RSA_IMPLICIT_REJECTION, NULL, "rsa_pkcs1_implicit_rejection", OSSL_ASYM_CIPHER_PARAM_IMPLICIT_REJECTION, OSSL_PARAM_UNSIGNED_INTEGER, NULL }, - { SET, EVP_PKEY_RSA_PSS, 0, EVP_PKEY_OP_TYPE_GEN, + { OSSL_ACTION_SET, EVP_PKEY_RSA_PSS, 0, EVP_PKEY_OP_TYPE_GEN, EVP_PKEY_CTRL_MD, "rsa_pss_keygen_md", NULL, OSSL_ALG_PARAM_DIGEST, OSSL_PARAM_UTF8_STRING, fix_md }, - { SET, EVP_PKEY_RSA_PSS, 0, EVP_PKEY_OP_TYPE_GEN, + { OSSL_ACTION_SET, EVP_PKEY_RSA_PSS, 0, EVP_PKEY_OP_TYPE_GEN, EVP_PKEY_CTRL_RSA_MGF1_MD, "rsa_pss_keygen_mgf1_md", NULL, OSSL_PKEY_PARAM_MGF1_DIGEST, OSSL_PARAM_UTF8_STRING, fix_md }, - { SET, EVP_PKEY_RSA_PSS, 0, EVP_PKEY_OP_TYPE_GEN, + { OSSL_ACTION_SET, EVP_PKEY_RSA_PSS, 0, EVP_PKEY_OP_TYPE_GEN, EVP_PKEY_CTRL_RSA_PSS_SALTLEN, "rsa_pss_keygen_saltlen", NULL, OSSL_SIGNATURE_PARAM_PSS_SALTLEN, OSSL_PARAM_INTEGER, NULL }, - { SET, EVP_PKEY_RSA, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_KEYGEN, + { OSSL_ACTION_SET, EVP_PKEY_RSA, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_KEYGEN, EVP_PKEY_CTRL_RSA_KEYGEN_BITS, "rsa_keygen_bits", NULL, OSSL_PKEY_PARAM_RSA_BITS, OSSL_PARAM_UNSIGNED_INTEGER, NULL }, - { SET, EVP_PKEY_RSA, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_KEYGEN, + { OSSL_ACTION_SET, EVP_PKEY_RSA, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_KEYGEN, EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP, "rsa_keygen_pubexp", NULL, OSSL_PKEY_PARAM_RSA_E, OSSL_PARAM_UNSIGNED_INTEGER, NULL }, - { SET, EVP_PKEY_RSA, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_KEYGEN, + { OSSL_ACTION_SET, EVP_PKEY_RSA, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_KEYGEN, EVP_PKEY_CTRL_RSA_KEYGEN_PRIMES, "rsa_keygen_primes", NULL, OSSL_PKEY_PARAM_RSA_PRIMES, OSSL_PARAM_UNSIGNED_INTEGER, NULL }, @@ -2354,7 +2357,7 @@ static const struct translation_st evp_pkey_ctx_translations[] = { * SipHash * ====== */ - { SET, -1, -1, EVP_PKEY_OP_TYPE_SIG, + { OSSL_ACTION_SET, -1, -1, EVP_PKEY_OP_TYPE_SIG, EVP_PKEY_CTRL_SET_DIGEST_SIZE, "digestsize", NULL, OSSL_MAC_PARAM_SIZE, OSSL_PARAM_UNSIGNED_INTEGER, NULL }, @@ -2362,13 +2365,13 @@ static const struct translation_st evp_pkey_ctx_translations[] = { * TLS1-PRF * ======== */ - { SET, -1, -1, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, -1, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_TLS_MD, "md", NULL, OSSL_KDF_PARAM_DIGEST, OSSL_PARAM_UTF8_STRING, fix_md }, - { SET, -1, -1, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, -1, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_TLS_SECRET, "secret", "hexsecret", OSSL_KDF_PARAM_SECRET, OSSL_PARAM_OCTET_STRING, NULL }, - { SET, -1, -1, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, -1, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_TLS_SEED, "seed", "hexseed", OSSL_KDF_PARAM_SEED, OSSL_PARAM_OCTET_STRING, NULL }, @@ -2376,19 +2379,19 @@ static const struct translation_st evp_pkey_ctx_translations[] = { * HKDF * ==== */ - { SET, -1, -1, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, -1, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_HKDF_MD, "md", NULL, OSSL_KDF_PARAM_DIGEST, OSSL_PARAM_UTF8_STRING, fix_md }, - { SET, -1, -1, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, -1, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_HKDF_SALT, "salt", "hexsalt", OSSL_KDF_PARAM_SALT, OSSL_PARAM_OCTET_STRING, NULL }, - { SET, -1, -1, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, -1, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_HKDF_KEY, "key", "hexkey", OSSL_KDF_PARAM_KEY, OSSL_PARAM_OCTET_STRING, NULL }, - { SET, -1, -1, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, -1, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_HKDF_INFO, "info", "hexinfo", OSSL_KDF_PARAM_INFO, OSSL_PARAM_OCTET_STRING, NULL }, - { SET, -1, -1, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, -1, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_HKDF_MODE, "mode", NULL, OSSL_KDF_PARAM_MODE, OSSL_PARAM_INTEGER, fix_hkdf_mode }, @@ -2396,36 +2399,36 @@ static const struct translation_st evp_pkey_ctx_translations[] = { * Scrypt * ====== */ - { SET, -1, -1, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, -1, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_PASS, "pass", "hexpass", OSSL_KDF_PARAM_PASSWORD, OSSL_PARAM_OCTET_STRING, NULL }, - { SET, -1, -1, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, -1, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_SCRYPT_SALT, "salt", "hexsalt", OSSL_KDF_PARAM_SALT, OSSL_PARAM_OCTET_STRING, NULL }, - { SET, -1, -1, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, -1, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_SCRYPT_N, "N", NULL, OSSL_KDF_PARAM_SCRYPT_N, OSSL_PARAM_UNSIGNED_INTEGER, NULL }, - { SET, -1, -1, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, -1, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_SCRYPT_R, "r", NULL, OSSL_KDF_PARAM_SCRYPT_R, OSSL_PARAM_UNSIGNED_INTEGER, NULL }, - { SET, -1, -1, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, -1, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_SCRYPT_P, "p", NULL, OSSL_KDF_PARAM_SCRYPT_P, OSSL_PARAM_UNSIGNED_INTEGER, NULL }, - { SET, -1, -1, EVP_PKEY_OP_DERIVE, + { OSSL_ACTION_SET, -1, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_SCRYPT_MAXMEM_BYTES, "maxmem_bytes", NULL, OSSL_KDF_PARAM_SCRYPT_MAXMEM, OSSL_PARAM_UNSIGNED_INTEGER, NULL }, - { SET, -1, -1, EVP_PKEY_OP_KEYGEN | EVP_PKEY_OP_TYPE_CRYPT, + { OSSL_ACTION_SET, -1, -1, EVP_PKEY_OP_KEYGEN | EVP_PKEY_OP_TYPE_CRYPT, EVP_PKEY_CTRL_CIPHER, NULL, NULL, OSSL_PKEY_PARAM_CIPHER, OSSL_PARAM_UTF8_STRING, fix_cipher }, - { SET, -1, -1, EVP_PKEY_OP_KEYGEN, + { OSSL_ACTION_SET, -1, -1, EVP_PKEY_OP_KEYGEN, EVP_PKEY_CTRL_SET_MAC_KEY, "key", "hexkey", OSSL_PKEY_PARAM_PRIV_KEY, OSSL_PARAM_OCTET_STRING, NULL }, - { SET, -1, -1, EVP_PKEY_OP_TYPE_SIG, + { OSSL_ACTION_SET, -1, -1, EVP_PKEY_OP_TYPE_SIG, EVP_PKEY_CTRL_MD, NULL, NULL, OSSL_SIGNATURE_PARAM_DIGEST, OSSL_PARAM_UTF8_STRING, fix_md }, - { GET, -1, -1, EVP_PKEY_OP_TYPE_SIG, + { OSSL_ACTION_GET, -1, -1, EVP_PKEY_OP_TYPE_SIG, EVP_PKEY_CTRL_GET_MD, NULL, NULL, OSSL_SIGNATURE_PARAM_DIGEST, OSSL_PARAM_UTF8_STRING, fix_md }, @@ -2433,13 +2436,13 @@ static const struct translation_st evp_pkey_ctx_translations[] = { * ECX * === */ - { SET, EVP_PKEY_X25519, EVP_PKEY_X25519, EVP_PKEY_OP_KEYGEN, -1, NULL, NULL, + { OSSL_ACTION_SET, EVP_PKEY_X25519, EVP_PKEY_X25519, EVP_PKEY_OP_KEYGEN, -1, NULL, NULL, OSSL_PKEY_PARAM_GROUP_NAME, OSSL_PARAM_UTF8_STRING, fix_group_ecx }, - { SET, EVP_PKEY_X25519, EVP_PKEY_X25519, EVP_PKEY_OP_PARAMGEN, -1, NULL, NULL, + { OSSL_ACTION_SET, EVP_PKEY_X25519, EVP_PKEY_X25519, EVP_PKEY_OP_PARAMGEN, -1, NULL, NULL, OSSL_PKEY_PARAM_GROUP_NAME, OSSL_PARAM_UTF8_STRING, fix_group_ecx }, - { SET, EVP_PKEY_X448, EVP_PKEY_X448, EVP_PKEY_OP_KEYGEN, -1, NULL, NULL, + { OSSL_ACTION_SET, EVP_PKEY_X448, EVP_PKEY_X448, EVP_PKEY_OP_KEYGEN, -1, NULL, NULL, OSSL_PKEY_PARAM_GROUP_NAME, OSSL_PARAM_UTF8_STRING, fix_group_ecx }, - { SET, EVP_PKEY_X448, EVP_PKEY_X448, EVP_PKEY_OP_PARAMGEN, -1, NULL, NULL, + { OSSL_ACTION_SET, EVP_PKEY_X448, EVP_PKEY_X448, EVP_PKEY_OP_PARAMGEN, -1, NULL, NULL, OSSL_PKEY_PARAM_GROUP_NAME, OSSL_PARAM_UTF8_STRING, fix_group_ecx }, }; @@ -2452,134 +2455,134 @@ static const struct translation_st evp_pkey_translations[] = { */ /* DH, DSA & EC */ - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_GROUP_NAME, OSSL_PARAM_UTF8_STRING, get_payload_group_name }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_PRIV_KEY, OSSL_PARAM_UNSIGNED_INTEGER, get_payload_private_key }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_PUB_KEY, 0 /* no data type, let get_payload_public_key() handle that */, get_payload_public_key }, - { GET, -1, -1, -1, 0, NULL, NULL, - OSSL_PKEY_PARAM_EC_PUB_X, OSSL_PARAM_UNSIGNED_INTEGER, - get_payload_public_key_ec }, - { GET, -1, -1, -1, 0, NULL, NULL, - OSSL_PKEY_PARAM_EC_PUB_Y, OSSL_PARAM_UNSIGNED_INTEGER, - get_payload_public_key_ec }, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, + OSSL_PKEY_PARAM_EC_PUB_X, OSSL_PARAM_UNSIGNED_INTEGER, + get_payload_public_key_ec }, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, + OSSL_PKEY_PARAM_EC_PUB_Y, OSSL_PARAM_UNSIGNED_INTEGER, + get_payload_public_key_ec }, /* DH and DSA */ - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_FFC_P, OSSL_PARAM_UNSIGNED_INTEGER, get_dh_dsa_payload_p }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_FFC_G, OSSL_PARAM_UNSIGNED_INTEGER, get_dh_dsa_payload_g }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_FFC_Q, OSSL_PARAM_UNSIGNED_INTEGER, get_dh_dsa_payload_q }, /* RSA */ - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_N, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_n }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_E, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_e }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_D, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_d }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_FACTOR1, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_f1 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_FACTOR2, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_f2 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_FACTOR3, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_f3 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_FACTOR4, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_f4 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_FACTOR5, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_f5 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_FACTOR6, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_f6 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_FACTOR7, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_f7 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_FACTOR8, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_f8 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_FACTOR9, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_f9 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_FACTOR10, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_f10 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_EXPONENT1, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_e1 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_EXPONENT2, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_e2 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_EXPONENT3, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_e3 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_EXPONENT4, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_e4 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_EXPONENT5, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_e5 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_EXPONENT6, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_e6 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_EXPONENT7, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_e7 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_EXPONENT8, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_e8 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_EXPONENT9, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_e9 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_EXPONENT10, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_e10 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_COEFFICIENT1, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_c1 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_COEFFICIENT2, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_c2 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_COEFFICIENT3, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_c3 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_COEFFICIENT4, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_c4 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_COEFFICIENT5, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_c5 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_COEFFICIENT6, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_c6 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_COEFFICIENT7, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_c7 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_COEFFICIENT8, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_c8 }, - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_RSA_COEFFICIENT9, OSSL_PARAM_UNSIGNED_INTEGER, get_rsa_payload_c9 }, /* EC */ - { GET, -1, -1, -1, 0, NULL, NULL, + { OSSL_ACTION_GET, -1, -1, -1, 0, NULL, NULL, OSSL_PKEY_PARAM_EC_DECODED_FROM_EXPLICIT_PARAMS, OSSL_PARAM_INTEGER, get_ec_decoded_from_explicit_params }, }; @@ -2636,8 +2639,8 @@ lookup_translation(struct translation_st *tmpl, * for setting, never for getting. Therefore, we only look at * the setter items. */ - if (item->action_type != NONE - && item->action_type != SET) + if (item->action_type != OSSL_ACTION_NONE + && item->action_type != OSSL_ACTION_SET) continue; /* * At least one of the ctrl cmd names must be match the ctrl @@ -2673,7 +2676,7 @@ lookup_translation(struct translation_st *tmpl, * key name can therefore be used in both directions. We must * therefore take the action type into account in this case. */ - if ((item->action_type != NONE + if ((item->action_type != OSSL_ACTION_NONE && tmpl->action_type != item->action_type) || (item->param_key != NULL && OPENSSL_strcasecmp(tmpl->param_key, @@ -2748,10 +2751,10 @@ int evp_pkey_ctx_ctrl_to_param(EVP_PKEY_CTX *pctx, default: /* fixup_args is expected to make sure this is dead code */ break; - case GET: + case OSSL_ACTION_GET: ret = evp_pkey_ctx_get_params_strict(pctx, ctx.params); break; - case SET: + case OSSL_ACTION_SET: ret = evp_pkey_ctx_set_params_strict(pctx, ctx.params); break; } @@ -2785,7 +2788,7 @@ int evp_pkey_ctx_ctrl_str_to_param(EVP_PKEY_CTX *pctx, int ret; fixup_args_fn *fixup = default_fixup_args; - tmpl.action_type = SET; + tmpl.action_type = OSSL_ACTION_SET; tmpl.keytype1 = tmpl.keytype2 = keytype; tmpl.optype = optype; tmpl.ctrl_str = name; @@ -2799,7 +2802,7 @@ int evp_pkey_ctx_ctrl_str_to_param(EVP_PKEY_CTX *pctx, ctx.ishex = (tmpl.ctrl_hexstr != NULL); } else { /* String controls really only support setting */ - ctx.action_type = SET; + ctx.action_type = OSSL_ACTION_SET; } ctx.ctrl_str = name; ctx.p1 = (int)strlen(value); @@ -2814,13 +2817,13 @@ int evp_pkey_ctx_ctrl_str_to_param(EVP_PKEY_CTX *pctx, default: /* fixup_args is expected to make sure this is dead code */ break; - case GET: + case OSSL_ACTION_GET: /* * this is dead code, but must be present, or some compilers * will complain */ break; - case SET: + case OSSL_ACTION_SET: ret = evp_pkey_ctx_set_params_strict(pctx, ctx.params); break; } @@ -2865,7 +2868,7 @@ static int evp_pkey_ctx_setget_params_to_ctrl(EVP_PKEY_CTX *pctx, ret = fixup(PRE_PARAMS_TO_CTRL, translation, &ctx); - if (ret > 0 && ctx.action_type != NONE) + if (ret > 0 && ctx.action_type != OSSL_ACTION_NONE) ret = EVP_PKEY_CTX_ctrl(pctx, keytype, optype, ctx.ctrl_cmd, ctx.p1, ctx.p2); @@ -2897,14 +2900,14 @@ int evp_pkey_ctx_set_params_to_ctrl(EVP_PKEY_CTX *ctx, const OSSL_PARAM *params) { if (ctx->keymgmt != NULL) return 0; - return evp_pkey_ctx_setget_params_to_ctrl(ctx, SET, (OSSL_PARAM *)params); + return evp_pkey_ctx_setget_params_to_ctrl(ctx, OSSL_ACTION_SET, (OSSL_PARAM *)params); } int evp_pkey_ctx_get_params_to_ctrl(EVP_PKEY_CTX *ctx, OSSL_PARAM *params) { if (ctx->keymgmt != NULL) return 0; - return evp_pkey_ctx_setget_params_to_ctrl(ctx, GET, params); + return evp_pkey_ctx_setget_params_to_ctrl(ctx, OSSL_ACTION_GET, params); } /* This must ONLY be called for legacy EVP_PKEYs */ @@ -2938,7 +2941,7 @@ static int evp_pkey_setget_params_to_ctrl(const EVP_PKEY *pkey, * support getting. */ if (!ossl_assert(translation != NULL) - || !ossl_assert(translation->action_type == GET) + || !ossl_assert(translation->action_type == OSSL_ACTION_GET) || !ossl_assert(translation->fixup_args != NULL)) { return -2; } @@ -2952,5 +2955,5 @@ static int evp_pkey_setget_params_to_ctrl(const EVP_PKEY *pkey, int evp_pkey_get_params_to_ctrl(const EVP_PKEY *pkey, OSSL_PARAM *params) { - return evp_pkey_setget_params_to_ctrl(pkey, GET, params); + return evp_pkey_setget_params_to_ctrl(pkey, OSSL_ACTION_GET, params); } diff --git a/crypto/evp/evp_err.c b/crypto/evp/evp_err.c index d8440fc76d13..028f8202c867 100644 --- a/crypto/evp/evp_err.c +++ b/crypto/evp/evp_err.c @@ -1,6 +1,6 @@ /* * Generated by util/mkerr.pl DO NOT EDIT - * Copyright 1995-2024 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2025 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -151,6 +151,18 @@ static const ERR_STRING_DATA EVP_str_reasons[] = { "private key decode error"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_PRIVATE_KEY_ENCODE_ERROR), "private key encode error"}, + {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_PROVIDER_ASYM_CIPHER_FAILURE), + "provider asym cipher failure"}, + {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_PROVIDER_ASYM_CIPHER_NOT_SUPPORTED), + "provider asym cipher not supported"}, + {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_PROVIDER_KEYMGMT_FAILURE), + "provider keymgmt failure"}, + {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_PROVIDER_KEYMGMT_NOT_SUPPORTED), + "provider keymgmt not supported"}, + {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_PROVIDER_SIGNATURE_FAILURE), + "provider signature failure"}, + {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_PROVIDER_SIGNATURE_NOT_SUPPORTED), + "provider signature not supported"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_PUBLIC_KEY_NOT_RSA), "public key not rsa"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_SETTING_XOF_FAILED), "setting xof failed"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_SET_DEFAULT_PROPERTY_FAILURE), diff --git a/crypto/evp/evp_rand.c b/crypto/evp/evp_rand.c index 50334042a9cc..fd2aeb3bcf1f 100644 --- a/crypto/evp/evp_rand.c +++ b/crypto/evp/evp_rand.c @@ -1,5 +1,5 @@ /* - * Copyright 2020-2023 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2020-2025 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -646,10 +646,8 @@ static int evp_rand_nonce_locked(EVP_RAND_CTX *ctx, unsigned char *out, { unsigned int str = evp_rand_strength_locked(ctx); - if (ctx->meth->nonce == NULL) - return 0; - if (ctx->meth->nonce(ctx->algctx, out, str, outlen, outlen)) - return 1; + if (ctx->meth->nonce != NULL) + return ctx->meth->nonce(ctx->algctx, out, str, outlen, outlen) > 0; return evp_rand_generate_locked(ctx, out, outlen, str, 0, NULL, 0); } @@ -657,6 +655,11 @@ int EVP_RAND_nonce(EVP_RAND_CTX *ctx, unsigned char *out, size_t outlen) { int res; + if (ctx == NULL || out == NULL || outlen == 0) { + ERR_raise(ERR_LIB_EVP, ERR_R_PASSED_NULL_PARAMETER); + return 0; + } + if (!evp_rand_lock(ctx)) return 0; res = evp_rand_nonce_locked(ctx, out, outlen); diff --git a/crypto/evp/keymgmt_meth.c b/crypto/evp/keymgmt_meth.c index 108bbf957973..f54684852b7c 100644 --- a/crypto/evp/keymgmt_meth.c +++ b/crypto/evp/keymgmt_meth.c @@ -451,9 +451,20 @@ const OSSL_PARAM *EVP_KEYMGMT_gen_gettable_params(const EVP_KEYMGMT *keymgmt) void *evp_keymgmt_gen(const EVP_KEYMGMT *keymgmt, void *genctx, OSSL_CALLBACK *cb, void *cbarg) { - if (keymgmt->gen == NULL) + void *ret; + const char *desc = keymgmt->description != NULL ? keymgmt->description : ""; + + if (keymgmt->gen == NULL) { + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_KEYMGMT_NOT_SUPPORTED, + "%s key generation:%s", keymgmt->type_name, desc); return NULL; - return keymgmt->gen(genctx, cb, cbarg); + } + + ret = keymgmt->gen(genctx, cb, cbarg); + if (ret == NULL) + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_KEYMGMT_FAILURE, + "%s key generation:%s", keymgmt->type_name, desc); + return ret; } void evp_keymgmt_gen_cleanup(const EVP_KEYMGMT *keymgmt, void *genctx) diff --git a/crypto/evp/legacy_sha.c b/crypto/evp/legacy_sha.c index 38423ff540f5..a9894d4d2abc 100644 --- a/crypto/evp/legacy_sha.c +++ b/crypto/evp/legacy_sha.c @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2019-2025 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -216,7 +216,7 @@ const EVP_MD *EVP_shake##bitlen(void) \ NID_shake##bitlen, \ 0, \ bitlen / 8, \ - EVP_MD_FLAG_XOF, \ + EVP_MD_FLAG_XOF | EVP_MD_FLAG_DIGALGID_ABSENT, \ EVP_ORIG_GLOBAL, \ LEGACY_EVP_MD_METH_TABLE(shake_init, sha3_int_update, sha3_int_final, \ shake_ctrl, (KECCAK1600_WIDTH - bitlen * 2) / 8), \ diff --git a/crypto/evp/m_sigver.c b/crypto/evp/m_sigver.c index 2d1839fedb2f..d5df497da770 100644 --- a/crypto/evp/m_sigver.c +++ b/crypto/evp/m_sigver.c @@ -42,6 +42,7 @@ static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, { EVP_PKEY_CTX *locpctx = NULL; EVP_SIGNATURE *signature = NULL; + const char *desc; EVP_KEYMGMT *tmp_keymgmt = NULL; const OSSL_PROVIDER *tmp_prov = NULL; const char *supported_sig = NULL; @@ -251,16 +252,19 @@ static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, } } + desc = signature->description != NULL ? signature->description : ""; if (ver) { if (signature->digest_verify_init == NULL) { - ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_NOT_SUPPORTED, + "%s digest_verify_init:%s", signature->type_name, desc); goto err; } ret = signature->digest_verify_init(locpctx->op.sig.algctx, mdname, provkey, params); } else { if (signature->digest_sign_init == NULL) { - ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_NOT_SUPPORTED, + "%s digest_sign_init:%s", signature->type_name, desc); goto err; } ret = signature->digest_sign_init(locpctx->op.sig.algctx, @@ -275,6 +279,9 @@ static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, goto end; if (type == NULL) /* This check is redundant but clarifies matters */ ERR_raise(ERR_LIB_EVP, EVP_R_NO_DEFAULT_DIGEST); + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_FAILURE, + ver ? "%s digest_verify_init:%s" : "%s digest_sign_init:%s", + signature->type_name, desc); err: evp_pkey_ctx_free_old_ops(locpctx); @@ -395,7 +402,10 @@ int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, int EVP_DigestSignUpdate(EVP_MD_CTX *ctx, const void *data, size_t dsize) { + EVP_SIGNATURE *signature; + const char *desc; EVP_PKEY_CTX *pctx = ctx->pctx; + int ret; if ((ctx->flags & EVP_MD_CTX_FLAG_FINALISED) != 0) { ERR_raise(ERR_LIB_EVP, EVP_R_UPDATE_ERROR); @@ -408,13 +418,19 @@ int EVP_DigestSignUpdate(EVP_MD_CTX *ctx, const void *data, size_t dsize) || pctx->op.sig.signature == NULL) goto legacy; - if (pctx->op.sig.signature->digest_sign_update == NULL) { - ERR_raise(ERR_LIB_EVP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); + signature = pctx->op.sig.signature; + desc = signature->description != NULL ? signature->description : ""; + if (signature->digest_sign_update == NULL) { + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_NOT_SUPPORTED, + "%s digest_sign_update:%s", signature->type_name, desc); return 0; } - return pctx->op.sig.signature->digest_sign_update(pctx->op.sig.algctx, - data, dsize); + ret = signature->digest_sign_update(pctx->op.sig.algctx, data, dsize); + if (ret <= 0) + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_FAILURE, + "%s digest_sign_update:%s", signature->type_name, desc); + return ret; legacy: if (pctx != NULL) { @@ -430,7 +446,10 @@ int EVP_DigestSignUpdate(EVP_MD_CTX *ctx, const void *data, size_t dsize) int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *data, size_t dsize) { + EVP_SIGNATURE *signature; + const char *desc; EVP_PKEY_CTX *pctx = ctx->pctx; + int ret; if ((ctx->flags & EVP_MD_CTX_FLAG_FINALISED) != 0) { ERR_raise(ERR_LIB_EVP, EVP_R_UPDATE_ERROR); @@ -443,13 +462,19 @@ int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *data, size_t dsize) || pctx->op.sig.signature == NULL) goto legacy; - if (pctx->op.sig.signature->digest_verify_update == NULL) { - ERR_raise(ERR_LIB_EVP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); + signature = pctx->op.sig.signature; + desc = signature->description != NULL ? signature->description : ""; + if (signature->digest_verify_update == NULL) { + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_NOT_SUPPORTED, + "%s digest_verify_update:%s", signature->type_name, desc); return 0; } - return pctx->op.sig.signature->digest_verify_update(pctx->op.sig.algctx, - data, dsize); + ret = signature->digest_verify_update(pctx->op.sig.algctx, data, dsize); + if (ret <= 0) + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_FAILURE, + "%s digest_verify_update:%s", signature->type_name, desc); + return ret; legacy: if (pctx != NULL) { @@ -466,6 +491,8 @@ int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *data, size_t dsize) int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen) { + EVP_SIGNATURE *signature; + const char *desc; int sctx = 0; int r = 0; EVP_PKEY_CTX *dctx = NULL, *pctx = ctx->pctx; @@ -481,15 +508,26 @@ int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, || pctx->op.sig.signature == NULL) goto legacy; + signature = pctx->op.sig.signature; + desc = signature->description != NULL ? signature->description : ""; + if (signature->digest_sign_final == NULL) { + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_NOT_SUPPORTED, + "%s digest_sign_final:%s", signature->type_name, desc); + return 0; + } + if (sigret != NULL && (ctx->flags & EVP_MD_CTX_FLAG_FINALISE) == 0) { /* try dup */ dctx = EVP_PKEY_CTX_dup(pctx); if (dctx != NULL) pctx = dctx; } - r = pctx->op.sig.signature->digest_sign_final(pctx->op.sig.algctx, - sigret, siglen, - sigret == NULL ? 0 : *siglen); + + r = signature->digest_sign_final(pctx->op.sig.algctx, sigret, siglen, + sigret == NULL ? 0 : *siglen); + if (!r) + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_FAILURE, + "%s digest_sign_final:%s", signature->type_name, desc); if (dctx == NULL && sigret != NULL) ctx->flags |= EVP_MD_CTX_FLAG_FINALISED; else @@ -574,6 +612,7 @@ int EVP_DigestSign(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen, const unsigned char *tbs, size_t tbslen) { EVP_PKEY_CTX *pctx = ctx->pctx; + int ret; if (pctx == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); @@ -588,13 +627,19 @@ int EVP_DigestSign(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen, if (pctx->operation == EVP_PKEY_OP_SIGNCTX && pctx->op.sig.algctx != NULL && pctx->op.sig.signature != NULL) { - if (pctx->op.sig.signature->digest_sign != NULL) { + EVP_SIGNATURE *signature = pctx->op.sig.signature; + + if (signature->digest_sign != NULL) { + const char *desc = signature->description != NULL ? signature->description : ""; + if (sigret != NULL) ctx->flags |= EVP_MD_CTX_FLAG_FINALISED; - return pctx->op.sig.signature->digest_sign(pctx->op.sig.algctx, - sigret, siglen, - sigret == NULL ? 0 : *siglen, - tbs, tbslen); + ret = signature->digest_sign(pctx->op.sig.algctx, sigret, siglen, + sigret == NULL ? 0 : *siglen, tbs, tbslen); + if (ret <= 0) + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_FAILURE, + "%s digest_sign:%s", signature->type_name, desc); + return ret; } } else { /* legacy */ @@ -610,6 +655,8 @@ int EVP_DigestSign(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen, int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig, size_t siglen) { + EVP_SIGNATURE *signature; + const char *desc; int vctx = 0; unsigned int mdlen = 0; unsigned char md[EVP_MAX_MD_SIZE]; @@ -627,14 +674,25 @@ int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig, || pctx->op.sig.signature == NULL) goto legacy; + signature = pctx->op.sig.signature; + desc = signature->description != NULL ? signature->description : ""; + if (signature->digest_verify_final == NULL) { + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_NOT_SUPPORTED, + "%s digest_verify_final:%s", signature->type_name, desc); + return 0; + } + if ((ctx->flags & EVP_MD_CTX_FLAG_FINALISE) == 0) { /* try dup */ dctx = EVP_PKEY_CTX_dup(pctx); if (dctx != NULL) pctx = dctx; } - r = pctx->op.sig.signature->digest_verify_final(pctx->op.sig.algctx, - sig, siglen); + + r = signature->digest_verify_final(pctx->op.sig.algctx, sig, siglen); + if (!r) + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_FAILURE, + "%s digest_verify_final:%s", signature->type_name, desc); if (dctx == NULL) ctx->flags |= EVP_MD_CTX_FLAG_FINALISED; else @@ -702,10 +760,16 @@ int EVP_DigestVerify(EVP_MD_CTX *ctx, const unsigned char *sigret, && pctx->op.sig.algctx != NULL && pctx->op.sig.signature != NULL) { if (pctx->op.sig.signature->digest_verify != NULL) { + EVP_SIGNATURE *signature = pctx->op.sig.signature; + const char *desc = signature->description != NULL ? signature->description : ""; + int ret; + ctx->flags |= EVP_MD_CTX_FLAG_FINALISED; - return pctx->op.sig.signature->digest_verify(pctx->op.sig.algctx, - sigret, siglen, - tbs, tbslen); + ret = signature->digest_verify(pctx->op.sig.algctx, sigret, siglen, tbs, tbslen); + if (ret <= 0) + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_FAILURE, + "%s digest_verify:%s", signature->type_name, desc); + return ret; } } else { /* legacy */ diff --git a/crypto/evp/pmeth_lib.c b/crypto/evp/pmeth_lib.c index 665cafbc21a7..08c0d6a7b2b7 100644 --- a/crypto/evp/pmeth_lib.c +++ b/crypto/evp/pmeth_lib.c @@ -480,6 +480,12 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_dup(const EVP_PKEY_CTX *pctx) } rctx->legacy_keytype = pctx->legacy_keytype; + if (pctx->keymgmt != NULL) { + if (!EVP_KEYMGMT_up_ref(pctx->keymgmt)) + goto err; + rctx->keymgmt = pctx->keymgmt; + } + if (EVP_PKEY_CTX_IS_DERIVE_OP(pctx)) { if (pctx->op.kex.exchange != NULL) { rctx->op.kex.exchange = pctx->op.kex.exchange; @@ -584,6 +590,9 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_dup(const EVP_PKEY_CTX *pctx) EVP_KEYMGMT *tmp_keymgmt = pctx->keymgmt; void *provkey; + if (pctx->pkey == NULL) + return rctx; + provkey = evp_pkey_export_to_provider(pctx->pkey, pctx->libctx, &tmp_keymgmt, pctx->propquery); if (provkey == NULL) diff --git a/crypto/evp/signature.c b/crypto/evp/signature.c index e5bb7da255f3..d01df3282fa4 100644 --- a/crypto/evp/signature.c +++ b/crypto/evp/signature.c @@ -55,6 +55,7 @@ static void *evp_signature_from_algorithm(int name_id, { const OSSL_DISPATCH *fns = algodef->implementation; EVP_SIGNATURE *signature = NULL; + const char *desc; /* Counts newctx / freectx */ int ctxfncnt = 0; /* Counts all init functions */ @@ -72,6 +73,7 @@ static void *evp_signature_from_algorithm(int name_id, if ((signature->type_name = ossl_algorithm_get1_first_name(algodef)) == NULL) goto err; signature->description = algodef->algorithm_description; + desc = signature->description != NULL ? signature->description : ""; for (; fns->function_id != 0; fns++) { switch (fns->function_id) { @@ -290,23 +292,30 @@ static void *evp_signature_from_algorithm(int name_id, */ valid = 1; /* Start with the ones where counters say enough */ - if (ctxfncnt != 2) - /* newctx or freectx missing */ + if (ctxfncnt != 2) { + ERR_raise_data(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS, + "missing %s newctx or freectx:%s", signature->type_name, desc); valid = 0; + } if (valid && ((gparamfncnt != 0 && gparamfncnt != 2) || (sparamfncnt != 0 && sparamfncnt != 2) || (gmdparamfncnt != 0 && gmdparamfncnt != 2) - || (smdparamfncnt != 0 && smdparamfncnt != 2))) + || (smdparamfncnt != 0 && smdparamfncnt != 2))) { /* * Params functions are optional, but if defined, they must * be pairwise complete sets, i.e. a getter must have an * associated gettable, etc */ + ERR_raise_data(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS, + "missing %s params getter or setter:%s", signature->type_name, desc); valid = 0; - if (valid && initfncnt == 0) - /* No init functions */ + } + if (valid && initfncnt == 0) { + ERR_raise_data(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS, + "missing %s init:%s", signature->type_name, desc); valid = 0; + } /* Now we check for function combinations */ if (valid @@ -315,17 +324,23 @@ static void *evp_signature_from_algorithm(int name_id, || (signature->sign_message_init != NULL && signature->sign == NULL && (signature->sign_message_update == NULL - || signature->sign_message_final == NULL)))) - /* sign_init functions with no signing function? That's weird */ + || signature->sign_message_final == NULL)))) { + /* sign_init function(s) with no signing function? That's weird */ + ERR_raise_data(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS, + "missing %s signing function:%s", signature->type_name, desc); valid = 0; + } if (valid && (signature->sign != NULL || signature->sign_message_update != NULL || signature->sign_message_final != NULL) && signature->sign_init == NULL - && signature->sign_message_init == NULL) - /* signing functions with no sign_init? That's odd */ + && signature->sign_message_init == NULL) { + /* signing function(s) with no sign_init? That's odd */ + ERR_raise_data(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS, + "missing %s sign_init or sign_message_init:%s", signature->type_name, desc); valid = 0; + } if (valid && ((signature->verify_init != NULL @@ -333,46 +348,105 @@ static void *evp_signature_from_algorithm(int name_id, || (signature->verify_message_init != NULL && signature->verify == NULL && (signature->verify_message_update == NULL - || signature->verify_message_final == NULL)))) - /* verify_init functions with no verification function? That's weird */ + || signature->verify_message_final == NULL)))) { + /* verify_init function(s) with no verification function? That's weird */ + ERR_raise_data(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS, + "missing %s verification function:%s", signature->type_name, desc); valid = 0; + } if (valid && (signature->verify != NULL || signature->verify_message_update != NULL || signature->verify_message_final != NULL) && signature->verify_init == NULL - && signature->verify_message_init == NULL) - /* verification functions with no verify_init? That's odd */ + && signature->verify_message_init == NULL) { + ERR_raise_data(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS, + "missing %s verify_init or verify_message_init:%s", + signature->type_name, desc); + /* verification function(s) with no verify_init? That's odd */ valid = 0; + } if (valid && (signature->verify_recover_init != NULL) - && (signature->verify_recover == NULL)) - /* verify_recover_init functions with no verify_recover? How quaint */ + && (signature->verify_recover == NULL)) { + /* verify_recover_init function with no verify_recover? How quaint */ + ERR_raise_data(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS, + "missing %s verify_recover:%s", signature->type_name, desc); valid = 0; + } if (valid && (signature->digest_sign_init != NULL && signature->digest_sign == NULL && (signature->digest_sign_update == NULL - || signature->digest_sign_final == NULL))) - /* - * You can't have a digest_sign_init without *some* performing functions - */ + || signature->digest_sign_final == NULL))) { + /* You can't have a digest_sign_init without *some* performing functions */ + ERR_raise_data(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS, + "missing %s digest_sign function:%s", signature->type_name, desc); valid = 0; + } if (valid && ((signature->digest_verify_init != NULL && signature->digest_verify == NULL && (signature->digest_verify_update == NULL - || signature->digest_verify_final == NULL)))) - /* - * You can't have a digest_verify_init without *some* performing functions - */ + || signature->digest_verify_final == NULL)))) { + /* You can't have a digest_verify_init without *some* performing functions */ + ERR_raise_data(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS, + "missing %s digest_verify function:%s", signature->type_name, desc); valid = 0; + } - if (!valid) { - ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS); + if (!valid) + goto err; + + if ((signature->digest_sign != NULL + || signature->digest_sign_update != NULL + || signature->digest_sign_final != NULL) + && signature->digest_sign_init == NULL) { + /* digest signing function(s) with no digest_sign_init? That's odd */ + ERR_raise_data(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS, + "missing %s digest_sign_init:%s", signature->type_name, desc); + goto err; + } + + if ((signature->digest_verify != NULL + || signature->digest_verify_update != NULL + || signature->digest_verify_final != NULL) + && signature->digest_verify_init == NULL) { + /* digest verification function(s) with no digest_verify_init? That's odd */ + ERR_raise_data(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS, + "missing %s digest_verify_init:%s", signature->type_name, desc); + goto err; + } + + if ((signature->sign_message_update == NULL) != + (signature->sign_message_final == NULL)) { + ERR_raise_data(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS, + "only one of %s message signing update and final available:%s", + signature->type_name, desc); + goto err; + } + if ((signature->verify_message_update == NULL) != + (signature->verify_message_final == NULL)) { + ERR_raise_data(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS, + "only one of %s message verification update and final available:%s", + signature->type_name, desc); + goto err; + } + if ((signature->digest_sign_update == NULL) != + (signature->digest_sign_final == NULL)) { + ERR_raise_data(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS, + "only one of %s digest signing update and final available:%s", + signature->type_name, desc); + goto err; + } + if ((signature->digest_verify_update == NULL) != + (signature->digest_verify_final == NULL)) { + ERR_raise_data(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS, + "only one of %s digest verification update and final available:%s", + signature->type_name, desc); goto err; } @@ -499,6 +573,7 @@ const OSSL_PARAM *EVP_SIGNATURE_settable_ctx_params(const EVP_SIGNATURE *sig) static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, EVP_SIGNATURE *signature, int operation, const OSSL_PARAM params[]) { + const char *desc; int ret = 0; void *provkey = NULL; EVP_KEYMGMT *tmp_keymgmt = NULL; @@ -557,7 +632,7 @@ static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, EVP_SIGNATURE *signature, * ensured that the key is at least exported to a provider (above). */ if (signature->query_key_types != NULL) { - /* This is expect to be a NULL terminated array */ + /* This is expected to be a NULL-terminated array */ const char **keytypes; keytypes = signature->query_key_types(); @@ -708,6 +783,8 @@ static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, EVP_SIGNATURE *signature, /* No more legacy from here down to legacy: */ ctx->op.sig.signature = signature; + desc = signature->description != NULL ? signature->description : ""; + ctx->op.sig.algctx = signature->newctx(ossl_provider_ctx(signature->prov), ctx->propquery); if (ctx->op.sig.algctx == NULL) { @@ -719,7 +796,8 @@ static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, EVP_SIGNATURE *signature, switch (operation) { case EVP_PKEY_OP_SIGN: if (signature->sign_init == NULL) { - ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_NOT_SUPPORTED, + "%s sign_init:%s", signature->type_name, desc); ret = -2; goto err; } @@ -727,7 +805,8 @@ static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, EVP_SIGNATURE *signature, break; case EVP_PKEY_OP_SIGNMSG: if (signature->sign_message_init == NULL) { - ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_NOT_SUPPORTED, + "%s sign_message_init:%s", signature->type_name, desc); ret = -2; goto err; } @@ -735,7 +814,8 @@ static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, EVP_SIGNATURE *signature, break; case EVP_PKEY_OP_VERIFY: if (signature->verify_init == NULL) { - ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_NOT_SUPPORTED, + "%s verify_init:%s", signature->type_name, desc); ret = -2; goto err; } @@ -743,7 +823,8 @@ static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, EVP_SIGNATURE *signature, break; case EVP_PKEY_OP_VERIFYMSG: if (signature->verify_message_init == NULL) { - ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_NOT_SUPPORTED, + "%s verify_message_init:%s", signature->type_name, desc); ret = -2; goto err; } @@ -751,7 +832,8 @@ static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, EVP_SIGNATURE *signature, break; case EVP_PKEY_OP_VERIFYRECOVER: if (signature->verify_recover_init == NULL) { - ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_NOT_SUPPORTED, + "%s verify_recover_init:%s", signature->type_name, desc); ret = -2; goto err; } @@ -849,6 +931,10 @@ int EVP_PKEY_sign_message_init(EVP_PKEY_CTX *ctx, int EVP_PKEY_sign_message_update(EVP_PKEY_CTX *ctx, const unsigned char *in, size_t inlen) { + EVP_SIGNATURE *signature; + const char *desc; + int ret; + if (ctx == NULL) { ERR_raise(ERR_LIB_EVP, ERR_R_PASSED_NULL_PARAMETER); return -1; @@ -859,18 +945,28 @@ int EVP_PKEY_sign_message_update(EVP_PKEY_CTX *ctx, return -1; } - if (ctx->op.sig.signature->sign_message_update == NULL) { - ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); + signature = ctx->op.sig.signature; + desc = signature->description != NULL ? signature->description : ""; + if (signature->sign_message_update == NULL) { + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_NOT_SUPPORTED, + "%s sign_message_update:%s", signature->type_name, desc); return -2; } - return ctx->op.sig.signature->sign_message_update(ctx->op.sig.algctx, - in, inlen); + ret = signature->sign_message_update(ctx->op.sig.algctx, in, inlen); + if (ret <= 0) + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_FAILURE, + "%s sign_message_update:%s", signature->type_name, desc); + return ret; } int EVP_PKEY_sign_message_final(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen) { + EVP_SIGNATURE *signature; + const char *desc; + int ret; + if (ctx == NULL) { ERR_raise(ERR_LIB_EVP, ERR_R_PASSED_NULL_PARAMETER); return -1; @@ -881,20 +977,28 @@ int EVP_PKEY_sign_message_final(EVP_PKEY_CTX *ctx, return -1; } - if (ctx->op.sig.signature->sign_message_final == NULL) { - ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); + signature = ctx->op.sig.signature; + desc = signature->description != NULL ? signature->description : ""; + if (signature->sign_message_final == NULL) { + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_NOT_SUPPORTED, + "%s sign_message_final:%s", signature->type_name, desc); return -2; } - return ctx->op.sig.signature->sign_message_final(ctx->op.sig.algctx, - sig, siglen, - (sig == NULL) ? 0 : *siglen); + ret = signature->sign_message_final(ctx->op.sig.algctx, sig, siglen, + (sig == NULL) ? 0 : *siglen); + if (ret <= 0) + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_FAILURE, + "%s sign_message_final:%s", signature->type_name, desc); + return ret; } int EVP_PKEY_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs, size_t tbslen) { + EVP_SIGNATURE *signature; + const char *desc; int ret; if (ctx == NULL) { @@ -911,14 +1015,19 @@ int EVP_PKEY_sign(EVP_PKEY_CTX *ctx, if (ctx->op.sig.algctx == NULL) goto legacy; - if (ctx->op.sig.signature->sign == NULL) { - ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); + signature = ctx->op.sig.signature; + desc = signature->description != NULL ? signature->description : ""; + if (signature->sign == NULL) { + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_NOT_SUPPORTED, + "%s sign:%s", signature->type_name, desc); return -2; } - ret = ctx->op.sig.signature->sign(ctx->op.sig.algctx, sig, siglen, - (sig == NULL) ? 0 : *siglen, tbs, tbslen); - + ret = signature->sign(ctx->op.sig.algctx, sig, siglen, + (sig == NULL) ? 0 : *siglen, tbs, tbslen); + if (ret <= 0) + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_FAILURE, + "%s sign:%s", signature->type_name, desc); return ret; legacy: @@ -977,6 +1086,10 @@ int EVP_PKEY_CTX_set_signature(EVP_PKEY_CTX *ctx, int EVP_PKEY_verify_message_update(EVP_PKEY_CTX *ctx, const unsigned char *in, size_t inlen) { + EVP_SIGNATURE *signature; + const char *desc; + int ret; + if (ctx == NULL) { ERR_raise(ERR_LIB_EVP, ERR_R_PASSED_NULL_PARAMETER); return -1; @@ -987,17 +1100,27 @@ int EVP_PKEY_verify_message_update(EVP_PKEY_CTX *ctx, return -1; } - if (ctx->op.sig.signature->verify_message_update == NULL) { - ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); + signature = ctx->op.sig.signature; + desc = signature->description != NULL ? signature->description : ""; + if (signature->verify_message_update == NULL) { + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_NOT_SUPPORTED, + "%s verify_message_update:%s", signature->type_name, desc); return -2; } - return ctx->op.sig.signature->verify_message_update(ctx->op.sig.algctx, - in, inlen); + ret = signature->verify_message_update(ctx->op.sig.algctx, in, inlen); + if (ret <= 0) + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_FAILURE, + "%s verify_message_update:%s", signature->type_name, desc); + return ret; } int EVP_PKEY_verify_message_final(EVP_PKEY_CTX *ctx) { + EVP_SIGNATURE *signature; + const char *desc; + int ret; + if (ctx == NULL) { ERR_raise(ERR_LIB_EVP, ERR_R_PASSED_NULL_PARAMETER); return -1; @@ -1008,19 +1131,28 @@ int EVP_PKEY_verify_message_final(EVP_PKEY_CTX *ctx) return -1; } - if (ctx->op.sig.signature->verify_message_final == NULL) { - ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); + signature = ctx->op.sig.signature; + desc = signature->description != NULL ? signature->description : ""; + if (signature->verify_message_final == NULL) { + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_NOT_SUPPORTED, + "%s verify_message_final:%s", signature->type_name, desc); return -2; } /* The signature must have been set with EVP_PKEY_CTX_set_signature() */ - return ctx->op.sig.signature->verify_message_final(ctx->op.sig.algctx); + ret = signature->verify_message_final(ctx->op.sig.algctx); + if (ret <= 0) + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_FAILURE, + "%s verify_message_final:%s", signature->type_name, desc); + return ret; } int EVP_PKEY_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig, size_t siglen, const unsigned char *tbs, size_t tbslen) { + EVP_SIGNATURE *signature; + const char *desc; int ret; if (ctx == NULL) { @@ -1037,13 +1169,19 @@ int EVP_PKEY_verify(EVP_PKEY_CTX *ctx, if (ctx->op.sig.algctx == NULL) goto legacy; - if (ctx->op.sig.signature->verify == NULL) { - ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); + signature = ctx->op.sig.signature; + desc = signature->description != NULL ? signature->description : ""; + if (signature->verify == NULL) { + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_NOT_SUPPORTED, + "%s verify:%s", signature->type_name, desc); return -2; } ret = ctx->op.sig.signature->verify(ctx->op.sig.algctx, sig, siglen, tbs, tbslen); + if (ret <= 0) + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_FAILURE, + "%s verify:%s", signature->type_name, desc); return ret; legacy: @@ -1076,6 +1214,8 @@ int EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx, unsigned char *rout, size_t *routlen, const unsigned char *sig, size_t siglen) { + EVP_SIGNATURE *signature; + const char *desc; int ret; if (ctx == NULL) { @@ -1091,15 +1231,19 @@ int EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx, if (ctx->op.sig.algctx == NULL) goto legacy; - if (ctx->op.sig.signature->verify_recover == NULL) { - ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); + signature = ctx->op.sig.signature; + desc = signature->description != NULL ? signature->description : ""; + if (signature->verify_recover == NULL) { + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_NOT_SUPPORTED, + "%s verify_recover:%s", signature->type_name, desc); return -2; } - ret = ctx->op.sig.signature->verify_recover(ctx->op.sig.algctx, rout, - routlen, - (rout == NULL ? 0 : *routlen), - sig, siglen); + ret = signature->verify_recover(ctx->op.sig.algctx, rout, routlen, + (rout == NULL ? 0 : *routlen), sig, siglen); + if (ret <= 0) + ERR_raise_data(ERR_LIB_EVP, EVP_R_PROVIDER_SIGNATURE_FAILURE, + "%s verify_recover:%s", signature->type_name, desc); return ret; legacy: if (ctx->pmeth == NULL || ctx->pmeth->verify_recover == NULL) { diff --git a/crypto/hmac/hmac_s390x.c b/crypto/hmac/hmac_s390x.c index 02e1cd1dd650..70a17a7664af 100644 --- a/crypto/hmac/hmac_s390x.c +++ b/crypto/hmac/hmac_s390x.c @@ -1,5 +1,5 @@ /* - * Copyright 2024 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2024-2025 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,6 +14,7 @@ #include "hmac_local.h" #include "openssl/obj_mac.h" #include "openssl/evp.h" +#include "openssl/err.h" #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) # include <openssl/engine.h> #endif @@ -189,6 +190,11 @@ int s390x_HMAC_update(HMAC_CTX *ctx, const unsigned char *data, size_t len) { size_t remain, num; + if (ctx->plat.s390x.iimp != 1) { + ERR_raise(ERR_LIB_EVP, EVP_R_UPDATE_ERROR); + return 0; + } + if (len == 0) return 1; @@ -250,6 +256,11 @@ int s390x_HMAC_final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len) void *result; unsigned int res_len; + if (ctx->plat.s390x.iimp != 1) { + ERR_raise(ERR_LIB_EVP, EVP_R_FINAL_ERROR); + return 0; + } + ctx->plat.s390x.iimp = 0; /* last block */ s390x_call_kmac(ctx, ctx->plat.s390x.buf, ctx->plat.s390x.num); diff --git a/crypto/http/http_lib.c b/crypto/http/http_lib.c index 725ec1908499..fcf8a69e07a8 100644 --- a/crypto/http/http_lib.c +++ b/crypto/http/http_lib.c @@ -59,7 +59,7 @@ int OSSL_parse_url(const char *url, char **pscheme, char **puser, char **phost, const char *user, *user_end; const char *host, *host_end; const char *port, *port_end; - unsigned int portnum; + unsigned int portnum = 0; const char *path, *path_end; const char *query, *query_end; const char *frag, *frag_end; @@ -107,13 +107,7 @@ int OSSL_parse_url(const char *url, char **pscheme, char **puser, char **phost, p = ++host_end; } else { /* look for start of optional port, path, query, or fragment */ - host_end = strchr(host, ':'); - if (host_end == NULL) - host_end = strchr(host, '/'); - if (host_end == NULL) - host_end = strchr(host, '?'); - if (host_end == NULL) - host_end = strchr(host, '#'); + host_end = strpbrk(host, ":/?#"); if (host_end == NULL) /* the remaining string is just the hostname */ host_end = host + strlen(host); p = host_end; diff --git a/crypto/ml_kem/ml_kem.c b/crypto/ml_kem/ml_kem.c index ec7523343584..4474af0f87cb 100644 --- a/crypto/ml_kem/ml_kem.c +++ b/crypto/ml_kem/ml_kem.c @@ -9,6 +9,7 @@ #include <openssl/byteorder.h> #include <openssl/rand.h> +#include <openssl/proverr.h> #include "crypto/ml_kem.h" #include "internal/common.h" #include "internal/constant_time.h" @@ -1278,16 +1279,26 @@ static int parse_pubkey(const uint8_t *in, EVP_MD_CTX *mdctx, ML_KEM_KEY *key) const ML_KEM_VINFO *vinfo = key->vinfo; /* Decode and check |t| */ - if (!vector_decode_12(key->t, in, vinfo->rank)) + if (!vector_decode_12(key->t, in, vinfo->rank)) { + ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_KEY, + "%s invalid public 't' vector", + vinfo->algorithm_name); return 0; + } /* Save the matrix |m| recovery seed |rho| */ memcpy(key->rho, in + vinfo->vector_bytes, ML_KEM_RANDOM_BYTES); /* * Pre-compute the public key hash, needed for both encap and decap. * Also pre-compute the matrix expansion, stored with the public key. */ - return hash_h(key->pkhash, in, vinfo->pubkey_bytes, mdctx, key) - && matrix_expand(mdctx, key); + if (!hash_h(key->pkhash, in, vinfo->pubkey_bytes, mdctx, key) + || !matrix_expand(mdctx, key)) { + ERR_raise_data(ERR_LIB_CRYPTO, ERR_R_INTERNAL_ERROR, + "internal error while parsing %s public key", + vinfo->algorithm_name); + return 0; + } + return 1; } /* @@ -1301,8 +1312,12 @@ static int parse_prvkey(const uint8_t *in, EVP_MD_CTX *mdctx, ML_KEM_KEY *key) const ML_KEM_VINFO *vinfo = key->vinfo; /* Decode and check |s|. */ - if (!vector_decode_12(key->s, in, vinfo->rank)) + if (!vector_decode_12(key->s, in, vinfo->rank)) { + ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_KEY, + "%s invalid private 's' vector", + vinfo->algorithm_name); return 0; + } in += vinfo->vector_bytes; if (!parse_pubkey(in, mdctx, key)) @@ -1310,8 +1325,12 @@ static int parse_prvkey(const uint8_t *in, EVP_MD_CTX *mdctx, ML_KEM_KEY *key) in += vinfo->pubkey_bytes; /* Check public key hash. */ - if (memcmp(key->pkhash, in, ML_KEM_PKHASH_BYTES) != 0) + if (memcmp(key->pkhash, in, ML_KEM_PKHASH_BYTES) != 0) { + ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_KEY, + "%s public key hash mismatch", + vinfo->algorithm_name); return 0; + } in += ML_KEM_PKHASH_BYTES; memcpy(key->z, in, ML_KEM_RANDOM_BYTES); @@ -1405,6 +1424,11 @@ int genkey(const uint8_t seed[ML_KEM_SEED_BYTES], end: OPENSSL_cleanse((void *)augmented_seed, ML_KEM_RANDOM_BYTES); OPENSSL_cleanse((void *)sigma, ML_KEM_RANDOM_BYTES); + if (ret == 0) { + ERR_raise_data(ERR_LIB_CRYPTO, ERR_R_INTERNAL_ERROR, + "internal error while generating %s private key", + vinfo->algorithm_name); + } return ret; } @@ -1430,10 +1454,14 @@ int encap(uint8_t *ctext, uint8_t secret[ML_KEM_SHARED_SECRET_BYTES], memcpy(input + ML_KEM_RANDOM_BYTES, key->pkhash, ML_KEM_PKHASH_BYTES); ret = hash_g(Kr, input, sizeof(input), mdctx, key) && encrypt_cpa(ctext, entropy, r, tmp, mdctx, key); + OPENSSL_cleanse((void *)input, sizeof(input)); if (ret) memcpy(secret, Kr, ML_KEM_SHARED_SECRET_BYTES); - OPENSSL_cleanse((void *)input, sizeof(input)); + else + ERR_raise_data(ERR_LIB_CRYPTO, ERR_R_INTERNAL_ERROR, + "internal error while performing %s encapsulation", + key->vinfo->algorithm_name); return ret; } @@ -1477,8 +1505,12 @@ int decap(uint8_t secret[ML_KEM_SHARED_SECRET_BYTES], * The same action is taken, if also |encrypt_cpa| should catastrophically * fail, due to failure of the |PRF| underlying the CBD functions. */ - if (!kdf(failure_key, key->z, ctext, vinfo->ctext_bytes, mdctx, key)) + if (!kdf(failure_key, key->z, ctext, vinfo->ctext_bytes, mdctx, key)) { + ERR_raise_data(ERR_LIB_CRYPTO, ERR_R_INTERNAL_ERROR, + "internal error while performing %s decapsulation", + vinfo->algorithm_name); return 0; + } decrypt_cpa(decrypted, ctext, tmp, key); memcpy(decrypted + ML_KEM_SHARED_SECRET_BYTES, pkhash, ML_KEM_PKHASH_BYTES); if (!hash_g(Kr, decrypted, sizeof(decrypted), mdctx, key) @@ -1550,7 +1582,7 @@ ossl_ml_kem_key_reset(ML_KEM_KEY *key) */ if (ossl_ml_kem_have_prvkey(key)) OPENSSL_cleanse(key->s, - key->vinfo->vector_bytes + 2 * ML_KEM_RANDOM_BYTES); + key->vinfo->rank * sizeof(scalar) + 2 * ML_KEM_RANDOM_BYTES); OPENSSL_free(key->t); key->d = key->z = (uint8_t *)(key->s = key->m = key->t = NULL); } @@ -1582,8 +1614,11 @@ ML_KEM_KEY *ossl_ml_kem_key_new(OSSL_LIB_CTX *libctx, const char *properties, const ML_KEM_VINFO *vinfo = ossl_ml_kem_get_vinfo(evp_type); ML_KEM_KEY *key; - if (vinfo == NULL) + if (vinfo == NULL) { + ERR_raise_data(ERR_LIB_CRYPTO, ERR_R_PASSED_INVALID_ARGUMENT, + "unsupported ML-KEM key type: %d", evp_type); return NULL; + } if ((key = OPENSSL_malloc(sizeof(*key))) == NULL) return NULL; @@ -1602,9 +1637,12 @@ ML_KEM_KEY *ossl_ml_kem_key_new(OSSL_LIB_CTX *libctx, const char *properties, && key->shake256_md != NULL && key->sha3_256_md != NULL && key->sha3_512_md != NULL) - return key; + return key; ossl_ml_kem_key_free(key); + ERR_raise_data(ERR_LIB_CRYPTO, ERR_R_INTERNAL_ERROR, + "missing SHA3 digest algorithms while creating %s key", + vinfo->algorithm_name); return NULL; } diff --git a/crypto/params_dup.c b/crypto/params_dup.c index 769629bbf324..362a0e62faaa 100644 --- a/crypto/params_dup.c +++ b/crypto/params_dup.c @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2021-2025 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -190,18 +190,18 @@ OSSL_PARAM *OSSL_PARAM_merge(const OSSL_PARAM *p1, const OSSL_PARAM *p2) while (1) { /* If list1 is finished just tack list2 onto the end */ if (*p1cur == NULL) { - do { + while (*p2cur != NULL) { *dst++ = **p2cur; p2cur++; - } while (*p2cur != NULL); + } break; } /* If list2 is finished just tack list1 onto the end */ if (*p2cur == NULL) { - do { + while (*p1cur != NULL) { *dst++ = **p1cur; p1cur++; - } while (*p1cur != NULL); + } break; } /* consume the list element with the smaller key */ diff --git a/crypto/params_from_text.c b/crypto/params_from_text.c index 7532d4d43923..f408717849f4 100644 --- a/crypto/params_from_text.c +++ b/crypto/params_from_text.c @@ -1,5 +1,5 @@ /* - * Copyright 2019-2024 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2019-2025 The OpenSSL Project Authors. All Rights Reserved. * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use @@ -220,9 +220,9 @@ int OSSL_PARAM_print_to_bio(const OSSL_PARAM *p, BIO *bio, int print_values) BIGNUM *bn; #ifndef OPENSSL_SYS_UEFI double d; + int dok; #endif int ok = -1; - int dok; /* * Iterate through each key in the array printing its key and value @@ -280,16 +280,16 @@ int OSSL_PARAM_print_to_bio(const OSSL_PARAM *p, BIO *bio, int print_values) case OSSL_PARAM_OCTET_STRING: ok = BIO_dump(bio, (char *)p->data, p->data_size); break; +#ifndef OPENSSL_SYS_UEFI case OSSL_PARAM_REAL: dok = 0; -#ifndef OPENSSL_SYS_UEFI dok = OSSL_PARAM_get_double(p, &d); -#endif if (dok == 1) ok = BIO_printf(bio, "%f\n", d); else ok = BIO_printf(bio, "error getting value\n"); break; +#endif default: ok = BIO_printf(bio, "unknown type (%u) of %zu bytes\n", p->data_type, p->data_size); diff --git a/crypto/perlasm/x86_64-xlate.pl b/crypto/perlasm/x86_64-xlate.pl index 2cd9a219c239..d677963c6176 100755 --- a/crypto/perlasm/x86_64-xlate.pl +++ b/crypto/perlasm/x86_64-xlate.pl @@ -218,6 +218,25 @@ my @segment_stack = (); my $current_function; my %globals; +{ package vex_prefix; # pick up vex prefixes, example: {vex} vpmadd52luq m256, %ymm, %ymm + sub re { + my ($class, $line) = @_; + my $self = {}; + my $ret; + + if ($$line =~ /(^\{vex\})/) { + bless $self,$class; + $self->{value} = $1; + $ret = $self; + $$line = substr($$line,@+[0]); $$line =~ s/^\s+//; + } + $ret; + } + sub out { + my $self = shift; + $self->{value}; + } +} { package opcode; # pick up opcodes sub re { my ($class, $line) = @_; @@ -1396,7 +1415,11 @@ while(defined(my $line=<>)) { if (my $directive=directive->re(\$line)) { printf "%s",$directive->out(); - } elsif (my $opcode=opcode->re(\$line)) { + } else { + if (my $vex_prefix=vex_prefix->re(\$line)) { + printf "%s",$vex_prefix->out(); + } + if (my $opcode=opcode->re(\$line)) { my $asm = eval("\$".$opcode->mnemonic()); if ((ref($asm) eq 'CODE') && scalar(my @bytes=&$asm($line))) { @@ -1446,6 +1469,7 @@ while(defined(my $line=<>)) { } else { printf "\t%s",$opcode->out(); } + } } print $line,"\n"; diff --git a/crypto/pkcs7/pk7_smime.c b/crypto/pkcs7/pk7_smime.c index 3f9ba3b7d6df..99f3b9eb9719 100644 --- a/crypto/pkcs7/pk7_smime.c +++ b/crypto/pkcs7/pk7_smime.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2024 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2025 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -333,10 +333,8 @@ int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, if (flags & PKCS7_TEXT) { if (!SMIME_text(tmpout, out)) { ERR_raise(ERR_LIB_PKCS7, PKCS7_R_SMIME_TEXT_ERROR); - BIO_free(tmpout); goto err; } - BIO_free(tmpout); } /* Now Verify All Signatures */ @@ -354,6 +352,8 @@ int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, ret = 1; err: + if (flags & PKCS7_TEXT) + BIO_free(tmpout); X509_STORE_CTX_free(cert_ctx); OPENSSL_free(buf); if (indata != NULL) diff --git a/crypto/property/property.c b/crypto/property/property.c index 2c35222f76f8..4141c1760300 100644 --- a/crypto/property/property.c +++ b/crypto/property/property.c @@ -348,7 +348,7 @@ int ossl_method_store_add(OSSL_METHOD_STORE *store, const OSSL_PROVIDER *prov, /* Insert into the hash table if required */ if (!ossl_property_write_lock(store)) { - OPENSSL_free(impl); + impl_free(impl); return 0; } diff --git a/crypto/provider_conf.c b/crypto/provider_conf.c index 5ec50f97e4a5..9649517dd264 100644 --- a/crypto/provider_conf.c +++ b/crypto/provider_conf.c @@ -379,7 +379,7 @@ static int provider_conf_load(OSSL_LIB_CTX *libctx, const char *name, ok = provider_conf_params(NULL, &entry, NULL, value, cnf); if (ok >= 1 && (entry.path != NULL || entry.parameters != NULL)) { ok = ossl_provider_info_add_to_store(libctx, &entry); - added = 1; + added = ok; } if (added == 0) ossl_provider_info_clear(&entry); diff --git a/crypto/provider_core.c b/crypto/provider_core.c index 490991b5e58b..0b675946485c 100644 --- a/crypto/provider_core.c +++ b/crypto/provider_core.c @@ -1511,6 +1511,16 @@ static int provider_activate_fallbacks(struct provider_store_st *store) return ret; } +int ossl_provider_activate_fallbacks(OSSL_LIB_CTX *ctx) +{ + struct provider_store_st *store = get_provider_store(ctx); + + if (store == NULL) + return 0; + + return provider_activate_fallbacks(store); +} + int ossl_provider_doall_activated(OSSL_LIB_CTX *ctx, int (*cb)(OSSL_PROVIDER *provider, void *cbdata), @@ -1948,12 +1958,12 @@ const OSSL_ALGORITHM *ossl_provider_query_operation(const OSSL_PROVIDER *prov, BIO_printf(trc_out, "(provider %s) names %s, prop_def %s, desc %s\n", prov->name, - res->algorithm_names == NULL ? "none" : - res->algorithm_names, - res->property_definition == NULL ? "none" : - res->property_definition, - res->algorithm_description == NULL ? "none" : - res->algorithm_description); + idx->algorithm_names == NULL ? "none" : + idx->algorithm_names, + idx->property_definition == NULL ? "none" : + idx->property_definition, + idx->algorithm_description == NULL ? "none" : + idx->algorithm_description); } } else { BIO_printf(trc_out, "(provider %s) query_operation failed\n", prov->name); diff --git a/crypto/rand/rand_lib.c b/crypto/rand/rand_lib.c index 9233322b5ff5..5b9713eda629 100644 --- a/crypto/rand/rand_lib.c +++ b/crypto/rand/rand_lib.c @@ -289,6 +289,9 @@ const RAND_METHOD *RAND_get_rand_method(void) if (!RUN_ONCE(&rand_init, do_rand_init)) return NULL; + if (rand_meth_lock == NULL) + return NULL; + if (!CRYPTO_THREAD_read_lock(rand_meth_lock)) return NULL; tmp_meth = default_RAND_meth; @@ -755,7 +758,7 @@ static EVP_RAND_CTX *rand_new_crngt(OSSL_LIB_CTX *libctx, EVP_RAND_CTX *parent) */ static EVP_RAND_CTX *rand_get0_primary(OSSL_LIB_CTX *ctx, RAND_GLOBAL *dgbl) { - EVP_RAND_CTX *ret; + EVP_RAND_CTX *ret, *seed, *newseed = NULL, *primary; if (dgbl == NULL) return NULL; @@ -764,34 +767,26 @@ static EVP_RAND_CTX *rand_get0_primary(OSSL_LIB_CTX *ctx, RAND_GLOBAL *dgbl) return NULL; ret = dgbl->primary; + seed = dgbl->seed; CRYPTO_THREAD_unlock(dgbl->lock); if (ret != NULL) return ret; - if (!CRYPTO_THREAD_write_lock(dgbl->lock)) - return NULL; - - ret = dgbl->primary; - if (ret != NULL) { - CRYPTO_THREAD_unlock(dgbl->lock); - return ret; - } - #if !defined(FIPS_MODULE) || !defined(OPENSSL_NO_FIPS_JITTER) /* Create a seed source for libcrypto or jitter enabled FIPS provider */ - if (dgbl->seed == NULL) { + if (seed == NULL) { ERR_set_mark(); - dgbl->seed = rand_new_seed(ctx); + seed = newseed = rand_new_seed(ctx); ERR_pop_to_mark(); } #endif /* !FIPS_MODULE || !OPENSSL_NO_FIPS_JITTER */ #if defined(FIPS_MODULE) /* The FIPS provider has entropy health tests instead of the primary */ - ret = rand_new_crngt(ctx, dgbl->seed); + ret = rand_new_crngt(ctx, seed); #else /* FIPS_MODULE */ - ret = rand_new_drbg(ctx, dgbl->seed, PRIMARY_RESEED_INTERVAL, + ret = rand_new_drbg(ctx, seed, PRIMARY_RESEED_INTERVAL, PRIMARY_RESEED_TIME_INTERVAL); #endif /* FIPS_MODULE */ @@ -799,12 +794,30 @@ static EVP_RAND_CTX *rand_get0_primary(OSSL_LIB_CTX *ctx, RAND_GLOBAL *dgbl) * The primary DRBG may be shared between multiple threads so we must * enable locking. */ - dgbl->primary = ret; - if (ret != NULL && !EVP_RAND_enable_locking(ret)) { - ERR_raise(ERR_LIB_EVP, EVP_R_UNABLE_TO_ENABLE_LOCKING); + if (ret == NULL || !EVP_RAND_enable_locking(ret)) { + if (ret != NULL) { + ERR_raise(ERR_LIB_EVP, EVP_R_UNABLE_TO_ENABLE_LOCKING); + EVP_RAND_CTX_free(ret); + } + if (newseed == NULL) + return NULL; + /* else carry on and store seed */ + ret = NULL; + } + + if (!CRYPTO_THREAD_write_lock(dgbl->lock)) + return NULL; + + primary = dgbl->primary; + if (primary != NULL) { + CRYPTO_THREAD_unlock(dgbl->lock); EVP_RAND_CTX_free(ret); - ret = dgbl->primary = NULL; + EVP_RAND_CTX_free(newseed); + return primary; } + if (newseed != NULL) + dgbl->seed = newseed; + dgbl->primary = ret; CRYPTO_THREAD_unlock(dgbl->lock); return ret; diff --git a/crypto/sm3/asm/sm3-armv8.pl b/crypto/sm3/asm/sm3-armv8.pl index 1437f028922c..f36e0e2be98c 100644 --- a/crypto/sm3/asm/sm3-armv8.pl +++ b/crypto/sm3/asm/sm3-armv8.pl @@ -153,13 +153,13 @@ $code.=<<___; .Loop: // load input - ld1 {$s0.16b-$s3.16b}, [$pdata], #64 + ld1 {$s0.4s-$s3.4s}, [$pdata], #64 sub $num, $num, #1 mov $bkstate1.16b, $state1.16b mov $bkstate2.16b, $state2.16b -#ifndef __ARMEB__ +#ifndef __AARCH64EB__ rev32 $s0.16b, $s0.16b rev32 $s1.16b, $s1.16b rev32 $s2.16b, $s2.16b diff --git a/crypto/sm4/asm/sm4-armv8.pl b/crypto/sm4/asm/sm4-armv8.pl index 8003df41ab29..1fe12dead49b 100755 --- a/crypto/sm4/asm/sm4-armv8.pl +++ b/crypto/sm4/asm/sm4-armv8.pl @@ -32,7 +32,7 @@ sub rev32() { my $dst = shift; my $src = shift; $code.=<<___; -#ifndef __ARMEB__ +#ifndef __AARCH64EB__ rev32 $dst.16b,$src.16b #endif ___ @@ -404,7 +404,7 @@ ___ &enc_blk($ivec); &rev32($ivec,$ivec); $code.=<<___; - st1 {$ivec.16b},[$out],#16 + st1 {$ivec.4s},[$out],#16 b.ne 1b b 3f .Ldec: @@ -485,11 +485,11 @@ ___ $code.=<<___; eor @dat[0].16b,@dat[0].16b,$ivec.16b mov $ivec.16b,@in[0].16b - st1 {@dat[0].16b},[$out],#16 + st1 {@dat[0].4s},[$out],#16 b.ne 1b 3: // save back IV - st1 {$ivec.16b},[$ivp] + st1 {$ivec.4s},[$ivp] ldp d8,d9,[sp],#16 ret .size ${prefix}_cbc_encrypt,.-${prefix}_cbc_encrypt diff --git a/crypto/store/store_result.c b/crypto/store/store_result.c index b5e50557c238..9944d353dc60 100644 --- a/crypto/store/store_result.c +++ b/crypto/store/store_result.c @@ -153,8 +153,19 @@ int ossl_store_handle_load_result(const OSSL_PARAM params[], void *arg) goto err; ERR_pop_to_mark(); - if (*v == NULL) - ERR_raise(ERR_LIB_OSSL_STORE, ERR_R_UNSUPPORTED); + if (*v == NULL) { + const char *hint = ""; + + if (!OSSL_PROVIDER_available(libctx, "default")) + hint = ":maybe need to load the default provider?"; + if (provider != NULL) + ERR_raise_data(ERR_LIB_OSSL_STORE, ERR_R_UNSUPPORTED, "provider=%s%s", + OSSL_PROVIDER_get0_name(provider), hint); + else if (hint[0] != '\0') + ERR_raise_data(ERR_LIB_OSSL_STORE, ERR_R_UNSUPPORTED, "%s", hint); + else + ERR_raise(ERR_LIB_OSSL_STORE, ERR_R_UNSUPPORTED); + } return (*v != NULL); err: diff --git a/crypto/threads_none.c b/crypto/threads_none.c index 240b7d9fdcfe..ac61f384501f 100644 --- a/crypto/threads_none.c +++ b/crypto/threads_none.c @@ -1,5 +1,5 @@ /* - * Copyright 2016-2024 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2016-2025 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -153,18 +153,28 @@ int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void)) # define OPENSSL_CRYPTO_THREAD_LOCAL_KEY_MAX 256 -static void *thread_local_storage[OPENSSL_CRYPTO_THREAD_LOCAL_KEY_MAX]; +struct thread_local_storage_entry { + void *data; + uint8_t used; +}; + +static struct thread_local_storage_entry thread_local_storage[OPENSSL_CRYPTO_THREAD_LOCAL_KEY_MAX]; int CRYPTO_THREAD_init_local(CRYPTO_THREAD_LOCAL *key, void (*cleanup)(void *)) { - static unsigned int thread_local_key = 0; + int entry_idx = 0; - if (thread_local_key >= OPENSSL_CRYPTO_THREAD_LOCAL_KEY_MAX) - return 0; + for (entry_idx = 0; entry_idx < OPENSSL_CRYPTO_THREAD_LOCAL_KEY_MAX; entry_idx++) { + if (!thread_local_storage[entry_idx].used) + break; + } - *key = thread_local_key++; + if (entry_idx == OPENSSL_CRYPTO_THREAD_LOCAL_KEY_MAX) + return 0; - thread_local_storage[*key] = NULL; + *key = entry_idx; + thread_local_storage[*key].used = 1; + thread_local_storage[*key].data = NULL; return 1; } @@ -174,7 +184,7 @@ void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key) if (*key >= OPENSSL_CRYPTO_THREAD_LOCAL_KEY_MAX) return NULL; - return thread_local_storage[*key]; + return thread_local_storage[*key].data; } int CRYPTO_THREAD_set_local(CRYPTO_THREAD_LOCAL *key, void *val) @@ -182,13 +192,18 @@ int CRYPTO_THREAD_set_local(CRYPTO_THREAD_LOCAL *key, void *val) if (*key >= OPENSSL_CRYPTO_THREAD_LOCAL_KEY_MAX) return 0; - thread_local_storage[*key] = val; + thread_local_storage[*key].data = val; return 1; } int CRYPTO_THREAD_cleanup_local(CRYPTO_THREAD_LOCAL *key) { + if (*key >= OPENSSL_CRYPTO_THREAD_LOCAL_KEY_MAX) + return 0; + + thread_local_storage[*key].used = 0; + thread_local_storage[*key].data = NULL; *key = OPENSSL_CRYPTO_THREAD_LOCAL_KEY_MAX + 1; return 1; } diff --git a/crypto/threads_pthread.c b/crypto/threads_pthread.c index 750ef201210b..44d6ebe09231 100644 --- a/crypto/threads_pthread.c +++ b/crypto/threads_pthread.c @@ -624,7 +624,7 @@ CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void) __owur int CRYPTO_THREAD_read_lock(CRYPTO_RWLOCK *lock) { # ifdef USE_RWLOCK - if (pthread_rwlock_rdlock(lock) != 0) + if (!ossl_assert(pthread_rwlock_rdlock(lock) == 0)) return 0; # else if (pthread_mutex_lock(lock) != 0) { @@ -639,7 +639,7 @@ __owur int CRYPTO_THREAD_read_lock(CRYPTO_RWLOCK *lock) __owur int CRYPTO_THREAD_write_lock(CRYPTO_RWLOCK *lock) { # ifdef USE_RWLOCK - if (pthread_rwlock_wrlock(lock) != 0) + if (!ossl_assert(pthread_rwlock_wrlock(lock) == 0)) return 0; # else if (pthread_mutex_lock(lock) != 0) { diff --git a/crypto/ts/ts_rsp_sign.c b/crypto/ts/ts_rsp_sign.c index 2465aede8560..0547736aa04f 100644 --- a/crypto/ts/ts_rsp_sign.c +++ b/crypto/ts/ts_rsp_sign.c @@ -648,8 +648,12 @@ static int ossl_ess_add1_signing_cert(PKCS7_SIGNER_INFO *si, } OPENSSL_free(pp); - return PKCS7_add_signed_attribute(si, NID_id_smime_aa_signingCertificate, - V_ASN1_SEQUENCE, seq); + if (!PKCS7_add_signed_attribute(si, NID_id_smime_aa_signingCertificate, + V_ASN1_SEQUENCE, seq)) { + ASN1_STRING_free(seq); + return 0; + } + return 1; } static int ossl_ess_add1_signing_cert_v2(PKCS7_SIGNER_INFO *si, @@ -671,8 +675,12 @@ static int ossl_ess_add1_signing_cert_v2(PKCS7_SIGNER_INFO *si, } OPENSSL_free(pp); - return PKCS7_add_signed_attribute(si, NID_id_smime_aa_signingCertificateV2, - V_ASN1_SEQUENCE, seq); + if (!PKCS7_add_signed_attribute(si, NID_id_smime_aa_signingCertificateV2, + V_ASN1_SEQUENCE, seq)) { + ASN1_STRING_free(seq); + return 0; + } + return 1; } static int ts_RESP_sign(TS_RESP_CTX *ctx) diff --git a/crypto/ui/ui_lib.c b/crypto/ui/ui_lib.c index a8756af1cdea..160e4c80c6e6 100644 --- a/crypto/ui/ui_lib.c +++ b/crypto/ui/ui_lib.c @@ -1,5 +1,5 @@ /* - * Copyright 2001-2023 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2001-2025 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -205,6 +205,7 @@ int UI_dup_input_string(UI *ui, const char *prompt, int flags, char *result_buf, int minsize, int maxsize) { char *prompt_copy = NULL; + int ret; if (prompt != NULL) { prompt_copy = OPENSSL_strdup(prompt); @@ -212,9 +213,13 @@ int UI_dup_input_string(UI *ui, const char *prompt, int flags, return 0; } - return general_allocate_string(ui, prompt_copy, 1, - UIT_PROMPT, flags, result_buf, minsize, - maxsize, NULL); + ret = general_allocate_string(ui, prompt_copy, 1, + UIT_PROMPT, flags, result_buf, minsize, + maxsize, NULL); + if (ret <= 0) + OPENSSL_free(prompt_copy); + + return ret; } int UI_add_verify_string(UI *ui, const char *prompt, int flags, @@ -231,6 +236,7 @@ int UI_dup_verify_string(UI *ui, const char *prompt, int flags, const char *test_buf) { char *prompt_copy = NULL; + int ret; if (prompt != NULL) { prompt_copy = OPENSSL_strdup(prompt); @@ -238,9 +244,12 @@ int UI_dup_verify_string(UI *ui, const char *prompt, int flags, return -1; } - return general_allocate_string(ui, prompt_copy, 1, - UIT_VERIFY, flags, result_buf, minsize, - maxsize, test_buf); + ret = general_allocate_string(ui, prompt_copy, 1, + UIT_VERIFY, flags, result_buf, minsize, + maxsize, test_buf); + if (ret <= 0) + OPENSSL_free(prompt_copy); + return ret; } int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc, @@ -260,6 +269,7 @@ int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc, char *action_desc_copy = NULL; char *ok_chars_copy = NULL; char *cancel_chars_copy = NULL; + int ret; if (prompt != NULL) { prompt_copy = OPENSSL_strdup(prompt); @@ -285,9 +295,14 @@ int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc, goto err; } - return general_allocate_boolean(ui, prompt_copy, action_desc_copy, - ok_chars_copy, cancel_chars_copy, 1, - UIT_BOOLEAN, flags, result_buf); + ret = general_allocate_boolean(ui, prompt_copy, action_desc_copy, + ok_chars_copy, cancel_chars_copy, 1, + UIT_BOOLEAN, flags, result_buf); + if (ret <= 0) + goto err; + + return ret; + err: OPENSSL_free(prompt_copy); OPENSSL_free(action_desc_copy); @@ -305,6 +320,7 @@ int UI_add_info_string(UI *ui, const char *text) int UI_dup_info_string(UI *ui, const char *text) { char *text_copy = NULL; + int ret; if (text != NULL) { text_copy = OPENSSL_strdup(text); @@ -312,8 +328,11 @@ int UI_dup_info_string(UI *ui, const char *text) return -1; } - return general_allocate_string(ui, text_copy, 1, UIT_INFO, 0, NULL, - 0, 0, NULL); + ret = general_allocate_string(ui, text_copy, 1, UIT_INFO, 0, NULL, + 0, 0, NULL); + if (ret <= 0) + OPENSSL_free(text_copy); + return ret; } int UI_add_error_string(UI *ui, const char *text) @@ -325,14 +344,19 @@ int UI_add_error_string(UI *ui, const char *text) int UI_dup_error_string(UI *ui, const char *text) { char *text_copy = NULL; + int ret; if (text != NULL) { text_copy = OPENSSL_strdup(text); if (text_copy == NULL) return -1; } - return general_allocate_string(ui, text_copy, 1, UIT_ERROR, 0, NULL, - 0, 0, NULL); + + ret = general_allocate_string(ui, text_copy, 1, UIT_ERROR, 0, NULL, + 0, 0, NULL); + if (ret <= 0) + OPENSSL_free(text_copy); + return ret; } char *UI_construct_prompt(UI *ui, const char *phrase_desc, diff --git a/crypto/x509/by_store.c b/crypto/x509/by_store.c index d1e186f4fc2d..def06be1fe8c 100644 --- a/crypto/x509/by_store.c +++ b/crypto/x509/by_store.c @@ -7,23 +7,34 @@ * https://www.openssl.org/source/license.html */ +#include <openssl/safestack.h> #include <openssl/store.h> #include "internal/cryptlib.h" #include "crypto/x509.h" #include "x509_local.h" +typedef struct cached_store_st { + char *uri; + OSSL_LIB_CTX *libctx; + char *propq; + OSSL_STORE_CTX *ctx; +} CACHED_STORE; + +DEFINE_STACK_OF(CACHED_STORE) + /* Generic object loader, given expected type and criterion */ -static int cache_objects(X509_LOOKUP *lctx, const char *uri, - const OSSL_STORE_SEARCH *criterion, - int depth, OSSL_LIB_CTX *libctx, const char *propq) +static int cache_objects(X509_LOOKUP *lctx, CACHED_STORE *store, + const OSSL_STORE_SEARCH *criterion, int depth) { int ok = 0; - OSSL_STORE_CTX *ctx = NULL; + OSSL_STORE_CTX *ctx = store->ctx; X509_STORE *xstore = X509_LOOKUP_get_store(lctx); - if ((ctx = OSSL_STORE_open_ex(uri, libctx, propq, NULL, NULL, NULL, - NULL, NULL)) == NULL) + if (ctx == NULL + && (ctx = OSSL_STORE_open_ex(store->uri, store->libctx, store->propq, + NULL, NULL, NULL, NULL, NULL)) == NULL) return 0; + store->ctx = ctx; /* * We try to set the criterion, but don't care if it was valid or not. @@ -62,9 +73,15 @@ static int cache_objects(X509_LOOKUP *lctx, const char *uri, * This is an entry in the "directory" represented by the current * uri. if |depth| allows, dive into it. */ - if (depth > 0) - ok = cache_objects(lctx, OSSL_STORE_INFO_get0_NAME(info), - criterion, depth - 1, libctx, propq); + if (depth > 0) { + CACHED_STORE substore; + + substore.uri = (char *)OSSL_STORE_INFO_get0_NAME(info); + substore.libctx = store->libctx; + substore.propq = store->propq; + substore.ctx = NULL; + ok = cache_objects(lctx, &substore, criterion, depth - 1); + } } else { /* * We know that X509_STORE_add_{cert|crl} increments the object's @@ -88,21 +105,26 @@ static int cache_objects(X509_LOOKUP *lctx, const char *uri, break; } OSSL_STORE_close(ctx); + store->ctx = NULL; return ok; } -/* Because OPENSSL_free is a macro and for C type match */ -static void free_uri(OPENSSL_STRING data) +static void free_store(CACHED_STORE *store) { - OPENSSL_free(data); + if (store != NULL) { + OSSL_STORE_close(store->ctx); + OPENSSL_free(store->uri); + OPENSSL_free(store->propq); + OPENSSL_free(store); + } } static void by_store_free(X509_LOOKUP *ctx) { - STACK_OF(OPENSSL_STRING) *uris = X509_LOOKUP_get_method_data(ctx); - sk_OPENSSL_STRING_pop_free(uris, free_uri); + STACK_OF(CACHED_STORE) *stores = X509_LOOKUP_get_method_data(ctx); + sk_CACHED_STORE_pop_free(stores, free_store); } static int by_store_ctrl_ex(X509_LOOKUP *ctx, int cmd, const char *argp, @@ -112,27 +134,49 @@ static int by_store_ctrl_ex(X509_LOOKUP *ctx, int cmd, const char *argp, switch (cmd) { case X509_L_ADD_STORE: if (argp != NULL) { - STACK_OF(OPENSSL_STRING) *uris = X509_LOOKUP_get_method_data(ctx); - char *data = OPENSSL_strdup(argp); + STACK_OF(CACHED_STORE) *stores = X509_LOOKUP_get_method_data(ctx); + CACHED_STORE *store = OPENSSL_zalloc(sizeof(*store)); - if (data == NULL) { + if (store == NULL) { return 0; } - if (uris == NULL) { - uris = sk_OPENSSL_STRING_new_null(); - X509_LOOKUP_set_method_data(ctx, uris); + + store->uri = OPENSSL_strdup(argp); + store->libctx = libctx; + if (propq != NULL) + store->propq = OPENSSL_strdup(propq); + store->ctx = OSSL_STORE_open_ex(argp, libctx, propq, NULL, NULL, + NULL, NULL, NULL); + if (store->ctx == NULL + || (propq != NULL && store->propq == NULL) + || store->uri == NULL) { + free_store(store); + return 0; + } + + if (stores == NULL) { + stores = sk_CACHED_STORE_new_null(); + if (stores != NULL) + X509_LOOKUP_set_method_data(ctx, stores); } - if (sk_OPENSSL_STRING_push(uris, data) <= 0) { - OPENSSL_free(data); + if (stores == NULL || sk_CACHED_STORE_push(stores, store) <= 0) { + free_store(store); return 0; } return 1; } /* NOP if no URI is given. */ return 1; - case X509_L_LOAD_STORE: + case X509_L_LOAD_STORE: { /* This is a shortcut for quick loading of specific containers */ - return cache_objects(ctx, argp, NULL, 0, libctx, propq); + CACHED_STORE store; + + store.uri = (char *)argp; + store.libctx = libctx; + store.propq = (char *)propq; + store.ctx = NULL; + return cache_objects(ctx, &store, NULL, 0); + } default: /* Unsupported command */ return 0; @@ -146,16 +190,15 @@ static int by_store_ctrl(X509_LOOKUP *ctx, int cmd, } static int by_store(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type, - const OSSL_STORE_SEARCH *criterion, X509_OBJECT *ret, - OSSL_LIB_CTX *libctx, const char *propq) + const OSSL_STORE_SEARCH *criterion, X509_OBJECT *ret) { - STACK_OF(OPENSSL_STRING) *uris = X509_LOOKUP_get_method_data(ctx); + STACK_OF(CACHED_STORE) *stores = X509_LOOKUP_get_method_data(ctx); int i; int ok = 0; - for (i = 0; i < sk_OPENSSL_STRING_num(uris); i++) { - ok = cache_objects(ctx, sk_OPENSSL_STRING_value(uris, i), criterion, - 1 /* depth */, libctx, propq); + for (i = 0; i < sk_CACHED_STORE_num(stores); i++) { + ok = cache_objects(ctx, sk_CACHED_STORE_value(stores, i), criterion, + 1 /* depth */); if (ok) break; @@ -163,13 +206,12 @@ static int by_store(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type, return ok; } -static int by_store_subject_ex(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type, - const X509_NAME *name, X509_OBJECT *ret, - OSSL_LIB_CTX *libctx, const char *propq) +static int by_store_subject(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type, + const X509_NAME *name, X509_OBJECT *ret) { OSSL_STORE_SEARCH *criterion = OSSL_STORE_SEARCH_by_name((X509_NAME *)name); /* won't modify it */ - int ok = by_store(ctx, type, criterion, ret, libctx, propq); + int ok = by_store(ctx, type, criterion, ret); STACK_OF(X509_OBJECT) *store_objects = X509_STORE_get0_objects(X509_LOOKUP_get_store(ctx)); X509_OBJECT *tmp = NULL; @@ -217,12 +259,6 @@ static int by_store_subject_ex(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type, return ok; } -static int by_store_subject(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type, - const X509_NAME *name, X509_OBJECT *ret) -{ - return by_store_subject_ex(ctx, type, name, ret, NULL, NULL); -} - /* * We lack the implementations for get_by_issuer_serial, get_by_fingerprint * and get_by_alias. There's simply not enough support in the X509_LOOKUP @@ -240,7 +276,7 @@ static X509_LOOKUP_METHOD x509_store_lookup = { NULL, /* get_by_issuer_serial */ NULL, /* get_by_fingerprint */ NULL, /* get_by_alias */ - by_store_subject_ex, + NULL, /* get_by_subject_ex */ by_store_ctrl_ex }; diff --git a/crypto/x509/v3_lib.c b/crypto/x509/v3_lib.c index 077b22c863ec..86d8721b6060 100644 --- a/crypto/x509/v3_lib.c +++ b/crypto/x509/v3_lib.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2023 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2025 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -100,7 +100,11 @@ int X509V3_EXT_add_alias(int nid_to, int nid_from) *tmpext = *ext; tmpext->ext_nid = nid_to; tmpext->ext_flags |= X509V3_EXT_DYNAMIC; - return X509V3_EXT_add(tmpext); + if (!X509V3_EXT_add(tmpext)) { + OPENSSL_free(tmpext); + return 0; + } + return 1; } void X509V3_EXT_cleanup(void) |
