Conversation
de88a89 to
4e74881
Compare
…ests OpenSSL 3.x rejects a NULL pointer passed to EVP_PKEY_CTX_set1_hkdf_salt() even with length 0. Use an empty string "" instead of nullptr when useSalt is false. This works on both OpenSSL 1.1.x and 3.x. Also added version-guard comments to all #if/#else/#endif blocks for clarity. Fixes rdkcentral#75
4e74881 to
610caf8
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes HKDF salt handling in the OpenSSL-backed hkdf() helper used by DH/ECDH key exchange tests so that the no-salt (useSalt=SEC_FALSE) path works on OpenSSL 3.x.
Changes:
- Avoid passing a NULL salt pointer to
EVP_PKEY_CTX_set1_hkdf_salt()by using an empty string pointer with length 0. - Remove the OpenSSL-version conditional around the salt setter call.
- Update the file copyright header year range.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // OpenSSL 3.x OSSL_PARAM_construct_octet_string() rejects NULL data pointer | ||
| // even when length is 0, causing EVP_PKEY_CTX_set1_hkdf_salt() to fail. | ||
| // Pass "" instead of nullptr to satisfy the non-NULL check. | ||
| if (EVP_PKEY_CTX_set1_hkdf_salt(pctx, | ||
| reinterpret_cast<const unsigned char*>(use_salt ? "salt" : ""), | ||
| use_salt ? 4 : 0) <= 0) { |
There was a problem hiding this comment.
The PR description says descriptive comments were added to all remaining #if/#else/#endif blocks, but in this file there are still preprocessor blocks without explanatory comments (e.g., the #if OPENSSL_VERSION_NUMBER >= 0x30000000 around EVP_PKEY_CTX_add1_hkdf_info later in hkdf()). Either update the PR description to match the actual change set, or add the missing comments for consistency.
| // Pass "" instead of nullptr to satisfy the non-NULL check. | ||
| if (EVP_PKEY_CTX_set1_hkdf_salt(pctx, | ||
| reinterpret_cast<const unsigned char*>(use_salt ? "salt" : ""), | ||
| use_salt ? 4 : 0) <= 0) { |
There was a problem hiding this comment.
use_salt ? 4 : 0 hard-codes the length of the string literal "salt". To avoid accidental mismatches if the literal changes (and to mirror common practice elsewhere), prefer deriving the length from the literal (e.g., sizeof("salt") - 1) or a named constant.
| use_salt ? 4 : 0) <= 0) { | |
| use_salt ? sizeof("salt") - 1 : 0) <= 0) { |
Summary
Fix 8 DH/ECDH key exchange test failures on OpenSSL 3.x when
useSalt=SEC_FALSE.Problem
The
hkdf()function inexchange.cpppassesnullptrtoEVP_PKEY_CTX_set1_hkdf_salt()when no salt is used. OpenSSL 3.x rejectsa NULL pointer even with length 0, causing all
testKeyExchangeDHandtestKeyExchangeECDHtests withSEC_FALSEto fail.Fix
Replace
nullptrwith""(empty string) for the no-salt case. This providesa valid non-NULL pointer with length 0, which both OpenSSL 1.1.x and 3.x accept.
The version-specific
#if/#elseguard for this call is no longer needed andhas been removed.
Also added descriptive comments to all remaining
#if/#else/#endifblocks.Testing
Verified 8/8 affected tests pass on:
Fixes #75
Test Results: DH/ECDH Key Exchange (Tests 1193–1207)
Affected Tests
testKeyExchangeDHAES_128SEC_FALSEtestKeyExchangeDHAES_256SEC_FALSEtestKeyExchangeDHHMAC_128SEC_FALSEtestKeyExchangeDHHMAC_256SEC_FALSEtestKeyExchangeECDHAES_128SEC_FALSEtestKeyExchangeECDHAES_256SEC_FALSEtestKeyExchangeECDHHMAC_128SEC_FALSEtestKeyExchangeECDHHMAC_256SEC_FALSEResults Matrix
Without fix (main branch)
With fix (PR #76)