Skip to content

Commit 5cc0595

Browse files
authored
Merge pull request #7485 from dgarske/pkcs11_async
Improved the prioritization of crypto callback vs async crypt in ECC …
2 parents bd9a27a + 5af0b1e commit 5cc0595

4 files changed

Lines changed: 21 additions & 73 deletions

File tree

wolfcrypt/src/ecc.c

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6094,20 +6094,11 @@ WOLFSSL_ABI
60946094
int wc_ecc_init_ex(ecc_key* key, void* heap, int devId)
60956095
{
60966096
int ret = 0;
6097-
#if defined(HAVE_PKCS11)
6098-
int isPkcs11 = 0;
6099-
#endif
61006097

61016098
if (key == NULL) {
61026099
return BAD_FUNC_ARG;
61036100
}
61046101

6105-
#if defined(HAVE_PKCS11)
6106-
if (key->isPkcs11) {
6107-
isPkcs11 = 1;
6108-
}
6109-
#endif
6110-
61116102
#ifdef ECC_DUMP_OID
61126103
wc_ecc_dump_oids();
61136104
#endif
@@ -6161,16 +6152,17 @@ int wc_ecc_init_ex(ecc_key* key, void* heap, int devId)
61616152
#endif
61626153

61636154
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC)
6164-
#if defined(HAVE_PKCS11)
6165-
if (!isPkcs11)
6155+
#ifdef WOLF_CRYPTO_CB
6156+
/* prefer crypto callback */
6157+
if (key->devId != INVALID_DEVID)
61666158
#endif
6167-
{
6168-
/* handle as async */
6169-
ret = wolfAsync_DevCtxInit(&key->asyncDev, WOLFSSL_ASYNC_MARKER_ECC,
6170-
key->heap, devId);
6171-
}
6172-
#elif defined(HAVE_PKCS11)
6173-
(void)isPkcs11;
6159+
{
6160+
/* handle as async */
6161+
ret = wolfAsync_DevCtxInit(&key->asyncDev, WOLFSSL_ASYNC_MARKER_ECC,
6162+
key->heap, devId);
6163+
}
6164+
if (ret != 0)
6165+
return ret;
61746166
#endif
61756167

