openssl.git
20 months agoEnable the record layer to call the ssl_security callback
Matt Caswell [Wed, 25 May 2022 16:10:38 +0000 (17:10 +0100)]
Enable the record layer to call the ssl_security callback

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

20 months agoUse a record layer specific message callback
Matt Caswell [Wed, 25 May 2022 15:41:30 +0000 (16:41 +0100)]
Use a record layer specific message callback

Don't use the message callback from the SSL object. Instead we use a
wrapper callback so that the record layer does not need to be aware of the
SSL object.

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

20 months agoMove early data counting out of the SSL object and into the record layer
Matt Caswell [Wed, 25 May 2022 14:16:48 +0000 (15:16 +0100)]
Move early data counting out of the SSL object and into the record layer

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

20 months agoMove the sequence number into the OSSL_RECORD_LAYER object
Matt Caswell [Tue, 24 May 2022 15:00:50 +0000 (16:00 +0100)]
Move the sequence number into the OSSL_RECORD_LAYER object

This removes some references to the SSL object from the record layer.

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

20 months agoRemove use of SSL object for fragment length checking in record layer
Matt Caswell [Mon, 23 May 2022 10:31:53 +0000 (11:31 +0100)]
Remove use of SSL object for fragment length checking in record layer

Pass the max fragment length to the record layer when it is applicable
to avoid the need to go through the SSL object.

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

20 months agoRemove use of ossl_statem_in_error() from the record layer
Matt Caswell [Fri, 20 May 2022 15:58:51 +0000 (16:58 +0100)]
Remove use of ossl_statem_in_error() from the record layer

We remove the dependency on the SSL object. Instead we check if the
record layer has already set an alert code.

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

20 months agoMake the record layer directly aware of EtM
Matt Caswell [Fri, 20 May 2022 15:54:12 +0000 (16:54 +0100)]
Make the record layer directly aware of EtM

We no longer have to go through the SSL object to discover whether EtM has
been negotiated.

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

20 months agoRemove SSL_USE_EXPLICT_IV() from the record layer methods
Matt Caswell [Thu, 19 May 2022 16:11:13 +0000 (17:11 +0100)]
Remove SSL_USE_EXPLICT_IV() from the record layer methods

Instead we introduce RLAYER_USE_EXPLICIT_IV(). This removes a dependency
on the SSL object.

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

20 months agoRemove some use of SSL object from record layer
Matt Caswell [Thu, 19 May 2022 15:58:45 +0000 (16:58 +0100)]
Remove some use of SSL object from record layer

Remove SSL_IS_TLS13() and hello_retry_request

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

20 months agoUpdate the oqs-provider submodule to a more recent commit
Matt Caswell [Thu, 19 May 2022 14:49:32 +0000 (15:49 +0100)]
Update the oqs-provider submodule to a more recent commit

Also update the oqsprovider.sh file to not run the preptests.sh script
which is no longer required

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

20 months agoDisallow SSL2_VERSION record version in an SSLv3 record header
Matt Caswell [Wed, 18 May 2022 14:26:04 +0000 (15:26 +0100)]
Disallow SSL2_VERSION record version in an SSLv3 record header

When validate_record_header() gets called it should be able to rely on
the fact that an SSLv2 record version means that the record was received in
SSLv2 format.

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

20 months agoFix some no-comp compilation failures
Matt Caswell [Wed, 18 May 2022 13:30:24 +0000 (14:30 +0100)]
Fix some no-comp compilation failures

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

20 months agoAdd support for moving data from one epoch to the next
Matt Caswell [Tue, 17 May 2022 15:16:40 +0000 (16:16 +0100)]
Add support for moving data from one epoch to the next

Sometimes data read by a record layer in one epoch is actually intended for
the next epoch. For example in a TLS with read_ahead, the read_ahead data
could contain a KeyUpdate message followed by application data encrypted
with new keys. Therefore we implement a mechanism for passing this data
across the epochs.

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

20 months agoAdd a test for read_ahead data crossing a key change
Matt Caswell [Tue, 17 May 2022 13:36:39 +0000 (14:36 +0100)]
Add a test for read_ahead data crossing a key change

If read_ahead is switched on, it should still work even if the data that
is read cross epochs.

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

20 months agoRemove unneccesary KTLS code from non-KTLS specific files
Matt Caswell [Thu, 12 May 2022 16:21:25 +0000 (17:21 +0100)]
Remove unneccesary KTLS code from non-KTLS specific files

This also moves other protocol specific code to the protocol specific
files.

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

20 months agoMove ktls.c into the record layer
Matt Caswell [Thu, 12 May 2022 16:00:59 +0000 (17:00 +0100)]
Move ktls.c into the record layer

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

20 months agoDistinguish between fatal and non-fatal errors when creating a record layer
Matt Caswell [Thu, 12 May 2022 15:35:52 +0000 (16:35 +0100)]
Distinguish between fatal and non-fatal errors when creating a record layer

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

