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