5 #include "sw/device/lib/crypto/drivers/entropy.h"
6 #include "sw/device/lib/crypto/drivers/otbn.h"
7 #include "sw/device/lib/crypto/impl/ecc/p256.h"
10 #include "sw/device/lib/testing/test_framework/check.h"
17 #include "ecdsa_p256_verify_testvectors.h"
20 const ecdsa_p256_verify_test_vector_t *testvec) {
24 .len = testvec->msg_len,
26 uint32_t digest_buf[kSha256DigestWords];
28 .mode = kOtcryptoHashModeSha256,
30 .len = kSha256DigestWords,
35 TRY(p256_ecdsa_verify_start(&testvec->signature, digest.data,
36 &testvec->public_key));
38 TRY(p256_ecdsa_verify_finalize(&testvec->signature, &result));
41 LOG_ERROR(
"Valid signature failed verification.");
42 return OTCRYPTO_RECOV_ERR;
44 LOG_ERROR(
"Invalid signature passed verification.");
45 return OTCRYPTO_RECOV_ERR;
51 OTTF_DEFINE_TEST_CONFIG();
57 CHECK_STATUS_OK(entropy_complex_init());
60 LOG_INFO(
"Starting ecdsa_p256_verify_test:%s", RULE_NAME);
61 for (uint32_t i = 0; i < kEcdsaP256VerifyNumTests; i++) {
62 LOG_INFO(
"Starting ecdsa_p256_verify_test on test vector %d of %d...",
63 i + 1, kEcdsaP256VerifyNumTests);
65 ecdsa_p256_verify_test_vector_t testvec = ecdsa_p256_verify_tests[i];
66 status_t err = ecdsa_p256_verify_test(&testvec);
68 LOG_INFO(
"Finished ecdsa_p256_verify_test on test vector %d : ok", i + 1);
70 LOG_ERROR(
"Finished ecdsa_p256_verify_test on test vector %d : error %r",
74 LOG_INFO(
"OTBN error bits: 0x%08x", otbn_err_bits_get());
75 LOG_INFO(
"OTBN instruction count: 0x%08x", otbn_instruction_count_get());
76 LOG_INFO(
"Test notes: %s", testvec.comment);
80 LOG_INFO(
"Finished ecdsa_p256_verify_test:%s", RULE_NAME);