20 months agoImplement KTLS in the new read record layer code
Matt Caswell [Tue, 10 May 2022 17:50:00 +0000 (18:50 +0100)]
Implement KTLS in the new read record layer code

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

20 months agoMove protocol version specific code into separate files
Matt Caswell [Mon, 9 May 2022 11:00:54 +0000 (12:00 +0100)]
Move protocol version specific code into separate files

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

20 months agoEnsure various SSL options are passed down to the record layer
Matt Caswell [Fri, 6 May 2022 14:10:00 +0000 (15:10 +0100)]
Ensure various SSL options are passed down to the record layer

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

20 months agoConvert TLSv1.3 code to use the new read side record layer
Matt Caswell [Fri, 29 Apr 2022 16:13:23 +0000 (17:13 +0100)]
Convert TLSv1.3 code to use the new read side record layer

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

20 months agoConvert SSLv3 code to use the new read side record layer
Matt Caswell [Thu, 28 Apr 2022 15:57:07 +0000 (16:57 +0100)]
Convert SSLv3 code to use the new read side record layer

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

20 months agoMove Record layer methods code into a sub-directory
Matt Caswell [Tue, 19 Apr 2022 16:15:54 +0000 (17:15 +0100)]
Move Record layer methods code into a sub-directory

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

20 months agoMove the TLS1.0/1.1/1.2 record crypto code into the new record layer
Matt Caswell [Mon, 18 Apr 2022 07:57:32 +0000 (08:57 +0100)]
Move the TLS1.0/1.1/1.2 record crypto code into the new record layer

Only done for the read side so far. Still need to do TLS1.3 and SSL3.0.
Also need to separate out KTLS.

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

20 months agoConvert ssl3_get_record to tls_read_record
Matt Caswell [Tue, 12 Apr 2022 13:50:28 +0000 (14:50 +0100)]
Convert ssl3_get_record to tls_read_record

We move the old ssl3_get_record function to conform with the new record
layer design.

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

20 months agoAdd a DTLSv1_listen() test
Matt Caswell [Mon, 11 Apr 2022 13:37:16 +0000 (14:37 +0100)]
Add a DTLSv1_listen() test

Add a test to ensure that a connection started via DTLSv1_listen() can
be completed through to handshake success. Previous DTLSv1_listen()
testing only tested the function itself and did not confirm that a
connection can actually be achieved using it.

This is important to test some codepaths being affected by the record layer
refactor.

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

20 months agoTransfer the functionality from ssl3_read_n to the new record layer
Matt Caswell [Thu, 7 Apr 2022 16:35:36 +0000 (17:35 +0100)]
Transfer the functionality from ssl3_read_n to the new record layer

This transfers the low level function ssl3_read_n to the new record layer.
We temporarily make the read_n function a top level record layer function.
Eventually, in later commits in this refactor, we will remove it as a top
level function and it will just be called from read_record.

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

20 months agoMake settings and options parameters const in recordmethod.h
Matt Caswell [Thu, 7 Apr 2022 16:35:08 +0000 (17:35 +0100)]
Make settings and options parameters const in recordmethod.h

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

20 months agoAdd a skeleton TLS record method
Matt Caswell [Thu, 7 Apr 2022 13:09:25 +0000 (14:09 +0100)]
Add a skeleton TLS record method

It doesn't yet do anything. This is a placeholder which will be filled in
by susbsequent commits.

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

20 months agoFix compilation issues in the imported recordmethod.h
Matt Caswell [Thu, 7 Apr 2022 11:38:13 +0000 (12:38 +0100)]
Fix compilation issues in the imported recordmethod.h

Also, rename the "new" function pointer to "new_record_layer" to avoid a
C++ reserved name

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

20 months agoAdd the recordmethod header from the draft design
Matt Caswell [Thu, 7 Apr 2022 11:30:30 +0000 (12:30 +0100)]
Add the recordmethod header from the draft design

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

20 months agoUpdate session timeout code with OSSL_TIME
Todd Short [Thu, 11 Aug 2022 13:58:52 +0000 (09:58 -0400)]
Update session timeout code with OSSL_TIME

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

20 months agoAdd some documentation for X509_gmtime_adj()
Matt Caswell [Wed, 10 Aug 2022 08:53:12 +0000 (09:53 +0100)]
Add some documentation for X509_gmtime_adj()

Other very similar functions were documented, but this one was missing.

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

20 months agoAdd CODE-OF-CONDUCT.md
Dr. Matthias St. Pierre [Mon, 15 Aug 2022 13:01:11 +0000 (15:01 +0200)]
Add CODE-OF-CONDUCT.md

Fixes #18820

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

20 months agocms: Create test for for purpose verification in cms application
Lutz Jaenicke [Wed, 15 Jun 2022 17:01:43 +0000 (19:01 +0200)]
cms: Create test for for purpose verification in cms application

The tests only cover the correct handling of the codesigning purpose in the certificates
in the context of the cms command line tool.
The interpretation of the certificate purpose is tested in the context of the "verify"
app. The correct handling of the cms objects is tested by other tests in 80-test_cms.t.

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

