5 #include "sw/device/lib/testing/otbn_testutils_rsa.h"
7 #include "sw/device/lib/base/status.h"
22 static const otbn_addr_t kOtbnVarRsaModulus =
OTBN_ADDR_T_INIT(rsa, modulus);
26 kOtbnWideWordBytes = 256 / 8,
31 status_t otbn_testutils_rsa_load(dif_otbn_t *otbn) {
33 return INVALID_ARGUMENT();
38 status_t otbn_testutils_rsa_modexp_f4_start(dif_otbn_t *otbn,
39 const uint8_t *modulus,
42 if (otbn == NULL || size_bytes % kOtbnWideWordBytes != 0) {
43 return INVALID_ARGUMENT();
46 uint32_t n_limbs = size_bytes / kOtbnWideWordBytes;
47 if (n_limbs == 0 || n_limbs > 16) {
48 return INVALID_ARGUMENT();
52 uint32_t mode = kModeEncrypt;
64 status_t otbn_testutils_rsa_modexp_consttime_start(
65 dif_otbn_t *otbn,
const uint8_t *modulus,
const uint8_t *private_exponent,
66 const uint8_t *in,
size_t size_bytes) {
67 if (otbn == NULL || size_bytes % kOtbnWideWordBytes != 0) {
68 return INVALID_ARGUMENT();
71 uint32_t n_limbs = size_bytes / kOtbnWideWordBytes;
72 if (n_limbs == 0 || n_limbs > 16) {
73 return INVALID_ARGUMENT();
77 uint32_t mode = kModeDecrypt;
90 static status_t modexp_finalize(dif_otbn_t *otbn, uint8_t *out,
92 if (otbn == NULL || size_bytes % kOtbnWideWordBytes != 0) {
93 return INVALID_ARGUMENT();
96 uint32_t n_limbs = size_bytes / kOtbnWideWordBytes;
97 if (n_limbs == 0 || n_limbs > 16) {
98 return INVALID_ARGUMENT();
108 status_t otbn_testutils_rsa_modexp_f4_finalize(dif_otbn_t *otbn, uint8_t *out,
110 return modexp_finalize(otbn, out, size_bytes);
113 status_t otbn_testutils_rsa_modexp_consttime_finalize(dif_otbn_t *otbn,
116 return modexp_finalize(otbn, out, size_bytes);