Bug 2160733

Summary: In FIPS mode, openssl KDFs should only allow selected hash algorithms
Product: Red Hat Enterprise Linux 9 Reporter: Clemens Lang <cllang>
Component: opensslAssignee: Clemens Lang <cllang>
Status: CLOSED ERRATA QA Contact: Alicja Kario <hkario>
Severity: high Docs Contact:
Priority: high    
Version: 9.0CC: cllang, dbelyavs, hkario, ssorce
Target Milestone: rcKeywords: Triaged, ZStream
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: openssl-3.0.7-17.el9 Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of:
: 2175860 2175861 2175862 (view as bug list) Environment:
Last Closed: 2023-11-07 08:52:59 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2175860, 2175861, 2175862    
Attachments:
Description Flags
Reproducer for arbitrary KDFs
none
Reproducer for arbitrary KDFs (now queries indicator after EVP_KDF_derive and supports PBKDF2)
none
Reproducer for arbitrary KDFs (now queries indicator after EVP_KDF_derive and supports PBKDF2, TLS1PRF, TLS13KDF) none

Description Clemens Lang 2023-01-13 14:12:50 UTC
Created attachment 1937800 [details]
Reproducer for arbitrary KDFs

Description of problem:

OpenSSL implements various KDFs that are available in FIPS mode:
 - KBKDF (https://www.openssl.org/docs/man3.0/man7/EVP_KDF-KB.html)
 - HKDF (https://www.openssl.org/docs/man3.0/man7/EVP_KDF-HKDF.html)
 - SSHKDF (https://www.openssl.org/docs/man3.0/man7/EVP_KDF-SSHKDF.html)
 - SSKDF (https://www.openssl.org/docs/man3.0/man7/EVP_KDF-SS.html)
   - in H(x) = hash(x, digest=md) mode
   - in H(x) = HMAC_hash(x, key=salt, digest=md) mode
   - in H(x) = KMACxxx(x, key=salt, custom="KDF", outlen=mac_size) mode
 - X9.63 KDF (https://www.openssl.org/docs/man3.0/man7/EVP_KDF-X963.html), implemented together with SSKDF
 - X9.42 KDF (https://www.openssl.org/docs/manmaster/man7/EVP_KDF-X942-ASN1.html)
 - TLS1PRF (https://www.openssl.org/docs/man3.0/man7/EVP_KDF-TLS1_PRF.html)
 - TLS1.3PRF (https://www.openssl.org/docs/man3.0/man7/EVP_KDF-TLS13_KDF.html)

Most of these KDFs (with the exception of SSKDF in KMAC mode) use hash functions. Not all hash functions are acceptable for FIPS according to our lab.

Specifically, we need to place the following restrictions:

 - TLS1PRF: SHA-256, SHA-384, and SHA-512 only
 - X9.42, X9.63, and SSHKDF: SHA-1, SHA-224, SHA-256, SHA-384, and SHA-512 only

We should also reconfirm what restrictions are required for HKDF, SSKDF, and TLS1.3PRF, if any.


Version-Release number of selected component (if applicable):
openssl-libs-3.0.1-44.el9_0.1.x86_64

How reproducible:
Run the attached reproducer with algorithms that should not be supported (e.g., SHAKE128/SHAKE256)

Steps to Reproduce:
1. head -1 kdf2.c | sed -E 's#^// ##g'
2. ./kdf2 SSHKDF SHAKE128 "" 14 14 14 32
3. ./kdf2 SSKDF SHAKE128 "" 14 14 14 32
4. ./kdf2 X963KDF SHAKE256 "" 14 14 14 32
5. ./kdf2 X942KDF-ASN1 SHAKE128 AES-128-WRAP 14 14 14 32

Actual results:
Use of SHAKE128 works

Expected results:
THese calls fail

Additional info:
Restrictions are specified in FIPS 140-3 IG C.C, SP 800-135r1 5.2, SP 800-135r1 4.2, and other sections of SP 800-135r1.

Comment 3 Clemens Lang 2023-01-17 18:49:10 UTC
As a clarification:

- for X9.63 KDF, SHA-1 is not approved, i.e. SHA-224, SHA-256, SHA-384, and SHA-512 only
- KBKDF: all except SHAKE
- HKDF: all except SHAKE
- SSKDF: all except SHAKE
- TLS1.3PRF: SHA-256 and SHA-384 only

Comment 4 Clemens Lang 2023-02-13 09:00:51 UTC
Further clarification from NIST is available that says FIPS 180-4 or FIPS 202 hash functions are permissible where FIPS 180-3 is referenced, and can be vendor-affirmed where testing by ACVP is not yet available.
This means that the only limitations now are on hash functions approved for specific applications (TLS1PRF, TLS1.3PRF, SSHKDF) and on the use of SHAKE. In summary:

- X9.63, X9.42, KBKDF, HKDF, SSKDF: all except SHAKE
- TLS1PRF: SHA-256, SHA-384, and SHA-512 only
- TLS1.3PRF: SHA-256 and SHA-384 only
- SSHKDF: SHA-1, SHA-224, SHA-256, SHA-384, and SHA-512 only

Comment 5 Clemens Lang 2023-02-17 13:21:04 UTC
Created attachment 1944757 [details]
Reproducer for arbitrary KDFs (now queries indicator after EVP_KDF_derive and supports PBKDF2)

Comment 6 Clemens Lang 2023-02-21 09:05:21 UTC
Further further clarification from the lab and NIST (https://github.com/usnistgov/ACVP/issues/1403#issuecomment-1435300395) now says that SHA-1 in X9.63 is not approved, but the same implementation with a different order of fields that are concatenated to be hashed is SSKDF are approved, so X9.63 needs to set the indicator to unapproved when SHA-1 is used.

Comment 11 Clemens Lang 2023-03-16 14:11:56 UTC
Created attachment 1951291 [details]
Reproducer for arbitrary KDFs (now queries indicator after EVP_KDF_derive and supports PBKDF2, TLS1PRF, TLS13KDF)

Comment 20 errata-xmlrpc 2023-11-07 08:52:59 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (openssl bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2023:6627