20 months agoX509: add tests for purpose code signing in verify application
Lutz Jaenicke [Wed, 15 Jun 2022 15:31:19 +0000 (17:31 +0200)]
X509: add tests for purpose code signing in verify application

Correct configuration according to CA Browser forum:
  KU: critical,digitalSignature
  XKU: codeSiging

Note: I did not find any other document formally defining the requirements
for code signing certificates.

Some combinations are explicitly forbidden, some flags can be ignored

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

20 months agoX509: Add "code sign" as purpose for verification of certificates
Lutz Jaenicke [Thu, 14 Oct 2021 13:24:18 +0000 (15:24 +0200)]
X509: Add "code sign" as purpose for verification of certificates

Code signing certificates have other properties as for example described in
CA Browser Forum documents. This leads to "unsupported certificate purpose" errors when
verifying signed objects.
This patch adds the purpose "codesign" to the table in X.509 certificate verification and
the verification parameter "code_sign" to X509_VERIFY_PARAM.

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

20 months agocrypto/x509/x509_vpm.c: update format of X509_VERIFY_PARAM default_table
Lutz Jaenicke [Wed, 15 Jun 2022 12:25:54 +0000 (14:25 +0200)]
crypto/x509/x509_vpm.c: update format of X509_VERIFY_PARAM default_table

Put "}," on separate lines as suggested in PR #18567

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

20 months agoClarify documentation in regards to EC key parameters
Tomas Mraz [Thu, 28 Jul 2022 13:45:02 +0000 (15:45 +0200)]
Clarify documentation in regards to EC key parameters

Also clarify that EVP_PKEY_fromdata ignores parameters that
are unknown or incorrect for given selection.

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

20 months agoAdd testcases for EVP_PKEY_get1_encoded_public_key
Tomas Mraz [Thu, 28 Jul 2022 12:13:06 +0000 (14:13 +0200)]
Add testcases for EVP_PKEY_get1_encoded_public_key

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

20 months agoec_kmgmt.c: Do not crash when getting OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY
Tomas Mraz [Thu, 28 Jul 2022 11:57:02 +0000 (13:57 +0200)]
ec_kmgmt.c: Do not crash when getting OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY

If the public key is not set on the key, return error instead of crash.

Fixes #18495

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

20 months agoFix ossl_x509v3_cache_extensions(): EXFLAG_NO_FINGERPRINT should not be an error
Dr. David von Oheimb [Sun, 11 Jul 2021 16:55:12 +0000 (18:55 +0200)]
Fix ossl_x509v3_cache_extensions(): EXFLAG_NO_FINGERPRINT should not be an error

This allows reverting the recent workaround on cmp_ctx_test regarding X509_new()

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

20 months agoRename "RX Frame Handler" to "RX Depacketizer" in the overview
Richard Levitte [Wed, 17 Aug 2022 05:18:52 +0000 (07:18 +0200)]
Rename "RX Frame Handler" to "RX Depacketizer" in the overview

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

20 months agoRX depacketizer (QUIC)
Richard Levitte [Mon, 20 Jun 2022 10:53:55 +0000 (12:53 +0200)]
RX depacketizer (QUIC)

The same-ish module as the TX packetizer, handling the opposite direction.

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

20 months agoFix memory leak in BN_rand_range()
valdaarhun [Wed, 10 Aug 2022 19:18:05 +0000 (00:48 +0530)]
Fix memory leak in BN_rand_range()

The patch enables BN_rand_range() to exit immediately
if BIGNUM *rnd is NULL.

CLA: trivial

Fixes: #18951
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18982)

20 months agoEnsure we build ub sanitizer builds with -DPEDANTIC
Matt Caswell [Mon, 15 Aug 2022 11:07:37 +0000 (12:07 +0100)]
Ensure we build ub sanitizer builds with -DPEDANTIC

Otherwise we may get spurious results from ub sanitizer. For example we
assume we can tolerate some unaligned write without this define that ub
sanitizer will complain about.

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18983)

20 months agoDon't incorrectly skip the multiblock test
Matt Caswell [Thu, 11 Aug 2022 11:02:44 +0000 (12:02 +0100)]
Don't incorrectly skip the multiblock test

sslapitest has a test for multiblock writes. Since multiblock writing is
only available on some platforms the multiblock test checks whether we are
on such a platform first, and skips the test if we are not. Unfortunately
a bug in the check meant that we always skipped the test regardless of the
platform.

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18983)

20 months agoSHAKE documentation updates for default output length.
slontis [Wed, 22 Jun 2022 05:21:13 +0000 (15:21 +1000)]
SHAKE documentation updates for default output length.

Fixes #18586

In order to not break existing applications the OpenSSL documentation
related to SHAKE has been updated.

Background:

