]> git.ipfire.org Git - thirdparty/openssl.git/log
thirdparty/openssl.git
5 months agox509_acert: Add, remove and get attribute certificate attributes
Damian Hobson-Garcia [Fri, 30 Jun 2023 21:12:38 +0000 (17:12 -0400)] 
x509_acert: Add, remove and get attribute certificate attributes

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

5 months agoAttribute certificate printing functions
Damian Hobson-Garcia [Fri, 30 Jun 2023 21:44:29 +0000 (17:44 -0400)] 
Attribute certificate printing functions

Add functions to print an attribute certificate.  Several
attribute value types defined by the RFC 5755 specification
are multi-field values (i.e ASN1_SEQUENCE rather than an ASN1_STRING
or similar format).  Currently those values are printed using
`ASN1_item_print`.  A more user-friendly output mechanism (maybe
similar to the i2r_ functions used for X509 extensions) could be
added in future.

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

5 months agoAttribute certificate getter and setter API
Damian Hobson-Garcia [Fri, 18 Jun 2021 14:37:18 +0000 (23:37 +0900)] 
Attribute certificate getter and setter API

Only fields that are allowed by RFC 5755 are
accessible through this API.  Fields that are only supported
in version 1 attribute certificates (e.g. the AttCertIssuer
v1Form fields) are not implemented.

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

5 months agoAdd RFC 5755 attribute certificate support
Damian Hobson-Garcia [Thu, 13 May 2021 02:53:59 +0000 (11:53 +0900)] 
Add RFC 5755 attribute certificate support

Add support for attribute certificates (v2) as described
in RFC 5755 profile.

Attribute certificates provide a mechanism to manage authorization
information separately from the identity information provided by
public key certificates.

This initial patch adds the ASN.1 definitions
and I/O API.  Accessor functions for the certificate fields
will be added in subsequent patches.

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

5 months agoRemove all references to FLOSS for NonStop Builds.
Randall S. Becker [Fri, 19 Apr 2024 22:15:10 +0000 (22:15 +0000)] 
Remove all references to FLOSS for NonStop Builds.

FLOSS is no longer a dependency for NonStop as of the deprecation of the SPT
thread model builds.

Fixes: #24214
Signed-off-by: Randall S. Becker <randall.becker@nexbridge.ca>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24217)

5 months agoupdating fuzz-corpora submodule
Neil Horman [Mon, 18 Mar 2024 18:32:33 +0000 (14:32 -0400)] 
updating fuzz-corpora submodule

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

5 months agoadding a multithreaded hashtable test
Neil Horman [Fri, 1 Mar 2024 21:28:53 +0000 (16:28 -0500)] 
adding a multithreaded hashtable test

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

5 months agoAdding hashtable fuzzer
Neil Horman [Tue, 20 Feb 2024 11:12:59 +0000 (06:12 -0500)] 
Adding hashtable fuzzer

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

5 months agoIntroduce new internal hashtable implementation
Neil Horman [Sun, 28 Jan 2024 15:50:38 +0000 (10:50 -0500)] 
Introduce new internal hashtable implementation

Create a new hashtable that is more efficient than the existing LHASH_OF
implementation.  the new ossl_ht api offers several new features that
improve performance opportunistically

* A more generalized hash function.  Currently using fnv1a, provides a
  more general hash function, but can still be overridden where needed

* Improved locking and reference counting.  This hash table is
  internally locked with an RCU lock, and optionally reference counts
  elements, allowing for users to not have to create and manage their
  own read/write locks

* Lockless operation.  The hash table can be configured to operate
  locklessly on the read side, improving performance, at the sacrifice
  of the ability to grow the hash table or delete elements from it

* A filter function allowing for the retrieval of several elements at a
  time matching a given criteria without having to hold a lock
  permanently

* a doall_until iterator variant, that allows callers which need to
  iterate over the entire hash table until a given condition is met (as
  defined by the return value of the iterator callback).  This allows
  for callers attempting to do expensive cache searches for a small
  number of elements to terminate the iteration early, saving cpu cycles

* Dynamic type safety.  The hash table provides operations to set and
  get data of a specific type without having to define a type at the
  instatiation point

* Multiple data type storage.  The hash table can store multiple data
  types allowing for more flexible usage

* Ubsan safety.  Because the API deals with concrete single types
  (HT_KEY and HT_VALUE), leaving specific type casting to the call
  recipient with dynamic type validation, this implementation is safe
  from the ubsan undefined behavior warnings that require additional
  thunking on callbacks.

Testing of this new hashtable with an equivalent hash function, I can
observe approximately a 6% performance improvement in the lhash_test

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

5 months agoAdd CRYPTO_atomic_store api
Neil Horman [Fri, 8 Mar 2024 16:58:07 +0000 (11:58 -0500)] 
Add CRYPTO_atomic_store api

Generally we can get away with just using CRYPTO_atomic_load to do
stores by reversing the source and target variables, but doing so
creates a problem for the thread sanitizer as CRYPTO_atomic_load hard
codes an __ATOMIC_ACQUIRE constraint, which confuses tsan into thinking
that loads and stores aren't properly ordered, leading to RAW/WAR
hazzards getting reported.  Instead create a CRYPTO_atomic_store api
that is identical to the load variant, save for the fact that the value
is a unit64_t rather than a pointer that gets stored using an
__ATOMIC_RELEASE constraint, satisfying tsan.

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

5 months agoFix list appending in win ossl_rcu_call
Neil Horman [Thu, 29 Feb 2024 14:49:37 +0000 (09:49 -0500)] 
Fix list appending in win ossl_rcu_call

The ossl_rcu_call function for windows creates a linked list loop.  fix
it to work like the pthread version properly

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

5 months agoMake thread sanitizer cope with rcu locks
Neil Horman [Thu, 29 Feb 2024 22:22:06 +0000 (17:22 -0500)] 
Make thread sanitizer cope with rcu locks

This is unfortunate, but seems necessecary

tsan in gcc/clang tracks data races by recording memory references made
while various locks are held.  If it finds that a given address is
read/written while under lock (or under no locks without the use of
atomics), it issues a warning

