Skip to content

[WIP] Openssl 111 features - #11900

Closed
bernd-edlinger wants to merge 78 commits into
openssl:OpenSSL_1_1_1-stablefrom
bernd-edlinger:openssl-111-features
Closed

bernd-edlinger wants to merge 78 commits into
openssl:OpenSSL_1_1_1-stablefrom
bernd-edlinger:openssl-111-features

Conversation

@bernd-edlinger

@bernd-edlinger bernd-edlinger commented May 21, 2020 •

Copy link
Copy Markdown
Member

@bernd-edlinger bernd-edlinger added the branch: 1.1.1 Applies to OpenSSL_1_1_1-stable branch (EOL) label May 21, 2020
@bernd-edlinger
bernd-edlinger force-pushed the openssl-111-features branch 4 times, most recently from 91b364d to 7de3879 Compare May 25, 2020 21:16
@bernd-edlinger
bernd-edlinger force-pushed the openssl-111-features branch from 4b2b6a4 to 941a114 Compare May 29, 2020 15:15
@bernd-edlinger
bernd-edlinger force-pushed the openssl-111-features branch 2 times, most recently from 4fc29cf to a578a17 Compare June 7, 2020 15:08
@bernd-edlinger

Copy link
Copy Markdown
Member Author

Some openssl speed results follow :-)
Summary: The AES speed is much higher with this PR, while HMAC speed is much slower in master.

This PR:

OpenSSL 1.1.1j-dev  xx XXX xxxx
built on: Tue Feb  2 15:12:39 2021 UTC
options:bn(64,64) rc4(8x,int) des(int) aes(partial) idea(int) blowfish(ptr) 
compiler: gcc -fPIC -pthread -m64 -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE -DL_ENDIAN
 -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT
 -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM
 -DKECCAK1600_ASM -DRC4_ASM -DMD5_ASM -DAESNI_ASM -DVPAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM
 -DX25519_ASM -DPOLY1305_ASM -DNDEBUG
CPUINFO: OPENSSL_ia32cap=0x3e983a0b078bffff:0x8
The 'numbers' are in 1000s of bytes per second processed.
type             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes  16384 bytes
hmac(md5)        16624.98k    48422.63k   129789.95k   218423.98k   272373.08k   241893.38k
aes-128 cbc     205035.68k   214994.01k   235380.27k   239841.96k   241369.09k   241325.40k
aes-192 cbc     182248.97k   182586.75k   197160.28k   200586.24k   201648.81k   201758.04k
aes-256 cbc     158688.05k   159745.43k   170027.52k   172667.56k   173509.29k   173533.87k

1.1.1 :

OpenSSL 1.1.1j-dev  xx XXX xxxx
built on: Tue Feb  2 14:44:59 2021 UTC
options:bn(64,64) rc4(8x,int) des(int) aes(partial) idea(int) blowfish(ptr) 
compiler: gcc -fPIC -pthread -m64 -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE
 -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT
 -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM
 -DKECCAK1600_ASM -DRC4_ASM -DMD5_ASM -DAESNI_ASM -DVPAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM
 -DX25519_ASM -DPOLY1305_ASM -DNDEBUG
The 'numbers' are in 1000s of bytes per second processed.
type             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes  16384 bytes
hmac(md5)        15504.83k    46094.08k   125609.98k   213659.31k   270592.68k   252160.68k
aes-128 cbc      36293.51k    38649.39k    39906.90k    92897.96k    94401.88k    94546.60k
aes-192 cbc      30687.49k    32379.39k    33132.03k    79068.84k    79951.19k    79839.23k
aes-256 cbc      26539.78k    27727.89k    28413.87k    68765.01k    69186.90k    69216.94k

master:

version: 3.0.0-alpha12-dev
built on: built on: Tue Feb  2 13:28:43 2021 UTC
options:bn(64,64) rc4(8x,int) des(int) aes(partial) idea(int) blowfish(ptr) 
compiler: gcc -fPIC -pthread -m64 -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE
 -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_BUILDING_OPENSSL -DNDEBUG
