Skip to content

Commit abc910c

Browse files
committed
SP: Remove check of NULL before XFREE
Removed more checks of NULL before XFREE. Formatting fixes as well.
1 parent 92952a5 commit abc910c

7 files changed

Lines changed: 144 additions & 186 deletions

File tree

wolfcrypt/src/sp_arm32.c

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -73547,15 +73547,15 @@ static int sp_256_ecc_mulmod_fast_8(sp_point_256* r, const sp_point_256* g, cons
7354773547
#endif
7354873548
}
7354973549
#ifndef WC_NO_CACHE_RESISTANT
73550-
#ifdef WOLFSSL_SP_SMALL_STACK
73550+
#ifdef WOLFSSL_SP_SMALL_STACK
7355173551
if (p != NULL)
73552+
#endif
73553+
{
73554+
ForceZero(p, sizeof(sp_point_256));
73555+
#ifdef WOLFSSL_SP_SMALL_STACK
73556+
XFREE(p, heap, DYNAMIC_TYPE_ECC);
7355273557
#endif
73553-
{
73554-
ForceZero(p, sizeof(sp_point_256));
73555-
#ifdef WOLFSSL_SP_SMALL_STACK
73556-
XFREE(p, heap, DYNAMIC_TYPE_ECC);
73557-
#endif
73558-
}
73558+
}
7355973559
#endif /* !WC_NO_CACHE_RESISTANT */
7356073560
#ifdef WOLFSSL_SP_SMALL_STACK
7356173561
if (t != NULL)
@@ -76464,10 +76464,8 @@ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap)
7646476464

7646576465
#ifdef WOLFSSL_SP_SMALL_STACK
7646676466
XFREE(k, heap, DYNAMIC_TYPE_ECC);
76467-
if (point != NULL) {
76468-
/* point is not sensitive, so no need to zeroize */
76469-
XFREE(point, heap, DYNAMIC_TYPE_ECC);
76470-
}
76467+
/* point is not sensitive, so no need to zeroize */
76468+
XFREE(point, heap, DYNAMIC_TYPE_ECC);
7647176469
#endif
7647276470

7647376471
return err;
@@ -91268,15 +91266,15 @@ static int sp_384_ecc_mulmod_fast_12(sp_point_384* r, const sp_point_384* g, con
9126891266
#endif
9126991267
}
9127091268
#ifndef WC_NO_CACHE_RESISTANT
91271-
#ifdef WOLFSSL_SP_SMALL_STACK
91269+
#ifdef WOLFSSL_SP_SMALL_STACK
9127291270
if (p != NULL)
91271+
#endif
91272+
{
91273+
ForceZero(p, sizeof(sp_point_384));
91274+
#ifdef WOLFSSL_SP_SMALL_STACK
91275+
XFREE(p, heap, DYNAMIC_TYPE_ECC);
9127391276
#endif
91274-
{
91275-
ForceZero(p, sizeof(sp_point_384));
91276-
#ifdef WOLFSSL_SP_SMALL_STACK
91277-
XFREE(p, heap, DYNAMIC_TYPE_ECC);
91278-
#endif
91279-
}
91277+
}
9128091278
#endif /* !WC_NO_CACHE_RESISTANT */
9128191279
#ifdef WOLFSSL_SP_SMALL_STACK
9128291280
if (t != NULL)
@@ -94223,10 +94221,8 @@ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap)
9422394221

9422494222
#ifdef WOLFSSL_SP_SMALL_STACK
9422594223
XFREE(k, heap, DYNAMIC_TYPE_ECC);
94226-
if (point != NULL) {
94227-
/* point is not sensitive, so no need to zeroize */
94228-
XFREE(point, heap, DYNAMIC_TYPE_ECC);
94229-
}
94224+
/* point is not sensitive, so no need to zeroize */
94225+
XFREE(point, heap, DYNAMIC_TYPE_ECC);
9423094226
#endif
9423194227