this creates a specific problem for rcu, because on the write side of a
critical section, we write data under the protection of a lock, but by
definition the read side has no lock, and so rcu warns us about it,
which is really a false positive, because we know that, even if a
pointer changes its value, the data it points to will be valid.

The best way to fix it, short of implementing tsan hooks for rcu locks
in any thread sanitizer in the field, is to 'fake it'.  If thread
sanitization is activated, then in ossl_rcu_write_[lock|unlock] we add
annotations to make the sanitizer think that, after the write lock is
taken, that we immediately unlock it, and lock it right before we unlock
it again.  In this way tsan thinks there are no locks held while
referencing protected data on the read or write side.

we still need to use atomics to ensure that tsan recognizes that we are
doing atomic accesses safely, but thats ok, and we still get warnings if
we don't do that properly

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

5 months agoCoverity found the following issues:
Neil Horman [Fri, 2 Feb 2024 13:20:50 +0000 (08:20 -0500)] 
Coverity found the following issues:

1591471
1591474
1591476

which pertain to memory leaks in the conf_mod code

If an error is encountered after the module STACK_OF is duplicated or
created in the new_modules variable, we need to remember to free it in
the error path

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

5 months agoFix potential divide by zero error
Neil Horman [Fri, 2 Feb 2024 13:10:32 +0000 (08:10 -0500)] 
Fix potential divide by zero error

Coverity caught the following issues:
1591477
1591475
1591473
1591470

all of which are simmilar, in that they catch potential divide by zero
in double values.  It can't actually happen since the the threads which
increment these counters don't exit until they reach non-zero values,
but its easy to add the checks, so lets do that to ensure that we don't
change something in the future that causes it.

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

5 months agoInvoke tear_down when exiting test_encode_tls_sct() prematurely
shridhar kalavagunta [Sun, 21 Apr 2024 23:48:33 +0000 (18:48 -0500)] 
Invoke tear_down when exiting test_encode_tls_sct() prematurely

Fixes #24121

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24222)

5 months agocrypto/threads_pthread.c: Fix typos found by codespell
Logan Upchurch [Fri, 19 Apr 2024 13:38:31 +0000 (09:38 -0400)] 
crypto/threads_pthread.c: Fix typos found by codespell

CLA: trivial

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24206)

5 months agoBe more explicit about RSAES-PKCS#1v1.5 error handling
Hubert Kario [Tue, 16 Apr 2024 12:57:21 +0000 (14:57 +0200)] 
Be more explicit about RSAES-PKCS#1v1.5 error handling

And add a note how to perform side-channel free error stack handling.

Signed-off-by: Hubert Kario <hkario@redhat.com>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24159)

5 months agoUse empty renegotiate extension instead of SCSV for TLS > 1.0
Tim Perry [Tue, 16 Apr 2024 13:40:21 +0000 (15:40 +0200)] 
Use empty renegotiate extension instead of SCSV for TLS > 1.0

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

5 months agoFix missing NULL check in prov_config_test
Neil Horman [Fri, 19 Apr 2024 14:17:54 +0000 (10:17 -0400)] 
Fix missing NULL check in prov_config_test

coverity-1596500 caught a missing null check.  We should never hit it as
the test harness always sets the environment variable, but lets add the
check for safety

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24208)

5 months agofix sending error when no root CA cert update available
Rajeev Ranjan [Mon, 25 Mar 2024 13:00:58 +0000 (14:00 +0100)] 
fix sending error when no root CA cert update available

Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24169)

5 months agoFix migration guide mappings for i2o/o2i_ECPublicKey
slontis [Fri, 5 Apr 2024 04:32:23 +0000 (15:32 +1100)] 
Fix migration guide mappings for i2o/o2i_ECPublicKey

Fixes #23854

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24041)

5 months agoMake rcu_thread_key context-aware
Neil Horman [Mon, 15 Apr 2024 20:56:29 +0000 (16:56 -0400)] 
Make rcu_thread_key context-aware

Currently, rcu has a global bit of data, the CRYPTO_THREAD_LOCAL object
to store per thread data.  This works in some cases, but fails in FIPS,
becuase it contains its own copy of the global key.

So
1) Make the rcu_thr_key a per-context variable, and force
   ossl_rcu_lock_new to be context aware

2) Store a pointer to the context in the lock object

3) Use the context to get the global thread key on read/write lock

4) Use ossl_thread_start_init to properly register a cleanup on thread
   exit

5) Fix up missed calls to OSSL_thread_stop() in our tests

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

5 months agoOSSL_STORE: Add reference docs for the built-in Windows store implementation
Richard Levitte [Wed, 17 Apr 2024 09:31:31 +0000 (11:31 +0200)] 
OSSL_STORE: Add reference docs for the built-in Windows store implementation

Fixes openssl/project#422

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

5 months agoopenssl fipsinstall: fix cosmetic wart
Enji Cooper [Thu, 18 Apr 2024 04:10:15 +0000 (21:10 -0700)] 
openssl fipsinstall: fix cosmetic wart

This change makes the message on failure consistent with the message on
success by trimming a single space in the error message.

CLA: trivial
Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/24180)

5 months agoAdjust tests that were depending on X25519 and X448 in fips
Tomas Mraz [Wed, 17 Apr 2024 16:05:35 +0000 (18:05 +0200)] 
Adjust tests that were depending on X25519 and X448 in fips

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/24099)

5 months agoExclude X25519 and X448 from capabilities advertised by FIPS provider
Dimitri John Ledkov [Wed, 17 Apr 2024 07:04:59 +0000 (09:04 +0200)] 
Exclude X25519 and X448 from capabilities advertised by FIPS provider

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24099)

5 months agoMake X25519 and X448 FIPS unapproved
Tomas Mraz [Thu, 11 Apr 2024 06:57:51 +0000 (08:57 +0200)] 
Make X25519 and X448 FIPS unapproved

Partially fixes: #22105

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/24099)

5 months agoFix up path generation to use OPENSSL_MODULES
Neil Horman [Fri, 5 Apr 2024 13:06:10 +0000 (09:06 -0400)] 
Fix up path generation to use OPENSSL_MODULES

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

