openssl.git
2 years agoEVP demo for XOF digest using SHAKE256
Hugo Landau [Thu, 3 Mar 2022 08:20:05 +0000 (08:20 +0000)]
EVP demo for XOF digest using SHAKE256

This demo optionally accepts a single command line argument, allowing
the output length to be specified.

Fixes #14106.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17803)

2 years agoapps: several return value checks for BIO_new()
xkernel [Wed, 5 Jan 2022 07:54:10 +0000 (15:54 +0800)]
apps: several return value checks for BIO_new()

Also check return value of functions that call BIO_new() internally
such as dup_bio_out().

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17421)

2 years agoRework dependencies between config files and build files
Richard Levitte [Wed, 23 Feb 2022 10:00:39 +0000 (11:00 +0100)]
Rework dependencies between config files and build files

Before PR #15310, which reworked how build files (Makefile, ...) were
generated, everything was done when configuring, so configdata.pm
could depend on build file templates and we'd get away with it.

However, since building configdata.pm is now independent of the build
file templates, that dependency is unnecessary, and would lead to
surprises of the build file template is updated, with an unexpected
full reconfiguration as a result, when all that's needed is to run
configdata.pm with no flags to get the build file re-generated.

This change is therefore a completion of what was forgotten in #15310.

Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17756)

2 years agoFix build issue with aes-gcm-armv8-unroll8_64.S on older aarch64 assemblers
XiaokangQian [Wed, 2 Mar 2022 03:27:43 +0000 (03:27 +0000)]
Fix build issue with aes-gcm-armv8-unroll8_64.S on older aarch64 assemblers

The EOR3 instruction is implemented with .inst, and the code here is enabled
using run-time detection of the CPU capabilities, so no need to explicitly
ask for the sha3 extension.

Fixes #17773

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17795)

2 years agoAdd EVP demo for X25519 key exchange
Hugo Landau [Wed, 2 Mar 2022 13:08:53 +0000 (13:08 +0000)]
Add EVP demo for X25519 key exchange

This offers both a known answer test with fixed keys and also
demonstrates a more realistic usage with random keys.

Fixes #14118.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17799)

2 years agoFix typo in EVP_MD-BLAKE2(7)
Hugo Landau [Tue, 1 Mar 2022 17:48:11 +0000 (17:48 +0000)]
Fix typo in EVP_MD-BLAKE2(7)

Reviewed-by: Todd Short <todd.short@me.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17790)

2 years agos_server: Do not use SSL_sendfile when KTLS is not being used
Hugo Landau [Tue, 1 Mar 2022 16:47:03 +0000 (16:47 +0000)]
s_server: Do not use SSL_sendfile when KTLS is not being used

Fix a bug in `openssl s_server -WWW` where it would attempt to invoke
`SSL_sendfile` if `-ktls -sendfile` was passed on the command line, even
if KTLS has not actually been enabled, for example because it is not
supported by the host. Since `SSL_sendfile` is only supported when KTLS
is actually being used, this resulted in a failure to serve requests.

Fixes #17503.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17788)

2 years agoPerturb the malloc output during tests
Matt Caswell [Thu, 24 Feb 2022 16:20:14 +0000 (16:20 +0000)]
Perturb the malloc output during tests

Set the environment variable MALLOC_PERTURB_ during tests to perturb the
output from OPENSSL_malloc() calls (see the mallopt man page for details
about this environment variable). This could be a low cost way of spotting
uninit reads in "make test" runs in some situations.

In tests I have found it to be a little unreliable (sometimes it seemed to
not perturb the output for inexplicable reasons) - but since this is easy
to implement I think it is worthwhile.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17768)

2 years agoasn1_string_to_time_t: Use timegm on FreeBSD.
John Baldwin [Thu, 24 Feb 2022 01:18:22 +0000 (17:18 -0800)]
asn1_string_to_time_t: Use timegm on FreeBSD.

FreeBSD does not provide a global timezone variable containing the
offset to UTC.  Instead, FreeBSD's libc includes a legacy timezone
function dating back to Version 7 AT&T UNIX.  As a result,
asn1_string_to_time_t currently fails to compile on FreeBSD as it
subtracts a function from a time_t value:

../crypto/asn1/a_time.c:625:37: error: invalid operands to binary expression ('time_t' (aka 'long') and 'char *(int, int)')
    timestamp_utc = timestamp_local - timezone;
                    ~~~~~~~~~~~~~~~ ^ ~~~~~~~~
1 error generated.

However, FreeBSD's libc does include a non-standard (but widely
available) timegm function which converts a struct tm directly to a
UTC time_t value.  Use this on FreeBSD instead of mktime.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17765)

2 years agoAdd testing of OBJ_find_sigid_by_algs()
Michael Baentsch [Wed, 2 Mar 2022 07:48:46 +0000 (08:48 +0100)]
Add testing of OBJ_find_sigid_by_algs()

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17733)

2 years agoenable CMS sign/verify for provider-implemented PKEYs
Michael Baentsch [Fri, 18 Feb 2022 13:10:04 +0000 (14:10 +0100)]
enable CMS sign/verify for provider-implemented PKEYs

We need to handle signatures with and without digest algs
and we generalize the ossl_cms_ecdsa_dsa_sign() function
to other algorithms that are handled in the same way.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17733)

2 years agoSM4 optimization for non-asm mode
zhangzhilei [Thu, 24 Feb 2022 04:26:57 +0000 (12:26 +0800)]
SM4 optimization for non-asm mode

