6 #include "sw/device/lib/crypto/drivers/entropy.h"
7 #include "sw/device/lib/crypto/drivers/otbn.h"
8 #include "sw/device/lib/crypto/impl/rsa/rsa_3072_verify.h"
10 #include "sw/device/lib/testing/test_framework/check.h"
17 #include "rsa_3072_verify_testvectors.h"
19 status_t rsa_3072_verify_test(
const rsa_3072_verify_test_vector_t *testvec) {
23 rsa_3072_encode_sha256(testvec->msg, testvec->msgLen, &encodedMessage));
27 TRY(rsa_3072_compute_constants(&testvec->publicKey, &constants));
31 status_t err = rsa_3072_verify(&testvec->signature, &encodedMessage,
32 &testvec->publicKey, &constants, &result);
39 LOG_ERROR(
"Valid signature failed verification.");
40 return OTCRYPTO_RECOV_ERR;
45 LOG_ERROR(
"Invalid signature passed verification.");
46 return OTCRYPTO_RECOV_ERR;
49 if (!status_ok(err) && err.value != kOtcryptoStatusValueBadArgs) {
50 LOG_ERROR(
"Unexpected error on invalid signature: %r.", err);
58 OTTF_DEFINE_TEST_CONFIG();
65 CHECK_STATUS_OK(entropy_complex_init());
68 LOG_INFO(
"Starting rsa_3072_verify_test:%s", RULE_NAME);
69 for (uint32_t i = 0; i < RSA_3072_VERIFY_NUM_TESTS; i++) {
70 LOG_INFO(
"Starting rsa_3072_verify_test on test vector %d of %d...", i + 1,
71 RSA_3072_VERIFY_NUM_TESTS);
75 rsa_3072_verify_test_vector_t testvec = rsa_3072_verify_tests[i];
76 if (testvec.publicKey.e != 65537) {
77 testvec.valid =
false;
81 status_t err = rsa_3072_verify_test(&testvec);
83 LOG_INFO(
"Finished rsa_3072_verify_test on test vector %d : ok", i + 1);
85 LOG_ERROR(
"Finished rsa_3072_verify_test on test vector %d : error %r",
89 LOG_INFO(
"OTBN error bits: 0x%08x", otbn_err_bits_get());
90 LOG_INFO(
"OTBN instruction count: 0x%08x", otbn_instruction_count_get());
91 LOG_INFO(
"Test notes: %s", testvec.comment);
95 LOG_INFO(
"Finished rsa_3072_verify_test:%s", RULE_NAME);