Skip to content

Commit 58f48a9

Browse files
authored
Merge pull request #9836 from Frauschi/pkcs11_dilithium
Add support for ML-DSA in PKCS#11
2 parents c65e3e5 + ad22f9a commit 58f48a9

14 files changed

Lines changed: 1283 additions & 162 deletions

File tree

.wolfssl_known_macro_extras

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ NO_PKCS11_ECC
420420
NO_PKCS11_ECDH
421421
NO_PKCS11_EC_KEYGEN
422422
NO_PKCS11_HMAC
423+
NO_PKCS11_MLDSA
423424
NO_PKCS11_RNG
424425
NO_PKCS11_RSA
425426
NO_PKCS11_RSA_PKCS

wolfcrypt/src/aes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13613,7 +13613,7 @@ void wc_AesFree(Aes* aes)
1361313613
#endif
1361413614
{
1361513615
int ret = wc_CryptoCb_Free(aes->devId, WC_ALGO_TYPE_CIPHER,
13616-
WC_CIPHER_AES, aes);
13616+
WC_CIPHER_AES, 0, aes);
1361713617
#ifdef WOLF_CRYPTO_CB_AES_SETKEY
1361813618
aes->devCtx = NULL; /* Clear device context handle */
1361913619
#endif

wolfcrypt/src/cryptocb.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2120,11 +2120,13 @@ int wc_CryptoCb_Copy(int devId, int algo, int type, void* src, void* dst)
21202120
* WC_ALGO_TYPE_CIPHER, etc
21212121
* type: Specific type - for HASH: enum wc_HashType, for CIPHER:
21222122
* enum wc_CipherType
2123+
* subType: Specific subtype - for PQC: enum wc_PqcKemType,
2124+
* enum wc_PqcSignatureType
21232125
* obj: Pointer to object structure to free
21242126
* Returns: 0 on success, negative on error, CRYPTOCB_UNAVAILABLE if not
21252127
* handled
21262128
*/
2127-
int wc_CryptoCb_Free(int devId, int algo, int type, void* obj)
2129+
int wc_CryptoCb_Free(int devId, int algo, int type, int subType, void* obj)
21282130
{
21292131
int ret = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE);
21302132
CryptoCb* dev;
@@ -2137,6 +2139,7 @@ int wc_CryptoCb_Free(int devId, int algo, int type, void* obj)
21372139
cryptoInfo.algo_type = WC_ALGO_TYPE_FREE;
21382140
cryptoInfo.free.algo = algo;
21392141
cryptoInfo.free.type = type;
2142+
cryptoInfo.free.subType = subType;
21402143
cryptoInfo.free.obj = obj;
21412144

21422145
ret = dev->cb(dev->devId, &cryptoInfo, dev->ctx);

