@@ -267,12 +267,21 @@ static void wc_RsaCleanup(RsaKey* key)
267267
268268int wc_InitRsaKey_ex (RsaKey * key , void * heap , int devId )
269269{
270- int ret = 0 ;
270+ int ret = 0 ;
271+ #if defined(HAVE_PKCS11 )
272+ int isPkcs11 = 0 ;
273+ #endif
271274
272275 if (key == NULL ) {
273276 return BAD_FUNC_ARG ;
274277 }
275278
279+ #if defined(HAVE_PKCS11 )
280+ if (key -> isPkcs11 ) {
281+ isPkcs11 = 1 ;
282+ }
283+ #endif
284+
276285 XMEMSET (key , 0 , sizeof (RsaKey ));
277286
278287 key -> type = RSA_TYPE_UNKNOWN ;
@@ -299,12 +308,19 @@ int wc_InitRsaKey_ex(RsaKey* key, void* heap, int devId)
299308 #endif
300309
301310 #ifdef WC_ASYNC_ENABLE_RSA
302- /* handle as async */
303- ret = wolfAsync_DevCtxInit (& key -> asyncDev , WOLFSSL_ASYNC_MARKER_RSA ,
304- key -> heap , devId );
305- if (ret != 0 )
306- return ret ;
311+ #if defined(HAVE_PKCS11 )
312+ if (!isPkcs11 )
313+ #endif
314+ {
315+ /* handle as async */
316+ ret = wolfAsync_DevCtxInit (& key -> asyncDev ,
317+ WOLFSSL_ASYNC_MARKER_RSA , key -> heap , devId );
318+ if (ret != 0 )
319+ return ret ;
320+ }
307321 #endif /* WC_ASYNC_ENABLE_RSA */
322+ #elif defined(HAVE_PKCS11 )
323+ (void )isPkcs11 ;
308324#endif /* WOLFSSL_ASYNC_CRYPT */
309325
310326#ifndef WOLFSSL_RSA_PUBLIC_ONLY
@@ -370,6 +386,11 @@ int wc_InitRsaKey_Id(RsaKey* key, unsigned char* id, int len, void* heap,
370386 if (ret == 0 && (len < 0 || len > RSA_MAX_ID_LEN ))
371387 ret = BUFFER_E ;
372388
389+ #if defined(HAVE_PKCS11 )
390+ XMEMSET (key , 0 , sizeof (RsaKey ));
391+ key -> isPkcs11 = 1 ;
392+ #endif
393+
373394 if (ret == 0 )
374395 ret = wc_InitRsaKey_ex (key , heap , devId );
375396 if (ret == 0 && id != NULL && len != 0 ) {
@@ -400,6 +421,11 @@ int wc_InitRsaKey_Label(RsaKey* key, const char* label, void* heap, int devId)
400421 ret = BUFFER_E ;
401422 }
402423
424+ #if defined(HAVE_PKCS11 )
425+ XMEMSET (key , 0 , sizeof (RsaKey ));
426+ key -> isPkcs11 = 1 ;
427+ #endif
428+
403429 if (ret == 0 )
404430 ret = wc_InitRsaKey_ex (key , heap , devId );
405431 if (ret == 0 ) {
0 commit comments