9423294228
return err;
@@ -118420,15 +118416,15 @@ static int sp_521_ecc_mulmod_fast_17(sp_point_521* r, const sp_point_521* g, con
118420118416
#endif
118421118417
}
118422118418
#ifndef WC_NO_CACHE_RESISTANT
118423-
#ifdef WOLFSSL_SP_SMALL_STACK
118419+
#ifdef WOLFSSL_SP_SMALL_STACK
118424118420
if (p != NULL)
118421+
#endif
118422+
{
118423+
ForceZero(p, sizeof(sp_point_521));
118424+
#ifdef WOLFSSL_SP_SMALL_STACK
118425+
XFREE(p, heap, DYNAMIC_TYPE_ECC);
118425118426
#endif
118426-
{
118427-
ForceZero(p, sizeof(sp_point_521));
118428-
#ifdef WOLFSSL_SP_SMALL_STACK
118429-
XFREE(p, heap, DYNAMIC_TYPE_ECC);
118430-
#endif
118431-
}
118427+
}
118432118428
#endif /* !WC_NO_CACHE_RESISTANT */
118433118429
#ifdef WOLFSSL_SP_SMALL_STACK
118434118430
if (t != NULL)
@@ -121969,10 +121965,8 @@ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap)
121969121965

121970121966
#ifdef WOLFSSL_SP_SMALL_STACK
121971121967
XFREE(k, heap, DYNAMIC_TYPE_ECC);
121972-
if (point != NULL) {
121973-
/* point is not sensitive, so no need to zeroize */
121974-
XFREE(point, heap, DYNAMIC_TYPE_ECC);
121975-
}
121968+
/* point is not sensitive, so no need to zeroize */
121969+
XFREE(point, heap, DYNAMIC_TYPE_ECC);
121976121970
#endif
121977121971

121978121972
return err;
@@ -144551,16 +144545,16 @@ static void sp_1024_point_free_32(sp_point_1024* p, int clear, void* heap)
144551144545
{
144552144546
#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
144553144547
defined(WOLFSSL_SP_SMALL_STACK)
144554-
/* If valid pointer then clear point data if requested and free data. */
144548+
/* If valid pointer then clear point data if requested and free data. */
144555144549
if (p != NULL) {
144556-
if (clear != 0) {
144550+
if (clear) {
144557144551
XMEMSET(p, 0, sizeof(*p));
144558144552
}
144559144553
XFREE(p, heap, DYNAMIC_TYPE_ECC);
144560144554
}
144561144555
#else
144562-
/* Clear point data if requested. */
144563-
if ((p != NULL) && (clear != 0)) {
144556+
/* Clear point data if requested. */
144557+
if ((p != NULL) && clear) {
144564144558
XMEMSET(p, 0, sizeof(*p));
144565144559
}
144566144560
#endif

wolfcrypt/src/sp_arm64.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39858,10 +39858,8 @@ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap)
3985839858

3985939859
#ifdef WOLFSSL_SP_SMALL_STACK
3986039860
XFREE(k, heap, DYNAMIC_TYPE_ECC);
39861-
if (point != NULL) {
39862-
/* point is not sensitive, so no need to zeroize */
39863-
XFREE(point, heap, DYNAMIC_TYPE_ECC);
39864-
}
39861+
/* point is not sensitive, so no need to zeroize */
39862+
XFREE(point, heap, DYNAMIC_TYPE_ECC);
3986539863
#endif
3986639864

3986739865
return err;
@@ -66598,10 +66596,8 @@ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap)
6659866596

6659966597
#ifdef WOLFSSL_SP_SMALL_STACK
6660066598
XFREE(k, heap, DYNAMIC_TYPE_ECC);
66601-
if (point != NULL) {
66602-
/* point is not sensitive, so no need to zeroize */
66603-
XFREE(point, heap, DYNAMIC_TYPE_ECC);
66604-
}
66599+
/* point is not sensitive, so no need to zeroize */
66600+
XFREE(point, heap, DYNAMIC_TYPE_ECC);
6660566601
#endif
6660666602

6660766603
return err;
@@ -111737,10 +111733,8 @@ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap)
111737111733