This patch use table-lookup borrow from aes in crypto/aes/aes_core.c.

Test on my PC(AMD Ryzen Threadripper 3990X 64-Core Processor),

before and after optimization:

debug mode:

Before:
type             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes  16384 bytes
SM4-CBC          40101.14k    41453.80k    42073.86k    42174.81k    42216.11k    42227.03k
SM4-ECB          41222.60k    42074.88k    42673.66k    42868.05k    42896.04k    42844.16k
SM4-CTR          35867.22k    36874.47k    37004.97k    37083.82k    37052.42k    37076.99k

After:
type             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes  16384 bytes
SM4-CBC          47273.51k    48957.40k    49665.19k    49810.77k    49859.24k    49834.67k
SM4-ECB          48100.01k    49323.34k    50224.04k    50273.28k    50533.72k    50730.12k
SM4-CTR          41352.64k    42621.29k    42971.22k    43061.59k    43089.92k    43100.84k

non-debug mode:

Before:
type             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes  16384 bytes
SM4-CBC         141596.59k   145102.93k   146794.50k   146540.89k   146650.45k   146877.10k
SM4-ECB         144774.71k   155106.28k   158166.36k   158279.00k   158520.66k   159280.97k
SM4-CTR         138021.10k   141577.60k   142493.53k   142736.38k   142852.10k   143125.16k

After:
type             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes  16384 bytes
SM4-CBC         142016.95k   150068.48k   152238.25k   152773.97k   153094.83k   152027.14k
SM4-ECB         148842.94k   159919.87k   163628.37k   164515.84k   164697.43k   164790.27k
SM4-CTR         141774.23k   146206.89k   147470.25k   147816.28k   146770.60k   148346.20k

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17766)

2 years agoFix NULL pointer dereference for BN_mod_exp2_mont
Hugo Landau [Tue, 1 Mar 2022 14:08:12 +0000 (14:08 +0000)]
Fix NULL pointer dereference for BN_mod_exp2_mont

This fixes a bug whereby BN_mod_exp2_mont can dereference a NULL pointer
if BIGNUM argument m represents zero.

Regression test added. Fixes #17648.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17783)

2 years agoEnable openssl req -x509 to create certificates from CSRs
Hugo Landau [Tue, 1 Mar 2022 12:55:03 +0000 (12:55 +0000)]
Enable openssl req -x509 to create certificates from CSRs

`openssl req -x509` has code allowing it to generate certificates from CSRs
as a replacement for `openssl x509`, but a bug prevents it from working
properly. -CA and -CAkey can now be passed to generate a CA-signed
certificate as documented in openssl-req(1).

Regression testing has been added to `openssl req`.

Fixes #17736.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17782)

2 years agoImprove documentation of BIO_FLAGS_BASE64_NO_NL flag.
Daniel [Mon, 21 Feb 2022 12:25:25 +0000 (13:25 +0100)]
Improve documentation of BIO_FLAGS_BASE64_NO_NL flag.

Fixes #12491.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17744)

2 years ago[ssl] Add tests for Perfect Forward Secrecy criteria on SECLEVEL >= 3
Nicola Tuveri [Wed, 23 Feb 2022 21:05:22 +0000 (23:05 +0200)]
[ssl] Add tests for Perfect Forward Secrecy criteria on SECLEVEL >= 3

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17763)

2 years ago[ssl] Add SSL_kDHEPSK and SSL_kECDHEPSK as PFS ciphersuites for SECLEVEL >= 3
Nicola Tuveri [Tue, 22 Feb 2022 14:26:26 +0000 (16:26 +0200)]
[ssl] Add SSL_kDHEPSK and SSL_kECDHEPSK as PFS ciphersuites for SECLEVEL >= 3

Fixes #17743

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17763)

2 years ago[ssl] Prefer SSL_k(EC)?DHE to the SSL_kE(EC)?DH alias
Nicola Tuveri [Tue, 22 Feb 2022 12:47:11 +0000 (14:47 +0200)]
[ssl] Prefer SSL_k(EC)?DHE to the SSL_kE(EC)?DH alias

`SSL_kECDHE` and `SSL_kEECDH`, and `SSL_kDHE` and `SSL_kEDH` are already
marked as aliases of each other in the headers.
This commit, for each pair, replaces the leftover uses of the latter
synonym with the first one, which is considered more common.

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17763)

2 years agoaarch64: Fix async_fibre_swapcontext() on clang BTI builds
Tom Cosgrove [Mon, 14 Feb 2022 11:23:57 +0000 (11:23 +0000)]
aarch64: Fix async_fibre_swapcontext() on clang BTI builds

Reverting to using swapcontext() when compiling with clang on BTI-enabled
builds fixes the BTI setjmp() failure seen when running asynctest.

The issue with setjmp/longjmp is a known clang bug: see
https://github.com/llvm/llvm-project/issues/48888

Change-Id: I6eeaaa2e15f402789f1b3e742038f84bef846e29

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17698)

2 years agocrypto/x509/v3_utl.c: Add missing check for OPENSSL_strndup
Jiasheng Jiang [Mon, 21 Feb 2022 01:51:54 +0000 (09:51 +0800)]
crypto/x509/v3_utl.c: Add missing check for OPENSSL_strndup

