diff options
| author | tb <> | 2022-05-05 18:29:34 +0000 |
|---|---|---|
| committer | tb <> | 2022-05-05 18:29:34 +0000 |
| commit | 5ca6164aa9bf6ef7aa404bf1f75a806912d87c26 (patch) | |
| tree | 258f59832824a7ff97bca4ce631bdf8cae8bf0c4 /src | |
| parent | 14561e7c4537eee9ff1f86cc079c74e822b7b9e0 (diff) | |
| download | openbsd-5ca6164aa9bf6ef7aa404bf1f75a806912d87c26.tar.gz openbsd-5ca6164aa9bf6ef7aa404bf1f75a806912d87c26.tar.bz2 openbsd-5ca6164aa9bf6ef7aa404bf1f75a806912d87c26.zip | |
Fix HMAC() with NULL key
If a NULL key is passed to HMAC_Init_ex(), it tries to reuse the
previous key. This makes no sense inside HMAC() since the HMAC_CTX
has no key set yet. This is hit by HKDF() with NULL salt() via the
EVP API and results in a few Wycheproof test failures. If key is
NULL, use a zero length dummy key.
This was not hit from wycheproof.go since we pass a []byte with a
single NUL from Go.
Matches OpenSSL if key is NULL and key_len is 0. If key_len != 0,
OpenSSL will still fail by passing a NULL key which makes no sense,
so set key_len to 0 instead.
ok beck jsing
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/hmac/hmac.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/lib/libcrypto/hmac/hmac.c b/src/lib/libcrypto/hmac/hmac.c index 55989988ad..3421119b7e 100644 --- a/src/lib/libcrypto/hmac/hmac.c +++ b/src/lib/libcrypto/hmac/hmac.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: hmac.c,v 1.27 2021/12/12 21:30:14 tb Exp $ */ | 1 | /* $OpenBSD: hmac.c,v 1.28 2022/05/05 18:29:34 tb Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -261,11 +261,16 @@ HMAC(const EVP_MD *evp_md, const void *key, int key_len, const unsigned char *d, | |||
| 261 | { | 261 | { |
| 262 | HMAC_CTX c; | 262 | HMAC_CTX c; |
| 263 | static unsigned char m[EVP_MAX_MD_SIZE]; | 263 | static unsigned char m[EVP_MAX_MD_SIZE]; |
| 264 | const unsigned char dummy_key[1] = { 0 }; | ||
| 264 | 265 | ||
| 265 | if (md == NULL) | 266 | if (md == NULL) |
| 266 | md = m; | 267 | md = m; |
| 268 | if (key == NULL) { | ||
| 269 | key = dummy_key; | ||
| 270 | key_len = 0; | ||
| 271 | } | ||
| 267 | HMAC_CTX_init(&c); | 272 | HMAC_CTX_init(&c); |
| 268 | if (!HMAC_Init(&c, key, key_len, evp_md)) | 273 | if (!HMAC_Init_ex(&c, key, key_len, evp_md, NULL)) |
| 269 | goto err; | 274 | goto err; |
| 270 | if (!HMAC_Update(&c, d, n)) | 275 | if (!HMAC_Update(&c, d, n)) |
| 271 | goto err; | 276 | goto err; |
