Topic: ECDSA using STM32WB55's PKA
Hi there,
I'm trying to use the STM32WB55's PKA to generate and verify signatures in wolfCrypt 4.7. Whenever I call wc_ecc_verify_hash(), res is set to 0, as returned by HAL_PKA_ECDSAVerif_IsValidSignature() in stm32.c. If I turn PKA support off, res is set to 1.
In my example below, I'm hashing the input, generating a signature, and verifying it. wolfCrypt is configured to use static memory with a buffer size of 16KB. I have also attached the configuration file generated by STM32CubeIDE.
Due to timing and energy constraints, I need to use the PKA. Is there something that I'm missing to get the PKA to work?
Example:
ecc_key key;
uint32_t keysize = wc_ecc_get_curve_size_from_id(ECC_SECP256R1);
WC_RNG rng;
byte test[] = "sunny days!", sig[72];
memset(sig, 0, sizeof(sig));
uint32_t sigLen = sizeof(sig);
uint8_t hash[WC_SHA256_DIGEST_SIZE];
memset(hash, 0, sizeof(hash));
uint32_t hash_len = WC_SHA256_DIGEST_SIZE;
int32_t isVerified = 0;
HAL_PKA_Init(&hpka);
wc_ret = wc_InitRng_ex(&rng, _wcHeapHint, INVALID_DEVID);
wc_ret |= wc_ecc_init_ex(&key, _wcHeapHint, INVALID_DEVID);
wc_ret |= wc_ecc_make_key_ex(&rng, keysize, &key, ECC_SECP256R1);
// Produce a hash of the input data
wc_ret = wc_Hash(WC_HASH_TYPE_SHA256, test, sizeof(test), hash, hash_len);
wc_ret |= wc_ecc_sign_hash(hash, hash_len, sig, (word32*)&sigLen, &rng, &key);
wc_ret |= wc_ecc_verify_hash(sig, sigLen, hash, hash_len, (int*)&isVerified, &key);