Since the potential failure of memory allocation, it
should be better to check the return value of the
OPENSSL_strndup(), like x509v3_add_len_value().
And following the comment of 'if (astrlen < 0)',
return -1 if fails.

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17737)

2 years agofuzz/fuzz_rand.c: Add check for OSSL_LIB_CTX_new
Jiasheng Jiang [Mon, 21 Feb 2022 02:10:23 +0000 (10:10 +0800)]
fuzz/fuzz_rand.c: Add check for OSSL_LIB_CTX_new

As the potential failure of the OPENSSL_zalloc(), the OSSL_LIB_CTX_new()
could return NULL.
Therefore, it should be better to check it and return error if fails in
order to guarantee the success of the initialization.

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17738)

2 years agoCorrect the UnsafeLegacyServerConnect docs
Matt Caswell [Tue, 22 Feb 2022 10:40:33 +0000 (10:40 +0000)]
Correct the UnsafeLegacyServerConnect docs

This option is no longer set by default from OpenSSL 3.0.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Ben Kaduk <kaduk@mit.edu>
(Merged from https://github.com/openssl/openssl/pull/17748)

2 years agocheck the return value of CRYPTO_strdup()
xkernel [Mon, 21 Feb 2022 07:17:46 +0000 (15:17 +0800)]
check the return value of CRYPTO_strdup()

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17741)

2 years agoChange `strlen' argument name to `strlength' to avoid c++ reserved words.
Pauli [Wed, 23 Feb 2022 22:52:52 +0000 (09:52 +1100)]
Change `strlen' argument name to `strlength' to avoid c++ reserved words.

Fixes #17753

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/17764)

2 years agofetch: convert a NULL property query to ""
Pauli [Fri, 25 Feb 2022 02:37:08 +0000 (13:37 +1100)]
fetch: convert a NULL property query to ""

Previously, a NULL property query was never cached and this lead to a
performance degregation.  Now, such a query is converted to an empty string
and cached.

Fixes #17752
Fixes https://github.openssl.org/openssl/openssl/issues/26

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17769)

2 years agoVMS: copy prologue/epilogue headers when header files are generated
Richard Levitte [Wed, 23 Feb 2022 08:05:10 +0000 (09:05 +0100)]
VMS: copy prologue/epilogue headers when header files are generated

This is crucial when the build tree isn't the source tree, as they
only take effect in directories where included header files reside.

The issue only comes up when linking with the static libraries, since
the shared libraries have upper case aliases of all symbols.

Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/17755)

2 years agotest/crltest.c: Add check for glue2bio
Jiasheng Jiang [Thu, 17 Feb 2022 09:47:00 +0000 (17:47 +0800)]
test/crltest.c: Add check for glue2bio

As the glue2bio() could return NULL pointer if fails,
it should be better to check the return value in order
to avoid the use of NULL pointer.

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17718)

2 years agobio_enc.c: add check for BIO_new_mem_buf
Jiasheng Jiang [Fri, 18 Feb 2022 02:13:08 +0000 (10:13 +0800)]
bio_enc.c: add check for BIO_new_mem_buf

Since the memory allocation may fail, the BIO_new_mem_buf() may
return NULL pointer.
Therefore, it should be better to check it and return error if fails.

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17730)

2 years agoX509_VERIFY_PARAM_set_flags.pod: fix typos
Carlo Teubner [Fri, 18 Feb 2022 10:00:52 +0000 (10:00 +0000)]
X509_VERIFY_PARAM_set_flags.pod: fix typos

CLA: trivial

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17731)

2 years agoAdd -quiet option to pkcs7 for -print_certs
Raul Ferrando [Tue, 15 Feb 2022 15:02:41 +0000 (16:02 +0100)]
Add -quiet option to pkcs7 for -print_certs

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17708)

2 years agoUndeprecate OPENSSL_VERSION_NUMBER and OpenSSL_version_num()
Matt Caswell [Tue, 22 Feb 2022 11:49:04 +0000 (11:49 +0000)]
Undeprecate OPENSSL_VERSION_NUMBER and OpenSSL_version_num()

This macro and function were deprecated in the documentation but not in
the source.

Following an OTC vote the deprecation has been removed from the
documentation.

See https://github.com/openssl/technical-policies/issues/26

Fixes #17517

Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17750)

2 years agodoc: Fix KDF example for scrypt
msa42 [Mon, 21 Feb 2022 18:23:34 +0000 (18:23 +0000)]
doc: Fix KDF example for scrypt

CLA: trivial

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17745)

2 years agoFix a failure in sslapitest
Matt Caswell [Wed, 23 Feb 2022 11:16:07 +0000 (11:16 +0000)]
Fix a failure in sslapitest

The SNI test in test_cert_cb_int() was always failing because it used
SSL_CTX_new() instead of SSL_CTX_new_ex() and was therefore not using the
correct libctx. PR #17739 amended the test to check the return value from
SSL_CTX_new() which made the failure obvious.

Fixes #17757

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/17758)

2 years agocheck *libctx which is allocated by OSSL_LIB_CTX_new()
xkernel [Mon, 21 Feb 2022 07:29:25 +0000 (15:29 +0800)]
check *libctx which is allocated by OSSL_LIB_CTX_new()

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17740)

2 years agotest/sslapitest.c: Add check for SSL_CTX_new
Jiasheng Jiang [Mon, 21 Feb 2022 02:54:29 +0000 (10:54 +0800)]
test/sslapitest.c: Add check for SSL_CTX_new

