mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-30 10:47:28 +02:00
Skip Async_DevCtxInit when using init rsa/ecc label/id api's (#6393)
* Skip Async_DevCtxInit when using init rsa/ecc label/id api's --------- Co-authored-by: Lealem Amedie <lealem47@github.com>
This commit is contained in:
@ -5804,12 +5804,21 @@ int wc_ecc_make_key(WC_RNG* rng, int keysize, ecc_key* key)
|
|||||||
WOLFSSL_ABI
|
WOLFSSL_ABI
|
||||||
int wc_ecc_init_ex(ecc_key* key, void* heap, int devId)
|
int wc_ecc_init_ex(ecc_key* key, void* heap, int devId)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
#if defined(HAVE_PKCS11)
|
||||||
|
int isPkcs11 = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (key == NULL) {
|
if (key == NULL) {
|
||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(HAVE_PKCS11)
|
||||||
|
if (key->isPkcs11) {
|
||||||
|
isPkcs11 = 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef ECC_DUMP_OID
|
#ifdef ECC_DUMP_OID
|
||||||
wc_ecc_dump_oids();
|
wc_ecc_dump_oids();
|
||||||
#endif
|
#endif
|
||||||
@ -5862,9 +5871,16 @@ int wc_ecc_init_ex(ecc_key* key, void* heap, int devId)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC)
|
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC)
|
||||||
/* handle as async */
|
#if defined(HAVE_PKCS11)
|
||||||
ret = wolfAsync_DevCtxInit(&key->asyncDev, WOLFSSL_ASYNC_MARKER_ECC,
|
if (!isPkcs11)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
/* handle as async */
|
||||||
|
ret = wolfAsync_DevCtxInit(&key->asyncDev, WOLFSSL_ASYNC_MARKER_ECC,
|
||||||
key->heap, devId);
|
key->heap, devId);
|
||||||
|
}
|
||||||
|
#elif defined(HAVE_PKCS11)
|
||||||
|
(void)isPkcs11;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(WOLFSSL_DSP)
|
#if defined(WOLFSSL_DSP)
|
||||||
@ -5917,6 +5933,11 @@ int wc_ecc_init_id(ecc_key* key, unsigned char* id, int len, void* heap,
|
|||||||
if (ret == 0 && (len < 0 || len > ECC_MAX_ID_LEN))
|
if (ret == 0 && (len < 0 || len > ECC_MAX_ID_LEN))
|
||||||
ret = BUFFER_E;
|
ret = BUFFER_E;
|
||||||
|
|
||||||
|
#if defined(HAVE_PKCS11)
|
||||||
|
XMEMSET(key, 0, sizeof(ecc_key));
|
||||||
|
key->isPkcs11 = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
ret = wc_ecc_init_ex(key, heap, devId);
|
ret = wc_ecc_init_ex(key, heap, devId);
|
||||||
if (ret == 0 && id != NULL && len != 0) {
|
if (ret == 0 && id != NULL && len != 0) {
|
||||||
@ -5947,6 +5968,11 @@ int wc_ecc_init_label(ecc_key* key, const char* label, void* heap, int devId)
|
|||||||
ret = BUFFER_E;
|
ret = BUFFER_E;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(HAVE_PKCS11)
|
||||||
|
XMEMSET(key, 0, sizeof(ecc_key));
|
||||||
|
key->isPkcs11 = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
ret = wc_ecc_init_ex(key, heap, devId);
|
ret = wc_ecc_init_ex(key, heap, devId);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
|
@ -267,12 +267,21 @@ static void wc_RsaCleanup(RsaKey* key)
|
|||||||
|
|
||||||
int wc_InitRsaKey_ex(RsaKey* key, void* heap, int devId)
|
int wc_InitRsaKey_ex(RsaKey* key, void* heap, int devId)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
#if defined(HAVE_PKCS11)
|
||||||
|
int isPkcs11 = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (key == NULL) {
|
if (key == NULL) {
|
||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(HAVE_PKCS11)
|
||||||
|
if (key->isPkcs11) {
|
||||||
|
isPkcs11 = 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
XMEMSET(key, 0, sizeof(RsaKey));
|
XMEMSET(key, 0, sizeof(RsaKey));
|
||||||
|
|
||||||
key->type = RSA_TYPE_UNKNOWN;
|
key->type = RSA_TYPE_UNKNOWN;
|
||||||
@ -299,12 +308,19 @@ int wc_InitRsaKey_ex(RsaKey* key, void* heap, int devId)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WC_ASYNC_ENABLE_RSA
|
#ifdef WC_ASYNC_ENABLE_RSA
|
||||||
/* handle as async */
|
#if defined(HAVE_PKCS11)
|
||||||
ret = wolfAsync_DevCtxInit(&key->asyncDev, WOLFSSL_ASYNC_MARKER_RSA,
|
if (!isPkcs11)
|
||||||
key->heap, devId);
|
#endif
|
||||||
if (ret != 0)
|
{
|
||||||
return ret;
|
/* handle as async */
|
||||||
|
ret = wolfAsync_DevCtxInit(&key->asyncDev,
|
||||||
|
WOLFSSL_ASYNC_MARKER_RSA, key->heap, devId);
|
||||||
|
if (ret != 0)
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
#endif /* WC_ASYNC_ENABLE_RSA */
|
#endif /* WC_ASYNC_ENABLE_RSA */
|
||||||
|
#elif defined(HAVE_PKCS11)
|
||||||
|
(void)isPkcs11;
|
||||||
#endif /* WOLFSSL_ASYNC_CRYPT */
|
#endif /* WOLFSSL_ASYNC_CRYPT */
|
||||||
|
|
||||||
#ifndef WOLFSSL_RSA_PUBLIC_ONLY
|
#ifndef WOLFSSL_RSA_PUBLIC_ONLY
|
||||||
@ -370,6 +386,11 @@ int wc_InitRsaKey_Id(RsaKey* key, unsigned char* id, int len, void* heap,
|
|||||||
if (ret == 0 && (len < 0 || len > RSA_MAX_ID_LEN))
|
if (ret == 0 && (len < 0 || len > RSA_MAX_ID_LEN))
|
||||||
ret = BUFFER_E;
|
ret = BUFFER_E;
|
||||||
|
|
||||||
|
#if defined(HAVE_PKCS11)
|
||||||
|
XMEMSET(key, 0, sizeof(RsaKey));
|
||||||
|
key->isPkcs11 = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
ret = wc_InitRsaKey_ex(key, heap, devId);
|
ret = wc_InitRsaKey_ex(key, heap, devId);
|
||||||
if (ret == 0 && id != NULL && len != 0) {
|
if (ret == 0 && id != NULL && len != 0) {
|
||||||
@ -400,6 +421,11 @@ int wc_InitRsaKey_Label(RsaKey* key, const char* label, void* heap, int devId)
|
|||||||
ret = BUFFER_E;
|
ret = BUFFER_E;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(HAVE_PKCS11)
|
||||||
|
XMEMSET(key, 0, sizeof(RsaKey));
|
||||||
|
key->isPkcs11 = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
ret = wc_InitRsaKey_ex(key, heap, devId);
|
ret = wc_InitRsaKey_ex(key, heap, devId);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
|
@ -504,6 +504,9 @@ struct ecc_key {
|
|||||||
#if defined(PLUTON_CRYPTO_ECC) || defined(WOLF_CRYPTO_CB)
|
#if defined(PLUTON_CRYPTO_ECC) || defined(WOLF_CRYPTO_CB)
|
||||||
int devId;
|
int devId;
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(HAVE_PKCS11)
|
||||||
|
byte isPkcs11 : 1; /* indicate if PKCS11 is preferred */
|
||||||
|
#endif
|
||||||
#ifdef WOLFSSL_SILABS_SE_ACCEL
|
#ifdef WOLFSSL_SILABS_SE_ACCEL
|
||||||
sl_se_command_context_t cmd_ctx;
|
sl_se_command_context_t cmd_ctx;
|
||||||
sl_se_key_descriptor_t key;
|
sl_se_key_descriptor_t key;
|
||||||
|
@ -215,6 +215,9 @@ struct RsaKey {
|
|||||||
#ifdef WOLF_CRYPTO_CB
|
#ifdef WOLF_CRYPTO_CB
|
||||||
int devId;
|
int devId;
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(HAVE_PKCS11)
|
||||||
|
byte isPkcs11 : 1; /* indicate if PKCS11 is preferred */
|
||||||
|
#endif
|
||||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
WC_ASYNC_DEV asyncDev;
|
WC_ASYNC_DEV asyncDev;
|
||||||
#ifdef WOLFSSL_CERT_GEN
|
#ifdef WOLFSSL_CERT_GEN
|
||||||
|
Reference in New Issue
Block a user