mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-31 19:24:42 +02:00
Merge pull request #8053 from danielinux/fix-no-malloc
Allow building with WOLFSSL_NO_MALLOC again
This commit is contained in:
@@ -11299,6 +11299,7 @@ int wc_AesCcmEncrypt_ex(Aes* aes, byte* out, const byte* in, word32 sz,
|
|||||||
|
|
||||||
#endif /* HAVE_AESCCM */
|
#endif /* HAVE_AESCCM */
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_NO_MALLOC
|
||||||
Aes* wc_AesNew(void* heap, int devId)
|
Aes* wc_AesNew(void* heap, int devId)
|
||||||
{
|
{
|
||||||
Aes* aes = (Aes*)XMALLOC(sizeof(Aes), heap, DYNAMIC_TYPE_AES);
|
Aes* aes = (Aes*)XMALLOC(sizeof(Aes), heap, DYNAMIC_TYPE_AES);
|
||||||
@@ -11313,6 +11314,7 @@ Aes* wc_AesNew(void* heap, int devId)
|
|||||||
}
|
}
|
||||||
return aes;
|
return aes;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Initialize Aes for use with async hardware */
|
/* Initialize Aes for use with async hardware */
|
||||||
int wc_AesInit(Aes* aes, void* heap, int devId)
|
int wc_AesInit(Aes* aes, void* heap, int devId)
|
||||||
@@ -11449,14 +11451,18 @@ int wc_AesInit_Label(Aes* aes, const char* label, void* heap, int devId)
|
|||||||
void wc_AesFree(Aes* aes)
|
void wc_AesFree(Aes* aes)
|
||||||
{
|
{
|
||||||
void* heap;
|
void* heap;
|
||||||
|
#ifndef WOLFSSL_NO_MALLOC
|
||||||
byte isAllocated;
|
byte isAllocated;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (aes == NULL) {
|
if (aes == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_NO_MALLOC
|
||||||
heap = aes->heap;
|
heap = aes->heap;
|
||||||
isAllocated = aes->isAllocated;
|
isAllocated = aes->isAllocated;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||||
(void)wc_debug_CipherLifecycleFree(&aes->CipherLifecycleTag, heap, 1);
|
(void)wc_debug_CipherLifecycleFree(&aes->CipherLifecycleTag, heap, 1);
|
||||||
@@ -11525,9 +11531,12 @@ void wc_AesFree(Aes* aes)
|
|||||||
wc_MemZero_Check(aes, sizeof(Aes));
|
wc_MemZero_Check(aes, sizeof(Aes));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_NO_MALLOC
|
||||||
if (isAllocated) {
|
if (isAllocated) {
|
||||||
XFREE(aes, heap, DYNAMIC_TYPE_AES);
|
XFREE(aes, heap, DYNAMIC_TYPE_AES);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
(void)heap;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -968,6 +968,7 @@ int wc_ed25519ph_verify_msg(const byte* sig, word32 sigLen, const byte* msg,
|
|||||||
}
|
}
|
||||||
#endif /* HAVE_ED25519_VERIFY */
|
#endif /* HAVE_ED25519_VERIFY */
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_NO_MALLOC
|
||||||
ed25519_key* wc_ed25519_new(void* heap, int devId)
|
ed25519_key* wc_ed25519_new(void* heap, int devId)
|
||||||
{
|
{
|
||||||
ed25519_key* key = (ed25519_key*)XMALLOC(sizeof(ed25519_key), heap,
|
ed25519_key* key = (ed25519_key*)XMALLOC(sizeof(ed25519_key), heap,
|
||||||
@@ -983,6 +984,7 @@ ed25519_key* wc_ed25519_new(void* heap, int devId)
|
|||||||
}
|
}
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* initialize information and memory for key */
|
/* initialize information and memory for key */
|
||||||
int wc_ed25519_init_ex(ed25519_key* key, void* heap, int devId)
|
int wc_ed25519_init_ex(ed25519_key* key, void* heap, int devId)
|
||||||
@@ -1024,13 +1026,16 @@ int wc_ed25519_init(ed25519_key* key)
|
|||||||
void wc_ed25519_free(ed25519_key* key)
|
void wc_ed25519_free(ed25519_key* key)
|
||||||
{
|
{
|
||||||
void* heap;
|
void* heap;
|
||||||
|
#ifndef WOLFSSL_NO_MALLOC
|
||||||
byte isAllocated = 0;
|
byte isAllocated = 0;
|
||||||
|
#endif
|
||||||
if (key == NULL)
|
if (key == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_NO_MALLOC
|
||||||
heap = key->heap;
|
heap = key->heap;
|
||||||
isAllocated = key->isAllocated;
|
isAllocated = key->isAllocated;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef WOLFSSL_ED25519_PERSISTENT_SHA
|
#ifdef WOLFSSL_ED25519_PERSISTENT_SHA
|
||||||
ed25519_hash_free(key, &key->sha);
|
ed25519_hash_free(key, &key->sha);
|
||||||
@@ -1045,10 +1050,13 @@ void wc_ed25519_free(ed25519_key* key)
|
|||||||
wc_MemZero_Check(key, sizeof(ed25519_key));
|
wc_MemZero_Check(key, sizeof(ed25519_key));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_NO_MALLOC
|
||||||
if (isAllocated) {
|
if (isAllocated) {
|
||||||
XFREE(key, heap, DYNAMIC_TYPE_ED25519);
|
XFREE(key, heap, DYNAMIC_TYPE_ED25519);
|
||||||
(void)heap;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
(void)heap;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -686,6 +686,7 @@ int wc_Hash(enum wc_HashType hash_type, const byte* data,
|
|||||||
NULL, INVALID_DEVID);
|
NULL, INVALID_DEVID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_NO_MALLOC
|
||||||
wc_HashAlg* wc_HashNew(enum wc_HashType type, void* heap, int devId)
|
wc_HashAlg* wc_HashNew(enum wc_HashType type, void* heap, int devId)
|
||||||
{
|
{
|
||||||
wc_HashAlg* hash = (wc_HashAlg*)XMALLOC(sizeof(wc_HashAlg), heap,
|
wc_HashAlg* hash = (wc_HashAlg*)XMALLOC(sizeof(wc_HashAlg), heap,
|
||||||
@@ -701,6 +702,7 @@ wc_HashAlg* wc_HashNew(enum wc_HashType type, void* heap, int devId)
|
|||||||
}
|
}
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int wc_HashInit_ex(wc_HashAlg* hash, enum wc_HashType type, void* heap,
|
int wc_HashInit_ex(wc_HashAlg* hash, enum wc_HashType type, void* heap,
|
||||||
int devId)
|
int devId)
|
||||||
@@ -710,7 +712,9 @@ int wc_HashInit_ex(wc_HashAlg* hash, enum wc_HashType type, void* heap,
|
|||||||
if (hash == NULL)
|
if (hash == NULL)
|
||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_NO_MALLOC
|
||||||
hash->isAllocated = 0;
|
hash->isAllocated = 0;
|
||||||
|
#endif
|
||||||
hash->type = type;
|
hash->type = type;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -1042,11 +1046,13 @@ int wc_HashFree(wc_HashAlg* hash, enum wc_HashType type)
|
|||||||
{
|
{
|
||||||
int ret = WC_NO_ERR_TRACE(HASH_TYPE_E); /* Default to hash type error */
|
int ret = WC_NO_ERR_TRACE(HASH_TYPE_E); /* Default to hash type error */
|
||||||
void* heap = NULL;
|
void* heap = NULL;
|
||||||
|
#ifndef WOLFSSL_NO_MALLOC
|
||||||
byte isAllocated = 0;
|
byte isAllocated = 0;
|
||||||
|
#endif
|
||||||
if (hash == NULL)
|
if (hash == NULL)
|
||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG_WOLFSSL
|
#ifdef DEBUG_WOLFSSL
|
||||||
if (hash->type != type) {
|
if (hash->type != type) {
|
||||||
WOLFSSL_MSG("Hash free type mismatch!");
|
WOLFSSL_MSG("Hash free type mismatch!");
|
||||||
@@ -1054,7 +1060,9 @@ int wc_HashFree(wc_HashAlg* hash, enum wc_HashType type)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_NO_MALLOC
|
||||||
isAllocated = hash->isAllocated;
|
isAllocated = hash->isAllocated;
|
||||||
|
#endif
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case WC_HASH_TYPE_MD5:
|
case WC_HASH_TYPE_MD5:
|
||||||
@@ -1170,10 +1178,12 @@ int wc_HashFree(wc_HashAlg* hash, enum wc_HashType type)
|
|||||||
ret = BAD_FUNC_ARG;
|
ret = BAD_FUNC_ARG;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_NO_MALLOC
|
||||||
if (isAllocated) {
|
if (isAllocated) {
|
||||||
XFREE(hash, heap, DYNAMIC_TYPE_HASHES);
|
XFREE(hash, heap, DYNAMIC_TYPE_HASHES);
|
||||||
(void)heap;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
(void)heap;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@@ -151,8 +151,8 @@ struct wc_Sha {
|
|||||||
#else
|
#else
|
||||||
word32 digest[WC_SHA_DIGEST_SIZE / sizeof(word32)];
|
word32 digest[WC_SHA_DIGEST_SIZE / sizeof(word32)];
|
||||||
#endif
|
#endif
|
||||||
void* heap;
|
|
||||||
#endif
|
#endif
|
||||||
|
void* heap;
|
||||||
#ifdef WOLFSSL_PIC32MZ_HASH
|
#ifdef WOLFSSL_PIC32MZ_HASH
|
||||||
hashUpdCache cache; /* cache for updates */
|
hashUpdCache cache; /* cache for updates */
|
||||||
#endif
|
#endif
|
||||||
|
@@ -194,13 +194,13 @@ struct wc_Sha256 {
|
|||||||
word32 buffLen; /* in bytes */
|
word32 buffLen; /* in bytes */
|
||||||
word32 loLen; /* length in bytes */
|
word32 loLen; /* length in bytes */
|
||||||
word32 hiLen; /* length in bytes */
|
word32 hiLen; /* length in bytes */
|
||||||
void* heap;
|
|
||||||
|
|
||||||
#ifdef WC_C_DYNAMIC_FALLBACK
|
#ifdef WC_C_DYNAMIC_FALLBACK
|
||||||
int sha_method;
|
int sha_method;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
void* heap;
|
||||||
#ifdef WOLFSSL_PIC32MZ_HASH
|
#ifdef WOLFSSL_PIC32MZ_HASH
|
||||||
hashUpdCache cache; /* cache for updates */
|
hashUpdCache cache; /* cache for updates */
|
||||||
#endif
|
#endif
|
||||||
|
@@ -144,6 +144,7 @@ struct wc_Sha512 {
|
|||||||
cy_stc_crypto_sha_state_t hash_state;
|
cy_stc_crypto_sha_state_t hash_state;
|
||||||
cy_en_crypto_sha_mode_t sha_mode;
|
cy_en_crypto_sha_mode_t sha_mode;
|
||||||
cy_stc_crypto_v2_sha512_buffers_t sha_buffers;
|
cy_stc_crypto_v2_sha512_buffers_t sha_buffers;
|
||||||
|
void* heap;
|
||||||
#else
|
#else
|
||||||
word64 digest[WC_SHA512_DIGEST_SIZE / sizeof(word64)];
|
word64 digest[WC_SHA512_DIGEST_SIZE / sizeof(word64)];
|
||||||
word64 buffer[WC_SHA512_BLOCK_SIZE / sizeof(word64)];
|
word64 buffer[WC_SHA512_BLOCK_SIZE / sizeof(word64)];
|
||||||
|
@@ -943,7 +943,8 @@ typedef struct w64wrapper {
|
|||||||
WOLFSSL_API int wc_strncasecmp(const char *s1, const char *s2, size_t n);
|
WOLFSSL_API int wc_strncasecmp(const char *s1, const char *s2, size_t n);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(XSTRDUP) && !defined(USE_WOLF_STRDUP)
|
#if !defined(XSTRDUP) && !defined(USE_WOLF_STRDUP) &&\
|
||||||
|
!defined (WOLFSSL_NO_MALLOC)
|
||||||
#define USE_WOLF_STRDUP
|
#define USE_WOLF_STRDUP
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_WOLF_STRDUP
|
#ifdef USE_WOLF_STRDUP
|
||||||
|
Reference in New Issue
Block a user