diff --git a/wolfcrypt/src/rsa.c b/wolfcrypt/src/rsa.c index 158e3591e..afeec506d 100755 --- a/wolfcrypt/src/rsa.c +++ b/wolfcrypt/src/rsa.c @@ -1146,17 +1146,15 @@ static int RsaPublicEncryptEx(const byte* in, word32 inLen, byte* out, /* Async operations that include padding */ if (rsa_type == RSA_PUBLIC_ENCRYPT && pad_value == RSA_BLOCK_TYPE_2) { - key->state = RSA_STATE_ENCRYPT_EXPTMOD; + key->state = RSA_STATE_ENCRYPT_RES; key->dataLen = key->n.raw.len; - ret = NitroxRsaPublicEncrypt(in, inLen, out, outLen, key); - break; + return NitroxRsaPublicEncrypt(in, inLen, out, outLen, key); } else if (rsa_type == RSA_PRIVATE_ENCRYPT && pad_value == RSA_BLOCK_TYPE_1) { - key->state = RSA_STATE_ENCRYPT_EXPTMOD; + key->state = RSA_STATE_ENCRYPT_RES; key->dataLen = key->n.raw.len; - ret = NitroxRsaSSL_Sign(in, inLen, out, outLen, key); - break; + return NitroxRsaSSL_Sign(in, inLen, out, outLen, key); } } #endif @@ -1235,29 +1233,25 @@ static int RsaPrivateDecryptEx(byte* in, word32 inLen, byte* out, case RSA_STATE_NONE: case RSA_STATE_DECRYPT_EXPTMOD: key->state = RSA_STATE_DECRYPT_EXPTMOD; + key->dataLen = inLen; #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_RSA) && \ defined(HAVE_CAVIUM) /* Async operations that include padding */ if (key->asyncDev.marker == WOLFSSL_ASYNC_MARKER_RSA) { - key->dataLen = 0; if (rsa_type == RSA_PRIVATE_DECRYPT && pad_value == RSA_BLOCK_TYPE_2) { - key->state = RSA_STATE_DECRYPT_UNPAD; + key->state = RSA_STATE_DECRYPT_RES; key->data = NULL; - ret = NitroxRsaPrivateDecrypt(in, inLen, out, outLen, key); - if (ret > 0) { - if (outPtr) - *outPtr = in; - } - break; + if (outPtr) + *outPtr = in; + return NitroxRsaPrivateDecrypt(in, inLen, out, &key->dataLen, key); } else if (rsa_type == RSA_PUBLIC_DECRYPT && pad_value == RSA_BLOCK_TYPE_1) { - key->state = RSA_STATE_DECRYPT_UNPAD; + key->state = RSA_STATE_DECRYPT_RES; key->data = NULL; - ret = NitroxRsaSSL_Verify(in, inLen, out, outLen, key); - break; + return NitroxRsaSSL_Verify(in, inLen, out, &key->dataLen, key); } } #endif @@ -1269,7 +1263,6 @@ static int RsaPrivateDecryptEx(byte* in, word32 inLen, byte* out, } /* if not doing this inline then allocate a buffer for it */ - key->dataLen = inLen; if (outPtr == NULL) { key->data = (byte*)XMALLOC(inLen, key->heap, DYNAMIC_TYPE_WOLF_BIGINT); key->dataIsAlloc = 1; @@ -1324,6 +1317,11 @@ static int RsaPrivateDecryptEx(byte* in, word32 inLen, byte* out, if (key->asyncDev.marker == WOLFSSL_ASYNC_MARKER_RSA) { /* return event ret */ ret = key->asyncDev.event.ret; + if (ret == 0) { + /* convert result */ + byte* dataLen = (byte*)&key->dataLen; + ret = (dataLen[0] << 8) | (dataLen[1]); + } } #endif break; diff --git a/wolfssl/wolfcrypt/asn_public.h b/wolfssl/wolfcrypt/asn_public.h index 539a6ada0..1fdfa61ef 100644 --- a/wolfssl/wolfcrypt/asn_public.h +++ b/wolfssl/wolfcrypt/asn_public.h @@ -25,24 +25,21 @@ #define WOLF_CRYPT_ASN_PUBLIC_H #include -#ifdef HAVE_ECC - #include -#endif -#if defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA) - #include -#endif #ifdef __cplusplus extern "C" { #endif -#ifndef HAVE_ECC +/* guard on redeclaration */ +#ifndef WC_ECCKEY_TYPE_DEFINED typedef struct ecc_key ecc_key; + #define WC_ECCKEY_TYPE_DEFINED #endif -#ifdef NO_RSA +#ifndef WC_RSAKEY_TYPE_DEFINED typedef struct RsaKey RsaKey; + #define WC_RSAKEY_TYPE_DEFINED #endif -#ifndef WC_RNG_TYPE_DEFINED /* guard on redeclaration */ +#ifndef WC_RNG_TYPE_DEFINED typedef struct WC_RNG WC_RNG; #define WC_RNG_TYPE_DEFINED #endif diff --git a/wolfssl/wolfcrypt/ecc.h b/wolfssl/wolfcrypt/ecc.h index beb3ec54f..24e78359d 100644 --- a/wolfssl/wolfcrypt/ecc.h +++ b/wolfssl/wolfcrypt/ecc.h @@ -262,7 +262,7 @@ enum { }; /* An ECC Key */ -typedef struct ecc_key { +struct ecc_key { int type; /* Public or Private */ int idx; /* Index into the ecc_sets[] for the parameters of this curve if -1, this key is using user supplied @@ -287,7 +287,12 @@ typedef struct ecc_key { CertSignCtx certSignCtx; /* context info for cert sign (MakeSignature) */ #endif #endif /* WOLFSSL_ASYNC_CRYPT */ -} ecc_key; +}; + +#ifndef WC_ECCKEY_TYPE_DEFINED + typedef struct ecc_key ecc_key; + #define WC_ECCKEY_TYPE_DEFINED +#endif /* ECC predefined curve sets */ diff --git a/wolfssl/wolfcrypt/rsa.h b/wolfssl/wolfcrypt/rsa.h index 66c46d109..a64eb8708 100644 --- a/wolfssl/wolfcrypt/rsa.h +++ b/wolfssl/wolfcrypt/rsa.h @@ -81,7 +81,7 @@ enum { /* RSA */ -typedef struct RsaKey { +struct RsaKey { mp_int n, e, d, p, q, dP, dQ, u; void* heap; /* for user memory overrides */ byte* data; /* temp buffer for async RSA */ @@ -98,7 +98,13 @@ typedef struct RsaKey { #endif #endif /* WOLFSSL_ASYNC_CRYPT */ byte dataIsAlloc; -} RsaKey; +}; + +#ifndef WC_RSAKEY_TYPE_DEFINED + typedef struct RsaKey RsaKey; + #define WC_RSAKEY_TYPE_DEFINED +#endif + #endif /*HAVE_FIPS */ WOLFSSL_API int wc_InitRsaKey(RsaKey* key, void* heap);