mirror of
https://github.com/libtom/libtomcrypt
synced 2026-08-25 20:26:07 -04:00
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>
|
||
|---|---|---|
| .. | ||
| asn1 | ||
| pem | ||
| rsa | ||
| rsa-pkcs8 | ||
| argon2_test.c | ||
| base16_test.c | ||
| base32_test.c | ||
| base64_test.c | ||
| bcrypt_test.c | ||
| cipher_hash_test.c | ||
| CMakeLists.txt | ||
| common.c | ||
| common.h | ||
| deprecated_test.c | ||
| der_test.c | ||
| dh_test.c | ||
| dsa_test.c | ||
| ecc_test.c | ||
| ed25519_test.c | ||
| file_test.c | ||
| mac_test.c | ||
| misc_test.c | ||
| modes_test.c | ||
| mpi_test.c | ||
| multi_test.c | ||
| no_null_termination_check_test.c | ||
| no_prng.c | ||
| padding_test.c | ||
| pem_test.c | ||
| pk_oid_test.c | ||
| pkcs_1_eme_test.c | ||
| pkcs_1_emsa_test.c | ||
| pkcs_1_oaep_test.c | ||
| pkcs_1_pss_test.c | ||
| pkcs_1_test.c | ||
| prng_test.c | ||
| rotate_test.c | ||
| rsa_test.c | ||
| scrypt_test.c | ||
| siv_wycheproof.h | ||
| siv_wycheproof_test.c | ||
| sources.cmake | ||
| ssh_test.c | ||
| store_test.c | ||
| test.c | ||
| test.der | ||
| test.key | ||
| test_dsa.key | ||
| tomcrypt_test.h | ||
| x25519_test.c | ||