Skip to content

Commit 2a91c3f

Browse files
ColtonWilleypadelsbach
authored andcommitted
Fix NULL salt handling in hkdf to reflect proper version specific behavior
1 parent 935e104 commit 2a91c3f

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/wp_hkdf.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,38 @@
3030
#include <wolfprovider/alg_funcs.h>
3131
#include <wolfprovider/internal.h>
3232

33+
/**
34+
* Define WP_HKDF_NULL_SALT_ALLOWED for OpenSSL versions that allow NULL salt in HKDF.
35+
* Behavior changed at different patch versions for each minor version.
36+
*/
37+
#if OPENSSL_VERSION_MAJOR == 3
38+
#if OPENSSL_VERSION_MINOR == 0
39+
#if OPENSSL_VERSION_PATCH <= 16
40+
#define WP_HKDF_NULL_SALT_ALLOWED
41+
#endif
42+
#elif OPENSSL_VERSION_MINOR == 1
43+
#if OPENSSL_VERSION_PATCH <= 8
44+
#define WP_HKDF_NULL_SALT_ALLOWED
45+
#endif
46+
#elif OPENSSL_VERSION_MINOR == 2
47+
#if OPENSSL_VERSION_PATCH <= 4
48+
#define WP_HKDF_NULL_SALT_ALLOWED
49+
#endif
50+
#elif OPENSSL_VERSION_MINOR == 3
51+
#if OPENSSL_VERSION_PATCH <= 3
52+
#define WP_HKDF_NULL_SALT_ALLOWED
53+
#endif
54+
#elif OPENSSL_VERSION_MINOR == 4
55+
#if OPENSSL_VERSION_PATCH <= 1
56+
#define WP_HKDF_NULL_SALT_ALLOWED
57+
#endif
58+
#elif OPENSSL_VERSION_MINOR == 5
59+
#if OPENSSL_VERSION_PATCH <= 0
60+
#define WP_HKDF_NULL_SALT_ALLOWED
61+
#endif
62+
#endif
63+
#endif
64+
3365
/** Base set of parameters settable against context. */
3466
#define WP_HKDF_BASE_SETTABLES \
3567
OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_MODE, NULL, 0), \
@@ -330,7 +362,11 @@ static int wp_hkdf_base_set_ctx_params(wp_HkdfCtx* ctx,
330362
}
331363
if (ok) {
332364
p = OSSL_PARAM_locate((OSSL_PARAM *)params, OSSL_KDF_PARAM_SALT);
365+
#ifdef WP_HKDF_NULL_SALT_ALLOWED
333366
if ((p != NULL) && (p->data != NULL)) {
367+
#else
368+
if (p != NULL) {
369+
#endif
334370
OPENSSL_free(ctx->salt);
335371
ctx->salt = NULL;
336372
if (!OSSL_PARAM_get_octet_string(

0 commit comments

Comments
 (0)