Check nomalloc with verify inline

This commit is contained in:
Tesfa Mael
2022-05-04 09:33:38 -07:00
parent 97f54e8e0a
commit bdd6072ede
2 changed files with 14 additions and 8 deletions

View File

@ -239,7 +239,7 @@ enum {
static void wc_RsaCleanup(RsaKey* key) static void wc_RsaCleanup(RsaKey* key)
{ {
#ifndef WOLFSSL_RSA_VERIFY_INLINE #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && !defined(WOLFSSL_NO_MALLOC)
if (key && key->data) { if (key && key->data) {
/* make sure any allocated memory is free'd */ /* make sure any allocated memory is free'd */
if (key->dataIsAlloc) { if (key->dataIsAlloc) {
@ -273,7 +273,7 @@ int wc_InitRsaKey_ex(RsaKey* key, void* heap, int devId)
key->type = RSA_TYPE_UNKNOWN; key->type = RSA_TYPE_UNKNOWN;
key->state = RSA_STATE_NONE; key->state = RSA_STATE_NONE;
key->heap = heap; key->heap = heap;
#ifndef WOLFSSL_RSA_VERIFY_INLINE #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && !defined(WOLFSSL_NO_MALLOC)
key->dataIsAlloc = 0; key->dataIsAlloc = 0;
key->data = NULL; key->data = NULL;
#endif #endif
@ -3284,7 +3284,8 @@ static int RsaPrivateDecryptEx(const byte* in, word32 inLen, byte* out,
#endif /* WOLFSSL_CRYPTOCELL */ #endif /* WOLFSSL_CRYPTOCELL */
#if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_VERIFY_INLINE) #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_VERIFY_INLINE) && \
!defined(WOLFSSL_NO_MALLOC)
/* verify the tmp ptr is NULL, otherwise indicates bad state */ /* verify the tmp ptr is NULL, otherwise indicates bad state */
if (key->data != NULL) { if (key->data != NULL) {
ret = BAD_STATE_E; ret = BAD_STATE_E;
@ -3312,7 +3313,8 @@ static int RsaPrivateDecryptEx(const byte* in, word32 inLen, byte* out,
FALL_THROUGH; FALL_THROUGH;
case RSA_STATE_DECRYPT_EXPTMOD: case RSA_STATE_DECRYPT_EXPTMOD:
#if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_VERIFY_INLINE) #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_VERIFY_INLINE) && \
!defined(WOLFSSL_NO_MALLOC)
ret = wc_RsaFunction_ex(key->data, inLen, key->data, &key->dataLen, ret = wc_RsaFunction_ex(key->data, inLen, key->data, &key->dataLen,
rsa_type, key, rng, rsa_type, key, rng,
pad_type != WC_RSA_OAEP_PAD); pad_type != WC_RSA_OAEP_PAD);
@ -3331,7 +3333,8 @@ static int RsaPrivateDecryptEx(const byte* in, word32 inLen, byte* out,
FALL_THROUGH; FALL_THROUGH;
case RSA_STATE_DECRYPT_UNPAD: case RSA_STATE_DECRYPT_UNPAD:
#if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_VERIFY_INLINE) #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_VERIFY_INLINE) && \
!defined(WOLFSSL_NO_MALLOC)
ret = wc_RsaUnPad_ex(key->data, key->dataLen, &pad, pad_value, pad_type, ret = wc_RsaUnPad_ex(key->data, key->dataLen, &pad, pad_value, pad_type,
hash, mgf, label, labelSz, saltLen, hash, mgf, label, labelSz, saltLen,
mp_count_bits(&key->n), key->heap); mp_count_bits(&key->n), key->heap);
@ -3343,13 +3346,15 @@ static int RsaPrivateDecryptEx(const byte* in, word32 inLen, byte* out,
if (rsa_type == RSA_PUBLIC_DECRYPT && ret > (int)outLen) if (rsa_type == RSA_PUBLIC_DECRYPT && ret > (int)outLen)
ret = RSA_BUFFER_E; ret = RSA_BUFFER_E;
else if (ret >= 0 && pad != NULL) { else if (ret >= 0 && pad != NULL) {
#if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_VERIFY_INLINE) #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_VERIFY_INLINE) && \
!defined(WOLFSSL_NO_MALLOC)
signed char c; signed char c;
#endif #endif
/* only copy output if not inline */ /* only copy output if not inline */
if (outPtr == NULL) { if (outPtr == NULL) {
#if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_VERIFY_INLINE) #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_VERIFY_INLINE) && \
!defined(WOLFSSL_NO_MALLOC)
if (rsa_type == RSA_PRIVATE_DECRYPT) { if (rsa_type == RSA_PRIVATE_DECRYPT) {
word32 i = 0; word32 i = 0;
word32 j; word32 j;

View File

@ -205,7 +205,8 @@ struct RsaKey {
char label[RSA_MAX_LABEL_LEN]; char label[RSA_MAX_LABEL_LEN];
int labelLen; int labelLen;
#endif #endif
#if defined(WOLFSSL_ASYNC_CRYPT) || !defined(WOLFSSL_RSA_VERIFY_INLINE) #if defined(WOLFSSL_ASYNC_CRYPT) || !defined(WOLFSSL_RSA_VERIFY_INLINE) && \
!defined(WOLFSSL_NO_MALLOC)
byte dataIsAlloc; byte dataIsAlloc;
#endif #endif
#ifdef WC_RSA_NONBLOCK #ifdef WC_RSA_NONBLOCK