forked from wolfSSL/wolfssl
Merge pull request #4223 from SparkiDev/mem_usage_fixes_1
Memory allocation: fixes from memory usage generation
This commit is contained in:
@ -1100,7 +1100,7 @@ AC_ARG_ENABLE([lowresource],
|
|||||||
if test "$ENABLED_LOWRESOURCE" = "yes"
|
if test "$ENABLED_LOWRESOURCE" = "yes"
|
||||||
then
|
then
|
||||||
# low memory / flash flags
|
# low memory / flash flags
|
||||||
AM_CFLAGS="$AM_CFLAGS -DNO_SESSION_CACHE -DRSA_LOW_MEM -DALT_ECC_SIZE -DGCM_SMALL -DCURVE25519_SMALL -DED25519_SMALL -DWOLFSSL_SMALL_CERT_VERIFY"
|
AM_CFLAGS="$AM_CFLAGS -DNO_SESSION_CACHE -DRSA_LOW_MEM -DGCM_SMALL -DCURVE25519_SMALL -DED25519_SMALL -DWOLFSSL_SMALL_CERT_VERIFY"
|
||||||
|
|
||||||
# low flash flags
|
# low flash flags
|
||||||
AM_CFLAGS="$AM_CFLAGS -DUSE_SLOW_SHA -DUSE_SLOW_SHA256 -DUSE_SLOW_SHA512"
|
AM_CFLAGS="$AM_CFLAGS -DUSE_SLOW_SHA -DUSE_SLOW_SHA256 -DUSE_SLOW_SHA512"
|
||||||
@ -2044,6 +2044,11 @@ then
|
|||||||
AM_CFLAGS="$AM_CFLAGS -DWC_ECC_NONBLOCK"
|
AM_CFLAGS="$AM_CFLAGS -DWC_ECC_NONBLOCK"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if test "$ENABLED_LOWRESOURCE" = "yes" && test "$ENABLED_FASTMATH" = "yes"
|
||||||
|
then
|
||||||
|
AM_CFLAGS="$AM_CFLAGS -DALT_ECC_SIZE"
|
||||||
|
fi
|
||||||
|
|
||||||
ENABLED_CERTS=yes
|
ENABLED_CERTS=yes
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -7043,8 +7043,7 @@ static int TLSX_KeyShare_GenEccKey(WOLFSSL *ssl, KeyShareEntry* kse)
|
|||||||
kse->pubKeyLen = keySize * 2 + 1;
|
kse->pubKeyLen = keySize * 2 + 1;
|
||||||
|
|
||||||
/* Allocate an ECC key to hold private key. */
|
/* Allocate an ECC key to hold private key. */
|
||||||
kse->key = (byte*)XMALLOC(sizeof(ecc_key), ssl->heap,
|
kse->key = (byte*)XMALLOC(sizeof(ecc_key), ssl->heap, DYNAMIC_TYPE_ECC);
|
||||||
DYNAMIC_TYPE_PRIVATE_KEY);
|
|
||||||
if (kse->key == NULL) {
|
if (kse->key == NULL) {
|
||||||
WOLFSSL_MSG("EccTempKey Memory error");
|
WOLFSSL_MSG("EccTempKey Memory error");
|
||||||
return MEMORY_E;
|
return MEMORY_E;
|
||||||
|
@ -699,16 +699,18 @@ int wc_ed25519_verify_msg_ex(const byte* sig, word32 sigLen, const byte* msg,
|
|||||||
return ret;
|
return ret;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ret = ed25519_verify_msg_init_with_sha(sig, sigLen, key, sha,
|
ret = ed25519_verify_msg_init_with_sha(sig, sigLen, key, sha, type, context,
|
||||||
type, context, contextLen);
|
contextLen);
|
||||||
if (ret < 0)
|
if (ret == 0)
|
||||||
return ret;
|
ret = ed25519_verify_msg_update_with_sha(msg, msgLen, key, sha);
|
||||||
|
if (ret == 0)
|
||||||
|
ret = ed25519_verify_msg_final_with_sha(sig, sigLen, res, key, sha);
|
||||||
|
|
||||||
ret = ed25519_verify_msg_update_with_sha(msg, msgLen, key, sha);
|
#ifndef WOLFSSL_ED25519_PERSISTENT_SHA
|
||||||
if (ret < 0)
|
ed25519_hash_free(key, sha);
|
||||||
return ret;
|
#endif
|
||||||
|
|
||||||
return ed25519_verify_msg_final_with_sha(sig, sigLen, res, key, sha);
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -823,6 +823,9 @@ static int RsaMGF1(enum wc_HashType hType, byte* seed, word32 seedSz,
|
|||||||
int ret;
|
int ret;
|
||||||
word32 counter;
|
word32 counter;
|
||||||
word32 idx;
|
word32 idx;
|
||||||
|
#ifdef WOLFSSL_SMALL_STACK_CACHE
|
||||||
|
wc_HashAlg *hash;
|
||||||
|
#endif
|
||||||
hLen = wc_HashGetDigestSize(hType);
|
hLen = wc_HashGetDigestSize(hType);
|
||||||
counter = 0;
|
counter = 0;
|
||||||
idx = 0;
|
idx = 0;
|
||||||
@ -847,11 +850,31 @@ static int RsaMGF1(enum wc_HashType hType, byte* seed, word32 seedSz,
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* use array on the stack */
|
/* use array on the stack */
|
||||||
|
#ifndef WOLFSSL_SMALL_STACK_CACHE
|
||||||
tmpSz = sizeof(tmpA);
|
tmpSz = sizeof(tmpA);
|
||||||
|
#endif
|
||||||
tmp = tmpA;
|
tmp = tmpA;
|
||||||
tmpF = 0; /* no need to free memory at end */
|
tmpF = 0; /* no need to free memory at end */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_SMALL_STACK_CACHE
|
||||||
|
hash = (wc_HashAlg*)XMALLOC(sizeof(*hash), heap, DYNAMIC_TYPE_DIGEST);
|
||||||
|
if (hash == NULL) {
|
||||||
|
if (tmpF) {
|
||||||
|
XFREE(tmp, heap, DYNAMIC_TYPE_RSA_BUFFER);
|
||||||
|
}
|
||||||
|
return MEMORY_E;
|
||||||
|
}
|
||||||
|
ret = wc_HashInit_ex(hash, hType, heap, INVALID_DEVID);
|
||||||
|
if (ret != 0) {
|
||||||
|
XFREE(hash, heap, DYNAMIC_TYPE_DIGEST);
|
||||||
|
if (tmpF) {
|
||||||
|
XFREE(tmp, heap, DYNAMIC_TYPE_RSA_BUFFER);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
do {
|
do {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
XMEMCPY(tmp, seed, seedSz);
|
XMEMCPY(tmp, seed, seedSz);
|
||||||
@ -863,7 +886,15 @@ static int RsaMGF1(enum wc_HashType hType, byte* seed, word32 seedSz,
|
|||||||
tmp[seedSz + 3] = (byte)((counter) & 0xFF);
|
tmp[seedSz + 3] = (byte)((counter) & 0xFF);
|
||||||
|
|
||||||
/* hash and append to existing output */
|
/* hash and append to existing output */
|
||||||
if ((ret = wc_Hash(hType, tmp, (seedSz + 4), tmp, tmpSz)) != 0) {
|
#ifdef WOLFSSL_SMALL_STACK_CACHE
|
||||||
|
ret = wc_HashUpdate(hash, hType, tmp, (seedSz + 4));
|
||||||
|
if (ret == 0) {
|
||||||
|
ret = wc_HashFinal(hash, hType, tmp);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
ret = wc_Hash(hType, tmp, (seedSz + 4), tmp, tmpSz);
|
||||||
|
#endif
|
||||||
|
if (ret != 0) {
|
||||||
/* check for if dynamic memory was needed, then free */
|
/* check for if dynamic memory was needed, then free */
|
||||||
if (tmpF) {
|
if (tmpF) {
|
||||||
XFREE(tmp, heap, DYNAMIC_TYPE_RSA_BUFFER);
|
XFREE(tmp, heap, DYNAMIC_TYPE_RSA_BUFFER);
|
||||||
@ -881,6 +912,10 @@ static int RsaMGF1(enum wc_HashType hType, byte* seed, word32 seedSz,
|
|||||||
if (tmpF) {
|
if (tmpF) {
|
||||||
XFREE(tmp, heap, DYNAMIC_TYPE_RSA_BUFFER);
|
XFREE(tmp, heap, DYNAMIC_TYPE_RSA_BUFFER);
|
||||||
}
|
}
|
||||||
|
#ifdef WOLFSSL_SMALL_STACK_CACHE
|
||||||
|
wc_HashFree(hash, hType);
|
||||||
|
XFREE(hash, heap, DYNAMIC_TYPE_DIGEST);
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user