As the potential failure of the memory allocation, it should
be better to check the return value of SSL_CTX_new() and return
error if fails, like SSL_CTX_new_ex().

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17739)

2 years agoX509V3_get_d2i.pod: use I<> for arguments and remove B<> around NULL
Dr. David von Oheimb [Fri, 18 Feb 2022 08:36:00 +0000 (09:36 +0100)]
X509V3_get_d2i.pod: use I<> for arguments and remove B<> around NULL

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17724)

2 years agoX509V3_get_d2i.pod: Fix glitch on X509V3_get{,_ext}_d2i and align order
Dr. David von Oheimb [Thu, 17 Feb 2022 18:43:55 +0000 (19:43 +0100)]
X509V3_get_d2i.pod: Fix glitch on X509V3_get{,_ext}_d2i and align order

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17724)

2 years agoCMP: add subject of any provided CSR as default message sender
Dr. David von Oheimb [Thu, 17 Feb 2022 18:46:29 +0000 (19:46 +0100)]
CMP: add subject of any provided CSR as default message sender

Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17723)

2 years agochacha20 performance optimizations for ppc64le with 8x lanes,
Deepankar Bhattacharjee [Mon, 20 Sep 2021 14:45:15 +0000 (10:45 -0400)]
chacha20 performance optimizations for ppc64le with 8x lanes,
Performance increase around 50%.

Co-authored-by: Madhusudhanan Duraisamy <madurais@in.ibm.com>
Co-authored-by: Nilamjyoti Goswami <nilamgoswami@in.ibm.com>
Co-authored-by: Siva Sundar Anbareeswaran <srisivasundar@in.ibm.com>
Reviewed-by: Danny Tsen <dtsen@us.ibm.com>
Tested-by: Danny Tsen <dtsen@us.ibm.com>
Signed-off-by: Danny <dtsen@us.ibm.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/16637)

2 years agox509: handle returns from X509_TRUST_get_by_id() more consistently
Pauli [Tue, 15 Feb 2022 23:41:58 +0000 (10:41 +1100)]
x509: handle returns from X509_TRUST_get_by_id() more consistently

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/17709)

2 years agorand: Add missing check for rand_get_global
Jiasheng Jiang [Tue, 15 Feb 2022 09:45:04 +0000 (17:45 +0800)]
rand: Add missing check for rand_get_global

As the potential failure of the rand_get_global(),
for example fail to get lock, 'dgbl' could be NULL
pointer and be dereferenced later.
Therefore, it should be better to check it and return
error if fails, like RAND_get0_primary() and other callers.

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/17690)

2 years agofuzz/asn1.c: Add missing check for BIO_new
Jiasheng Jiang [Sat, 12 Feb 2022 11:27:09 +0000 (19:27 +0800)]
fuzz/asn1.c: Add missing check for BIO_new

Since the BIO_new may fail, the 'bio' could be NULL pointer and be used.
Therefore, it should be better to check it and skip the print if fails.

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/17690)

2 years agotest/mdc2test.c: Add check for OSSL_PROVIDER_load
Jiasheng Jiang [Fri, 18 Feb 2022 01:15:50 +0000 (09:15 +0800)]
test/mdc2test.c: Add check for OSSL_PROVIDER_load

Since the potential failure of the OSSL_PROVIDER_load(),
for example there is no lock, the provider could fail to
be loaded into the library context.
Therefore, it should be better to check it and return error
if fails.
Also, in order to avoid free unknown pointer, 'c' should be
initialized as NULL.

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/17729)

2 years agodoc: Refactored the example in crypto.pod
yangyangtiantianlonglong [Wed, 16 Feb 2022 15:33:17 +0000 (23:33 +0800)]
doc: Refactored the example in crypto.pod

Added return value and error code in the sample

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17721)

2 years agodoc: Update "SSL/TLS" old documentation description in openssl.pod
yangyangtiantianlonglong [Wed, 16 Feb 2022 15:01:38 +0000 (23:01 +0800)]
doc: Update "SSL/TLS" old documentation description in openssl.pod

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17721)

2 years agoFix typo
Dimitris Apostolou [Wed, 16 Feb 2022 08:05:35 +0000 (10:05 +0200)]
Fix typo

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/17713)

2 years agoAdd changes logs caption for the next release 1.1.1n
Oleg Pekar [Wed, 16 Feb 2022 16:58:14 +0000 (18:58 +0200)]
Add changes logs caption for the next release 1.1.1n

Co-authored-by: Matthias St. Pierre <matthias.st.pierre@ncp-e.com>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/17714)

2 years agoFixed the date of changes of 1.1.1m
Oleg Pekar [Wed, 16 Feb 2022 11:59:01 +0000 (13:59 +0200)]
Fixed the date of changes of 1.1.1m

Fixed the date in the heading of "Changes between 1.1.1l and 1.1.1m" to 14 Dec 2021

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/17714)

2 years agoenc : add support for wrap mode
EasySec [Sat, 12 Feb 2022 01:07:34 +0000 (02:07 +0100)]
enc : add support for wrap mode

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17691)

2 years agoPrefix output to avoid random ok to confuse test parser
Armin Fuerst [Fri, 11 Feb 2022 18:46:12 +0000 (19:46 +0100)]
Prefix output to avoid random ok to confuse test parser

Prefix output of generated dh parameters to avoid misinterpretation
of lines beginning with ok[^a-zA-Z0-9] as a testresult.

Also corrected indent and removed useless comma after last item.

Fixes #17480

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17689)

2 years agoapps/s_server: Add missing check for BIO_new
Jiasheng Jiang [Wed, 16 Feb 2022 03:27:23 +0000 (11:27 +0800)]
apps/s_server: Add missing check for BIO_new

As the potential failure of the BIO_new(), it should be better to check the return value and return error if fails in order to avoid the dereference of NULL pointer.
And because 'bio_s_msg' is checked before being used everytime, which has no need to add the check.
But 'bio_s_out' is not.
And since the check 'if (bio_s_out == NULL)' is redundant, it can be removed to make the code succincter.
Also the 'sbio' and so forth should be checked like the other places in the same file.

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17710)

2 years agoapps/ocsp: Add check for OPENSSL_strdup
Jiasheng Jiang [Thu, 10 Feb 2022 07:41:40 +0000 (15:41 +0800)]
apps/ocsp: Add check for OPENSSL_strdup

Just assert 'bn' to be non-NULL is not enough.
The check for 'itmp' is still needed.
If 'bn' is 0, the 'itmp' is assigned by OPENSSL_strdup().
Since OPENSSL_strdup() may fail because of the lack of memory,
the 'itmp' will be NULL and be an valid parameter hashed in
TXT_DB_get_by_index(), returning a wrong result.

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17677)

2 years agos_server: Add check for OPENSSL_strdup
Jiasheng Jiang [Wed, 9 Feb 2022 15:04:25 +0000 (23:04 +0800)]
s_server: Add check for OPENSSL_strdup

Since the OPENSSL_strdup() may return NULL if allocation
fails, the 'port' could be NULL.
And then it will be used in do_server(), which can accept
NULL as an valid parameter.
That means that the system could run with a wrong parameter.
Therefore it should be better to check it, like the other
memory allocation.

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17673)

2 years agoAdd back check for the DH public key size
Tomas Mraz [Thu, 10 Feb 2022 10:49:37 +0000 (11:49 +0100)]
Add back check for the DH public key size

This is needed for TLS-1.3.

Also add check for uncompressed point format for ECDHE as
the other formats are not allowed by RFC 8446.

Fixes #17667

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17678)

2 years agoAdd define guards to avoid multi-inclusion
Weiguo Li [Wed, 9 Feb 2022 18:30:25 +0000 (02:30 +0800)]
Add define guards to avoid multi-inclusion

This header files are included by multiple other headers.
It's better to add define guards to prevent multi-inclusion.
Adhere to the coding style, all preprocessor directives inside
the guards gain a space.

Signed-off-by: Weiguo Li <liwg06@foxmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/17666)

2 years agotest/helpers/handshake.c: Add check for OPENSSL_strdup
Jiasheng Jiang [Tue, 15 Feb 2022 02:46:38 +0000 (10:46 +0800)]
test/helpers/handshake.c: Add check for OPENSSL_strdup

As the potential failure of the memory allocation, the OPENSSL_strdup()
could return NULL pointer and then be assigned to 'server_ctx'.
In order to tell the callers the failure of the configuration, it should
be better to return error.

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17705)

2 years agoForce macOS 10.15 or later to be 64-bit
Todd Short [Wed, 9 Feb 2022 20:59:37 +0000 (15:59 -0500)]
Force macOS 10.15 or later to be 64-bit

macOS Catalina (10.15) no longer supports 32-bit applications.
Do not wait 5 seconds to give the user the option of using KERNEL_BITS=32
Do not accept the KERNEL_BITS=32 option

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17675)

2 years agoAdd tests for do_updatedb
Armin Fuerst [Fri, 4 Feb 2022 19:35:54 +0000 (20:35 +0100)]
Add tests for do_updatedb

Fixes #13944

Moved "opt_printf_stderr" out of apps.c to avoid duplicate definition in tests.

Added function "asn1_string_to_time_t" including tests.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17645)

2 years agodh_exch.c: Add check for OPENSSL_strdup
Jiasheng Jiang [Mon, 7 Feb 2022 11:13:43 +0000 (19:13 +0800)]
dh_exch.c: Add check for OPENSSL_strdup

Since the OPENSSL_strdup() may return NULL if allocation
fails, it should be better to check the return value.

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17651)

2 years agoApply the correct Apache v2 license
Tomas Mraz [Fri, 11 Feb 2022 08:44:52 +0000 (09:44 +0100)]
Apply the correct Apache v2 license

There were still a few files mentioning the old OpenSSL license.

Fixes #17684

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17686)

2 years agoopenssl rehash: add check for OPENSSL_strdup
Jiasheng Jiang [Thu, 10 Feb 2022 03:21:47 +0000 (11:21 +0800)]
openssl rehash: add check for OPENSSL_strdup

As the potential failure of the memory allocation,
it should be better to check the return value of
OPENSSL_strdup() and return error if fails.
Also, we need to restore the 'ep' to be NULL if fails.

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17676)

2 years agoImplement a new flag for running s_client in a non-interactive mode
Rami Khaldi [Tue, 23 Nov 2021 22:27:35 +0000 (23:27 +0100)]
Implement a new flag for running s_client in a non-interactive mode

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17097)

2 years agoUse C locale in Bash scripts.
Daniel [Wed, 9 Feb 2022 15:23:46 +0000 (16:23 +0100)]
Use C locale in Bash scripts.

Fixes openssl#17228.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17674)

2 years agoCleanup record length checks for KTLS
Bernd Edlinger [Fri, 14 Jan 2022 09:01:29 +0000 (10:01 +0100)]
Cleanup record length checks for KTLS

In some corner cases the check for packets
which exceed the allowed record length was missing
when KTLS is initially enabled, when some
unprocessed packets are still pending.

Add at least some tests for KTLS, since we have
currently not very much test coverage for KTLS.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17504)

2 years agoAdd test of FIPS provider from the master branch with 3.0 build
Tomas Mraz [Wed, 9 Feb 2022 11:03:16 +0000 (12:03 +0100)]
Add test of FIPS provider from the master branch with 3.0 build

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17671)

2 years agoevp_test: Skip testcase if r parameter is unsupported
Tomas Mraz [Wed, 9 Feb 2022 10:23:01 +0000 (11:23 +0100)]
evp_test: Skip testcase if r parameter is unsupported

The r parameter of the KBKDF is unsupported by 3.0 FIPS module.

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17671)

2 years agoAdd test of FIPS provider from the 3.0 branch with master build
Tomas Mraz [Tue, 8 Feb 2022 14:42:31 +0000 (15:42 +0100)]
Add test of FIPS provider from the 3.0 branch with master build

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17671)

2 years agoChange condition to avoid spurious compiler complaints.
Pauli [Wed, 9 Feb 2022 00:17:57 +0000 (11:17 +1100)]
Change condition to avoid spurious compiler complaints.

X509_TRUST_get0() is checking < 0, the code here was checking == -1.  Both are
equivalent in this situation but gcc-12 has conniptions about a subsequent
possible NULL dereference (which isn't possible).

Fixes #17665

Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17668)

2 years agoAdded checking for buflen overflow due to MAX_MISALIGNMENT.
Kevin K Biju [Sat, 5 Feb 2022 12:39:45 +0000 (18:09 +0530)]
Added checking for buflen overflow due to MAX_MISALIGNMENT.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17646)

2 years agobn_lib.c: Change Endianess check to as a binary condition.
Kelvin Lee [Sat, 22 Jan 2022 00:22:31 +0000 (11:22 +1100)]
bn_lib.c: Change Endianess check to as a binary condition.

This prevents VS2022 from mis-identify an uninitialized local pointer
variable.

CLA: trivial

Reviewed-by: Ben Kaduk <kaduk@mit.edu>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17567)

2 years agoAES-GCM enabled with AVX512 vAES and vPCLMULQDQ.
Andrey Matyukov [Wed, 9 Jun 2021 21:38:40 +0000 (14:38 -0700)]
AES-GCM enabled with AVX512 vAES and vPCLMULQDQ.

Vectorized 'stitched' encrypt + ghash implementation of AES-GCM enabled
with AVX512 vAES and vPCLMULQDQ instructions (available starting Intel's
IceLake micro-architecture).

The performance details for representative IceLake Server and Client
platforms are shown below

Performance data:
OpenSSL Speed KBs/Sec
Intel(R) Xeon(R) Platinum 8380 CPU @ 2.30GHz (1Core/1Thread)
Payload in Bytes       16          64        256         1024        8192      16384
AES-128-GCM
  Baseline      478708.27   1118296.96  2428092.52  3518199.4   4172355.99  4235762.07
  Patched       534613.95   2009345.55  3775588.15  5059517.64  8476794.88  8941541.79
  Speedup            1.12         1.80        1.55        1.44        2.03        2.11

AES-256-GCM
  Baseline      399237.27   961699.9    2136377.65  2979889.15  3554823.37  3617757.5
  Patched       475948.13   1720128.51  3462407.12  4696832.2   7532013.16  7924953.91
  Speedup            1.19        1.79         1.62        1.58        2.12        2.19
Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz (1Core/1Thread)
Payload in Bytes       16          64        256         1024        8192      16384
AES-128-GCM
  Baseline      259128.54   570756.43   1362554.16  1990654.57  2359128.88  2401671.58
  Patched       292139.47   1079320.95  2001974.63  2829007.46  4510318.59  4705314.41
  Speedup            1.13        1.89         1.47        1.42        1.91        1.96
AES-256-GCM
  Baseline      236000.34   550506.76   1234638.08  1716734.57  2011255.6   2028099.99
  Patched       247256.32   919731.34   1773270.43  2553239.55  3953115.14  4111227.29
  Speedup            1.05        1.67         1.44        1.49        1.97        2.03

Reviewed-by: TJ O'Dwyer, Marcel Cornu, Pablo de Lara
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17239)

2 years agoFix outdated comments
Weiguo Li [Wed, 9 Feb 2022 08:12:30 +0000 (16:12 +0800)]
Fix outdated comments

Update the comment "../md32_common.h" to "crypto/md32_common.h".

CLA: trivial

Signed-off-by: Weiguo Li <liwg06@foxmail.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/17670)

2 years agoFix small typo in EVP_KEYEXCH-ECDH.html doc example
EasySec [Mon, 7 Feb 2022 22:16:39 +0000 (23:16 +0100)]
Fix small typo in EVP_KEYEXCH-ECDH.html doc example

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17657)

2 years agoaarch64: fix branch target indications in arm64cpuid.pl and keccak1600
Tom Cosgrove [Mon, 7 Feb 2022 14:44:56 +0000 (14:44 +0000)]
aarch64: fix branch target indications in arm64cpuid.pl and keccak1600

