diff options
author | tb <> | 2022-05-05 18:29:34 +0000 |
---|---|---|
committer | tb <> | 2022-05-05 18:29:34 +0000 |
commit | e2b1ff706bb7ee07a20d8b6c0a20b7a36dbdbac4 (patch) | |
tree | 258f59832824a7ff97bca4ce631bdf8cae8bf0c4 /src/lib | |
parent | 84103403c54ab18df3b04c64b3d2007b5664ad62 (diff) | |
download | openbsd-e2b1ff706bb7ee07a20d8b6c0a20b7a36dbdbac4.tar.gz openbsd-e2b1ff706bb7ee07a20d8b6c0a20b7a36dbdbac4.tar.bz2 openbsd-e2b1ff706bb7ee07a20d8b6c0a20b7a36dbdbac4.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/lib')
-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; |