Also account for selftest for mp_get_digit refactor.

This commit is contained in:
Kareem
2025-06-12 12:52:35 -07:00
parent 05aa4f5f08
commit 9c9465aa23
3 changed files with 13 additions and 9 deletions

View File

@@ -46,7 +46,7 @@ int test_mp_get_digit_count(void)
ExpectIntEQ(mp_init(&a), 0);
#ifdef HAVE_FIPS
#if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
ExpectIntEQ(get_digit_count(NULL), 0);
ExpectIntEQ(get_digit_count(&a), 0);
#else
@@ -72,7 +72,7 @@ int test_mp_get_digit(void)
XMEMSET(&a, 0, sizeof(mp_int));
ExpectIntEQ(mp_init(&a), MP_OKAY);
#ifdef HAVE_FIPS
#if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
ExpectIntEQ(get_digit(NULL, n), 0);
ExpectIntEQ(get_digit(&a, n), 0);
#else
@@ -99,7 +99,7 @@ int test_mp_get_rand_digit(void)
ExpectIntEQ(wc_InitRng(&rng), 0);
#ifdef HAVE_FIPS
#if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
ExpectIntEQ(get_rand_digit(&rng, &d), 0);
ExpectIntEQ(get_rand_digit(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
ExpectIntEQ(get_rand_digit(NULL, &d), WC_NO_ERR_TRACE(BAD_FUNC_ARG));

View File

@@ -85,7 +85,7 @@ void mp_reverse(unsigned char *s, int len)
}
}
#ifdef HAVE_FIPS
#if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
int get_digit_count(const mp_int* a)
#else
int mp_get_digit_count(const mp_int* a)
@@ -97,7 +97,7 @@ int mp_get_digit_count(const mp_int* a)
return (int)a->used;
}
#ifdef HAVE_FIPS
#if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
mp_digit get_digit(const mp_int* a, int n)
#else
mp_digit mp_get_digit(const mp_int* a, int n)
@@ -146,14 +146,14 @@ 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
#if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
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
#if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
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;
@@ -172,7 +172,7 @@ int mp_cond_copy(mp_int* a, int copy, mp_int* b)
#ifndef WC_NO_RNG
#ifdef HAVE_FIPS
#if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
int get_rand_digit(WC_RNG* rng, mp_digit* d)
#else
int mp_get_rand_digit(WC_RNG* rng, mp_digit* d)
@@ -225,7 +225,11 @@ int mp_rand(mp_int* a, int digits, WC_RNG* rng)
#endif
/* ensure top digit is not zero */
while ((ret == MP_OKAY) && (a->dp[a->used - 1] == 0)) {
#if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
ret = get_rand_digit(rng, &a->dp[a->used - 1]);
#else
ret = mp_get_rand_digit(rng, &a->dp[a->used - 1]);
#endif
#ifdef USE_INTEGER_HEAP_MATH
a->dp[a->used - 1] &= MP_MASK;
#endif

View File

@@ -83,7 +83,7 @@ This library provides big integer math functions.
#if !defined(NO_BIG_INT)
/* common math functions */
#ifdef HAVE_FIPS
#if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
MP_API int get_digit_count(const mp_int* a);
MP_API mp_digit get_digit(const mp_int* a, int n);
MP_API int get_rand_digit(WC_RNG* rng, mp_digit* d);