111738111734
#ifdef WOLFSSL_SP_SMALL_STACK
111739111735
XFREE(k, heap, DYNAMIC_TYPE_ECC);
111740-
if (point != NULL) {
111741-
/* point is not sensitive, so no need to zeroize */
111742-
XFREE(point, heap, DYNAMIC_TYPE_ECC);
111743-
}
111736+
/* point is not sensitive, so no need to zeroize */
111737+
XFREE(point, heap, DYNAMIC_TYPE_ECC);
111744111738
#endif
111745111739

111746111740
return err;
@@ -115523,16 +115517,16 @@ static void sp_1024_point_free_16(sp_point_1024* p, int clear, void* heap)
115523115517
{
115524115518
#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
115525115519
defined(WOLFSSL_SP_SMALL_STACK)
115526-
/* If valid pointer then clear point data if requested and free data. */
115520+
/* If valid pointer then clear point data if requested and free data. */
115527115521
if (p != NULL) {
115528-
if (clear != 0) {
115522+
if (clear) {
115529115523
XMEMSET(p, 0, sizeof(*p));
115530115524
}
115531115525
XFREE(p, heap, DYNAMIC_TYPE_ECC);
115532115526
}
115533115527
#else
115534-
/* Clear point data if requested. */
115535-
if ((p != NULL) && (clear != 0)) {
115528+
/* Clear point data if requested. */
115529+
if ((p != NULL) && clear) {
115536115530
XMEMSET(p, 0, sizeof(*p));
115537115531
}
115538115532
#endif

wolfcrypt/src/sp_armthumb.c

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -101049,15 +101049,15 @@ static int sp_256_ecc_mulmod_fast_8(sp_point_256* r, const sp_point_256* g, cons
101049101049
#endif
101050101050
}
101051101051
#ifndef WC_NO_CACHE_RESISTANT
101052-
#ifdef WOLFSSL_SP_SMALL_STACK
101052+
#ifdef WOLFSSL_SP_SMALL_STACK
101053101053
if (p != NULL)
101054+
#endif
101055+
{
101056+
ForceZero(p, sizeof(sp_point_256));
101057+
#ifdef WOLFSSL_SP_SMALL_STACK
101058+
XFREE(p, heap, DYNAMIC_TYPE_ECC);
101054101059
#endif
101055-
{
101056-
ForceZero(p, sizeof(sp_point_256));
101057-
#ifdef WOLFSSL_SP_SMALL_STACK
101058-
XFREE(p, heap, DYNAMIC_TYPE_ECC);
101059-
#endif
101060-
}
101060+
}
101061101061
#endif /* !WC_NO_CACHE_RESISTANT */
101062101062
#ifdef WOLFSSL_SP_SMALL_STACK
101063101063
if (t != NULL)
@@ -104024,10 +104024,8 @@ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap)
104024104024

104025104025
#ifdef WOLFSSL_SP_SMALL_STACK
104026104026
XFREE(k, heap, DYNAMIC_TYPE_ECC);
104027-
if (point != NULL) {
104028-
/* point is not sensitive, so no need to zeroize */
104029-
XFREE(point, heap, DYNAMIC_TYPE_ECC);
104030-
}
104027+
/* point is not sensitive, so no need to zeroize */
104028+
XFREE(point, heap, DYNAMIC_TYPE_ECC);
104031104029
#endif
104032104030

104033104031
return err;
@@ -111877,15 +111875,15 @@ static int sp_384_ecc_mulmod_fast_12(sp_point_384* r, const sp_point_384* g, con
111877111875
#endif
111878111876
}
111879111877
#ifndef WC_NO_CACHE_RESISTANT
111880-
#ifdef WOLFSSL_SP_SMALL_STACK
111878+
#ifdef WOLFSSL_SP_SMALL_STACK
111881111879
if (p != NULL)
111880+
#endif
111881+
{
111882+
ForceZero(p, sizeof(sp_point_384));
111883+
#ifdef WOLFSSL_SP_SMALL_STACK
111884+
XFREE(p, heap, DYNAMIC_TYPE_ECC);
111882111885
#endif
111883-
{
111884-
ForceZero(p, sizeof(sp_point_384));
111885-
#ifdef WOLFSSL_SP_SMALL_STACK
111886-
XFREE(p, heap, DYNAMIC_TYPE_ECC);
111887-
#endif
111888-
}
111886+
}
111889111887
#endif /* !WC_NO_CACHE_RESISTANT */
111890111888
#ifdef WOLFSSL_SP_SMALL_STACK
111891111889
if (t != NULL)
@@ -114920,10 +114918,8 @@ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap)
114920114918

114921114919
#ifdef WOLFSSL_SP_SMALL_STACK
114922114920
XFREE(k, heap, DYNAMIC_TYPE_ECC);
114923-
if (point != NULL) {
114924-
/* point is not sensitive, so no need to zeroize */
114925-
XFREE(point, heap, DYNAMIC_TYPE_ECC);
114926-
}
114921+
/* point is not sensitive, so no need to zeroize */
114922+
XFREE(point, heap, DYNAMIC_TYPE_ECC);
114927114923
#endif
114928114924

114929114925
return err;
@@ -125477,15 +125473,15 @@ static int sp_521_ecc_mulmod_fast_17(sp_point_521* r, const sp_point_521* g, con
125477125473
#endif
125478125474
}
125479125475
#ifndef WC_NO_CACHE_RESISTANT
125480-
#ifdef WOLFSSL_SP_SMALL_STACK
125476+
#ifdef WOLFSSL_SP_SMALL_STACK
125481125477
if (p != NULL)
125478+
#endif
125479+
{
125480+
ForceZero(p, sizeof(sp_point_521));
125481+
#ifdef WOLFSSL_SP_SMALL_STACK
125482+
XFREE(p, heap, DYNAMIC_TYPE_ECC);
125482125483
#endif
125483-
{
125484-
ForceZero(p, sizeof(sp_point_521));
125485-
#ifdef WOLFSSL_SP_SMALL_STACK
125486-
XFREE(p, heap, DYNAMIC_TYPE_ECC);
125487-
#endif
125488-
}
125484+
}
125489125485
#endif /* !WC_NO_CACHE_RESISTANT */
125490125486
#ifdef WOLFSSL_SP_SMALL_STACK
125491125487
if (t != NULL)
@@ -129150,10 +129146,8 @@ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap)
129150129146

