openssl/providers
Nicky Mouha 56a51b5a1e Update hkdf.c to avoid potentially vulnerable code pattern
The expression "if (a+b>c) a=c-b" is incorrect if "a+b" overflows.
It should be replaced by "if (a>c-b) a=c-b", which avoids the
potential overflow and is much easier to understand.

This pattern is the root cause of CVE-2022-37454, a buffer overflow
vulnerability in the "official" SHA-3 implementation.

It has been confirmed that the addition in
https://github.com/openssl/openssl/blob/master/providers/implementations/kdfs/hkdf.c#L534
cannot overflow. So this is only a minor change proposal to avoid
a potentially vulnerable code pattern and to improve readability.
More information: https://github.com/github/codeql/pull/12036#issuecomment-1466056959

CLA: trivial

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20990)
2023-05-19 12:42:08 +02:00
..
common Declare FIPS option functions in their own header 2023-03-29 09:25:58 +11:00
fips Replaced '{ 0, NULL }' with OSSL_DISPATCH_END in OSSL_DISPATCH arrays 2023-04-21 16:19:11 +02:00
implementations Update hkdf.c to avoid potentially vulnerable code pattern 2023-05-19 12:42:08 +02:00
baseprov.c Replaced '{ 0, NULL }' with OSSL_DISPATCH_END in OSSL_DISPATCH arrays 2023-04-21 16:19:11 +02:00
build.info
decoders.inc Support decode SM2 parameters 2022-08-23 11:08:11 +10:00
defltprov.c Replaced '{ 0, NULL }' with OSSL_DISPATCH_END in OSSL_DISPATCH arrays 2023-04-21 16:19:11 +02:00
encoders.inc
fips-sources.checksums Rationalize FIPS sources 2023-02-08 16:20:55 +01:00
fips.checksum Rationalize FIPS sources 2023-02-08 16:20:55 +01:00
fips.module.sources Rationalize FIPS sources 2023-02-08 16:20:55 +01:00
legacyprov.c Replaced '{ 0, NULL }' with OSSL_DISPATCH_END in OSSL_DISPATCH arrays 2023-04-21 16:19:11 +02:00
nullprov.c Replaced '{ 0, NULL }' with OSSL_DISPATCH_END in OSSL_DISPATCH arrays 2023-04-21 16:19:11 +02:00
prov_running.c
stores.inc Add support for loading root CAs from Windows crypto API 2022-09-14 14:10:18 +01:00