5 months agoUpdate modulepath test for provider config to skip if not present
Neil Horman [Thu, 4 Apr 2024 19:39:17 +0000 (15:39 -0400)] 
Update modulepath test for provider config to skip if not present

If the p_test.so library isn't present, don't run the test

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

5 months agoAdd test for OSSL_PROVIDER_load with module path set
Neil Horman [Wed, 3 Apr 2024 19:18:33 +0000 (15:18 -0400)] 
Add test for OSSL_PROVIDER_load with module path set

Ensure that, with the modulepath setting set in a config field, that we
are able to load a provider from the path relative to OPENSSL_MODULES

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

5 months agoset module path from template
Neil Horman [Tue, 2 Apr 2024 19:02:51 +0000 (15:02 -0400)] 
set module path from template

Modules that aren't activated at conf load time don't seem to set the
module path from the template leading to load failures.  Make sure to
set that

Fixes #24020

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

5 months agoQUIC TXP: Fix reserve calculations for PING frames
Hugo Landau [Fri, 12 Apr 2024 06:58:24 +0000 (07:58 +0100)] 
QUIC TXP: Fix reserve calculations for PING frames

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

5 months agoFix fragile explicit cert date tests.
Viktor Dukhovni [Mon, 15 Apr 2024 02:04:21 +0000 (22:04 -0400)] 
Fix fragile explicit cert date tests.

The tests used localtime to format "today's" date, but then extracted a
GMT date from the cert.  The comparison breaks when run late in the
evening west of UTC, or early in the AM hours east of UTC.

Also took care of case when test runs at stroke of midnight, by
accepting either the "today" before the cert creation, or the
"today" after, should they be different.

Fixes fragile tests in #21716

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

5 months agoUpdate provider-compatibility.yml
rlvkleinhenz [Sun, 14 Apr 2024 19:42:13 +0000 (15:42 -0400)] 
Update provider-compatibility.yml

Documentation Change: Line 34

Changed 'utl' to 'url' to correctly reflect the variables used in the releases in this file.

CLA: trivial

Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24164)

5 months agoUpdated list formatting, added hyperlinks, modernized syntax
Dwiczz [Tue, 16 Apr 2024 17:12:51 +0000 (13:12 -0400)] 
Updated list formatting, added hyperlinks, modernized syntax

Updated list formatting to allow for easier readability, Added/adjusted hyperlinks, modernized command substitution syntax

CLA: trivial

Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/24165)

5 months ago.ctags.d is previous, include it in our tarballs
Richard Levitte [Tue, 16 Apr 2024 09:48:52 +0000 (11:48 +0200)] 
.ctags.d is previous, include it in our tarballs

This is a simple change of .gitattributes, so our tarballs continue to
be a reproducible output of a util/mktar.sh (i.e. git archive with no
other funny business).

Fixes #24090

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

5 months agoUse scalar ALU and vector ALU together for chacha20 stream cipher
Jerry Shih [Sat, 9 Mar 2024 07:03:56 +0000 (15:03 +0800)] 
Use scalar ALU and vector ALU together for chacha20 stream cipher

Fixes #24070

Use scalar ALU for 1 chacha block with rvv ALU simultaneously.
The tail elements(non-multiple of block length) will be handled by
the scalar logic.

Use rvv path if the input length > chacha_block_size.

And we have about 1.2x improvement comparing with the original code.

Reviewed-by: Hongren Zheng <i@zenithal.me>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24097)

5 months agopoly1305.c: fix typo on POLY1305_BLOCK_SIZE
Yangyu Chen [Sun, 14 Apr 2024 15:33:58 +0000 (23:33 +0800)] 
poly1305.c: fix typo on POLY1305_BLOCK_SIZE

no code change

Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24136)

5 months agoUnable to run asm code on OpenBSD (amd64)
Theo Buehler [Fri, 1 Mar 2024 07:07:42 +0000 (08:07 +0100)] 
Unable to run asm code on OpenBSD (amd64)

In order to get asm code running on OpenBSD we must place
all constants into .rodata sections.

davidben@ also pointed out we need to adjust `x86_64-xlate.pl` perlasm
script to adjust read-olny sections for various flavors (OSes). Those
changes were cherry-picked from boringssl.

closes #23312

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

5 months agoextend x86_64-xlate.pl perlasm so it can handle .rodata sections properly
Alexandr Nedvedicky [Thu, 11 Apr 2024 07:06:47 +0000 (09:06 +0200)] 
extend x86_64-xlate.pl perlasm so it can handle .rodata sections properly

For nasm/masm assembler flavors the xlate script must make sure the code
won't land in .rodata section along the data.

For masm we also need to introduce an .align option which can be passed
along section header. It's hint for masm to align rodata/rdata section
properly.

Also macos-x flavor requires small tweak to emit proper section header
for its assembler style.

Changes for masm flavor are based on SEGMENT description [1] in
MASM reference manual.

Changes for nasm flavor are based on nasm 2.14 manual chapter 7 [2].

Details behind macos-x changes can be found in 'Overview of the Mach-O
Executable Format' [3]

[1] https://learn.microsoft.com/en-us/cpp/assembler/masm/segment?view=msvc-170

[2] https://nasm.us/xdoc/2.14rc0/html/nasmdoc7.html

[3] https://developer.apple.com/library/archive/documentation/Performance/Conceptual/CodeFootprint/Articles/MachOOverview.html

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

5 months agofuzz/decoder.c: Limit the EVP_PKEY_param_check on DHX keys as well
Tomas Mraz [Fri, 12 Apr 2024 13:37:58 +0000 (15:37 +0200)] 
fuzz/decoder.c: Limit the EVP_PKEY_param_check on DHX keys as well

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

5 months agoDefine KU_ constants via corresponding X509v3_KU_
Viktor Dukhovni [Sun, 14 Apr 2024 23:43:30 +0000 (19:43 -0400)] 
Define KU_ constants via corresponding X509v3_KU_

