forked from wolfSSL/wolfssl
Fix STM32 PKA V2 (STM32U5) point multiply missing order/coefB.
This commit is contained in:
@ -638,10 +638,43 @@ static int stm32_get_from_hexstr(const char* hex, uint8_t* dst, int sz)
|
|||||||
return stm32_getabs_from_hexstr(hex, dst, sz, NULL);
|
return stm32_getabs_from_hexstr(hex, dst, sz, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* STM32 PKA supports up to 640-bit numbers */
|
/* STM32 PKA supports up to 640-bit numbers */
|
||||||
#define STM32_MAX_ECC_SIZE (80)
|
#define STM32_MAX_ECC_SIZE (80)
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_STM32_PKA_V2
|
||||||
|
/* find curve based on prime/modulus and return order/coefB */
|
||||||
|
static int stm32_get_curve_params(mp_int* modulus,
|
||||||
|
uint8_t* order, uint8_t* coefB)
|
||||||
|
{
|
||||||
|
int res, i, found = 0;
|
||||||
|
mp_int modulusChk;
|
||||||
|
res = mp_init(&modulusChk);
|
||||||
|
if (res != MP_OKAY)
|
||||||
|
return res;
|
||||||
|
for (i = 0; ecc_sets[i].size != 0 && ecc_sets[i].name != NULL; i++) {
|
||||||
|
const ecc_set_type* curve = &ecc_sets[i];
|
||||||
|
/* match based on curve prime */
|
||||||
|
if ((res = mp_read_radix(&modulusChk, curve->prime, MP_RADIX_HEX)) ==
|
||||||
|
MP_OKAY && (mp_cmp(modulus, &modulusChk) == MP_EQ))
|
||||||
|
{
|
||||||
|
found = 1;
|
||||||
|
if (order) {
|
||||||
|
res = stm32_get_from_hexstr(curve->order, order, curve->size);
|
||||||
|
}
|
||||||
|
if (coefB) {
|
||||||
|
res = stm32_get_from_hexstr(curve->Bf, coefB, curve->size);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mp_clear(&modulusChk);
|
||||||
|
if (!found && res == MP_OKAY) {
|
||||||
|
res = MP_RANGE;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
#endif /* WOLFSSL_STM32_PKA_V2 */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Perform a point multiplication (timing resistant)
|
Perform a point multiplication (timing resistant)
|
||||||
@ -706,8 +739,19 @@ int wc_ecc_mulmod_ex2(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
|
|||||||
#ifdef WOLFSSL_STM32_PKA_V2
|
#ifdef WOLFSSL_STM32_PKA_V2
|
||||||
XMEMSET(order, 0, sizeof(order));
|
XMEMSET(order, 0, sizeof(order));
|
||||||
XMEMSET(coefB, 0, sizeof(coefB));
|
XMEMSET(coefB, 0, sizeof(coefB));
|
||||||
if (res == MP_OKAY && o != NULL)
|
if (res == MP_OKAY) {
|
||||||
res = stm32_get_from_mp_int(order, o, szModulus);
|
if (o != NULL) {
|
||||||
|
/* use provided order and get coefB */
|
||||||
|
res = stm32_get_from_mp_int(order, o, szModulus);
|
||||||
|
if (res == MP_OKAY) {
|
||||||
|
res = stm32_get_curve_params(modulus, NULL, coefB);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* get order and coefB for matching prime */
|
||||||
|
res = stm32_get_curve_params(modulus, order, coefB);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if (res != MP_OKAY)
|
if (res != MP_OKAY)
|
||||||
return res;
|
return res;
|
||||||
|
Reference in New Issue
Block a user