wolfcrypt/src/dilithium.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10834,6 +10834,14 @@ int wc_dilithium_get_level(dilithium_key* key, byte* level)
1083410834
void wc_dilithium_free(dilithium_key* key)
1083510835
{
1083610836
if (key != NULL) {
10837+
#if defined(WOLF_CRYPTO_CB) && defined(WOLF_CRYPTO_CB_FREE)
10838+
if (key->devId != INVALID_DEVID) {
10839+
wc_CryptoCb_Free(key->devId, WC_ALGO_TYPE_PK,
10840+
WC_PK_TYPE_PQC_SIG_KEYGEN,
10841+
WC_PQC_SIG_TYPE_DILITHIUM,
10842+
(void*)key);
10843+
}
10844+
#endif
1083710845
#ifdef WOLFSSL_WC_DILITHIUM
1083810846
#ifndef WC_DILITHIUM_FIXED_ARRAY
1083910847
/* Dispose of cached items. */

wolfcrypt/src/ecc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7893,7 +7893,7 @@ int wc_ecc_free(ecc_key* key)
78937893
#if defined(WOLF_CRYPTO_CB) && defined(WOLF_CRYPTO_CB_FREE)
78947894
if (key->devId != INVALID_DEVID) {
78957895
wc_CryptoCb_Free(key->devId, WC_ALGO_TYPE_PK,
7896-
WC_PK_TYPE_EC_KEYGEN, key);
7896+
WC_PK_TYPE_EC_KEYGEN, 0, key);
78977897
}
78987898
#endif
78997899

wolfcrypt/src/sha.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ void wc_ShaFree(wc_Sha* sha)
10601060
#endif
10611061
{
10621062
ret = wc_CryptoCb_Free(sha->devId, WC_ALGO_TYPE_HASH,
1063-
WC_HASH_TYPE_SHA, (void*)sha);
1063+
WC_HASH_TYPE_SHA, 0, (void*)sha);
10641064
/* If they want the standard free, they can call it themselves */
10651065
/* via their callback setting devId to INVALID_DEVID */
10661066
/* otherwise assume the callback handled it */

wolfcrypt/src/sha256.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,7 +2305,7 @@ static WC_INLINE int Transform_Sha256_Len(wc_Sha256* sha256, const byte* data,
23052305
#endif
23062306
{
23072307
ret = wc_CryptoCb_Free(sha224->devId, WC_ALGO_TYPE_HASH,
2308-
WC_HASH_TYPE_SHA224, (void*)sha224);
2308+
WC_HASH_TYPE_SHA224, 0, (void*)sha224);
23092309
/* If they want the standard free, they can call it themselves */
23102310
/* via their callback setting devId to INVALID_DEVID */
23112311
/* otherwise assume the callback handled it */
@@ -2382,7 +2382,7 @@ void wc_Sha256Free(wc_Sha256* sha256)
23822382
#endif
23832383
{
23842384
ret = wc_CryptoCb_Free(sha256->devId, WC_ALGO_TYPE_HASH,
2385-
WC_HASH_TYPE_SHA256, (void*)sha256);
2385+
WC_HASH_TYPE_SHA256, 0, (void*)sha256);
23862386
/* If they want the standard free, they can call it themselves */
23872387
/* via their callback setting devId to INVALID_DEVID */
23882388
/* otherwise assume the callback handled it */

wolfcrypt/src/sha3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ static void wc_Sha3Free(wc_Sha3* sha3)
12521252
#endif
12531253
{
12541254
ret = wc_CryptoCb_Free(sha3->devId, WC_ALGO_TYPE_HASH,
1255-
sha3->hashType, (void*)sha3);
1255+
sha3->hashType, 0, (void*)sha3);
12561256
/* If they want the standard free, they can call it themselves */
12571257
/* via their callback setting devId to INVALID_DEVID */
12581258
/* otherwise assume the callback handled it */

wolfcrypt/src/sha512.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,7 @@ void wc_Sha512Free(wc_Sha512* sha512)
16321632
#endif
16331633
{
16341634
ret = wc_CryptoCb_Free(sha512->devId, WC_ALGO_TYPE_HASH,
1635-
WC_HASH_TYPE_SHA512, (void*)sha512);
1635+
WC_HASH_TYPE_SHA512, 0, (void*)sha512);
16361636
/* If they want the standard free, they can call it themselves */
16371637
/* via their callback setting devId to INVALID_DEVID */
16381638
/* otherwise assume the callback handled it */
@@ -2105,7 +2105,7 @@ void wc_Sha384Free(wc_Sha384* sha384)
21052105
#endif
21062106
{
21072107
ret = wc_CryptoCb_Free(sha384->devId, WC_ALGO_TYPE_HASH,
2108-
WC_HASH_TYPE_SHA384, (void*)sha384);
2108+
WC_HASH_TYPE_SHA384, 0, (void*)sha384);
21092109
/* If they want the standard free, they can call it themselves */
21102110
/* via their callback setting devId to INVALID_DEVID */
21112111
/* otherwise assume the callback handled it */

0 commit comments

Comments
 (0)