Add missing AARCH64_VALID_CALL_TARGET to armv8_rng_probe(). Also add
these to the functions defined by gen_random(), and note that this Perl
sub prints the assembler out directly, not going via the $code xlate
mechanism (and therefore coming before the include of arm_arch.h). So
fix this too.

In KeccakF1600_int, AARCH64_SIGN_LINK_REGISTER functions as
AARCH64_VALID_CALL_TARGET on BTI-only builds, so it needs to come before
the 'adr' line.

Change-Id: If241efe71591c88253a3e36647ced00300c3c1a3

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17653)

2 years agoAdd the check after calling OPENSSL_strdup
Jiasheng Jiang [Sat, 5 Feb 2022 11:31:11 +0000 (19:31 +0800)]
Add the check after calling OPENSSL_strdup

Since the potential failure of the memory allocation, the
OPENSSL_strdup() could return NULL pointer.
Therefore, it should be better to check it in order to guarantee the
success of the configuration, same as the check for
SSL_CTX_set_srp_username().

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17643)

2 years agoFix an enginetest failure when compiled with no-deprecated --api=1.1.1
Matt Caswell [Mon, 7 Feb 2022 10:32:08 +0000 (10:32 +0000)]
Fix an enginetest failure when compiled with no-deprecated --api=1.1.1

Fixes #17649

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17652)

2 years agoSend auxiliary messages to bio_err.
Daniel [Sun, 6 Feb 2022 14:01:14 +0000 (15:01 +0100)]
Send auxiliary messages to bio_err.

Fixes openssl#17613.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17650)

2 years agorsa: add check after calling BN_BLINDING_lock
Jiasheng Jiang [Sat, 5 Feb 2022 10:00:51 +0000 (18:00 +0800)]
rsa: add check after calling BN_BLINDING_lock

As the potential failure of getting lock, we need to check the return
value of the BN_BLINDING_lock() in order to avoid the dirty data.

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17642)

2 years agoCheck for presence of 1.1.x openssl runtime
Bernd Edlinger [Sun, 16 Jan 2022 16:59:17 +0000 (17:59 +0100)]
Check for presence of 1.1.x openssl runtime

if the newly loaded engine contains the symbol
EVP_PKEY_base_id, we know it is linked to 1.1.x openssl.
Abort loading this engine, as it will definitely crash.

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17112)

2 years agoPrevent crash with engine using different openssl runtime
Bernd Edlinger [Mon, 22 Nov 2021 20:50:04 +0000 (21:50 +0100)]
Prevent crash with engine using different openssl runtime

This problem happens usually because an application
links libcrypto and/or libssl statically which
installs an atexit handler, but later an engine using
a shared instance of libcrypto is installed.
The problem is in simple words that both instances
of libcrypto have an atexit handler installed,
but both are unable to coordinate with each other,
which causes a crash, typically a use-after-free
in the engine's destroy function.

Work around that by preventing the engine's
libcrypto to install the atexit handler.
This may result in a small memory leak, but that
memory is still reachable.

Fixes #15898

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17112)

2 years agoAdd testcases for EVP_PKEY_set1_encoded_public_key()
Tomas Mraz [Thu, 3 Feb 2022 15:30:21 +0000 (16:30 +0100)]
Add testcases for EVP_PKEY_set1_encoded_public_key()

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17630)

2 years agoReplace size check with more meaningful pubkey check
Tomas Mraz [Wed, 2 Feb 2022 16:47:26 +0000 (17:47 +0100)]
Replace size check with more meaningful pubkey check

It does not make sense to check the size because this
function can be used in other contexts than in TLS-1.3 and
the value might not be padded to the size of p.

However it makes sense to do the partial pubkey check because
there is no valid reason having the pubkey value outside the
1 < pubkey < p-1 bounds.

Fixes #15465

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17630)

2 years agodoc: Add hint to use EVP_PKEY_get_bn_param to retrieve big integers
Tomas Mraz [Wed, 5 Jan 2022 10:18:27 +0000 (11:18 +0100)]
doc: Add hint to use EVP_PKEY_get_bn_param to retrieve big integers

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17423)

2 years agoFix SIZE_MAX not defined on z/OS etc
Ankit Das [Wed, 2 Feb 2022 18:08:41 +0000 (23:38 +0530)]
Fix SIZE_MAX not defined on z/OS etc

Fixes openssl#17629 by including internal/numbers.h which defines SIZE_MAX

CLA: trivial

Fixes #17629

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17632)

2 years agoCorrect return type for BIO_ptr_ctrl
Thomas1664 [Thu, 20 Jan 2022 09:02:59 +0000 (10:02 +0100)]
Correct return type for BIO_ptr_ctrl

Fixes #17549
CLA: trivial

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17636)

2 years agoFixed counter overflow
Danny Tsen [Fri, 28 Jan 2022 00:49:59 +0000 (18:49 -0600)]
Fixed counter overflow

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17607)

2 years agoevp_test: Add the missing check after calling OPENSSL_strdup and sk_OPENSSL_STRING_ne...
Jiasheng Jiang [Wed, 2 Feb 2022 11:45:59 +0000 (19:45 +0800)]
evp_test: Add the missing check after calling OPENSSL_strdup and sk_OPENSSL_STRING_new_null

