5 #include "sw/device/silicon_creator/lib/sigverify/sphincsplus/verify.h"
10 #include "sw/device/lib/base/status.h"
13 #include "sw/device/lib/testing/profile.h"
14 #include "sw/device/lib/testing/test_framework/check.h"
21 #include "sphincsplus_testvectors.h"
24 static uint32_t test_index = 0;
26 OTTF_DEFINE_TEST_CONFIG();
33 kNumNegativeTests = 1,
44 static rom_error_t run_verify(
const spx_verify_test_vector_t *
test,
45 uint32_t *root, uint32_t *pub_root) {
47 spx_public_key_root(
test->pk, pub_root);
50 uint64_t t_start = profile_start();
51 rom_error_t err = spx_verify(
test->sig, NULL, 0, NULL, 0, NULL, 0,
test->msg,
53 uint32_t cycles = profile_end(t_start);
54 LOG_INFO(
"Verification took %u cycles.", cycles);
65 static rom_error_t spx_verify_test(
void) {
66 spx_verify_test_vector_t
test = spx_verify_tests[test_index];
68 uint32_t root[kSpxVerifyRootNumWords];
69 uint32_t pub_root[kSpxVerifyRootNumWords];
70 RETURN_IF_ERROR(run_verify(&
test, root, pub_root));
73 CHECK_ARRAYS_EQ(root, pub_root, kSpxVerifyRootNumWords);
83 static rom_error_t spx_verify_negative_test(
void) {
84 spx_verify_test_vector_t
test = spx_verify_tests[test_index];
86 if (
test.msg_len > 0) {
94 uint32_t root[kSpxVerifyRootNumWords];
95 uint32_t pub_root[kSpxVerifyRootNumWords];
96 RETURN_IF_ERROR(run_verify(&
test, root, pub_root));
99 CHECK_ARRAYS_NE(root, pub_root, kSpxVerifyRootNumWords);
106 CHECK(kNumNegativeTests <= kSpxVerifyNumTests,
107 "kNumNegativeTests (%d) cannot be larger than the total number of "
109 kNumNegativeTests, kSpxVerifyNumTests);
111 LOG_INFO(
"Running %d tests with valid signatures.", kSpxVerifyNumTests);
113 for (
size_t i = 0; i < kSpxVerifyNumTests; i++) {
116 LOG_INFO(
"Finished test %d of %d.", test_index, kSpxVerifyNumTests);
119 LOG_INFO(
"Running %d tests with invalid signatures.", kNumNegativeTests);
122 for (
size_t i = 0; i < kNumNegativeTests; i++) {
125 LOG_INFO(
"Finished negative test %d of %d.", test_index, kNumNegativeTests);
128 return status_ok(result);