mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-10-24 04:09:07 +03:00
wc_HmacInit_Id and wc_HmacInit_Label name a key held by a crypto callback device, and the caller keys the Hmac with wc_HmacSetKey(NULL, 0). Two things lost that key. Keying the Hmac again, for a new MAC or another hash, frees it first, and wc_HmacFree zeroes the whole struct. Only devId was put back, so the id and label were gone and the device got a key with no name and no bytes. Restore the id and label as well, as devId is. When the device declined an update or final, the software path ran with the empty key from wc_HmacSetKey(NULL, 0) and returned a MAC under it. Return MISSING_KEY instead when the Hmac is named by id or label and has no key bytes, as AES does for a key held on a device. An Hmac named by id that was given key bytes still uses them. A build with PK callbacks but no crypto callbacks also has wc_HmacInit_Id, but no device to hold the key and no keyRaw to tell, so the check is left out there. The check uses keyRaw, which is NULL only after wc_HmacSetKey(NULL, 0). keyLen keeps only the low 16 bits of the length, so it reads 0 for a key of 64 KiB. PKCS#11 declined every such key on a token that reports a minimum HMAC key size, because it checked hmac->keyLen, which is 0 when the key is on the token. Check the length only for a key passed in from software; C_SignInit checks the token key. test_wc_HmacId_CryptoCb keys an Hmac from wc_HmacInit_Id twice and checks that the device still sees the id, then that a declined update and final return MISSING_KEY. It also checks that a label survives a second wc_HmacSetKey. test_wc_HmacId_NoDevice checks that an Hmac named by id MACs with key bytes it is given, in builds with or without crypto callbacks, also with a 64 KiB key, and that one without key bytes gets MISSING_KEY when no device takes it.
83 lines
3.4 KiB
C
83 lines
3.4 KiB
C
/* test_hmac.h
|
|
*
|
|
* Copyright (C) 2006-2026 wolfSSL Inc.
|
|
*
|
|
* This file is part of wolfSSL.
|
|
*
|
|
* wolfSSL is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* wolfSSL is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
|
*/
|
|
|
|
#ifndef WOLFCRYPT_TEST_HMAC_H
|
|
#define WOLFCRYPT_TEST_HMAC_H
|
|
|
|
#include <tests/api/api_decl.h>
|
|
|
|
int test_wc_Md5HmacSetKey(void);
|
|
int test_wc_Md5HmacUpdate(void);
|
|
int test_wc_Md5HmacFinal(void);
|
|
int test_wc_ShaHmacSetKey(void);
|
|
int test_wc_ShaHmacUpdate(void);
|
|
int test_wc_ShaHmacFinal(void);
|
|
int test_wc_Sha224HmacSetKey(void);
|
|
int test_wc_Sha224HmacUpdate(void);
|
|
int test_wc_Sha224HmacFinal(void);
|
|
int test_wc_Sha256HmacSetKey(void);
|
|
int test_wc_Sha256HmacUpdate(void);
|
|
int test_wc_Sha256HmacFinal(void);
|
|
int test_wc_Sha384HmacSetKey(void);
|
|
int test_wc_Sha384HmacUpdate(void);
|
|
int test_wc_Sha384HmacFinal(void);
|
|
int test_tls_hmac_size_overflow(void);
|
|
int test_tls_timing_pad_verify_hmac_len(void);
|
|
int test_wc_HmacSizeByType(void);
|
|
int test_wc_HmacCopy(void);
|
|
int test_wc_HmacInit_Id(void);
|
|
int test_wc_HmacInit_Label(void);
|
|
int test_wc_HmacFree_CryptoCb(void);
|
|
int test_wc_HmacId_CryptoCb(void);
|
|
int test_wc_HmacId_NoDevice(void);
|
|
int test_wc_HKDF_NullKeyEdgeCases(void);
|
|
int test_wc_Tls13_HKDF_Extract_ZeroLenIkm(void);
|
|
|
|
#define TEST_HMAC_DECLS \
|
|
TEST_DECL_GROUP("hmac", test_wc_Md5HmacSetKey), \
|
|
TEST_DECL_GROUP("hmac", test_wc_Md5HmacUpdate), \
|
|
TEST_DECL_GROUP("hmac", test_wc_Md5HmacFinal), \
|
|
TEST_DECL_GROUP("hmac", test_wc_ShaHmacSetKey), \
|
|
TEST_DECL_GROUP("hmac", test_wc_ShaHmacUpdate), \
|
|
TEST_DECL_GROUP("hmac", test_wc_ShaHmacFinal), \
|
|
TEST_DECL_GROUP("hmac", test_wc_Sha224HmacSetKey), \
|
|
TEST_DECL_GROUP("hmac", test_wc_Sha224HmacUpdate), \
|
|
TEST_DECL_GROUP("hmac", test_wc_Sha224HmacFinal), \
|
|
TEST_DECL_GROUP("hmac", test_wc_Sha256HmacSetKey), \
|
|
TEST_DECL_GROUP("hmac", test_wc_Sha256HmacUpdate), \
|
|
TEST_DECL_GROUP("hmac", test_wc_Sha256HmacFinal), \
|
|
TEST_DECL_GROUP("hmac", test_wc_Sha384HmacSetKey), \
|
|
TEST_DECL_GROUP("hmac", test_wc_Sha384HmacUpdate), \
|
|
TEST_DECL_GROUP("hmac", test_wc_Sha384HmacFinal), \
|
|
TEST_DECL_GROUP("hmac", test_tls_hmac_size_overflow), \
|
|
TEST_DECL_GROUP("hmac", test_tls_timing_pad_verify_hmac_len), \
|
|
TEST_DECL_GROUP("hmac", test_wc_HmacSizeByType), \
|
|
TEST_DECL_GROUP("hmac", test_wc_HmacCopy), \
|
|
TEST_DECL_GROUP("hmac", test_wc_HmacInit_Id), \
|
|
TEST_DECL_GROUP("hmac", test_wc_HmacInit_Label), \
|
|
TEST_DECL_GROUP("hmac", test_wc_HmacFree_CryptoCb), \
|
|
TEST_DECL_GROUP("hmac", test_wc_HmacId_CryptoCb), \
|
|
TEST_DECL_GROUP("hmac", test_wc_HmacId_NoDevice), \
|
|
TEST_DECL_GROUP("hmac", test_wc_HKDF_NullKeyEdgeCases), \
|
|
TEST_DECL_GROUP("hmac", test_wc_Tls13_HKDF_Extract_ZeroLenIkm)
|
|
|
|
#endif /* WOLFCRYPT_TEST_HMAC_H */
|