CPUINFO: OPENSSL_ia32cap=0x3e983a0b078bffff:0x8
The 'numbers' are in 1000s of bytes per second processed.
type             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes  16384 bytes
hmac(md5)        11394.15k    36440.09k   103444.14k   188451.84k   262482.60k   246786.73k
aes-128 cbc      36293.51k    38649.39k    39906.90k    92897.96k    94401.88k    94546.60k
aes-192 cbc      30687.49k    32379.39k    33132.03k    79068.84k    79951.19k    79839.23k
aes-256 cbc      26539.78k    27727.89k    28413.87k    68765.01k    69186.90k    69216.94k

@bernd-edlinger
bernd-edlinger force-pushed the openssl-111-features branch from d25c445 to 657625e Compare June 3, 2021 07:39
@t8m t8m added triaged: bug The issue/pr is/fixes a bug triaged: feature The issue/pr requests/adds a feature and removed triaged: bug The issue/pr is/fixes a bug labels Aug 4, 2021
paulidale
paulidale previously approved these changes Aug 23, 2021
@paulidale
paulidale dismissed their stale review August 23, 2021 09:47

wrong PR :(

@bernd-edlinger
bernd-edlinger force-pushed the openssl-111-features branch 7 times, most recently from e2598db to 32f8869 Compare August 25, 2021 15:52
bernd-edlinger and others added 29 commits September 12, 2023 15:23
Fixes openssl#20693

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Tom Cosgrove <[email protected]>
(Merged from openssl#20708)

(cherry picked from commit efbff4d)
Fixes openssl#20268

Values such as q=1 or priv=0 caused infinite loops when calling
DSA_sign() without these changes.

There are other cases where bad domain parameters may have caused
infinite loops where the retry counter has been added. The simpler case
of priv=0 also hits this case. q=1 caused an infinite loop in the setup.

The max retry value has been set to an arbitrary value of 8 (it is
unlikely to ever do a single retry for valid values).

The minimum q bits was set to an arbitrary value of 128 (160 is still
used for legacy reasons when using 512 bit keys).

Thanks @guidovranken for detecting this, and @davidben for his
insightful analysis.

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from openssl#20384)

(cherry picked from commit 3a4e09a)
Similiar checks to the DSA code have been added for ECDSA also.
This should not be a problem when using named groups.

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from openssl#20384)

(cherry picked from commit 5f820bd)
(cherry picked from commit 2022b9e)
Similiar to the issue found in PR openssl#20553 for DSA_sign().
ECDSA_sign() leaked memory if the signature was NULL
when i2d_ECDSA_SIG was called.

Note that this does not affect the higher level EVP
functions as they correctly handle NULL.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from openssl#20554)

(cherry picked from commit 4befe81)
(cherry picked from commit 680b4be)
Related to openssl#20268

DSA_sign() assumes that the signature passed in is related to DSA_size().
If q is negative then DSA_size() actually fails and returns 0.

A test that tries to allocate the signature buffer using DSA_size() and then
pass it to DSA_sign() will then either.

(1) Have a signature buffer of NULL. In this case it was leaking data
returned via i2d_DSA_SIG.

(2) Cause a seg fault because we created a buffer that was not large
enough to hold the signature. As it already checked zero we also now
check for negative values also.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from openssl#20553)

(cherry picked from commit 9559ad0)
(cherry picked from commit ce90b5e)
macos-10.15 is no longer working,
add macos-12 instead.
"./config -DSSL3_ALIGN_PAYLOAD=0" used to work
before 1.1.1 but is now broken.
This patch fixes it again.
Clang 16 will be released shortly (beginning of March).

Signed-off-by: Sam James <[email protected]>

Reviewed-by: Hugo Landau <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from openssl#20346)

(cherry picked from commit 6de73f5)
This doubles the performance of curve448
with certain fully 64-bit capable compilers.
This saves one unnecessary AES key derivation per RAND_bytes call.
The ECB cipher is already set up here, and quite simple to use
if exactly one AES block output is needed.

This saves one additioal AES_set_encrypt_key call if RAND_bytes
is used to derive exactly 16 bytes.
The additional data value in rand_unix.c is 24 bytes on
x86_64-linux-gnu, due to structure alignment, while the
raw data values contain only 20 bytes.

Unfortunately this makes the ctr_df function use another
AES encyption round.

However the padding bytes are just filled with zero bytes
and do not add any security at all.

Therefore we use the raw data values, and not a C structure
with additional alignment bytes.  This makes the size of the
additional data value usually 4 bytes smaller, and saves
another 3 AES encryption operations each time the RAND_bytes
function is called.
TLS pipelining provides the ability for libssl to read or write multiple
records in parallel. It requires special ciphers to do this, and there are
currently no built-in ciphers that provide this capability. However, the
dasync engine does have such a cipher, so we add a test for this capability
using that engine.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Hugo Landau <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from openssl#20208)

(cherry picked from commit 24c7d36)
…lled

The pipeline input/output buf arrays must remain accessible to the
EVP_CIPHER_CTX until EVP_Cipher is subsequently called. This fixes an
asan error discovered by the newly added pipeline test.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Hugo Landau <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from openssl#20208)

(cherry picked from commit df9c7ce)
During read pipelining we must ensure that the buffer is sufficiently large
to read enough data to fill our pipelines. We also remove some code that
moved data to the start of the packet if we can. This was unnecessary
because of later code which would end up moving it anyway. The earlier move
was also incorrect in the case that |clearold| was 0. This would cause the
read pipelining code to fail with sufficiently large records.

Fixes openssl#20197

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Hugo Landau <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from openssl#20208)

(cherry picked from commit 1d06598)
We shouldn't be putting more data into a pipeline than the value of
split_send_fragment.

This is a backport of a fix which was included in a much larger commit in
master (c618679) related to moving the pipelining code into the new
record layer that exists there.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Hugo Landau <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from openssl#20208)

(cherry picked from commit 2c4b1c7)
With short messages the last pipeline buffer may be
empty, which happens in the pipelining test case.
Therefore the BIO_write returns 0, which is treated
as an error. Instead of treating that as a good result,
avoid the call to BIO_write completely.
when using write pipelines it is possible that there is not
enough data to fill all write buffers. In that case it is
pssible that empty write buffers are left at the end. However
RECORD_LAYER_write_pending did not handle that case properly.
That may cause data loss after a partial write, due to the
wrong result, because ssl3_write_pending will not be called,
and thus the pending data will be lost.

Fixes: openssl#21461
Test various scenarios for a write retry occuring during a handshake.

Reviewed-by: Dmitry Belyavskiy <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from openssl#21435)

(cherry picked from commit d6179e6)
A BIO is documented to return -1 on write retry - but sometimes they return
0. ssl3_do_write() was incorrectly handling a 0 response.

Fixes openssl#21422

Reviewed-by: Dmitry Belyavskiy <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from openssl#21435)

(cherry picked from commit 034ea1d)
When an early error happens in the test_pipelining
function and idx == 5 the error handling would try
to call OPENSSL_free(msg), but msg is at that time
just a string constant in read-only memory, so a
crash would be the result. Fixed that by using
fragsize as an indication when to free msg.

Reviewed-by: Tom Cosgrove <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#21512)

(cherry picked from commit 06a0d40)
Signed-off-by: Sam James <[email protected]>

Reviewed-by: Tom Cosgrove <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from openssl#20961)

(cherry picked from commit 5d16169)
for consistency with commit ee60a49 ("Bump actions/checkout from 2 to 4")
In the error handling case the memory in
vb->users_pwd was accidentally not released.

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#21981)

(cherry picked from commit 68e95f7)
when used in conjunction with -out and -modulus options.

Fixes openssl#21403
@t8m

t8m commented Sep 13, 2023

Copy link
Copy Markdown
Member

@bernd-edlinger Given the 1.1.1 EOL I am going to close this PR.

People can still get the patches from:
https://github.com/bernd-edlinger/openssl/tree/openssl-111-features
if interested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

branch: 1.1.1 Applies to OpenSSL_1_1_1-stable branch (EOL) triaged: feature The issue/pr requests/adds a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants