test/core/crypto/wycheproof: Update the tests to match recent changes

This needs to be merged before I can bump the wycheproof assets.
This commit is contained in:
Yawning Angel
2026-06-25 13:59:43 +09:00
parent 6fdaedf182
commit 83940eadfe
3 changed files with 34 additions and 13 deletions

View File

@@ -73,7 +73,7 @@ import "core:testing"
// - crypto/legacy/md5
// - crypto/tuplehash
ARENA_SIZE :: 4 * 1024 * 1024 // There is no kill like overkill.
ARENA_SIZE :: 8 * 1024 * 1024 // There is no kill like overkill.
BASE_PATH :: ODIN_ROOT + "tests/core/assets/Wycheproof"
SUFFIX_TEST_JSON :: "_test.json"

View File

@@ -494,6 +494,7 @@ test_mldsa :: proc(t: ^testing.T) {
test_mldsa_sign :: proc(t: ^testing.T, test_vectors: ^Test_Vectors(Mldsa_Test_Group)) -> bool {
FLAG_INTERNAL :: "Internal"
FLAG_RANDOMIZED :: "Randomized"
dummy_rnd: [_mldsa.RNDBYTES]byte
@@ -511,17 +512,31 @@ test_mldsa_sign :: proc(t: ^testing.T, test_vectors: ^Test_Vectors(Mldsa_Test_Gr
priv_key: mldsa.Private_Key
tg_len := len(test_group.tests)
if !testing.expectf(
t,
mldsa.private_key_set_bytes(&priv_key, params, seed),
"%s/Sign/%d: failed to set private key from seed: %s",
params_str,
tg_id,
test_group.private_seed,
) {
num_ran += tg_len
num_failed += tg_len
switch len(test_group.public_key) {
case 0:
for &test_vector in test_group.tests {
num_ran += 1
switch result_is_invalid(test_vector.result) {
case true:
num_passed += 1
case false:
num_failed += 1
}
}
continue
case:
if !testing.expectf(
t,
mldsa.private_key_set_bytes(&priv_key, params, seed),
"%s/Sign/%d: failed to set private key from seed: %s",
params_str,
tg_id,
test_group.private_seed,
) {
num_ran += tg_len
num_failed += tg_len
continue
}
}
pub_bytes := make([]byte, mldsa.PUBLIC_KEY_SIZES[params])
@@ -575,7 +590,7 @@ test_mldsa_sign :: proc(t: ^testing.T, test_vectors: ^Test_Vectors(Mldsa_Test_Gr
ctx := common.hexbytes_decode(test_vector.ctx)
msg := common.hexbytes_decode(test_vector.msg)
is_external_mu := slice.contains(test_vector.flags, FLAG_INTERNAL)
is_external_mu := slice.contains(test_vector.flags, FLAG_INTERNAL) || slice.contains(test_vector.flags, FLAG_RANDOMIZED)
switch is_external_mu {
case false:
ok = mldsa.sign(
@@ -586,11 +601,16 @@ test_mldsa_sign :: proc(t: ^testing.T, test_vectors: ^Test_Vectors(Mldsa_Test_Gr
true,
)
case true:
rnd := dummy_rnd[:]
if len(test_vector.rnd) != 0 {
rnd = common.hexbytes_decode(test_vector.rnd)
}
ok = _mldsa.dsa_sign_internal(
sig,
msg,
ctx,
dummy_rnd[:],
rnd,
&priv_key,
common.hexbytes_decode(test_vector.mu),
)

View File

@@ -234,6 +234,7 @@ Mldsa_Test_Vector :: struct {
tc_id: int `json:"tcId"`,
comment: string `json:"comment"`,
msg: common.Hex_Bytes `json:"msg"`,
rnd: common.Hex_Bytes `json:"rnd"`,
ctx: common.Hex_Bytes `json:"ctx"`,
mu: common.Hex_Bytes `json:"mu"`,
sig: common.Hex_Bytes `json:"sig"`,