Also wrap X509v3_KU_UNDEF in `#ifndef OPENSSL_NO_DEPRECATED_3_4`.

Fixes #22955

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

5 months agoHandle empty param in EVP_PKEY_CTX_add1_hkdf_info
trinity-1686a [Mon, 15 Apr 2024 09:13:14 +0000 (11:13 +0200)] 
Handle empty param in EVP_PKEY_CTX_add1_hkdf_info

Fixes #24130
The regression was introduced in PR #23456.

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

5 months agoOpenSSL 3.2.0, QUIC, macOS, error 56 on connected UDP socket
Alexandr Nedvedicky [Fri, 26 Jan 2024 07:05:47 +0000 (08:05 +0100)] 
OpenSSL 3.2.0, QUIC, macOS, error 56 on connected UDP socket

current `translate_msg()` function attempts to set `->msg_name`
(and `->msg_namelen`) with `BIO`'s peer name (connection destination)
regardless if underlying socket is connected or not. Such implementation
uncovers differences in socket implementation between various OSes.

As we have learned hard way `sendmsg()` and `sendmmsg()` on `OpenBSD`
and (`MacOS` too) fail to send messages with `->msg_name` being
set on connected socket. In such case the caller receives
`EISCON` errro.

I think `translate_msg()` caller should provide a hint to indicate
whether we deal with connected (or un-connected) socket. For
connected sockets the peer's name should not be set/filled
by `translate_msg()`. On the other hand if socket is un-connected,
then `translate_msg()` must populate `->msg_name` and `->msg_namelen`
members.

The caller can use `getpeername(2)` to see if socket is
connected. If `getpeername()` succeeds then we must be dealing
with connected socket and `translate_msg()` must not set
`->msg_name` and `->msg_namelen` members. If `getpeername(2)`
fails, then `translate_msg()` must provide peer's name (destination
address) in `->msg_name` and set `->msg_namelen` accordingly.

The propposed fix introduces `is_connected()` function,
which applies `getpeername()` to socket bound to `BIO` instance.
The `dgram_sendmmsg()` uses `is_connected()` as a hint
for `translate_msg()` function, so msghdr gets initialized
with respect to socket state.

The change also modifies existing `test/quic_client_test.c`
so it also covers the case of connected socket. To keep
things simple we can introduce optional argument `connect_first`
to `./quic_client_test` function. Without `connect_first`
the test run as usual. With `connect_first` the test creates
and connects socket first. Then it passes such socket to
`BIO` sub-system to perform `QUIC` connect test as usual.

Fixes #23251

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

5 months agodoc/fingerprints.txt: Add the future OpenSSL release key
Richard Levitte [Mon, 8 Apr 2024 13:14:40 +0000 (15:14 +0200)] 
doc/fingerprints.txt: Add the future OpenSSL release key

This will be used for future releases

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

5 months agocrypto/threads_pthread.c: refactor all atomics fallbacks for type safety
Richard Levitte [Fri, 12 Apr 2024 08:03:21 +0000 (10:03 +0200)] 
crypto/threads_pthread.c: refactor all atomics fallbacks for type safety

The atomics fallbacks were using 'void *' as a generic transport for all
possible scalar and pointer types, with the hypothesis that a pointer is
as large as the largest possible scalar type that we would use.

Then enters the use of uint64_t, which is larger than a pointer on any
32-bit system (or any system that has 32-bit pointer configurations).

We could of course choose a larger type as a generic transport.  However,
that only pushes the problem forward in time...  and it's still a hack.
It's therefore safer to reimplement the fallbacks per type that atomics
are used for, and deal with missing per type fallbacks when the need
arrises in the future.

For test build purposes, the macro USE_ATOMIC_FALLBACKS is introduced.
If OpenSSL is configured with '-DUSE_ATOMIC_FALLBACKS', the fallbacks
will be used, unconditionally.

Fixes #24096

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

5 months agocrypto/threads_pthread.c: Cleanup misaligned preprocessor directives
Richard Levitte [Thu, 11 Apr 2024 15:10:38 +0000 (17:10 +0200)] 
crypto/threads_pthread.c: Cleanup misaligned preprocessor directives

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

5 months agoRemove repetitive words
Neil Horman [Thu, 11 Apr 2024 20:19:01 +0000 (16:19 -0400)] 
Remove repetitive words

Signed-off-by: fanqiaojun <fanqiaojun@yeah.net>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24128)

5 months agoAdding missing NULL pointer check
afshinpir [Wed, 28 Feb 2024 03:58:03 +0000 (16:58 +1300)] 
Adding missing NULL pointer check

CLA: trivial
In the provider store API, it is not necessary to provide both open and
attach method at the same time and providing at least one of them is
enough. Adding some null pointer checks to prevent exceptions in case
of not providing both methods at the same time.

Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23703)

5 months agolist_provider_info(): Fix leak on error
Tomas Mraz [Thu, 11 Apr 2024 15:49:53 +0000 (17:49 +0200)] 
list_provider_info(): Fix leak on error

Fixes #24110

Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/24117)

5 months agoAugment README.md in top level to indicate Makefile presence
Neil Horman [Thu, 11 Apr 2024 20:19:01 +0000 (16:19 -0400)] 
Augment README.md in top level to indicate Makefile presence

