Fix for ecc_map, which is handled in hardware. Fix for NXP LTC mp_mul N value. Fix for MMCAU cast warnings.

This commit is contained in:
David Garske
2021-05-25 15:57:08 -07:00
parent 63ac9decfc
commit c59349c7a7
3 changed files with 31 additions and 22 deletions

View File

@@ -2278,7 +2278,7 @@ int ecc_projective_dbl_point(ecc_point *P, ecc_point *R, mp_int* a,
#endif
}
#if !defined(FREESCALE_LTC_ECC) && !defined(WOLFSSL_STM32_PKA)
/**
Map a projective Jacobian point back to affine space
P [in/out] The point to map
@@ -2497,6 +2497,7 @@ done:
return ECC_BAD_ARG_E;
#endif
}
#endif /* !FREESCALE_LTC_ECC && !WOLFSSL_STM32_PKA */
int ecc_map(ecc_point* P, mp_int* modulus, mp_digit mp)
{
@@ -4463,14 +4464,10 @@ static int ecc_make_pub_ex(ecc_key* key, ecc_curve_spec* curveIn,
err = MEMORY_E;
}
}
#ifndef FREESCALE_LTC_ECC /* this is done in hardware */
if (err == MP_OKAY) {
/* Use constant time map if compiled in */
err = ecc_map_ex(pub, curve->prime, mp, 1);
}
#else
(void)mp;
#endif
wc_ecc_del_point_ex(base, key->heap);
}

View File

@@ -127,7 +127,7 @@ static int Transform(wc_Md5* md5, const byte* data)
#ifdef FREESCALE_MMCAU_CLASSIC_SHA
cau_md5_hash_n((byte*)data, 1, (unsigned char*)md5->digest);
#else
MMCAU_MD5_HashN((byte*)data, 1, (word32*)md5->digest);
MMCAU_MD5_HashN((byte*)data, 1, (uint32_t*)md5->digest);
#endif
wolfSSL_CryptHwMutexUnLock();
}
@@ -148,7 +148,7 @@ static int Transform_Len(wc_Md5* md5, const byte* data, word32 len)
#ifdef FREESCALE_MMCAU_CLASSIC_SHA
cau_md5_hash_n(local, 1, (unsigned char*)md5->digest);
#else
MMCAU_MD5_HashN(local, 1, (word32*)md5->digest);
MMCAU_MD5_HashN(local, 1, (uint32_t*)md5->digest);
#endif
data += WC_MD5_BLOCK_SIZE;
len -= WC_MD5_BLOCK_SIZE;
@@ -162,7 +162,7 @@ static int Transform_Len(wc_Md5* md5, const byte* data, word32 len)
(unsigned char*)md5->digest);
#else
MMCAU_MD5_HashN((byte*)data, len / WC_MD5_BLOCK_SIZE,
(word32*)md5->digest);
(uint32_t*)md5->digest);
#endif
}
wolfSSL_CryptHwMutexUnLock();

View File

@@ -136,21 +136,28 @@ int mp_mul(mp_int *A, mp_int *B, mp_int *C)
uint8_t *ptrC = (uint8_t*)XMALLOC(LTC_MAX_INT_BYTES, NULL, DYNAMIC_TYPE_BIGINT);
if (ptrA && ptrB && ptrN && ptrC) {
uint16_t sizeA, sizeB, sizeC = 0;
uint16_t sizeA, sizeB, sizeN, sizeC = 0;
res = ltc_get_lsb_bin_from_mp_int(ptrA, A, &sizeA);
if (res == MP_OKAY)
res = ltc_get_lsb_bin_from_mp_int(ptrB, B, &sizeB);
if (res == MP_OKAY) {
XMEMSET(ptrN, 0xFF, LTC_MAX_INT_BYTES);
sizeN = sizeA + sizeB;
XMEMSET(ptrN, 0xFF, sizeN);
XMEMSET(ptrC, 0, LTC_MAX_INT_BYTES);
status = LTC_PKHA_ModMul(LTC_BASE, ptrA, sizeA, ptrB, sizeB, ptrN,
LTC_MAX_INT_BYTES, ptrC, &sizeC, kLTC_PKHA_IntegerArith,
status = LTC_PKHA_ModMul(LTC_BASE, ptrA, sizeA, ptrB, sizeB,
ptrN, sizeN, ptrC, &sizeC, kLTC_PKHA_IntegerArith,
kLTC_PKHA_NormalValue, kLTC_PKHA_NormalValue,
kLTC_PKHA_TimingEqualized);
if (status == kStatus_Success) {
ltc_reverse_array(ptrC, sizeC);
res = mp_read_unsigned_bin(C, ptrC, sizeC);
#ifndef WOLFSSL_SP_MATH
/* fix sign */
C->sign = neg;
#endif
}
else {
res = MP_VAL;
@@ -158,10 +165,6 @@ int mp_mul(mp_int *A, mp_int *B, mp_int *C)
}
}
#ifndef WOLFSSL_SP_MATH
/* fix sign */
C->sign = neg;
#endif
if (ptrA) {
XFREE(ptrA, NULL, DYNAMIC_TYPE_BIGINT);
}
@@ -388,15 +391,14 @@ int mp_mulmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d)
ptrB, sizeB, ptrC, sizeC, ptrD, &sizeD,
kLTC_PKHA_IntegerArith, kLTC_PKHA_NormalValue,
kLTC_PKHA_NormalValue, kLTC_PKHA_TimingEqualized);
if (status != kStatus_Success) {
if (status == kStatus_Success) {
ltc_reverse_array(ptrD, sizeD);
res = mp_read_unsigned_bin(d, ptrD, sizeD);
}
else {
res = MP_VAL;
}
}
if (res == MP_OKAY) {
ltc_reverse_array(ptrD, sizeD);
res = mp_read_unsigned_bin(d, ptrD, sizeD);
}
}
else {
res = MP_MEM;
@@ -892,6 +894,16 @@ int wc_ecc_mulmod_ex2(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
return wc_ecc_mulmod_ex(k, G, R, a, modulus, map, heap);
}
int ecc_map_ex(ecc_point* P, mp_int* modulus, mp_digit mp, int ct)
{
/* this is handled in hardware, so no projective mapping needed */
(void)P;
(void)modulus;
(void)mp;
(void)ct;
return MP_OKAY;
}
int wc_ecc_point_add(ecc_point *mG, ecc_point *mQ, ecc_point *mR, mp_int *m)
{
int res;