129151129147
#ifdef WOLFSSL_SP_SMALL_STACK
129152129148
XFREE(k, heap, DYNAMIC_TYPE_ECC);
129153-
if (point != NULL) {
129154-
/* point is not sensitive, so no need to zeroize */
129155-
XFREE(point, heap, DYNAMIC_TYPE_ECC);
129156-
}
129149+
/* point is not sensitive, so no need to zeroize */
129150+
XFREE(point, heap, DYNAMIC_TYPE_ECC);
129157129151
#endif
129158129152

129159129153
return err;
@@ -202402,16 +202396,16 @@ static void sp_1024_point_free_32(sp_point_1024* p, int clear, void* heap)
202402202396
{
202403202397
#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \
202404202398
defined(WOLFSSL_SP_SMALL_STACK)
202405-
/* If valid pointer then clear point data if requested and free data. */
202399+
/* If valid pointer then clear point data if requested and free data. */
202406202400
if (p != NULL) {
202407-
if (clear != 0) {
202401+
if (clear) {
202408202402
XMEMSET(p, 0, sizeof(*p));
202409202403
}
202410202404
XFREE(p, heap, DYNAMIC_TYPE_ECC);
202411202405
}
202412202406
#else
202413-
/* Clear point data if requested. */
202414-
if ((p != NULL) && (clear != 0)) {
202407+
/* Clear point data if requested. */
202408+
if ((p != NULL) && clear) {
202415202409
XMEMSET(p, 0, sizeof(*p));
202416202410
}
202417202411
#endif

0 commit comments

Comments
 (0)