Note that they are available but only meant as a guide to self building,
and are not used expressly to build as part of the overall openssl build

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
(Merged from https://github.com/openssl/openssl/pull/24047)

5 months agodisable http3 demo on windows
Neil Horman [Thu, 11 Apr 2024 19:45:34 +0000 (15:45 -0400)] 
disable http3 demo on windows

The external nghttp3 library seems to have a linking issue on windows
(several missing symbols).  Disable that build in windows for now until
its fixed

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
(Merged from https://github.com/openssl/openssl/pull/24047)

5 months agomake addr_len the right sign in sslecho
Neil Horman [Sun, 7 Apr 2024 13:12:54 +0000 (09:12 -0400)] 
make addr_len the right sign in sslecho

cygwin caught a signedness difference in this pointer.

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
(Merged from https://github.com/openssl/openssl/pull/24047)

5 months agoReplace getline with fgets in sslecho demo
Neil Horman [Sun, 7 Apr 2024 12:42:51 +0000 (08:42 -0400)] 
Replace getline with fgets in sslecho demo

Windows doesn't support getline, so we need to use fgets here

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
(Merged from https://github.com/openssl/openssl/pull/24047)

5 months agodont include unistd.h on windows for sslecho
Neil Horman [Sat, 6 Apr 2024 22:28:57 +0000 (18:28 -0400)] 
dont include unistd.h on windows for sslecho

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
(Merged from https://github.com/openssl/openssl/pull/24047)

5 months agoDon't include unistd.h in sconnect for windows
Neil Horman [Sat, 6 Apr 2024 20:30:50 +0000 (16:30 -0400)] 
Don't include unistd.h in sconnect for windows

The platform doesn't support it

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
(Merged from https://github.com/openssl/openssl/pull/24047)

5 months agoFix signal handling in saccept for windows
Neil Horman [Sat, 6 Apr 2024 19:01:48 +0000 (15:01 -0400)] 
Fix signal handling in saccept for windows

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
(Merged from https://github.com/openssl/openssl/pull/24047)

5 months agoFix warnings found by clang in CI
Neil Horman [Sat, 6 Apr 2024 14:16:50 +0000 (10:16 -0400)] 
Fix warnings found by clang in CI

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
(Merged from https://github.com/openssl/openssl/pull/24047)

5 months agoEnable demos in select builds
Neil Horman [Sat, 6 Apr 2024 03:02:11 +0000 (23:02 -0400)] 
Enable demos in select builds

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
(Merged from https://github.com/openssl/openssl/pull/24047)

5 months agofix all the warnings in our demos and make them enableable
Neil Horman [Sat, 6 Apr 2024 02:20:54 +0000 (22:20 -0400)] 
fix all the warnings in our demos and make them enableable

Fix up the warnings in the demos and make them configurable with
enable-demos

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
(Merged from https://github.com/openssl/openssl/pull/24047)

5 months agoConvert demos to primary build system
Neil Horman [Fri, 5 Apr 2024 20:19:01 +0000 (16:19 -0400)] 
Convert demos to primary build system

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
(Merged from https://github.com/openssl/openssl/pull/24047)

5 months agoossl_provider_new(): Fix memory leak on error
Tomas Mraz [Thu, 11 Apr 2024 07:27:47 +0000 (09:27 +0200)] 
ossl_provider_new(): Fix memory leak on error

Fixes #24095

Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24100)

5 months agomake_addressPrefix(): Fix a memory leak in error case
Tomas Mraz [Thu, 11 Apr 2024 07:40:18 +0000 (09:40 +0200)] 
make_addressPrefix(): Fix a memory leak in error case

Fixes #24098

Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24102)

5 months agoFix duplicate mutex allocation in threads_win.c
Neil Horman [Wed, 10 Apr 2024 12:28:43 +0000 (08:28 -0400)] 
Fix duplicate mutex allocation in threads_win.c

Creating an rcu lock does a double allocation of the underlying mutex.
Not sure how asan didn't catch this, but we clearly have a duplicate
line here

Fixes #24085

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

5 months agoVMS: Move defining _XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED to config target
Richard Levitte [Wed, 10 Apr 2024 08:18:46 +0000 (10:18 +0200)] 
VMS: Move defining _XOPEN_SOURCE and  _XOPEN_SOURCE_EXTENDED to config target

For all other platforms that need these macros defined, that's how it's
done, so we have VMS follow suit.  That avoids a crash between in source
definitions and command line definitions on some other platforms.

Fixes #24075

Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24083)

(cherry picked from commit 7f04bb065d9d948d049ef1ef1bd4062cb7831392)

5 months agocrypto/provider_core.c: Allocate activatecnt_lock
Oleg Bulatov [Tue, 9 Apr 2024 22:17:35 +0000 (00:17 +0200)] 
crypto/provider_core.c: Allocate activatecnt_lock

CRYPTO_atomic_add has a lock as a parameter, which is often ignored, but in
some cases (for example, when BROKEN_CLANG_ATOMICS is defined) it is required.

There is no easy way to determine if the lock is needed or not. The current
logic looks like this:

    if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG) && !defined(OPENSSL_SYS_WINDOWS)
      if defined(__GNUC__) && defined(__ATOMIC_ACQ_REL) && !defined(BROKEN_CLANG_ATOMICS)
        - It works without the lock, but in general the need for the
          lock depends on __atomic_is_lock_free results
      elif defined(__sun) && (defined(__SunOS_5_10) || defined(__SunOS_5_11))
        - The lock is not needed (unless ret is NULL, which should never
          happen?)
      else
        - The lock is required
      endif
    else
      - The lock is not needed
    endif

Adding such conditions outside of crypto.h is error-prone, so it is better to
always allocate the lock, otherwise CRYPTO_atomic_add may silently fail.

Fixes #23376.

CLA: trivial
Fixes: fc570b2605 ("Avoid taking a write lock in ossl_provider_doall_activated()")
Signed-off-by: Oleg Bulatov <oleg@bulatov.me>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24081)

5 months agoChange approach to SSL_pending API
Hugo Landau [Fri, 29 Mar 2024 14:51:35 +0000 (14:51 +0000)] 
Change approach to SSL_pending API

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

(cherry picked from commit 5a13d35f243be66f6ad914aefe99fb708812dff1)

5 months agoQUIC APL: Revise SSL_pending and SSL_has_pending handling for s_client compat
Hugo Landau [Thu, 28 Mar 2024 09:00:13 +0000 (09:00 +0000)] 
QUIC APL: Revise SSL_pending and SSL_has_pending handling for s_client compat

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

(cherry picked from commit 7c33eb1e7fd3248ad29c172b5b4c0658a7be3adc)

5 months agoQUIC QSM: Add function to determine if data is waiting
Hugo Landau [Thu, 28 Mar 2024 08:58:50 +0000 (08:58 +0000)] 
QUIC QSM: Add function to determine if data is waiting

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

(cherry picked from commit 3c2bc702eb9287b84e8584ad427e72da0ab21ec1)

5 months agotest: fix 20-test_dgst.t to use hexkey
Dimitri John Ledkov [Tue, 9 Apr 2024 01:59:03 +0000 (02:59 +0100)] 
test: fix 20-test_dgst.t to use hexkey

Currently 20-test_dgst.t calls a quite bogus command:

    $ openssl dgst -sha256 -hmac -macopt hexkey:FFFF test/data.bin test/data.bin
    hexkey:FFFF: No such file or directory
    HMAC-SHA2-256(test/data.bin)= b6727b7bb251dfa65846e0a8223bdd57d244aa6d7e312cb906d8e21f2dee3a57
    HMAC-SHA2-256(test/data.bin)= b6727b7bb251dfa65846e0a8223bdd57d244aa6d7e312cb906d8e21f2dee3a57
    805B632D4A730000:error:80000002:system library:file_ctrl:No such file or directory:crypto/bio/bss_file.c:297:calling fopen(hexkey:FFF, r)
    805B632D4A730000:error:10080002:BIO routines:file_ctrl:system lib:crypto/bio/bss_file.c:300:

Does not check status code, discards stderr, and verifies the
checksums as per above. Note that the checksum is for the HMAC key
"-macopt", and `hexkey:FFFF` is attempted to be opened as a file.

See HMAC values for key `-macopt` and `hexkey:FFFF` using `openssl-mac`:

    $ openssl mac -digest SHA256 -macopt hexkey:$(printf '%s' '-macopt' | xxd -p -u) -in ./test/data.bin HMAC
    B6727B7BB251DFA65846E0A8223BDD57D244AA6D7E312CB906D8E21F2DEE3A57

    $ openssl mac -digest SHA256 -macopt hexkey:FFFF -in ./test/data.bin HMAC
    7C02D4A17D2560A5BB6763EDBF33F3A34F415398F8F2E07F04B83FFD7C087DAE

Fix this test case to actually use HMAC with hexkey:FFFF as intended.

Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@surgut.co.uk>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/24068)

5 months agoDocument that private and pairwise checks are not bounded by key size
Tomas Mraz [Fri, 5 Apr 2024 14:31:05 +0000 (16:31 +0200)] 
Document that private and pairwise checks are not bounded by key size

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/24049)

5 months agofuzz/decoder.c: Limit the key sizes on which checks are run
Tomas Mraz [Fri, 5 Apr 2024 14:29:53 +0000 (16:29 +0200)] 
fuzz/decoder.c: Limit the key sizes on which checks are run

In particular the DH safe prime check will be limited to 8192 bits
and the private and pairwise checks are limited to 16384 bits on
any key types.

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/24049)

5 months agoFix socket descriptor checks on Windows
olszomal [Thu, 4 Apr 2024 09:34:33 +0000 (11:34 +0200)] 
Fix socket descriptor checks on Windows

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

5 months agoFix typos found by codespell
Dimitri Papadopoulos [Wed, 14 Feb 2024 09:03:05 +0000 (10:03 +0100)] 
Fix typos found by codespell

Reviewed-by: Todd Short <todd.short@me.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24013)

5 months agoman EVP_PKEY_CTX_set_params: document params is a list
Hubert Kario [Wed, 27 Mar 2024 16:44:42 +0000 (17:44 +0100)] 
man EVP_PKEY_CTX_set_params: document params is a list

Signed-off-by: Hubert Kario <hkario@redhat.com>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23986)

5 months agoaarch64: fix BTI in bsaes assembly code
Tom Cosgrove [Tue, 26 Mar 2024 13:18:00 +0000 (13:18 +0000)] 
aarch64: fix BTI in bsaes assembly code

Change-Id: I63f0fb2af5eb9cea515dec96485325f8efd50511

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
(Merged from https://github.com/openssl/openssl/pull/23982)

5 months agoEnsure proper memory barriers around ossl_rcu_deref/ossl_rcu_assign_ptr
Neil Horman [Tue, 26 Mar 2024 13:59:14 +0000 (09:59 -0400)] 
Ensure proper memory barriers around ossl_rcu_deref/ossl_rcu_assign_ptr

Since the addition of macos14 M1 runners in our CI jobs we've been
seeing periodic random failures in the test_threads CI job.
Specifically we've seen instances in which the shared pointer in the
test (which points to a monotonically incrementing uint64_t went
backwards.

From taking a look at the disassembled code in the failing case, we see
that __atomic_load_n when emitted in clang 15 looks like this
0000000100120488 <_ossl_rcu_uptr_deref>:
100120488f8bfc000     ldapr   x0, [x0]
10012048cd65f03c0     ret

Notably, when compiling with gcc on the same system we get this output
instead:
0000000100120488 <_ossl_rcu_uptr_deref>:
100120488f8bfc000     ldar   x0, [x0]
10012048cd65f03c0     ret

Checking the arm docs for the difference between ldar and ldapr:
https://developer.arm.com/documentation/ddi0602/2023-09/Base-Instructions/LDAPR--Load-Acquire-RCpc-Register-
https://developer.arm.com/documentation/dui0802/b/A64-Data-Transfer-Instructions/LDAR

It seems that the ldar instruction provides a global cpu fence, not
completing until all writes in a given cpus writeback queue have
completed

Conversely, the ldapr instruction attmpts to achieve performance
improvements by honoring the Local Ordering register available in the
system coprocessor, only flushing writes in the same address region as
other cpus on the system.

I believe that on M1 virtualized cpus the ldapr is not properly ordering
writes, leading to an out of order read, despite the needed fencing.
I've opened an issue with apple on this here:
https://developer.apple.com/forums/thread/749530

I believe that it is not safe to issue an ldapr instruction unless the
programmer knows that the Local order registers are properly configured
for use on the system.

So to fix it I'm proposing with this patch that we, in the event that:
1) __APPLE__ is defined
AND
2) __clang__ is defined
AND
3) __aarch64__ is defined

