Skip to content

Commit 27176a5

Browse files
authored
Merge pull request wolfSSL#8870 from kareem-wolfssl/zd20030
Various minor fixes.
2 parents e5a9c70 + 7e4ec84 commit 27176a5

File tree

8 files changed

+53
-37
lines changed

8 files changed

+53
-37
lines changed

src/internal.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35727,6 +35727,16 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3572735727
XFREE(args->verifySig, ssl->heap, DYNAMIC_TYPE_SIGNATURE);
3572835728
args->verifySig = NULL;
3572935729
#endif
35730+
35731+
if (
35732+
#ifdef WOLFSSL_ASYNC_IO
35733+
args != NULL &&
35734+
#endif
35735+
args->input != NULL) {
35736+
XFREE(args->input, ssl->heap, DYNAMIC_TYPE_IN_BUFFER);
35737+
args->input = NULL;
35738+
}
35739+
3573035740
(void)args;
3573135741
}
3573235742

tests/api/test_wolfmath.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
#include <tests/api/test_wolfmath.h>
3535

3636
/*
37-
* Testing get_digit_count
37+
* Testing mp_get_digit_count
3838
*/
39-
int test_get_digit_count(void)
39+
int test_mp_get_digit_count(void)
4040
{
4141
EXPECT_DECLS;
4242
#if !defined(WOLFSSL_SP_MATH) && defined(WOLFSSL_PUBLIC_MP)
@@ -46,18 +46,18 @@ int test_get_digit_count(void)
4646

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

49-
ExpectIntEQ(get_digit_count(NULL), 0);
50-
ExpectIntEQ(get_digit_count(&a), 0);
49+
ExpectIntEQ(mp_get_digit_count(NULL), 0);
50+
ExpectIntEQ(mp_get_digit_count(&a), 0);
5151

5252
mp_clear(&a);
5353
#endif
5454
return EXPECT_RESULT();
5555
} /* End test_get_digit_count */
5656

5757
/*
58-
* Testing get_digit
58+
* Testing mp_get_digit
5959
*/
60-
int test_get_digit(void)
60+
int test_mp_get_digit(void)
6161
{
6262
EXPECT_DECLS;
6363
#if defined(WOLFSSL_PUBLIC_MP)
@@ -67,18 +67,18 @@ int test_get_digit(void)
6767
XMEMSET(&a, 0, sizeof(mp_int));
6868

6969
ExpectIntEQ(mp_init(&a), MP_OKAY);
70-
ExpectIntEQ(get_digit(NULL, n), 0);
71-
ExpectIntEQ(get_digit(&a, n), 0);
70+
ExpectIntEQ(mp_get_digit(NULL, n), 0);
71+
ExpectIntEQ(mp_get_digit(&a, n), 0);
7272

7373
mp_clear(&a);
7474
#endif
7575
return EXPECT_RESULT();
7676
} /* End test_get_digit */
7777