All digests algorithms (including XOF's) use the bitlen as the default output length.
This results in a security strength of bitlen / 2.

This means that SHAKE128 will by default have an output length of 16
bytes and a security strength of 64 bits.

For SHAKE256 the default output length is 32 bytes and has a security
strength of 128 bits.

This behaviour was present in 1.1.1 and has been duplicated in the
provider SHAKE algorithms for 3.0.

The SHAKE XOF algorithms have a security strength of
min(bitlen, output xof length in bits / 2).

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

20 months agoFix unrolled montgomery multiplication for POWER9
Rohan McLure [Thu, 30 Jun 2022 06:21:06 +0000 (16:21 +1000)]
Fix unrolled montgomery multiplication for POWER9

In the reference C implementation in bn_asm.c, tp[num + 1] contains the
carry bit for accumulations into tp[num]. tp[num + 1] is only ever
assigned, never itself incremented.

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

20 months agoRevert "Revert "bn: Add fixed length (n=6), unrolled PPC Montgomery Multiplication""
Rohan McLure [Mon, 27 Jun 2022 02:14:55 +0000 (12:14 +1000)]
Revert "Revert "bn: Add fixed length (n=6), unrolled PPC Montgomery Multiplication""

This reverts commit 712d9cc90e355b2c98a959d4e9398610d2269c9e.

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

20 months agoCRYPTO_mem_debug_push() and CRYPTO_mem_debug_pop() should return 0
Matt Caswell [Tue, 9 Aug 2022 10:59:22 +0000 (11:59 +0100)]
CRYPTO_mem_debug_push() and CRYPTO_mem_debug_pop() should return 0

Those 2 functions historically only ever returned 0 or 1. In OpenSSL 3.0
they were made no-ops and the documentation says they always return 0. In
fact they were returning -1. If any application was actually using these
functions then it may appear that they were actually successful (e.g. -1
could be interpreted as "true").

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

20 months agoCorrect the documentation for OPENSSL_MALLOC_FD
Matt Caswell [Tue, 9 Aug 2022 10:55:45 +0000 (11:55 +0100)]
Correct the documentation for OPENSSL_MALLOC_FD

The documentation was misleading in that it suggests that this environment
variable will record information about all allocations. While this is true
it doesn't record the most useful information that you might expect such
as the requested size of the allocation! It is mainly for use in
conjunction with OPENSSL_MALLOC_FAILURES, and reports information about
what chance an allocation has of failing.

We also clarify that the mem_debug functions are actually no-ops in 3.0.

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

20 months agoAPPS: genrsa: Support setting properties
Clemens Lang [Mon, 4 Jul 2022 15:15:46 +0000 (17:15 +0200)]
APPS: genrsa: Support setting properties

The -provider and -propquery options did not work on genrsa. Fix this
and add a test that checks that operations that would usually fail with
the FIPS provider work when run with

| -provider default -propquery '?fips!=yes'

See also 30b2c3592e8511b60d44f93eb657a1ecb3662c08, which previously
fixed the same problem in dsaparam and gendsa. See also the initial
report in https://bugzilla.redhat.com/show_bug.cgi?id=2094956.

Signed-off-by: Clemens Lang <cllang@redhat.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/18717)

20 months agoAPPS: dgst: Support properties when signing
Clemens Lang [Mon, 4 Jul 2022 14:15:07 +0000 (16:15 +0200)]
APPS: dgst: Support properties when signing

The -provider and -propquery options did not work on dgst when using it
for signing or signature verification (including HMACs). Fix this and
add tests that check that operations that would usually fail with the
FIPS provider work when run with

| -provider default -propquery '?fips!=yes'

Additionally, modify the behavior of dgst -list to also use the current
library context and property query. This reduces the output below the
headline "Supported digests" to a list of the digest algorithms that
will actually work with the current configuration, which is closer to
what users probably expect with this headline.

See also 30b2c3592e8511b60d44f93eb657a1ecb3662c08, which previously
fixed the same problem in dsaparam and gendsa. See also the initial
report in https://bugzilla.redhat.com/show_bug.cgi?id=2094956.

Signed-off-by: Clemens Lang <cllang@redhat.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/18717)

20 months agoTEST: Check property query support of apps/pkey
Clemens Lang [Fri, 1 Jul 2022 14:35:44 +0000 (16:35 +0200)]
TEST: Check property query support of apps/pkey

Property query support works correctly for apps/pkey, but there does not
seem to be a test for it yet, so add one.

See also 30b2c3592e8511b60d44f93eb657a1ecb3662c08, which previously
fixed a similar problem in dsaparam and gendsa. See also the initial
report in https://bugzilla.redhat.com/show_bug.cgi?id=2094956.

Signed-off-by: Clemens Lang <cllang@redhat.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/18717)

20 months agoAPPS: pkeyparam: Support setting properties
Clemens Lang [Fri, 1 Jul 2022 13:35:22 +0000 (15:35 +0200)]
APPS: pkeyparam: Support setting properties

The -provider and -propquery options did not work on pkeyparam. Fix this
and add tests that check that operations that would usually fail with
the FIPS provider work when run with

| -provider default -propquery '?fips!=yes'

See also 30b2c3592e8511b60d44f93eb657a1ecb3662c08, which previously
fixed the same problem in dsaparam and gendsa. See also the initial
report in https://bugzilla.redhat.com/show_bug.cgi?id=2094956.

