Skip to content

Commit ad22f9a

Browse files
committed
Support for ML-DSA in PKCS#11
Offload ML-DSA operations onto a PKCS#11 token via the cryptoCb interface: * Key generation * Signature generation * Signature verification * Key import Both the pure and pre-hash versions are supported. Not yet supported are the pre-hash versions that also offload the hashing onto the token. This also fixes casting errors introduced in #9780 due to usage of uintptr_t, which is unavailable without including stdint.h on some platforms. Use the wolfssl own wc_ptr_t instead.
1 parent 5a72a37 commit ad22f9a

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
@@ -418,6 +418,7 @@ NO_PKCS11_ECC
418418
NO_PKCS11_ECDH
419419
NO_PKCS11_EC_KEYGEN
420420
NO_PKCS11_HMAC
421+
NO_PKCS11_MLDSA
421422
NO_PKCS11_RNG
422423
NO_PKCS11_RSA
423424
NO_PKCS11_RSA_PKCS

wolfcrypt/src/aes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13601,7 +13601,7 @@ void wc_AesFree(Aes* aes)
1360113601
#endif
1360213602
{
1360313603
int ret = wc_CryptoCb_Free(aes->devId, WC_ALGO_TYPE_CIPHER,
13604-
WC_CIPHER_AES, aes);
13604+
WC_CIPHER_AES, 0, aes);
1360513605
#ifdef WOLF_CRYPTO_CB_AES_SETKEY
1360613606
aes->devCtx = NULL; /* Clear device context handle */
1360713607
#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
@@ -7894,7 +7894,7 @@ int wc_ecc_free(ecc_key* key)
78947894
#if defined(WOLF_CRYPTO_CB) && defined(WOLF_CRYPTO_CB_FREE)
78957895
if (key->devId != INVALID_DEVID) {
78967896
wc_CryptoCb_Free(key->devId, WC_ALGO_TYPE_PK,
7897-
WC_PK_TYPE_EC_KEYGEN, key);
7897+
WC_PK_TYPE_EC_KEYGEN, 0, key);
78987898
}
78997899
#endif
79007900

wolfcrypt/src/sha.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ void wc_ShaFree(wc_Sha* sha)
10621062
#endif
10631063
{
10641064
ret = wc_CryptoCb_Free(sha->devId, WC_ALGO_TYPE_HASH,
1065-
WC_HASH_TYPE_SHA, (void*)sha);
1065+
WC_HASH_TYPE_SHA, 0, (void*)sha);
10661066
/* If they want the standard free, they can call it themselves */
10671067
/* via their callback setting devId to INVALID_DEVID */
10681068
/* 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
@@ -1635,7 +1635,7 @@ void wc_Sha512Free(wc_Sha512* sha512)
16351635
#endif
16361636
{
16371637
ret = wc_CryptoCb_Free(sha512->devId, WC_ALGO_TYPE_HASH,
1638-
WC_HASH_TYPE_SHA512, (void*)sha512);
1638+
WC_HASH_TYPE_SHA512, 0, (void*)sha512);
16391639
/* If they want the standard free, they can call it themselves */
16401640
/* via their callback setting devId to INVALID_DEVID */
16411641
/* otherwise assume the callback handled it */
@@ -2117,7 +2117,7 @@ void wc_Sha384Free(wc_Sha384* sha384)
21172117
#endif
21182118
{
21192119
ret = wc_CryptoCb_Free(sha384->devId, WC_ALGO_TYPE_HASH,
2120-
WC_HASH_TYPE_SHA384, (void*)sha384);
2120+
WC_HASH_TYPE_SHA384, 0, (void*)sha384);
21212121
/* If they want the standard free, they can call it themselves */
21222122
/* via their callback setting devId to INVALID_DEVID */
21232123
/* otherwise assume the callback handled it */

0 commit comments

Comments
 (0)