during the build, that we override the ATOMIC_LOAD_N macro in the rcu
code such that it uses a custom function with inline assembly to emit
the ldar instruction rather than the ldapr instruction.  The above
conditions should get us to where this is only used on more recent MAC
cpus, and only in the case where the affected clang compiler emits the
offending instruction.

I've run this patch 10 times in our CI and failed to reproduce the
issue, whereas previously I could trigger it within 5 runs routinely.

Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23974)

5 months agoDowngrade also the download-artifact action
Tomas Mraz [Mon, 8 Apr 2024 15:29:51 +0000 (17:29 +0200)] 
Downgrade also the download-artifact action

It has to have the same version as upload-artifact.

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/24065)

5 months agoffc/ffc_params_generate.c: Add the check for the EVP_MD_get_size()
Jiasheng Jiang [Mon, 25 Mar 2024 16:54:55 +0000 (16:54 +0000)] 
ffc/ffc_params_generate.c: Add the check for the EVP_MD_get_size()

Add the check for the EVP_MD_get_size() to avoid invalid negative numbers.

Fixes: 4f2271d58a ("Add ACVP fips module tests")
Signed-off-by: Jiasheng Jiang <jiasheng@purdue.edu>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23970)

5 months agots/ts_rsp_sign.c: Add the check for the EVP_MD_CTX_get_size()
Jiasheng Jiang [Sat, 23 Mar 2024 16:09:01 +0000 (16:09 +0000)] 
ts/ts_rsp_sign.c: Add the check for the EVP_MD_CTX_get_size()

