Skip to content

Commit

Permalink
Merge pull request #7738 from dgarske/pkcs11_rsakeygen
Browse files Browse the repository at this point in the history
Fix to support PKCS11 without RSA key generation
  • Loading branch information
SparkiDev authored Jul 11, 2024
2 parents d6ecaad + 28db1b1 commit e0494b5
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions wolfcrypt/src/wc_pkcs11.c
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ static int Pkcs11CreateSecretKey(CK_OBJECT_HANDLE* key, Pkcs11Session* session,
}
#endif

#ifndef NO_RSA
#if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
/**
* Create a PKCS#11 object containing the RSA private key data.
*
Expand Down Expand Up @@ -1024,7 +1024,7 @@ static int Pkcs11CreateRsaPrivateKey(CK_OBJECT_HANDLE* privateKey,

return ret;
}
#endif
#endif /* !NO_RSA && WOLFSSL_KEY_GEN */

#ifdef HAVE_ECC
/**
Expand Down Expand Up @@ -1380,7 +1380,7 @@ int wc_Pkcs11StoreKey(Pkcs11Token* token, int type, int clear, void* key)
break;
}
#endif
#ifndef NO_RSA
#if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
case PKCS11_KEY_TYPE_RSA: {
RsaKey* rsaKey = (RsaKey*)key;

Expand Down Expand Up @@ -1774,7 +1774,12 @@ static int Pkcs11RsaPrivateKey(Pkcs11Session* session, RsaKey* rsaKey,
int ret;

if (sessionKey) {
#ifdef WOLFSSL_KEY_GEN
ret = Pkcs11CreateRsaPrivateKey(privateKey, session, rsaKey, 0);
#else
/* RSA Key Generation support not compiled in */
ret = NOT_COMPILED_IN;
#endif
}
else if (rsaKey->labelLen > 0) {
ret = Pkcs11FindKeyByLabel(privateKey, CKO_PRIVATE_KEY, CKK_RSA,
Expand Down Expand Up @@ -1996,7 +2001,8 @@ static int Pkcs11Rsa(Pkcs11Session* session, wc_CryptoInfo* info)
/* Make a handle to a private key. */
ret = Pkcs11RsaPrivateKey(session, rsaKey, sessionKey, &key);
}

}
if (ret == 0) {
if (type == RSA_PUBLIC_ENCRYPT) {
WOLFSSL_MSG("PKCS#11: Public Encrypt");
if ((mechInfo.flags & CKF_ENCRYPT) != 0) {
Expand Down

0 comments on commit e0494b5

Please sign in to comment.