7878
/*
79-
* Testing get_rand_digit
79+
* Testing mp_get_rand_digit
8080
*/
81-
int test_get_rand_digit(void)
81+
int test_mp_get_rand_digit(void)
8282
{
8383
EXPECT_DECLS;
8484
#if !defined(WC_NO_RNG) && defined(WOLFSSL_PUBLIC_MP)
@@ -89,10 +89,10 @@ int test_get_rand_digit(void)
8989

9090
ExpectIntEQ(wc_InitRng(&rng), 0);
9191

92-
ExpectIntEQ(get_rand_digit(&rng, &d), 0);
93-
ExpectIntEQ(get_rand_digit(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
94-
ExpectIntEQ(get_rand_digit(NULL, &d), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
95-
ExpectIntEQ(get_rand_digit(&rng, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
92+
ExpectIntEQ(mp_get_rand_digit(&rng, &d), 0);
93+
ExpectIntEQ(mp_get_rand_digit(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
94+
ExpectIntEQ(mp_get_rand_digit(NULL, &d), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
95+
ExpectIntEQ(mp_get_rand_digit(&rng, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
9696

9797
DoExpectIntEQ(wc_FreeRng(&rng), 0);
9898
#endif

tests/api/test_wolfmath.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424

2525
#include <tests/api/api_decl.h>
2626

27-
int test_get_digit_count(void);
28-
int test_get_digit(void);
29-
int test_get_rand_digit(void);
27+
int test_mp_get_digit_count(void);
28+
int test_mp_get_digit(void);
29+
int test_mp_get_rand_digit(void);
3030
int test_mp_cond_copy(void);
3131
int test_mp_rand(void);
3232
int test_wc_export_int(void);
3333

3434
#define TEST_WOLFMATH_DECLS \
35-
TEST_DECL_GROUP("wolfmath", test_get_digit_count), \
36-
TEST_DECL_GROUP("wolfmath", test_get_digit), \
37-
TEST_DECL_GROUP("wolfmath", test_get_rand_digit), \
35+
TEST_DECL_GROUP("wolfmath", test_mp_get_digit_count), \
36+
TEST_DECL_GROUP("wolfmath", test_mp_get_digit), \
37+
TEST_DECL_GROUP("wolfmath", test_mp_get_rand_digit), \
3838
TEST_DECL_GROUP("wolfmath", test_mp_cond_copy), \
3939
TEST_DECL_GROUP("wolfmath", test_mp_rand), \
4040
TEST_DECL_GROUP("wolfmath", test_wc_export_int)

wolfcrypt/src/asn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31689,7 +31689,7 @@ static int MakeSignature(CertSignCtx* certSignCtx, const byte* buf, word32 sz,
3168931689
certSignCtx->state = CERTSIGN_STATE_DO;
3169031690
ret = -1; /* default to error, reassigned to ALGO_ID_E below. */
3169131691

31692-
#ifndef NO_RSA
31692+
#if !defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
3169331693
if (rsaKey) {
3169431694
/* signature */
3169531695
ret = wc_RsaSSL_Sign(certSignCtx->encSig,

wolfcrypt/src/ecc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,7 +2054,7 @@ static int _ecc_projective_add_point(ecc_point* P, ecc_point* Q, ecc_point* R,
20542054
}
20552055
if (err == MP_OKAY) {
20562056
if ( (mp_cmp(P->x, Q->x) == MP_EQ) &&
2057-
(get_digit_count(Q->z) && mp_cmp(P->z, Q->z) == MP_EQ) &&
2057+
(mp_get_digit_count(Q->z) && mp_cmp(P->z, Q->z) == MP_EQ) &&
20582058
(mp_cmp(P->y, Q->y) == MP_EQ || mp_cmp(P->y, t1) == MP_EQ)) {
20592059
mp_clear(t1);
20602060
mp_clear(t2);
@@ -2990,7 +2990,7 @@ static int ecc_mulmod(const mp_int* k, ecc_point* tG, ecc_point* R,
29902990
mode = 0;
29912991
bitcnt = 1;
29922992
buf = 0;
2993-
digidx = get_digit_count(k) - 1;
2993+
digidx = mp_get_digit_count(k) - 1;
29942994
bitcpy = bitbuf = 0;
29952995
first = 1;
29962996

@@ -3001,7 +3001,7 @@ static int ecc_mulmod(const mp_int* k, ecc_point* tG, ecc_point* R,
30013001
if (digidx == -1) {
30023002
break;
30033003
}
3004-
buf = get_digit(k, digidx);
3004+
buf = mp_get_digit(k, digidx);
30053005
bitcnt = (int) DIGIT_BIT;
30063006
--digidx;
30073007
}

wolfcrypt/src/rsa.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,7 +2551,7 @@ static int RsaFunctionPrivate(mp_int* tmp, RsaKey* key, WC_RNG* rng)
25512551

25522552
if (ret == 0) {
25532553
/* blind */
2554-
ret = mp_rand(rnd, get_digit_count(&key->n), rng);
2554+
ret = mp_rand(rnd, mp_get_digit_count(&key->n), rng);
25552555
}
25562556
if (ret == 0) {
25572557
/* rndi = 1/rnd mod n */
@@ -3871,7 +3871,7 @@ int wc_RsaSSL_VerifyInline(byte* in, word32 inLen, byte** out, RsaKey* key)
38713871
}
38723872
#endif
38733873

3874-
#ifndef WOLFSSL_RSA_VERIFY_ONLY
3874+
#ifndef WOLFSSL_RSA_VERIFY_INLINE
38753875
int wc_RsaSSL_Verify(const byte* in, word32 inLen, byte* out, word32 outLen,
38763876
RsaKey* key)
38773877
{
@@ -5090,7 +5090,7 @@ int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng)
50905090
/* Blind the inverse operation with a value that is invertable */
50915091
if (err == MP_OKAY) {
50925092
do {
5093-
err = mp_rand(&key->p, get_digit_count(tmp3), rng);
5093+
err = mp_rand(&key->p, mp_get_digit_count(tmp3), rng);
50945094
if (err == MP_OKAY)
50955095
err = mp_set_bit(&key->p, 0);
50965096
if (err == MP_OKAY)

wolfcrypt/src/wolfmath.c

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

88-
int get_digit_count(const mp_int* a)
88+
int mp_get_digit_count(const mp_int* a)
8989
{
9090
if (a == NULL)
9191
return 0;
9292

9393
return (int)a->used;
9494
}
9595

96-
mp_digit get_digit(const mp_int* a, int n)
96+
mp_digit mp_get_digit(const mp_int* a, int n)
9797
{
9898
if (a == NULL)
9999
return 0;
@@ -135,13 +135,13 @@ int mp_cond_copy(mp_int* a, int copy, mp_int* b)
135135
* When mask all set, b ^ b ^ a = a
136136
*/
137137
/* Conditionally copy all digits and then number of used digits.
138-
* get_digit() returns 0 when index greater than available digit.
138+
* mp_get_digit() returns 0 when index greater than available digit.
139139
*/
140140
for (i = 0; i < a->used; i++) {
141-
b->dp[i] ^= (get_digit(a, (int)i) ^ get_digit(b, (int)i)) & mask;
141+
b->dp[i] ^= (mp_get_digit(a, (int)i) ^ mp_get_digit(b, (int)i)) & mask;
142142
}
143143
for (; i < b->used; i++) {
144-
b->dp[i] ^= (get_digit(a, (int)i) ^ get_digit(b, (int)i)) & mask;
144+
b->dp[i] ^= (mp_get_digit(a, (int)i) ^ mp_get_digit(b, (int)i)) & mask;
145145
}
146146
b->used ^= (a->used ^ b->used) & (wc_mp_size_t)mask;
147147
#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)
156156

157157

158158
#ifndef WC_NO_RNG
159-
int get_rand_digit(WC_RNG* rng, mp_digit* d)
159+
int mp_get_rand_digit(WC_RNG* rng, mp_digit* d)
160160
{
161161
return wc_RNG_GenerateBlock(rng, (byte*)d, sizeof(mp_digit));
162162
}
@@ -205,7 +205,7 @@ int mp_rand(mp_int* a, int digits, WC_RNG* rng)
205205
#endif
206206
/* ensure top digit is not zero */
207207
while ((ret == MP_OKAY) && (a->dp[a->used - 1] == 0)) {
208-
ret = get_rand_digit(rng, &a->dp[a->used - 1]);
208+
ret = mp_get_rand_digit(rng, &a->dp[a->used - 1]);
209209
#ifdef USE_INTEGER_HEAP_MATH
210210
a->dp[a->used - 1] &= MP_MASK;
211211
#endif

wolfssl/wolfcrypt/wolfmath.h

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

8484
#if !defined(NO_BIG_INT)
8585
/* common math functions */
86-
MP_API int get_digit_count(const mp_int* a);
87-
MP_API mp_digit get_digit(const mp_int* a, int n);
88-
MP_API int get_rand_digit(WC_RNG* rng, mp_digit* d);
86+
MP_API int mp_get_digit_count(const mp_int* a);
87+
MP_API mp_digit mp_get_digit(const mp_int* a, int n);
88+
MP_API int mp_get_rand_digit(WC_RNG* rng, mp_digit* d);
8989
WOLFSSL_LOCAL void mp_reverse(unsigned char *s, int len);
9090

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+
9197
WOLFSSL_API int mp_cond_copy(mp_int* a, int copy, mp_int* b);
9298
WOLFSSL_API int mp_rand(mp_int* a, int digits, WC_RNG* rng);
9399
#endif

0 commit comments

Comments
 (0)