Signed-off-by: Clemens Lang <cllang@redhat.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/18717)

20 months agoAPPS: ecparam: Support setting properties
Clemens Lang [Fri, 1 Jul 2022 13:22:34 +0000 (15:22 +0200)]
APPS: ecparam: Support setting properties

The -provider and -propquery options did not work on ecparam. Fix this
and add tests that check that operations that would usually fail with
the FIPS provider work when run with

| -provider default -propquery '?fips!=yes'

See also 30b2c3592e8511b60d44f93eb657a1ecb3662c08, which previously
fixed the same problem in dsaparam and gendsa. See also the initial
report in https://bugzilla.redhat.com/show_bug.cgi?id=2094956.

Signed-off-by: Clemens Lang <cllang@redhat.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/18717)

20 months agoAPPS: dhparam: Support setting properties
Clemens Lang [Fri, 1 Jul 2022 12:50:59 +0000 (14:50 +0200)]
APPS: dhparam: Support setting properties

The -provider and -propquery options did not work on dhparam. Fix this
and add tests that check that operations that would usually fail with
the FIPS provider work when run with

| -provider default -propquery '?fips!=yes'

See also 30b2c3592e8511b60d44f93eb657a1ecb3662c08, which previously
fixed the same problem in dsaparam and gendsa. See also the initial
report in https://bugzilla.redhat.com/show_bug.cgi?id=2094956.

Signed-off-by: Clemens Lang <cllang@redhat.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/18717)

20 months agotest/timing_load_creds.c: fix coding style and other (mostly minor) issues
Dr. David von Oheimb [Mon, 25 Jul 2022 07:19:40 +0000 (09:19 +0200)]
test/timing_load_creds.c: fix coding style and other (mostly minor) issues

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from https://github.com/openssl/openssl/pull/18821)

20 months agoRename the "timing" program to "timing_load_creds" and integrate it with test/build...
Dr. David von Oheimb [Mon, 18 Jul 2022 18:26:57 +0000 (20:26 +0200)]
Rename the "timing" program to "timing_load_creds" and integrate it with test/build.info

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from https://github.com/openssl/openssl/pull/18821)

20 months agoAdd a stand-alone "timing" program
Rich Salz [Thu, 29 Apr 2021 17:48:45 +0000 (13:48 -0400)]
Add a stand-alone "timing" program

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from https://github.com/openssl/openssl/pull/18821)

20 months agoAdd ROTATE inline RISC-V zbb/zbkb asm for DES
Hongren (Zenithal) Zheng [Wed, 11 May 2022 10:32:13 +0000 (18:32 +0800)]
Add ROTATE inline RISC-V zbb/zbkb asm for DES

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

20 months agoFix asan finding in bio_tfo_test
Juergen Christ [Wed, 10 Aug 2022 16:02:49 +0000 (18:02 +0200)]
Fix asan finding in bio_tfo_test

Running bio_tfo_test under asan yields
==172342==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 380 byte(s) in 5 object(s) allocated from:
    #0 0x3ff89bba251 in malloc (/lib64/libasan.so.8+0xba251)
    #1 0x3ff88cf9fd5 in gaih_inet.constprop.0 (/lib64/libc.so.6+0xf9fd5)
    #2 0x3ff88cfaf6f in getaddrinfo (/lib64/libc.so.6+0xfaf6f)
    #3 0x3ff89ba52a9 in __interceptor_getaddrinfo.part.0 (/lib64/libasan.so.8+0xa52a9)
    #4 0x1004909 in test_fd_tfo test/bio_tfo_test.c:241
[...]

and fails the test.

Fix this by freeing the return addrinfo on exit.

Signed-off-by: Juergen Christ <jchrist@linux.ibm.com>
Reviewed-by: Todd Short <todd.short@me.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18979)

20 months agoFix asan finding in bio_addr
Juergen Christ [Wed, 10 Aug 2022 15:59:19 +0000 (17:59 +0200)]
Fix asan finding in bio_addr

Running test_tfo_cli under asan yields
==166214==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60700000d57c at pc 0x03ffa004ed86 bp 0x03ffe2977e80 sp 0x03ffe2977668
READ of size 112 at 0x60700000d57c thread T0
    #0 0x3ffa004ed85 in memcpy (/lib64/libasan.so.8+0x4ed85)
    #1 0x3ff9f3615b7 in BIO_ADDR_dup crypto/bio/bio_addr.c:77
[...]
and fails the test.

Fix this by copying the right structure of the union.

Signed-off-by: Juergen Christ <jchrist@linux.ibm.com>
Reviewed-by: Todd Short <todd.short@me.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18979)

20 months agoMake OSSL_TIME a structure
Pauli [Wed, 27 Jul 2022 01:52:17 +0000 (11:52 +1000)]
Make OSSL_TIME a structure

This prevents misuses creeping in.

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