Add the check for the return value of EVP_MD_CTX_get_size() to avoid invalid negative numbers.

Fixes: c7235be6e3 ("RFC 3161 compliant time stamp request creation, response generation and response verification.")
Signed-off-by: Jiasheng Jiang <jiasheng@purdue.edu>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23960)

5 months agosignature/dsa_sig.c: Add checks for the EVP_MD_get_size()
Jiasheng Jiang [Fri, 22 Mar 2024 22:12:50 +0000 (22:12 +0000)] 
signature/dsa_sig.c: Add checks for the EVP_MD_get_size()

Add checks for the EVP_MD_get_size() to avoid integer overflow and then explicitly cast from int to size_t.

Fixes: 45a845e40b ("Add EVP_DigestSign/EVP_DigestVerify support for DSA")
Signed-off-by: Jiasheng Jiang <jiasheng@purdue.edu>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23948)

5 months agosignature/ecdsa_sig.c: Add checks for the EVP_MD_get_size()
Jiasheng Jiang [Fri, 22 Mar 2024 20:49:27 +0000 (20:49 +0000)] 
signature/ecdsa_sig.c: Add checks for the EVP_MD_get_size()

Add checks for the EVP_MD_get_size() to avoid integer overflow and then explicitly cast from int to size_t.

Fixes: edd3b7a309 ("Add ECDSA to providers")
Signed-off-by: Jiasheng Jiang <jiasheng@purdue.edu>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23947)

5 months agoAdd docs noting requirements for SM2 signing
Neil Horman [Tue, 19 Mar 2024 08:52:57 +0000 (04:52 -0400)] 
Add docs noting requirements for SM2 signing

Reviewed-by: Paul Yang <kaishen.yy@antfin.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23887)

5 months agoAdd check for public key presence on sm2 signing
Neil Horman [Mon, 18 Mar 2024 18:59:32 +0000 (14:59 -0400)] 
Add check for public key presence on sm2 signing

SM2 requires that the public EC_POINT be present in a key when signing.
If its not there we crash on a NULL pointer.  Add a check to ensure that
its present, and raise an error if its not

Reviewed-by: Paul Yang <kaishen.yy@antfin.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23887)

5 months agoAPPS: Add missing OPENSSL_free() and combine the error handler
Jiasheng Jiang [Sat, 16 Mar 2024 21:27:14 +0000 (21:27 +0000)] 
APPS: Add missing OPENSSL_free() and combine the error handler

Add the OPENSSL_free() in the error handler to release the "*md_value"
allocated by app_malloc(). To make the code clear and avoid possible
future errors, combine the error handler in the "err" tag.
Then, we only need to use "goto err" instead of releasing the memory
separately.

Since the EVP_MD_get_size() may return negative numbers when an error occurs,
create_query() may fail to catch the error since it only considers 0 as an
error code.

Therefore, unifying the error codes of create_digest() from non-positive
numbers to 0 is better, which also benefits future programming.

Fixes: c7235be ("RFC 3161 compliant time stamp request creation, response generation and response verification.")
Signed-off-by: Jiasheng Jiang <jiasheng@purdue.edu>
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/23873)

5 months agoFix "Error finalizing cipher loop" when running openssl speed -evp -decrypt
Tom Cosgrove [Mon, 26 Feb 2024 17:14:48 +0000 (17:14 +0000)] 
Fix "Error finalizing cipher loop" when running openssl speed -evp -decrypt

When using CCM, openssl speed uses the loop function EVP_Update_loop_ccm() which
sets a (fake) tag when decrypting. When using -aead (which benchmarks a different
sequence than normal, to be comparable to TLS operation), the loop function
EVP_Update_loop_aead() is used, which also sets a tag when decrypting.

However, when using defaults, the loop function EVP_Update_loop() is used, which
does not set a tag on decryption, leading to "Error finalizing cipher loop".

To fix this, set a fake tag value if we're doing decryption on an AEAD cipher in
EVP_Update_loop(). We don't check the return value: this shouldn't really be able
to fail, and if it does, the following EVP_DecryptUpdate() is almost certain to
fail, so that can catch it.

The decryption is certain to fail (well, almost certain, but with a very low
probability of success), but this is no worse than at present. This minimal
change means that future benchmarking data should be comparable to previous
benchmarking data.

(This is benchmarking code: don't write real apps like this!)

Fixes #23657

Change-Id: Id581cf30503c1eb766464e315b1f33914040dcf7

Reviewed-by: Paul Yang <kaishen.yy@antfin.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23757)

5 months agoFix EVP_PKEY_CTX_add1_hkdf_info() behavior
Todd Short [Fri, 2 Feb 2024 04:09:38 +0000 (23:09 -0500)] 
Fix EVP_PKEY_CTX_add1_hkdf_info() behavior

