forked from wolfSSL/wolfssl
Progress with RSA fixes for Cavium Nitrox after async refactor. Improved method for RsaKey and ecc_key typedef to work with async.
This commit is contained in:
@ -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;
|
||||
|
@ -25,24 +25,21 @@
|
||||
#define WOLF_CRYPT_ASN_PUBLIC_H
|
||||
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
#ifdef HAVE_ECC
|
||||
#include <wolfssl/wolfcrypt/ecc.h>
|
||||
#endif
|
||||
#if defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA)
|
||||
#include <wolfssl/wolfcrypt/rsa.h>
|
||||
#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
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user