20 months agoVC++ 2008 or earlier x86 compilers do not have an inline implementation of Interlocke...
Daiyuu Nobori [Sun, 24 Jul 2022 01:34:05 +0000 (10:34 +0900)]
VC++ 2008 or earlier x86 compilers do not have an inline implementation of InterlockedOr64 for 32bit and will fail to run on Windows XP 32bit.
See: https://docs.microsoft.com/en-us/cpp/intrinsics/interlockedor-intrinsic-functions#requirements
To work around this problem, we implement a manual locking mechanism for only VC++ 2008 or earlier x86 compilers.

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18856)

20 months agoproperty: make cache flushing slight less deterministic
Pauli [Fri, 29 Jul 2022 01:00:50 +0000 (11:00 +1000)]
property: make cache flushing slight less deterministic

If there is no timer available to seed the stochastic flushing, revert to a
global seed that gets updated each flush.

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

20 months agoFix GHASH-ASM implementation on s390x
Juergen Christ [Tue, 2 Aug 2022 12:41:00 +0000 (14:41 +0200)]
Fix GHASH-ASM implementation on s390x

s390x GHASH assembler implementation assumed it was called from a
gcm128_context structure where the Xi paramter to the ghash function was
embedded in that structure.  Since the structure layout resembles the paramter
block required for kimd-GHASH, the assembler code simply assumed the 128 bytes
after Xi are the hash subkey.

This assumption was broken with the introduction of AES-GCM-SIV which uses the
GHASH implementation without a gcm128_context structure.  Furthermore, the
bytes following the Xi input parameter to the GHASH function do not contain
the hash subkey.  To fix this, we remove the assumption about the calling
context and build the parameter block on the stack.  This requires some
copying of data to and from the stack.  While this introduces a performance
degradation, new systems anyway use kma for GHASH/AES-GCM.

Finally fixes #18693 for s390x.

Signed-off-by: Juergen Christ <jchrist@linux.ibm.com>
Reviewed-by: Todd Short <todd.short@me.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18939)

20 months agotest/evp_test: Test if EVP_DigestSign() set signature's length.
Sebastian Andrzej Siewior [Mon, 1 Aug 2022 20:08:27 +0000 (22:08 +0200)]
test/evp_test: Test if EVP_DigestSign() set signature's length.

Increase the signature's length, that is passed to EVP_DigestSign(). The
implementation should set this parameter back to the actual length, that
has been written.

This (oneshot_digestsign_test_run()) fails for the ed25519/ ed448
implementation of s390 prio the fix. The change in digestsign_test_run()
follows the same pattern and is for collecting bonus points.

Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Todd Short <todd.short@me.com>
(Merged from https://github.com/openssl/openssl/pull/18928)

20 months agoproviders: Set the size of EC signature on s390.
Sebastian Andrzej Siewior [Mon, 1 Aug 2022 15:42:05 +0000 (17:42 +0200)]
providers: Set the size of EC signature on s390.

The s390x provides its custom implementation for the creation of the
ed448 and ed25519 signatures. Unfortunately it does not set the size.
Users that rely of this return parameter end up with wrong values and
will compare wrong sizes of signature.

Set the proper size of the returned signature on success. Set an error
if the signing operation fails.

Fixes: #18912
Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Todd Short <todd.short@me.com>
(Merged from https://github.com/openssl/openssl/pull/18928)

20 months agoChange name of parameter in documentation from sigret to sig
Kurt Roeckx [Tue, 2 Aug 2022 16:49:40 +0000 (18:49 +0200)]
Change name of parameter in documentation from sigret to sig

The rest of the documentation talks about sig, not sigret

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Todd Short <todd.short@me.com>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18943)

20 months agoProperly document deprecation of DH_new() and related functions
Tomas Mraz [Mon, 1 Aug 2022 11:08:45 +0000 (13:08 +0200)]
Properly document deprecation of DH_new() and related functions

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Todd Short <todd.short@me.com>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18925)

20 months agoFix EC_KEY_set_private_key() NULL priv_key docs
Roberto Hueso Gomez [Mon, 1 Aug 2022 18:11:22 +0000 (20:11 +0200)]
Fix EC_KEY_set_private_key() NULL priv_key docs

