@@ -85,7 +85,7 @@ void mp_reverse(unsigned char *s, int len)
8585 }
8686}
8787
88- #ifdef HAVE_FIPS
88+ #if defined( HAVE_FIPS ) || defined( HAVE_SELFTEST )
8989int get_digit_count (const mp_int * a )
9090#else
9191int mp_get_digit_count (const mp_int * a )
@@ -97,7 +97,7 @@ int mp_get_digit_count(const mp_int* a)
9797 return (int )a -> used ;
9898}
9999
100- #ifdef HAVE_FIPS
100+ #if defined( HAVE_FIPS ) || defined( HAVE_SELFTEST )
101101mp_digit get_digit (const mp_int * a , int n )
102102#else
103103mp_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)
146146 * mp_get_digit() returns 0 when index greater than available digit.
147147 */
148148 for (i = 0 ; i < a -> used ; i ++ ) {
149- #ifdef HAVE_FIPS
149+ #if defined( HAVE_FIPS ) || defined( HAVE_SELFTEST )
150150 b -> dp [i ] ^= (get_digit (a , (int )i ) ^ get_digit (b , (int )i )) & mask ;
151151#else
152152 b -> dp [i ] ^= (mp_get_digit (a , (int )i ) ^ mp_get_digit (b , (int )i )) & mask ;
153153#endif
154154 }
155155 for (; i < b -> used ; i ++ ) {
156- #ifdef HAVE_FIPS
156+ #if defined( HAVE_FIPS ) || defined( HAVE_SELFTEST )
157157 b -> dp [i ] ^= (get_digit (a , (int )i ) ^ get_digit (b , (int )i )) & mask ;
158158#else
159159 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)
172172
173173
174174#ifndef WC_NO_RNG
175- #ifdef HAVE_FIPS
175+ #if defined( HAVE_FIPS ) || defined( HAVE_SELFTEST )
176176int get_rand_digit (WC_RNG * rng , mp_digit * d )
177177#else
178178int 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)
225225#endif
226226 /* ensure top digit is not zero */
227227 while ((ret == MP_OKAY ) && (a -> dp [a -> used - 1 ] == 0 )) {
228+ #if defined(HAVE_FIPS ) || defined(HAVE_SELFTEST )
229+ ret = get_rand_digit (rng , & a -> dp [a -> used - 1 ]);
230+ #else
228231 ret = mp_get_rand_digit (rng , & a -> dp [a -> used - 1 ]);
232+ #endif
229233#ifdef USE_INTEGER_HEAP_MATH
230234 a -> dp [a -> used - 1 ] &= MP_MASK ;
231235#endif
0 commit comments