61766168
#if defined(WOLFSSL_DSP)
@@ -6222,12 +6214,6 @@ int wc_ecc_init_id(ecc_key* key, unsigned char* id, int len, void* heap,
62226214
ret = BAD_FUNC_ARG;
62236215
if (ret == 0 && (len < 0 || len > ECC_MAX_ID_LEN))
62246216
ret = BUFFER_E;
6225-
6226-
#if defined(HAVE_PKCS11)
6227-
XMEMSET(key, 0, sizeof(ecc_key));
6228-
key->isPkcs11 = 1;
6229-
#endif
6230-
62316217
if (ret == 0)
62326218
ret = wc_ecc_init_ex(key, heap, devId);
62336219
if (ret == 0 && id != NULL && len != 0) {
@@ -6257,12 +6243,6 @@ int wc_ecc_init_label(ecc_key* key, const char* label, void* heap, int devId)
62576243
if (labelLen == 0 || labelLen > ECC_MAX_LABEL_LEN)
62586244
ret = BUFFER_E;
62596245
}
6260-
6261-
#if defined(HAVE_PKCS11)
6262-
XMEMSET(key, 0, sizeof(ecc_key));
6263-
key->isPkcs11 = 1;
6264-
#endif
6265-
62666246
if (ret == 0)
62676247
ret = wc_ecc_init_ex(key, heap, devId);
62686248
if (ret == 0) {
@@ -7177,7 +7157,7 @@ int wc_ecc_sign_hash_ex(const byte* in, word32 inlen, WC_RNG* rng,
71777157

71787158

71797159
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) && \
7180-
defined(WOLFSSL_ASYNC_CRYPT_SW)
7160+
defined(WOLFSSL_ASYNC_CRYPT_SW)
71817161
if (key->asyncDev.marker == WOLFSSL_ASYNC_MARKER_ECC) {
71827162
if (wc_AsyncSwInit(&key->asyncDev, ASYNC_SW_ECC_SIGN)) {
71837163
WC_ASYNC_SW* sw = &key->asyncDev.sw;

wolfcrypt/src/rsa.c

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,11 @@ static void wc_RsaCleanup(RsaKey* key)
153153
int wc_InitRsaKey_ex(RsaKey* key, void* heap, int devId)
154154
{
155155
int ret = 0;
156-
#if defined(HAVE_PKCS11)
157-
int isPkcs11 = 0;
158-
#endif
159156

160157
if (key == NULL) {
161158
return BAD_FUNC_ARG;
162159
}
163160

164-
#if defined(HAVE_PKCS11)
165-
if (key->isPkcs11) {
166-
isPkcs11 = 1;
167-
}
168-
#endif
169-
170161
XMEMSET(key, 0, sizeof(RsaKey));
171162

172163
key->type = RSA_TYPE_UNKNOWN;
@@ -193,19 +184,18 @@ int wc_InitRsaKey_ex(RsaKey* key, void* heap, int devId)
193184
#endif
194185

195186
#ifdef WC_ASYNC_ENABLE_RSA
196-
#if defined(HAVE_PKCS11)
197-
if (!isPkcs11)
187+
#ifdef WOLF_CRYPTO_CB
188+
/* prefer crypto callback */
189+
if (key->devId != INVALID_DEVID)
198190
#endif
199-
{
200-
/* handle as async */
201-
ret = wolfAsync_DevCtxInit(&key->asyncDev,
202-
WOLFSSL_ASYNC_MARKER_RSA, key->heap, devId);
203-
if (ret != 0)
204-
return ret;
205-
}
191+
{
192+
/* handle as async */
193+
ret = wolfAsync_DevCtxInit(&key->asyncDev,
194+
WOLFSSL_ASYNC_MARKER_RSA, key->heap, devId);
195+
if (ret != 0)
196+
return ret;
197+
}
206198
#endif /* WC_ASYNC_ENABLE_RSA */
207-
#elif defined(HAVE_PKCS11)
208-
(void)isPkcs11;
209199
#endif /* WOLFSSL_ASYNC_CRYPT */
210200

211201
#ifndef WOLFSSL_RSA_PUBLIC_ONLY
@@ -278,14 +268,6 @@ int wc_InitRsaKey_Id(RsaKey* key, unsigned char* id, int len, void* heap,
278268
ret = BAD_FUNC_ARG;
279269
if (ret == 0 && (len < 0 || len > RSA_MAX_ID_LEN))
280270
ret = BUFFER_E;
281-
282-
#if defined(HAVE_PKCS11)
283-
if (ret == 0) {
284-
XMEMSET(key, 0, sizeof(RsaKey));
285-
key->isPkcs11 = 1;
286-
}
287-
#endif
288-
289271
if (ret == 0)
290272
ret = wc_InitRsaKey_ex(key, heap, devId);
291273
if (ret == 0 && id != NULL && len != 0) {
@@ -315,14 +297,6 @@ int wc_InitRsaKey_Label(RsaKey* key, const char* label, void* heap, int devId)
315297
if (labelLen == 0 || labelLen > RSA_MAX_LABEL_LEN)
316298
ret = BUFFER_E;
317299
}
318-
319-
#if defined(HAVE_PKCS11)
320-
if (ret == 0) {
321-
XMEMSET(key, 0, sizeof(RsaKey));
322-
key->isPkcs11 = 1;
323-
}
324-
#endif
325-
326300
if (ret == 0)
327301
ret = wc_InitRsaKey_ex(key, heap, devId);
328302
if (ret == 0) {

wolfssl/wolfcrypt/ecc.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,6 @@ struct ecc_key {
519519
void* devCtx;
520520
int devId;
521521
#endif
522-
#if defined(HAVE_PKCS11)
523-
byte isPkcs11 : 1; /* indicate if PKCS11 is preferred */
524-
#endif
525522
#ifdef WOLFSSL_SILABS_SE_ACCEL
526523
sl_se_command_context_t cmd_ctx;
527524
sl_se_key_descriptor_t key;

wolfssl/wolfcrypt/rsa.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,6 @@ struct RsaKey {
217217
void* devCtx;
218218
int devId;
219219
#endif
220-
#if defined(HAVE_PKCS11)
221-
byte isPkcs11 : 1; /* indicate if PKCS11 is preferred */
222-
#endif
223220
#ifdef WOLFSSL_ASYNC_CRYPT
224221
WC_ASYNC_DEV asyncDev;
225222
#ifdef WOLFSSL_CERT_GEN

0 commit comments

Comments
 (0)