Skip to content

Commit 4753e1c

Browse files
committed
Use byte for isAllocated bit-field. Cleanup some of the "heap" hint logic.
1 parent 59389a0 commit 4753e1c

9 files changed

Lines changed: 20 additions & 18 deletions

File tree

wolfcrypt/src/aes.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11448,16 +11448,18 @@ int wc_AesInit_Label(Aes* aes, const char* label, void* heap, int devId)
1144811448
/* Free Aes from use with async hardware */
1144911449
void wc_AesFree(Aes* aes)
1145011450
{
11451-
unsigned int isAllocated;
11451+
void* heap;
11452+
byte isAllocated;
1145211453

1145311454
if (aes == NULL) {
1145411455
return;
1145511456
}
1145611457

11458+
heap = aes->heap;
1145711459
isAllocated = aes->isAllocated;
1145811460

1145911461
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
11460-
(void)wc_debug_CipherLifecycleFree(&aes->CipherLifecycleTag, aes->heap, 1);
11462+
(void)wc_debug_CipherLifecycleFree(&aes->CipherLifecycleTag, heap, 1);
1146111463
#endif
1146211464

1146311465
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_AES)
@@ -11495,7 +11497,7 @@ void wc_AesFree(Aes* aes)
1149511497
#endif
1149611498
#if defined(WOLFSSL_AESGCM_STREAM) && defined(WOLFSSL_SMALL_STACK) && \
1149711499
!defined(WOLFSSL_AESNI)
11498-
XFREE(aes->streamData, aes->heap, DYNAMIC_TYPE_AES);
11500+
XFREE(aes->streamData, heap, DYNAMIC_TYPE_AES);
1149911501
aes->streamData = NULL;
1150011502
#endif
1150111503

@@ -11524,7 +11526,7 @@ void wc_AesFree(Aes* aes)
1152411526
#endif
1152511527

1152611528
if (isAllocated) {
11527-
XFREE(aes, aes->heap, DYNAMIC_TYPE_AES);
11529+
XFREE(aes, heap, DYNAMIC_TYPE_AES);
1152811530
}
1152911531

1153011532
}

wolfcrypt/src/curve25519.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,14 +707,14 @@ int wc_curve25519_init(curve25519_key* key)
707707
/* Clean the memory of a key */
708708
void wc_curve25519_free(curve25519_key* key)
709709
{
710-
int isAllocated = 0;
711710
void* heap;
711+
byte isAllocated = 0;
712712

713713
if (key == NULL)
714714
return;
715715

716-
isAllocated = key->isAllocated;
717716
heap = key->heap;
717+
isAllocated = key->isAllocated;
718718

719719
#ifdef WOLFSSL_SE050
720720
se050_curve25519_free_key(key);

wolfcrypt/src/ed25519.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,14 +1023,14 @@ int wc_ed25519_init(ed25519_key* key)
10231023
/* clear memory of key */
10241024
void wc_ed25519_free(ed25519_key* key)
10251025
{
1026-
int isAllocated = 0;
10271026
void* heap;
1027+
byte isAllocated = 0;
10281028

10291029
if (key == NULL)
10301030
return;
10311031

1032-
isAllocated = key->isAllocated;
10331032
heap = key->heap;
1033+
isAllocated = key->isAllocated;
10341034

10351035
#ifdef WOLFSSL_ED25519_PERSISTENT_SHA
10361036
ed25519_hash_free(key, &key->sha);

wolfcrypt/src/hash.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,8 +1041,8 @@ int wc_HashFinal(wc_HashAlg* hash, enum wc_HashType type, byte* out)
10411041
int wc_HashFree(wc_HashAlg* hash, enum wc_HashType type)
10421042
{
10431043
int ret = WC_NO_ERR_TRACE(HASH_TYPE_E); /* Default to hash type error */
1044-
int isAllocated = 0;
10451044
void* heap = NULL;
1045+
byte isAllocated = 0;
10461046

10471047
if (hash == NULL)
10481048
return BAD_FUNC_ARG;
@@ -1172,6 +1172,7 @@ int wc_HashFree(wc_HashAlg* hash, enum wc_HashType type)
11721172

11731173
if (isAllocated) {
11741174
XFREE(hash, heap, DYNAMIC_TYPE_HASHES);
1175+
(void)heap;
11751176
}
11761177

11771178
return ret;

wolfcrypt/src/rsa.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,15 +542,15 @@ int wc_RsaGetKeyId(RsaKey* key, word32* keyId)
542542
int wc_FreeRsaKey(RsaKey* key)
543543
{
544544
int ret = 0;
545-
int isAllocated = 0;
546545
void* heap;
546+
byte isAllocated = 0;
547547

548548
if (key == NULL) {
549549
return BAD_FUNC_ARG;
550550
}
551551

552-
isAllocated = key->isAllocated;
553552
heap = key->heap;
553+
isAllocated = key->isAllocated;
554554

555555
wc_RsaCleanup(key);
556556

@@ -587,7 +587,7 @@ int wc_FreeRsaKey(RsaKey* key)
587587
mp_clear(&key->n);
588588

589589
#ifdef WOLFSSL_XILINX_CRYPT
590-
XFREE(key->mod, key->heap, DYNAMIC_TYPE_KEY);
590+
XFREE(key->mod, heap, DYNAMIC_TYPE_KEY);
591591
key->mod = NULL;
592592
#endif
593593

wolfssl/wolfcrypt/curve25519.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ struct curve25519_key {
9999
/* bit fields */
100100
byte pubSet:1;
101101
byte privSet:1;
102-
103-
unsigned int isAllocated:1; /* flag indicates if structure was allocated */
102+
byte isAllocated:1; /* flag indicates if structure was allocated */
104103
};
105104

106105
enum {

wolfssl/wolfcrypt/ed25519.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ struct ed25519_key {
106106
void *heap;
107107
#ifdef WOLFSSL_ED25519_PERSISTENT_SHA
108108
wc_Sha512 sha;
109-
unsigned int sha_clean_flag : 1;
109+
byte sha_clean_flag : 1;
110110
#endif
111111
/* flag indicates if structure was allocated */
112-
unsigned int isAllocated : 1;
112+
byte isAllocated : 1;
113113
};
114114

115115
#ifndef WC_ED25519KEY_TYPE_DEFINED

wolfssl/wolfcrypt/hash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ typedef union {
125125
typedef struct {
126126
wc_Hashes alg;
127127
enum wc_HashType type; /* sanity check */
128-
unsigned int isAllocated:1; /* flag indicates if structure was allocated */
128+
byte isAllocated:1; /* flag indicates if structure was allocated */
129129
} wc_HashAlg;
130130
#endif /* !NO_HASH_WRAPPER */
131131

wolfssl/wolfcrypt/rsa.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ struct RsaKey {
269269
#if defined(WOLFSSL_RENESAS_FSPSM)
270270
FSPSM_RSA_CTX ctx;
271271
#endif
272-
unsigned int isAllocated:1; /* flag indicates if structure was allocated */
272+
byte isAllocated:1; /* flag indicates if structure was allocated */
273273
};
274274

275275
#ifndef WC_RSAKEY_TYPE_DEFINED

0 commit comments

Comments
 (0)