Since the memory allocation may fail, the 'mac_name' and 'controls'
could be NULL.
And the 'mac_name' will be printed in mac_test_run_mac() without check.
Also the result of 'params_n +
sk_OPENSSL_STRING_num(expected->controls)' in
mac_test_run_mac() will be 'params_n - 1' if allocation fails , which
does not make sense.
Therefore, it should be better to check them in order to guarantee the
complete success of initiation.
If fails, we also need to free the 'mdat' to avoid the memory leak.

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17628)

2 years agoFix typos
Dimitris Apostolou [Thu, 3 Feb 2022 16:51:26 +0000 (18:51 +0200)]
Fix typos

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17634)

2 years agoevp enc: cache cipher key length
Pauli [Thu, 27 Jan 2022 02:33:36 +0000 (13:33 +1100)]
evp enc: cache cipher key length

Instead of doing a heavy params based query every time a context is
asked for its key length, this value is cached in the context and only
queried if it could have been modified.

Fixes #17064

Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17543)

2 years agoevp enc: cache cipher IV length
Pauli [Wed, 26 Jan 2022 04:04:51 +0000 (15:04 +1100)]
evp enc: cache cipher IV length

Instead of doing a heavy params based query every time a context is asked for
its IV length, this value is cached in the context and only queried if it could
have been modified.

Fixes #17064

Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17543)

2 years agoaes: avoid accessing key length field directly
Pauli [Thu, 27 Jan 2022 01:51:13 +0000 (12:51 +1100)]
aes: avoid accessing key length field directly

Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17543)

2 years agoMove e_os.h to include/internal
Richard Levitte [Fri, 4 Feb 2022 14:13:01 +0000 (15:13 +0100)]
Move e_os.h to include/internal

Including e_os.h with a path from a header file doesn't work well on
certain exotic platform.  It simply fails to build.

Since we don't seem to be able to stop ourselves, the better move is
to move e_os.h to an include directory that's part of the inclusion
path given to the compiler.

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17641)

2 years agoAdd support for Chacha20-Poly1305 to kernel TLS on FreeBSD.
John Baldwin [Wed, 23 Dec 2020 22:09:51 +0000 (14:09 -0800)]
Add support for Chacha20-Poly1305 to kernel TLS on FreeBSD.

FreeBSD's kernel TLS supports Chacha20 for both TLS 1.2 and TLS 1.3.

Reviewed-by: Ben Kaduk <kaduk@mit.edu>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13752)

2 years agoAdd missing CRYPTO_THREAD_cleanup_local of default_context_thread_local
Harry Sintonen [Tue, 1 Feb 2022 21:48:19 +0000 (23:48 +0200)]
Add missing CRYPTO_THREAD_cleanup_local of default_context_thread_local

CLA: trivial

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17622)

2 years agoFix builds with DJGPP
Juan Manuel Guerrero [Tue, 1 Feb 2022 23:41:02 +0000 (00:41 +0100)]
Fix builds with DJGPP

CLA: trivial

To get the master branch compiled with DJGPP some minor
adjustments are required. They will have no impact on any other ports.
The DJGPP port uses the Watt-32 library to provide the required network
functionality and some of its headers need to be included.

Neither DJGPP nor the Watt-32 library provide in_addr_t thus it must be
provided as it is done for OPENSSL_SYS_WINDOWS in crypto/bio/b_addr.c.

In the DJGPP section of include/internal/sockets.h the following Watt-32
headers must be added:

  -  arpa/inet.h: to provide declaration of inet_ntoa required in crypto/bio/b_addr.c
  -  netinet/tcp.h: to provide defintion of TCP_NODELAY required in crypto/bio/b_sock2.c

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17623)

2 years agoopenssl-dgst.pod.in: Fix documentation of -list option
EasySec [Wed, 2 Feb 2022 00:42:27 +0000 (01:42 +0100)]
openssl-dgst.pod.in: Fix documentation of -list option

Mention openssl list -digest-algorithms, NOT -digest-commands.

Move option -list just after the related option -digest.

Fix HTML formatting of section 'Examples' by adding missing
newlines and add 2 examples variant to clarify syntax of the
command.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17626)

2 years agoFix copyrights
Todd Short [Thu, 27 Jan 2022 19:18:28 +0000 (14:18 -0500)]
Fix copyrights

Add copyright to files that were missing it.
Update license from OpenSSL to Apache as needed.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17606)

2 years agoUse opt_int_arg() to parse integers in apps/speed.c
Kevin K Biju [Tue, 1 Feb 2022 05:34:35 +0000 (11:04 +0530)]
Use opt_int_arg() to parse integers in apps/speed.c

We use opt_int_arg() to prevent malformed processing of
hexadecimal input to some command line options.

Updated help to mention the change.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17585)

2 years agoFix EVP todata and fromdata when used with selection of EVP_PKEY_PUBLIC_KEY.
slontis [Sun, 5 Dec 2021 23:27:12 +0000 (09:27 +1000)]
Fix EVP todata and fromdata when used with selection of EVP_PKEY_PUBLIC_KEY.

The private key for rsa, dsa, dh and ecx was being included when the
selector was just the public key. (ec was working correctly).
This matches the documented behaviour.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17200)

2 years agoadd SSL_get0_iana_groups() & SSL_client_hello_get_extension_order()
Phus Lu [Mon, 25 Oct 2021 10:47:00 +0000 (18:47 +0800)]
add SSL_get0_iana_groups() & SSL_client_hello_get_extension_order()

The function/macro allow user get groups/extensions without memory allcations.
So we could calculate the ssl fignerprint(ja3) in low cost.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/16910)