Updates the docs to describe EC_KEY_set_private_key() function behavior
when a NULL priv_key argument is passed.

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Todd Short <todd.short@me.com>
(Merged from https://github.com/openssl/openssl/pull/18942)

20 months agoAdd test for EC_KEY_set_private_key()
Roberto Hueso Gomez [Mon, 1 Aug 2022 00:08:47 +0000 (02:08 +0200)]
Add test for EC_KEY_set_private_key()

This tests the behavior and API of the EC_KEY_set_private_key function.
It tests compliance with legacy features related to NULL private keys
too.

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Todd Short <todd.short@me.com>
(Merged from https://github.com/openssl/openssl/pull/18942)

20 months agoFix EC_KEY_set_private_key() priv_key regression
Roberto Hueso Gomez [Tue, 26 Jul 2022 18:41:02 +0000 (20:41 +0200)]
Fix EC_KEY_set_private_key() priv_key regression

This allows to set EC_KEY's private key to NULL and fixes regression
issue following OTC guideline in
https://github.com/openssl/openssl/issues/18744#issuecomment-1195175696

Fixes #18744.

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Todd Short <todd.short@me.com>
(Merged from https://github.com/openssl/openssl/pull/18942)

20 months agoNote that EVP_CIPHER_get_iv_length returns negative values on error
Pauli [Thu, 28 Jul 2022 01:20:37 +0000 (11:20 +1000)]
Note that EVP_CIPHER_get_iv_length returns negative values on error

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

20 months agoFix bug in EVP_CIPHER_CTX_get_iv_length()
Pauli [Tue, 26 Jul 2022 01:46:45 +0000 (11:46 +1000)]
Fix bug in EVP_CIPHER_CTX_get_iv_length()

Out of range values could possibly be returned due to a lack of range checking.
Very unlikely to be exploitable for our provider because sensible values are
returned for all ciphers.

Also fixed the defaulting code so that the cipher's IV length is returned if
the cipher ctx doesn't support getting.

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

20 months agoAvoid resource leaks in do_ssl3_write
Dmitry Belyavskiy [Mon, 1 Aug 2022 10:33:39 +0000 (12:33 +0200)]
Avoid resource leaks in do_ssl3_write

Thanks Matt for pointing on it

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

20 months agoFree up space in the session cache before adding.
Todd Short [Fri, 29 Jul 2022 00:05:54 +0000 (20:05 -0400)]
Free up space in the session cache before adding.

Fixes #18690

In some circumstances, it's possible that when using an external
database for the session cache, that pulling in an entry from that
cache to the internal cache will cause the newly added entry to
be deleted from the internal cache. This is likely to happen when
the internal cache is set to have a small size, and the newly added
entry's timeout places it at the end of the cache list.

This could be fixed by updating the timestamp of the session (via
`SSL_SESSION_set_time()` or `SSL_SESSION_set_timeout()`) before
adding to the cache. But that may not be desireable.

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

20 months agoFix wrong default algorithm in openssl pkcs12 help
Arne Schwabe [Thu, 28 Jul 2022 14:51:58 +0000 (16:51 +0200)]
Fix wrong default algorithm in openssl pkcs12 help

The default that pkcs12 -export uses is SHA256 and not SHA1.

CLA: Trivial

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

20 months agoUpdating ifdefs to account for xlclang compiler frontend on AIX.
Rob Mc Gee [Wed, 27 Jul 2022 22:30:51 +0000 (15:30 -0700)]
Updating ifdefs to account for xlclang compiler frontend on AIX.

The fallback DEP works fine there. XLC should be unaffected.

CLA: trivial

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

20 months agoFix AES-GCM-SIV endian issues
Todd Short [Mon, 1 Aug 2022 01:24:13 +0000 (21:24 -0400)]
Fix AES-GCM-SIV endian issues

Fixes #18911

`BSWAP`x/`GETU`xx are no-ops on big-endian. Change the byte swapper.
Fix big-endian issues in the `mulx_ghash()` function

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

20 months agoCoverity 1507484: dereference before null check
Pauli [Fri, 29 Jul 2022 02:08:04 +0000 (12:08 +1000)]
Coverity 1507484: dereference before null check

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

20 months agoCheck that IV length is not less than zero
Dmitry Belyavskiy [Wed, 27 Jul 2022 10:15:07 +0000 (12:15 +0200)]
Check that IV length is not less than zero

As EVP_CIPHER_CTX_get_iv_length indicates failure with -1, this error
should be processed. Also the result of this function shouldn't be
assigned to an unsigned variable.

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

20 months agoTest that swapping the first app data record with Finished msg works
Matt Caswell [Mon, 25 Jul 2022 11:39:52 +0000 (12:39 +0100)]
Test that swapping the first app data record with Finished msg works

If the first app data record arrives before the Finished message we should
be able to buffer it and move on to the Finished message.

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

20 months agoFix SSL_pending() and SSL_has_pending() with DTLS
Matt Caswell [Mon, 25 Jul 2022 14:59:38 +0000 (15:59 +0100)]
Fix SSL_pending() and SSL_has_pending() with DTLS

If app data is received before a Finished message in DTLS then we buffer
it to return later. The function SSL_pending() is supposed to tell you
how much processed app data we have already buffered, and SSL_has_pending()
is supposed to tell you if we have any data buffered (whether processed or
not, and whether app data or not).

Neither SSL_pending() or SSL_has_pending() were taking account of this
DTLS specific app data buffer.

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

20 months agoImplement AES-GCM-SIV (RFC8452)
Todd Short [Thu, 28 Apr 2022 18:56:11 +0000 (14:56 -0400)]
Implement AES-GCM-SIV (RFC8452)

Fixes #16721

This uses AES-ECB to create a counter mode AES-CTR32 (32bit counter, I could
not get AES-CTR to work as-is), and GHASH to implement POLYVAL. Optimally,
there would be separate polyval assembly implementation(s), but the only one
I could find (and it was SSE2 x86_64 code) was not Apache 2.0 licensed.

This implementation lives only in the default provider; there is no legacy
implementation.

The code offered in #16721 is not used; that implementation sits on top of
OpenSSL, this one is embedded inside OpenSSL.

Full test vectors from RFC8452 are included, except the 0 length plaintext;
that is not supported; and I'm not sure it's worthwhile to do so.

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

20 months agoQUIC Frame Encoding and Decoding Functions
Hugo Landau [Mon, 11 Jul 2022 18:16:20 +0000 (19:16 +0100)]
QUIC Frame Encoding and Decoding Functions

This adds functions for encoding and decoding QUIC frames.

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

21 months agoFixes segfault occurrence in PEM_write()
valdaarhun [Mon, 25 Jul 2022 13:19:19 +0000 (18:49 +0530)]
Fixes segfault occurrence in PEM_write()

Checks if header is NULL or not before calling strlen().

CLA: trivial

Fixes #18825

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

21 months agoCorrection: uncompressed is the default value
GregoryTrzonkowski [Wed, 27 Jul 2022 09:43:25 +0000 (11:43 +0200)]
Correction: uncompressed is the default value

CLA: trivial

The description was incorrect. The uncompressed is the default value.

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

21 months agoFix regression from GCM mode refactoring
Tomas Mraz [Thu, 28 Jul 2022 14:23:51 +0000 (16:23 +0200)]
Fix regression from GCM mode refactoring

Fixes #18896

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

21 months agotest_external_oqsprovider: Use working checkout of liboqs
Tomas Mraz [Thu, 28 Jul 2022 09:40:36 +0000 (11:40 +0200)]
test_external_oqsprovider: Use working checkout of liboqs

Fixes #18898

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

21 months agoFix quotes install_fips in Configurations/windows-makefile.tmpl
Richard Levitte [Tue, 26 Jul 2022 17:38:02 +0000 (19:38 +0200)]
Fix quotes install_fips in Configurations/windows-makefile.tmpl

Directories and file names with spaces require quoting...  again

Fixes #18880

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

21 months agoHandle SMIME_crlf_copy return code
Alon Bar-Lev [Tue, 26 Jul 2022 12:17:06 +0000 (15:17 +0300)]
Handle SMIME_crlf_copy return code

Currently the SMIME_crlf_copy result is ignored in all usages. It does
return failure when memory allocation fails.

This patch handles the SMIME_crlf_copy return code in all occurrences.

Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18876)

21 months agoREGRESSION: CMS_final: do not ignore CMS_dataFinal result
Alon Bar-Lev [Tue, 26 Jul 2022 05:53:48 +0000 (08:53 +0300)]
REGRESSION: CMS_final: do not ignore CMS_dataFinal result

The CMS_dataFinal result is important as signature may fail, however, it
is ignored while returning success from CMS_final.

The SMIME_crlf_copy result is returned while it is ignored in the rest
of the openssl code.

Prefer the CMS_dataFinal result.

This is regression from openssl-1.

Blame finds c1669f41ei as root cause of regression.

Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18876)

21 months agoSSL object refactoring using SSL_CONNECTION object
Tomas Mraz [Mon, 20 Jun 2022 15:11:28 +0000 (17:11 +0200)]
SSL object refactoring using SSL_CONNECTION object

Make the SSL object polymorphic based on whether this is
a traditional SSL connection, QUIC connection, or later
to be implemented a QUIC stream.

It requires adding if after every SSL_CONNECTION_FROM_SSL() call
which itself has to be added to almost every public SSL_ API call.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18612)

