2020-06-17 10:15:27 +02:00
|
|
|
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
|
|
|
|
|
/* SPDX-License-Identifier: Unlicense */
|
2005-04-17 11:37:13 +00:00
|
|
|
/* test pmac/omac/hmac */
|
|
|
|
|
#include <tomcrypt_test.h>
|
|
|
|
|
|
|
|
|
|
int mac_test(void)
|
|
|
|
|
{
|
2006-11-17 14:21:24 +00:00
|
|
|
#ifdef LTC_HMAC
|
2017-02-24 20:50:37 +01:00
|
|
|
DO(hmac_test());
|
2005-04-17 11:37:13 +00:00
|
|
|
#endif
|
2006-11-17 14:21:24 +00:00
|
|
|
#ifdef LTC_PMAC
|
2017-02-24 20:50:37 +01:00
|
|
|
DO(pmac_test());
|
2005-04-17 11:37:13 +00:00
|
|
|
#endif
|
2006-11-17 14:21:24 +00:00
|
|
|
#ifdef LTC_OMAC
|
2017-02-24 20:50:37 +01:00
|
|
|
DO(omac_test());
|
2005-04-17 11:37:13 +00:00
|
|
|
#endif
|
2006-11-17 14:21:24 +00:00
|
|
|
#ifdef LTC_XCBC
|
|
|
|
|
DO(xcbc_test());
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_F9_MODE
|
|
|
|
|
DO(f9_test());
|
|
|
|
|
#endif
|
2007-07-20 17:48:02 +00:00
|
|
|
#ifdef LTC_EAX_MODE
|
2017-02-24 20:50:37 +01:00
|
|
|
DO(eax_test());
|
2005-04-17 11:37:13 +00:00
|
|
|
#endif
|
2012-08-05 01:21:13 +02:00
|
|
|
#ifdef LTC_OCB3_MODE
|
2017-02-24 20:50:37 +01:00
|
|
|
DO(ocb3_test());
|
2012-08-05 01:21:13 +02:00
|
|
|
#endif
|
2007-07-20 17:48:02 +00:00
|
|
|
#ifdef LTC_CCM_MODE
|
2005-04-17 11:37:13 +00:00
|
|
|
DO(ccm_test());
|
|
|
|
|
#endif
|
2007-07-20 17:48:02 +00:00
|
|
|
#ifdef LTC_GCM_MODE
|
2005-04-17 11:37:13 +00:00
|
|
|
DO(gcm_test());
|
|
|
|
|
#endif
|
2007-07-20 17:48:02 +00:00
|
|
|
#ifdef LTC_PELICAN
|
2005-04-17 11:37:13 +00:00
|
|
|
DO(pelican_test());
|
2017-03-21 19:42:54 +01:00
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_POLY1305
|
|
|
|
|
DO(poly1305_test());
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_CHACHA20POLY1305_MODE
|
|
|
|
|
DO(chacha20poly1305_test());
|
2017-04-21 15:50:47 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_BLAKE2SMAC
|
|
|
|
|
DO(blake2smac_test());
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_BLAKE2BMAC
|
|
|
|
|
DO(blake2bmac_test());
|
2017-10-25 15:44:41 +02:00
|
|
|
#endif
|
2026-05-06 16:11:45 +02:00
|
|
|
#ifdef LTC_KMAC
|
|
|
|
|
DO(kmac_test());
|
|
|
|
|
#endif
|
2017-10-25 15:44:41 +02:00
|
|
|
#ifdef LTC_SIV_MODE
|
|
|
|
|
DO(siv_test());
|
Add Project Wycheproof testvectors for SIV.
Gemini proposed this to convert
```
import json
import requests
def to_c_hex(hex_str):
if not hex_str: return "NULL"
bytes_list = [f"0x{hex_str[i:i+2]}" for i in range(0, len(hex_str), 2)]
return "{" + ",".join(bytes_list) + "}"
url = "https://raw.githubusercontent.com/C2SP/wycheproof/main/testvectors_v1/aes_siv_cmac_test.json"
data = requests.get(url).json()
print("#include <stdint.h>\n#include <stddef.h>\n")
print("typedef struct { int tcId; const char* comment; uint8_t key[64]; size_t keyLen; const uint8_t* aad; size_t aadLen; const uint8_t* msg; size_t msgLen; const uint8_t* ct; size_t ctLen; const char* result; } aes_siv_test_case;\n")
for group in data['testGroups']:
for test in group['tests']:
tid = test['tcId']
if test['aad']: print(f"static const uint8_t aad_{tid}[] = {to_c_hex(test['aad'])};")
if test['msg']: print(f"static const uint8_t msg_{tid}[] = {to_c_hex(test['msg'])};")
if test['ct']: print(f"static const uint8_t ct_{tid}[] = {to_c_hex(test['ct'])};")
print("\nstatic const aes_siv_test_case aes_siv_tests[] = {")
for group in data['testGroups']:
for test in group['tests']:
tid = test['tcId']
key_hex = to_c_hex(test['key'])
aad_ptr = f"aad_{tid}" if test['aad'] else "NULL"
msg_ptr = f"msg_{tid}" if test['msg'] else "NULL"
ct_ptr = f"ct_{tid}" if test['ct'] else "NULL"
print(f" {{ {tid}, \"{test['comment']}\", {key_hex}, {len(test['key'])//2}, {aad_ptr}, {len(test['aad'])//2}, {msg_ptr}, {len(test['msg'])//2}, {ct_ptr}, {len(test['ct'])//2}, \"{test['result']}\" }},")
print("};")
```
I manually modified the result type to be an enum.
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2026-04-23 09:23:11 +02:00
|
|
|
DO(siv_wycheproof_test());
|
2026-05-03 09:40:06 +02:00
|
|
|
#endif
|
|
|
|
|
#ifdef LTC_GCM_SIV_MODE
|
|
|
|
|
DO(gcm_siv_test());
|
2005-04-17 11:37:13 +00:00
|
|
|
#endif
|
|
|
|
|
return 0;
|
|
|
|
|
}
|