Rename get_digit* to mp_get_digit* to avoid conflicts with other functions named get_digit.

pull/8870/head
Kareem 2025-06-11 16:17:23 -07:00
parent 6633b52e28
commit e8c110d2ac
6 changed files with 35 additions and 35 deletions

View File

@ -34,9 +34,9 @@
#include <tests/api/test_wolfmath.h>
/*
* Testing get_digit_count
* Testing mp_get_digit_count
*/
int test_get_digit_count(void)
int test_mp_get_digit_count(void)
{
EXPECT_DECLS;
#if !defined(WOLFSSL_SP_MATH) && defined(WOLFSSL_PUBLIC_MP)
@ -46,8 +46,8 @@ int test_get_digit_count(void)
ExpectIntEQ(mp_init(&a), 0);
ExpectIntEQ(get_digit_count(NULL), 0);
ExpectIntEQ(get_digit_count(&a), 0);
ExpectIntEQ(mp_get_digit_count(NULL), 0);
ExpectIntEQ(mp_get_digit_count(&a), 0);
mp_clear(&a);
#endif
@ -55,9 +55,9 @@ int test_get_digit_count(void)
} /* End test_get_digit_count */
/*
* Testing get_digit
* Testing mp_get_digit
*/
int test_get_digit(void)
int test_mp_get_digit(void)
{
EXPECT_DECLS;
#if defined(WOLFSSL_PUBLIC_MP)
@ -67,8 +67,8 @@ int test_get_digit(void)
XMEMSET(&a, 0, sizeof(mp_int));
ExpectIntEQ(mp_init(&a), MP_OKAY);
ExpectIntEQ(get_digit(NULL, n), 0);
ExpectIntEQ(get_digit(&a, n), 0);
ExpectIntEQ(mp_get_digit(NULL, n), 0);
ExpectIntEQ(mp_get_digit(&a, n), 0);
mp_clear(&a);
#endif
@ -76,9 +76,9 @@ int test_get_digit(void)
} /* End test_get_digit */
/*
* Testing get_rand_digit
* Testing mp_get_rand_digit
*/
int test_get_rand_digit(void)
int test_mp_get_rand_digit(void)
{
EXPECT_DECLS;
#if !defined(WC_NO_RNG) && defined(WOLFSSL_PUBLIC_MP)
@ -89,10 +89,10 @@ int test_get_rand_digit(void)
ExpectIntEQ(wc_InitRng(&rng), 0);
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));
ExpectIntEQ(get_rand_digit(&rng, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
ExpectIntEQ(mp_get_rand_digit(&rng, &d), 0);
ExpectIntEQ(mp_get_rand_digit(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
ExpectIntEQ(mp_get_rand_digit(NULL, &d), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
ExpectIntEQ(mp_get_rand_digit(&rng, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
DoExpectIntEQ(wc_FreeRng(&rng), 0);
#endif

View File

@ -24,17 +24,17 @@
#include <tests/api/api_decl.h>
int test_get_digit_count(void);
int test_get_digit(void);
int test_get_rand_digit(void);
int test_mp_get_digit_count(void);
int test_mp_get_digit(void);
int test_mp_get_rand_digit(void);
int test_mp_cond_copy(void);
int test_mp_rand(void);
int test_wc_export_int(void);
#define TEST_WOLFMATH_DECLS \
TEST_DECL_GROUP("wolfmath", test_get_digit_count), \
TEST_DECL_GROUP("wolfmath", test_get_digit), \
TEST_DECL_GROUP("wolfmath", test_get_rand_digit), \
TEST_DECL_GROUP("wolfmath", test_mp_get_digit_count), \
TEST_DECL_GROUP("wolfmath", test_mp_get_digit), \
TEST_DECL_GROUP("wolfmath", test_mp_get_rand_digit), \
TEST_DECL_GROUP("wolfmath", test_mp_cond_copy), \
TEST_DECL_GROUP("wolfmath", test_mp_rand), \
TEST_DECL_GROUP("wolfmath", test_wc_export_int)

View File

@ -2054,7 +2054,7 @@ static int _ecc_projective_add_point(ecc_point* P, ecc_point* Q, ecc_point* R,
}
if (err == MP_OKAY) {
if ( (mp_cmp(P->x, Q->x) == MP_EQ) &&
(get_digit_count(Q->z) && mp_cmp(P->z, Q->z) == MP_EQ) &&
(mp_get_digit_count(Q->z) && mp_cmp(P->z, Q->z) == MP_EQ) &&
(mp_cmp(P->y, Q->y) == MP_EQ || mp_cmp(P->y, t1) == MP_EQ)) {
mp_clear(t1);
mp_clear(t2);
@ -2990,7 +2990,7 @@ static int ecc_mulmod(const mp_int* k, ecc_point* tG, ecc_point* R,
mode = 0;
bitcnt = 1;
buf = 0;
digidx = get_digit_count(k) - 1;
digidx = mp_get_digit_count(k) - 1;
bitcpy = bitbuf = 0;
first = 1;
@ -3001,7 +3001,7 @@ static int ecc_mulmod(const mp_int* k, ecc_point* tG, ecc_point* R,
if (digidx == -1) {
break;
}
buf = get_digit(k, digidx);
buf = mp_get_digit(k, digidx);
bitcnt = (int) DIGIT_BIT;
--digidx;
}

View File

@ -2551,7 +2551,7 @@ static int RsaFunctionPrivate(mp_int* tmp, RsaKey* key, WC_RNG* rng)
if (ret == 0) {
/* blind */
ret = mp_rand(rnd, get_digit_count(&key->n), rng);
ret = mp_rand(rnd, mp_get_digit_count(&key->n), rng);
}
if (ret == 0) {
/* rndi = 1/rnd mod n */
@ -5090,7 +5090,7 @@ int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng)
/* Blind the inverse operation with a value that is invertable */
if (err == MP_OKAY) {
do {
err = mp_rand(&key->p, get_digit_count(tmp3), rng);
err = mp_rand(&key->p, mp_get_digit_count(tmp3), rng);
if (err == MP_OKAY)
err = mp_set_bit(&key->p, 0);
if (err == MP_OKAY)

View File

@ -85,7 +85,7 @@ void mp_reverse(unsigned char *s, int len)
}
}
int get_digit_count(const mp_int* a)
int mp_get_digit_count(const mp_int* a)
{
if (a == NULL)
return 0;
@ -93,7 +93,7 @@ int get_digit_count(const mp_int* a)
return (int)a->used;
}
mp_digit get_digit(const mp_int* a, int n)
mp_digit mp_get_digit(const mp_int* a, int n)
{
if (a == NULL)
return 0;
@ -135,13 +135,13 @@ int mp_cond_copy(mp_int* a, int copy, mp_int* b)
* When mask all set, b ^ b ^ a = a
*/
/* Conditionally copy all digits and then number of used digits.
* get_digit() returns 0 when index greater than available digit.
* mp_get_digit() returns 0 when index greater than available digit.
*/
for (i = 0; i < a->used; i++) {
b->dp[i] ^= (get_digit(a, (int)i) ^ get_digit(b, (int)i)) & mask;
b->dp[i] ^= (mp_get_digit(a, (int)i) ^ mp_get_digit(b, (int)i)) & mask;
}
for (; i < b->used; i++) {
b->dp[i] ^= (get_digit(a, (int)i) ^ get_digit(b, (int)i)) & mask;
b->dp[i] ^= (mp_get_digit(a, (int)i) ^ mp_get_digit(b, (int)i)) & mask;
}
b->used ^= (a->used ^ b->used) & (wc_mp_size_t)mask;
#if (!defined(WOLFSSL_SP_MATH) && !defined(WOLFSSL_SP_MATH_ALL)) || \
@ -156,7 +156,7 @@ int mp_cond_copy(mp_int* a, int copy, mp_int* b)
#ifndef WC_NO_RNG
int get_rand_digit(WC_RNG* rng, mp_digit* d)
int mp_get_rand_digit(WC_RNG* rng, mp_digit* d)
{
return wc_RNG_GenerateBlock(rng, (byte*)d, sizeof(mp_digit));
}
@ -205,7 +205,7 @@ 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)) {
ret = get_rand_digit(rng, &a->dp[a->used - 1]);
ret = mp_get_rand_digit(rng, &a->dp[a->used - 1]);
#ifdef USE_INTEGER_HEAP_MATH
a->dp[a->used - 1] &= MP_MASK;
#endif

View File

@ -83,9 +83,9 @@ This library provides big integer math functions.
#if !defined(NO_BIG_INT)
/* common math functions */
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);
MP_API int mp_get_digit_count(const mp_int* a);
MP_API mp_digit mp_get_digit(const mp_int* a, int n);
MP_API int mp_get_rand_digit(WC_RNG* rng, mp_digit* d);
WOLFSSL_LOCAL void mp_reverse(unsigned char *s, int len);
WOLFSSL_API int mp_cond_copy(mp_int* a, int copy, mp_int* b);