mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-07-09 18:20:49 +02:00
Make mp_get_digit refactor FIPS friendly.
This commit is contained in:
@@ -85,7 +85,11 @@ void mp_reverse(unsigned char *s, int len)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_FIPS
|
||||
int get_digit_count(const mp_int* a)
|
||||
#else
|
||||
int mp_get_digit_count(const mp_int* a)
|
||||
#endif
|
||||
{
|
||||
if (a == NULL)
|
||||
return 0;
|
||||
@@ -93,7 +97,11 @@ int mp_get_digit_count(const mp_int* a)
|
||||
return (int)a->used;
|
||||
}
|
||||
|
||||
#ifdef HAVE_FIPS
|
||||
mp_digit get_digit(const mp_int* a, int n)
|
||||
#else
|
||||
mp_digit mp_get_digit(const mp_int* a, int n)
|
||||
#endif
|
||||
{
|
||||
if (a == NULL)
|
||||
return 0;
|
||||
@@ -138,10 +146,18 @@ int mp_cond_copy(mp_int* a, int copy, mp_int* b)
|
||||
* mp_get_digit() returns 0 when index greater than available digit.
|
||||
*/
|
||||
for (i = 0; i < a->used; i++) {
|
||||
#ifdef HAVE_FIPS
|
||||
b->dp[i] ^= (get_digit(a, (int)i) ^ get_digit(b, (int)i)) & mask;
|
||||
#else
|
||||
b->dp[i] ^= (mp_get_digit(a, (int)i) ^ mp_get_digit(b, (int)i)) & mask;
|
||||
#endif
|
||||
}
|
||||
for (; i < b->used; i++) {
|
||||
#ifdef HAVE_FIPS
|
||||
b->dp[i] ^= (get_digit(a, (int)i) ^ get_digit(b, (int)i)) & mask;
|
||||
#else
|
||||
b->dp[i] ^= (mp_get_digit(a, (int)i) ^ mp_get_digit(b, (int)i)) & mask;
|
||||
#endif
|
||||
}
|
||||
b->used ^= (a->used ^ b->used) & (wc_mp_size_t)mask;
|
||||
#if (!defined(WOLFSSL_SP_MATH) && !defined(WOLFSSL_SP_MATH_ALL)) || \
|
||||
@@ -156,7 +172,11 @@ int mp_cond_copy(mp_int* a, int copy, mp_int* b)
|
||||
|
||||
|
||||
#ifndef WC_NO_RNG
|
||||
#ifdef HAVE_FIPS
|
||||
int get_rand_digit(WC_RNG* rng, mp_digit* d)
|
||||
#else
|
||||
int mp_get_rand_digit(WC_RNG* rng, mp_digit* d)
|
||||
#endif
|
||||
{
|
||||
return wc_RNG_GenerateBlock(rng, (byte*)d, sizeof(mp_digit));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user