From e8c110d2ac54cecf268411af2dd09620adb1ad86 Mon Sep 17 00:00:00 2001 From: Kareem Date: Wed, 11 Jun 2025 16:17:23 -0700 Subject: [PATCH] Rename get_digit* to mp_get_digit* to avoid conflicts with other functions named get_digit. --- tests/api/test_wolfmath.c | 28 ++++++++++++++-------------- tests/api/test_wolfmath.h | 12 ++++++------ wolfcrypt/src/ecc.c | 6 +++--- wolfcrypt/src/rsa.c | 4 ++-- wolfcrypt/src/wolfmath.c | 14 +++++++------- wolfssl/wolfcrypt/wolfmath.h | 6 +++--- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/tests/api/test_wolfmath.c b/tests/api/test_wolfmath.c index 1b6c6ec85..7d15b4bd4 100644 --- a/tests/api/test_wolfmath.c +++ b/tests/api/test_wolfmath.c @@ -34,9 +34,9 @@ #include /* - * 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 diff --git a/tests/api/test_wolfmath.h b/tests/api/test_wolfmath.h index e02020c75..73f416933 100644 --- a/tests/api/test_wolfmath.h +++ b/tests/api/test_wolfmath.h @@ -24,17 +24,17 @@ #include -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) diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index 747f9f1fb..ea9db7e6f 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -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; } diff --git a/wolfcrypt/src/rsa.c b/wolfcrypt/src/rsa.c index 16f2159f6..fa455cc36 100644 --- a/wolfcrypt/src/rsa.c +++ b/wolfcrypt/src/rsa.c @@ -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) diff --git a/wolfcrypt/src/wolfmath.c b/wolfcrypt/src/wolfmath.c index 9f14d0190..9ca1865bd 100644 --- a/wolfcrypt/src/wolfmath.c +++ b/wolfcrypt/src/wolfmath.c @@ -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 diff --git a/wolfssl/wolfcrypt/wolfmath.h b/wolfssl/wolfcrypt/wolfmath.h index e2e854525..03d79d9f4 100644 --- a/wolfssl/wolfcrypt/wolfmath.h +++ b/wolfssl/wolfcrypt/wolfmath.h @@ -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);