Fix #23448

`EVP_PKEY_CTX_add1_hkdf_info()` behaves like a `set1` function.

Fix the setting of the parameter in the params code.
Update the TLS_PRF code to also use the params code.
Add tests.

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

5 months agoAdd demo for ECDH key exchange
slontis [Sat, 2 Dec 2023 23:09:46 +0000 (09:09 +1000)] 
Add demo for ECDH key exchange

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22916)

5 months agoapps: ca,req,x509: Add explicit start and end dates options
Stephan Wurm [Wed, 9 Aug 2023 07:07:46 +0000 (09:07 +0200)] 
apps: ca,req,x509: Add explicit start and end dates options

- Added options `-not_before` (start date) and `-not-after` (end date)
  for explicit setting of the validity period of a certificate in the
  apps `ca`, `req` and `x509`
- The new options accept time strings or "today"
- In app `ca`, use the new options as aliases of the already existing
  options `-startdate` and `-enddate`
- When used in apps `req` and `x509`, the end date must be >= the start
  date, in app `ca` end date < start date is also accepted
- In any case, `-not-after` overrides the `-days` option
- Added helper function `check_cert_time_string` to validate given
  certificate time strings
- Use the new helper function in apps `ca`, `req` and `x509`
- Moved redundant code for time string checking into `set_cert_times`
  helper function.
- Added tests for explicit start and end dates in apps `req` and `x509`
- test: Added auxiliary functions for parsing fields from `-text`
  formatted output to `tconversion.pl`
- CHANGES: Added to new section 3.4

Signed-off-by: Stephan Wurm <atomisirsi@gsklan.de>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/21716)

5 months agoCheck range of RSA plaintext and ciphertext when using no padding.
slontis [Mon, 8 Apr 2024 07:12:58 +0000 (17:12 +1000)] 
Check range of RSA plaintext and ciphertext when using no padding.

Fixes #24051

RSA with 'no padding' corresponds to RSAEP/RSADP.
The code was not checking the lower bounds.
The bounds are specified in SP800-56Br2, section 7.1.1.1 and 7.1.2.1
Note that RFC8017 expresses the range in a sentence using the word
between, and there is some ambiguity in this.
The upper bounds have change to match the definition in SP800.

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

5 months agoCopyright year updates
Matt Caswell [Fri, 29 Mar 2024 14:05:51 +0000 (14:05 +0000)] 
Copyright year updates

Reviewed-by: Neil Horman <nhorman@openssl.org>
Release: yes
(cherry picked from commit 3764f200f9d44622faa8ac1b15d2f3eb7c39e473)

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

5 months agoCopyright year updates
Richard Levitte [Wed, 20 Mar 2024 12:07:54 +0000 (13:07 +0100)] 
Copyright year updates

Reviewed-by: Neil Horman <nhorman@openssl.org>
Release: yes
(cherry picked from commit 0ce7d1f355c1240653e320a3f6f8109c1f05f8c0)

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

5 months agoSync libcrypto.num and libssl.num with 3.3 branch
Tomas Mraz [Thu, 4 Apr 2024 09:08:19 +0000 (11:08 +0200)] 
Sync libcrypto.num and libssl.num with 3.3 branch

Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24034)

5 months agoSync CHANGES.md and NEWS.md with 3.3 branch
Tomas Mraz [Thu, 4 Apr 2024 09:06:53 +0000 (11:06 +0200)] 
Sync CHANGES.md and NEWS.md with 3.3 branch

Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24034)

5 months agoUpdate the version to 3.4.0-dev
Tomas Mraz [Thu, 4 Apr 2024 08:57:43 +0000 (10:57 +0200)] 
Update the version to 3.4.0-dev

Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24034)

5 months agoAdd a test for session cache overflow
Matt Caswell [Fri, 15 Jul 2022 12:26:33 +0000 (13:26 +0100)] 
Add a test for session cache overflow

Test sessions behave as we expect even in the case that an overflow
occurs when adding a new session into the session cache.

Related to CVE-2024-2511

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

5 months agoHardening around not_resumable sessions
Matt Caswell [Fri, 15 Mar 2024 17:58:42 +0000 (17:58 +0000)] 
Hardening around not_resumable sessions

Make sure we can't inadvertently use a not_resumable session

Related to CVE-2024-2511

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

5 months agoAdd a CHANGES.md/NEWS.md entry for the unbounded memory growth bug
Matt Caswell [Tue, 5 Mar 2024 16:01:20 +0000 (16:01 +0000)] 
Add a CHANGES.md/NEWS.md entry for the unbounded memory growth bug

Related to CVE-2024-2511

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

5 months agoFix unconstrained session cache growth in TLSv1.3
Matt Caswell [Tue, 5 Mar 2024 15:43:53 +0000 (15:43 +0000)] 
Fix unconstrained session cache growth in TLSv1.3

In TLSv1.3 we create a new session object for each ticket that we send.
We do this by duplicating the original session. If SSL_OP_NO_TICKET is in
use then the new session will be added to the session cache. However, if
early data is not in use (and therefore anti-replay protection is being
used), then multiple threads could be resuming from the same session
simultaneously. If this happens and a problem occurs on one of the threads,
then the original session object could be marked as not_resumable. When we
duplicate the session object this not_resumable status gets copied into the
new session object. The new session object is then added to the session
cache even though it is not_resumable.

Subsequently, another bug means that the session_id_length is set to 0 for
sessions that are marked as not_resumable - even though that session is
still in the cache. Once this happens the session can never be removed from
the cache. When that object gets to be the session cache tail object the
cache never shrinks again and grows indefinitely.

CVE-2024-2511

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

5 months agoExtend the multi_resume test for simultaneous resumptions
Matt Caswell [Tue, 5 Mar 2024 15:35:51 +0000 (15:35 +0000)] 
Extend the multi_resume test for simultaneous resumptions

Test what happens if the same session gets resumed multiple times at the
same time - and one of them gets marked as not_resumable.

Related to CVE-2024-2511

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