Skip to content

Commit 7e4ec84

Browse files
Add macros for legacy get_digit functions for FIPS/selftest.
1 parent 9c9465a commit 7e4ec84

File tree

3 files changed

+6
-47
lines changed

3 files changed

+6
-47
lines changed

tests/api/test_wolfmath.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,8 @@ int test_mp_get_digit_count(void)
4646

4747
ExpectIntEQ(mp_init(&a), 0);
4848

49-
#if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
50-
ExpectIntEQ(get_digit_count(NULL), 0);
51-
ExpectIntEQ(get_digit_count(&a), 0);
52-
#else
5349
ExpectIntEQ(mp_get_digit_count(NULL), 0);
5450
ExpectIntEQ(mp_get_digit_count(&a), 0);
55-
#endif
5651

5752
mp_clear(&a);
5853
#endif
@@ -72,13 +67,8 @@ int test_mp_get_digit(void)
7267
XMEMSET(&a, 0, sizeof(mp_int));
7368

7469
ExpectIntEQ(mp_init(&a), MP_OKAY);
75-
#if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
76-
ExpectIntEQ(get_digit(NULL, n), 0);
77-
ExpectIntEQ(get_digit(&a, n), 0);
78-
#else
7970
ExpectIntEQ(mp_get_digit(NULL, n), 0);
8071
ExpectIntEQ(mp_get_digit(&a, n), 0);
81-
#endif
8272

8373
mp_clear(&a);
8474
#endif
@@ -99,17 +89,10 @@ int test_mp_get_rand_digit(void)
9989

10090
ExpectIntEQ(wc_InitRng(&rng), 0);
10191

102-
#if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
103-
ExpectIntEQ(get_rand_digit(&rng, &d), 0);
104-
ExpectIntEQ(get_rand_digit(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
105-
ExpectIntEQ(get_rand_digit(NULL, &d), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
106-
ExpectIntEQ(get_rand_digit(&rng, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
107-
#else
10892
ExpectIntEQ(mp_get_rand_digit(&rng, &d), 0);
10993
ExpectIntEQ(mp_get_rand_digit(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
11094
ExpectIntEQ(mp_get_rand_digit(NULL, &d), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
11195
ExpectIntEQ(mp_get_rand_digit(&rng, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
112-
#endif
11396

11497
DoExpectIntEQ(wc_FreeRng(&rng), 0);
11598
#endif

wolfcrypt/src/wolfmath.c

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,15 @@ void mp_reverse(unsigned char *s, int len)
8585
}
8686
}
8787

88-
#if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
89-
int get_digit_count(const mp_int* a)
90-
#else
9188
int mp_get_digit_count(const mp_int* a)
92-
#endif
9389
{
9490
if (a == NULL)
9591
return 0;
9692

9793
return (int)a->used;
9894
}
9995

100-
#if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
101-
mp_digit get_digit(const mp_int* a, int n)
102-
#else
10396
mp_digit mp_get_digit(const mp_int* a, int n)
104-
#endif
10597
{
10698
if (a == NULL)
10799
return 0;
@@ -146,18 +138,10 @@ int mp_cond_copy(mp_int* a, int copy, mp_int* b)
146138
* mp_get_digit() returns 0 when index greater than available digit.
147139
*/
148140
for (i = 0; i < a->used; i++) {
149-
#if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
150-
b->dp[i] ^= (get_digit(a, (int)i) ^ get_digit(b, (int)i)) & mask;
151-
#else
152141
b->dp[i] ^= (mp_get_digit(a, (int)i) ^ mp_get_digit(b, (int)i)) & mask;
153-
#endif
154142
}
155143
for (; i < b->used; i++) {
156-
#if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
157-
b->dp[i] ^= (get_digit(a, (int)i) ^ get_digit(b, (int)i)) & mask;
158-
#else
159144
b->dp[i] ^= (mp_get_digit(a, (int)i) ^ mp_get_digit(b, (int)i)) & mask;
160-
#endif
161145
}
162146
b->used ^= (a->used ^ b->used) & (wc_mp_size_t)mask;
163147
#if (!defined(WOLFSSL_SP_MATH) && !defined(WOLFSSL_SP_MATH_ALL)) || \
@@ -172,11 +156,7 @@ int mp_cond_copy(mp_int* a, int copy, mp_int* b)
172156

173157

174158
#ifndef WC_NO_RNG
175-
#if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
176-
int get_rand_digit(WC_RNG* rng, mp_digit* d)
177-
#else
178159
int mp_get_rand_digit(WC_RNG* rng, mp_digit* d)
179-
#endif
180160
{
181161
return wc_RNG_GenerateBlock(rng, (byte*)d, sizeof(mp_digit));
182162
}
@@ -225,11 +205,7 @@ int mp_rand(mp_int* a, int digits, WC_RNG* rng)
225205
#endif
226206
/* ensure top digit is not zero */
227207
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
231208
ret = mp_get_rand_digit(rng, &a->dp[a->used - 1]);
232-
#endif
233209
#ifdef USE_INTEGER_HEAP_MATH
234210
a->dp[a->used - 1] &= MP_MASK;
235211
#endif

wolfssl/wolfcrypt/wolfmath.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,17 @@ This library provides big integer math functions.
8383

8484
#if !defined(NO_BIG_INT)
8585
/* common math functions */
86-
#if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
87-
MP_API int get_digit_count(const mp_int* a);
88-
MP_API mp_digit get_digit(const mp_int* a, int n);
89-
MP_API int get_rand_digit(WC_RNG* rng, mp_digit* d);
90-
#else
9186
MP_API int mp_get_digit_count(const mp_int* a);
9287
MP_API mp_digit mp_get_digit(const mp_int* a, int n);
9388
MP_API int mp_get_rand_digit(WC_RNG* rng, mp_digit* d);
94-
#endif
9589
WOLFSSL_LOCAL void mp_reverse(unsigned char *s, int len);
9690

91+
#if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
92+
#define get_digit_count mp_get_digit_count
93+
#define get_digit mp_get_digit
94+
#define get_rand_digit mp_get_rand_digit
95+
#endif
96+
9797
WOLFSSL_API int mp_cond_copy(mp_int* a, int copy, mp_int* b);
9898
WOLFSSL_API int mp_rand(mp_int* a, int digits, WC_RNG* rng);
9999
#endif

0 commit comments

Comments
 (0)