21 months agoAdd some documentation for the BIO_s_mem() datagram capability
Matt Caswell [Thu, 16 Jun 2022 16:35:30 +0000 (17:35 +0100)]
Add some documentation for the BIO_s_mem() datagram capability

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

21 months agoAdd a test for BIO_s_mem() when using datagrams
Matt Caswell [Thu, 16 Jun 2022 16:30:46 +0000 (17:30 +0100)]
Add a test for BIO_s_mem() when using datagrams

The previous commit added support to BIO_s_mem() for using datagrams. We
now add tests for that functionality.

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

21 months agoGive BIO_s_mem() the ability to support datagrams
Matt Caswell [Thu, 16 Jun 2022 15:08:37 +0000 (16:08 +0100)]
Give BIO_s_mem() the ability to support datagrams

We introduce a new BIO ctrl that switches a BIO_s_mem() into datagram
mode. Packet boundaries are respected.

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

21 months agoUpdate EVP_KDF-X942-ASN1.pod
Joachim Vandersmissen [Tue, 26 Jul 2022 12:33:43 +0000 (12:33 +0000)]
Update EVP_KDF-X942-ASN1.pod

Replaced OSSL_KDF_PARAM_KEY with OSSL_KDF_PARAM_SECRET as that seems to be the intended value from the code (OSSL_KDF_PARAM_KEY is also supported but looks like a fallback).
Fixed name for OSSL_KDF_PARAM_X942_USE_KEYBITS.

CLA: trivial

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18878)