Skip to content

Commit b45530c

Browse files
committed
Move uefi-library to the wc_MlDsa API after the wolfSSL dilithium rename
1 parent 6d306a9 commit b45530c

5 files changed

Lines changed: 89 additions & 87 deletions

File tree

uefi-library/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ The protocol struct provides function pointers for:
165165
SHAKE-128, SHAKE-256
166166
- **MAC**: HMAC
167167
- **Asymmetric**: RSA, ECC, DH, Curve25519, Ed25519
168-
- **Post-quantum**: ML-KEM (Kyber), Dilithium (ML-DSA), Falcon, SPHINCS+, XMSS, LMS
168+
- **Post-quantum**: ML-KEM (Kyber), ML-DSA, Falcon, SPHINCS+, XMSS, LMS
169169
- **KDF**: PBKDF2, PKCS12-PBKDF, HKDF
170170
- **RNG**: hardware-seeded DRBG via UEFI `EFI_RNG_PROTOCOL`
171171
- **Misc**: logging, error strings, version

uefi-library/src/driver.c

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
#include <wolfssl/wolfcrypt/ed25519.h>
4343
#include <wolfssl/wolfcrypt/cmac.h>
4444
#include <wolfssl/wolfcrypt/kdf.h>
45-
#ifdef HAVE_DILITHIUM
46-
#include <wolfssl/wolfcrypt/dilithium.h>
45+
#ifdef WOLFSSL_HAVE_MLDSA
46+
#include <wolfssl/wolfcrypt/wc_mldsa.h>
4747
#endif
4848
#ifdef HAVE_FALCON
4949
#include <wolfssl/wolfcrypt/falcon.h>
@@ -412,23 +412,25 @@ WRAP_FUNC(int, wc_MlKemKey_EncodePublicKey,
412412
#endif /* WOLFSSL_HAVE_MLKEM */
413413

414414
/* ------------------------------------------------------------------ */
415-
/* Dilithium wrappers */
416-
/* ------------------------------------------------------------------ */
417-
#ifdef HAVE_DILITHIUM
418-
WRAP_FUNC(int, wc_dilithium_init, (dilithium_key* key), (key))
419-
WRAP_VOID(wc_dilithium_free, (dilithium_key* key), (key))
420-
WRAP_FUNC(int, wc_dilithium_set_level, (dilithium_key* key, byte level), (key, level))
421-
WRAP_FUNC(int, wc_dilithium_make_key, (dilithium_key* key, WC_RNG* rng), (key, rng))
422-
WRAP_FUNC(int, wc_dilithium_sign_msg, (const byte* in, word32 inLen, byte* out, word32* outLen,
423-
dilithium_key* key, WC_RNG* rng), (in, inLen, out, outLen, key, rng))
424-
WRAP_FUNC(int, wc_dilithium_verify_msg, (const byte* sig, word32 sigLen, const byte* msg,
425-
word32 msgLen, int* res, dilithium_key* key), (sig, sigLen, msg, msgLen, res, key))
426-
WRAP_FUNC(int, wc_dilithium_export_key, (dilithium_key* key, byte* priv, word32* privSz,
415+
/* ML-DSA wrappers */
416+
/* ------------------------------------------------------------------ */
417+
#ifdef WOLFSSL_HAVE_MLDSA
418+
WRAP_FUNC(int, wc_MlDsaKey_Init, (wc_MlDsaKey* key, void* heap, int devId),
419+
(key, heap, devId))
420+
WRAP_VOID(wc_MlDsaKey_Free, (wc_MlDsaKey* key), (key))
421+
WRAP_FUNC(int, wc_MlDsaKey_SetParams, (wc_MlDsaKey* key, byte level), (key, level))
422+
WRAP_FUNC(int, wc_MlDsaKey_MakeKey, (wc_MlDsaKey* key, WC_RNG* rng), (key, rng))
423+
WRAP_FUNC(int, wc_MlDsaKey_Sign, (wc_MlDsaKey* key, byte* sig, word32* sigLen,
424+
const byte* msg, word32 msgLen, WC_RNG* rng),
425+
(key, sig, sigLen, msg, msgLen, rng))
426+
WRAP_FUNC(int, wc_MlDsaKey_Verify, (wc_MlDsaKey* key, const byte* sig, word32 sigLen,
427+
const byte* msg, word32 msgLen, int* res),
428+
(key, sig, sigLen, msg, msgLen, res))
429+
WRAP_FUNC(int, wc_MlDsaKey_ExportKey, (wc_MlDsaKey* key, byte* priv, word32* privSz,
427430
byte* pub, word32* pubSz), (key, priv, privSz, pub, pubSz))
428-
WRAP_FUNC(int, wc_dilithium_import_key, (const byte* priv, word32 privSz,
429-
const byte* pub, word32 pubSz, dilithium_key* key),
430-
(priv, privSz, pub, pubSz, key))
431-
#endif /* HAVE_DILITHIUM */
431+
WRAP_FUNC(int, wc_MlDsaKey_ImportKey, (wc_MlDsaKey* key, const byte* priv, word32 privSz,
432+
const byte* pub, word32 pubSz), (key, priv, privSz, pub, pubSz))
433+
#endif /* WOLFSSL_HAVE_MLDSA */
432434

433435
/* ------------------------------------------------------------------ */
434436
/* Falcon wrappers */
@@ -670,16 +672,16 @@ static WOLFCRYPT_PROTOCOL g_wolfcrypt_api = {
670672
.wc_MlKemKey_EncodePublicKey = wc_MlKemKey_EncodePublicKey_EfiAPI,
671673
#endif
672674

673-
/* Dilithium */
674-
#ifdef HAVE_DILITHIUM
675-
.wc_dilithium_init = wc_dilithium_init_EfiAPI,
676-
.wc_dilithium_free = wc_dilithium_free_EfiAPI,
677-
.wc_dilithium_set_level = wc_dilithium_set_level_EfiAPI,
678-
.wc_dilithium_make_key = wc_dilithium_make_key_EfiAPI,
679-
.wc_dilithium_sign_msg = wc_dilithium_sign_msg_EfiAPI,
680-
.wc_dilithium_verify_msg = wc_dilithium_verify_msg_EfiAPI,
681-
.wc_dilithium_export_key = wc_dilithium_export_key_EfiAPI,
682-
.wc_dilithium_import_key = wc_dilithium_import_key_EfiAPI,
675+
/* ML-DSA */
676+
#ifdef WOLFSSL_HAVE_MLDSA
677+
.wc_MlDsaKey_Init = wc_MlDsaKey_Init_EfiAPI,
678+
.wc_MlDsaKey_Free = wc_MlDsaKey_Free_EfiAPI,
679+
.wc_MlDsaKey_SetParams = wc_MlDsaKey_SetParams_EfiAPI,
680+
.wc_MlDsaKey_MakeKey = wc_MlDsaKey_MakeKey_EfiAPI,
681+
.wc_MlDsaKey_Sign = wc_MlDsaKey_Sign_EfiAPI,
682+
.wc_MlDsaKey_Verify = wc_MlDsaKey_Verify_EfiAPI,
683+
.wc_MlDsaKey_ExportKey = wc_MlDsaKey_ExportKey_EfiAPI,
684+
.wc_MlDsaKey_ImportKey = wc_MlDsaKey_ImportKey_EfiAPI,
683685
#endif
684686

685687
/* Falcon */

uefi-library/src/test_app.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include <wolfssl/wolfcrypt/chacha20_poly1305.h>
3535
#include <wolfssl/wolfcrypt/mlkem.h>
3636
#include <wolfssl/wolfcrypt/wc_mlkem.h>
37-
#include <wolfssl/wolfcrypt/dilithium.h>
37+
#include <wolfssl/wolfcrypt/wc_mldsa.h>
3838

3939
#include "wolfcrypt_api.h"
4040

@@ -1251,50 +1251,50 @@ static EFI_STATUS TestMlKem(void)
12511251
#endif /* WOLFSSL_HAVE_MLKEM */
12521252

12531253
/* ------------------------------------------------------------------ */
1254-
/* Dilithium (ML-DSA-44): keygen, sign, verify */
1254+
/* ML-DSA-44: keygen, sign, verify */
12551255
/* ------------------------------------------------------------------ */
1256-
#if defined(HAVE_DILITHIUM)
1257-
static EFI_STATUS TestDilithium(void)
1256+
#if defined(WOLFSSL_HAVE_MLDSA)
1257+
static EFI_STATUS TestMlDsa(void)
12581258
{
12591259
EFI_STATUS status = EFI_SUCCESS;
12601260
int ret;
12611261
WC_RNG rng;
1262-
dilithium_key key;
1262+
wc_MlDsaKey key;
12631263
BOOLEAN rngInit = FALSE, keyInit = FALSE;
1264-
static const byte msg[] = "wolfCrypt UEFI Dilithium test";
1265-
byte sig[DILITHIUM_MAX_SIG_SIZE];
1264+
static const byte msg[] = "wolfCrypt UEFI ML-DSA test";
1265+
byte sig[MLDSA_MAX_SIG_SIZE];
12661266
word32 sigLen = sizeof(sig);
12671267
int verify = 0;
12681268

12691269
ZeroMem(&rng, sizeof(rng)); ZeroMem(&key, sizeof(key));
12701270

12711271
ret = InitRngDet(&rng);
1272-
status = CheckWolfResult(ret, L"wc_InitRng Dilithium"); if (EFI_ERROR(status)) return status;
1272+
status = CheckWolfResult(ret, L"wc_InitRng ML-DSA"); if (EFI_ERROR(status)) return status;
12731273
rngInit = TRUE;
12741274

1275-
ret = Api->wc_dilithium_init(&key);
1276-
status = CheckWolfResult(ret, L"wc_dilithium_init"); if (EFI_ERROR(status)) goto cleanup;
1275+
ret = Api->wc_MlDsaKey_Init(&key, NULL, INVALID_DEVID);
1276+
status = CheckWolfResult(ret, L"wc_MlDsaKey_Init"); if (EFI_ERROR(status)) goto cleanup;
12771277
keyInit = TRUE;
12781278

1279-
ret = Api->wc_dilithium_set_level(&key, 2); /* ML-DSA-44 */
1280-
status = CheckWolfResult(ret, L"wc_dilithium_set_level"); if (EFI_ERROR(status)) goto cleanup;
1279+
ret = Api->wc_MlDsaKey_SetParams(&key, WC_ML_DSA_44);
1280+
status = CheckWolfResult(ret, L"wc_MlDsaKey_SetParams"); if (EFI_ERROR(status)) goto cleanup;
12811281

1282-
ret = Api->wc_dilithium_make_key(&key, &rng);
1283-
status = CheckWolfResult(ret, L"wc_dilithium_make_key"); if (EFI_ERROR(status)) goto cleanup;
1282+
ret = Api->wc_MlDsaKey_MakeKey(&key, &rng);
1283+
status = CheckWolfResult(ret, L"wc_MlDsaKey_MakeKey"); if (EFI_ERROR(status)) goto cleanup;
12841284

1285-
ret = Api->wc_dilithium_sign_msg(msg, (word32)sizeof(msg)-1, sig, &sigLen, &key, &rng);
1286-
status = CheckWolfResult(ret, L"wc_dilithium_sign_msg"); if (EFI_ERROR(status)) goto cleanup;
1285+
ret = Api->wc_MlDsaKey_Sign(&key, sig, &sigLen, msg, (word32)sizeof(msg)-1, &rng);
1286+
status = CheckWolfResult(ret, L"wc_MlDsaKey_Sign"); if (EFI_ERROR(status)) goto cleanup;
12871287

1288-
ret = Api->wc_dilithium_verify_msg(sig, sigLen, msg, (word32)sizeof(msg)-1, &verify, &key);
1289-
status = CheckWolfResult(ret, L"wc_dilithium_verify_msg"); if (EFI_ERROR(status)) goto cleanup;
1290-
status = CheckCondition(verify == 1, L"Dilithium signature verified");
1288+
ret = Api->wc_MlDsaKey_Verify(&key, sig, sigLen, msg, (word32)sizeof(msg)-1, &verify);
1289+
status = CheckWolfResult(ret, L"wc_MlDsaKey_Verify"); if (EFI_ERROR(status)) goto cleanup;
1290+
status = CheckCondition(verify == 1, L"ML-DSA signature verified");
12911291

12921292
cleanup:
1293-
if (keyInit) Api->wc_dilithium_free(&key);
1293+
if (keyInit) Api->wc_MlDsaKey_Free(&key);
12941294
if (rngInit) Api->wc_FreeRng(&rng);
12951295
return status;
12961296
}
1297-
#endif /* HAVE_DILITHIUM */
1297+
#endif /* WOLFSSL_HAVE_MLDSA */
12981298

12991299
/* ------------------------------------------------------------------ */
13001300
/* Test runner */
@@ -1319,8 +1319,8 @@ static EFI_STATUS RunAllTests(void)
13191319
#if defined(WOLFSSL_HAVE_MLKEM)
13201320
{ L"ML-KEM", TestMlKem },
13211321
#endif
1322-
#if defined(HAVE_DILITHIUM)
1323-
{ L"Dilithium", TestDilithium },
1322+
#if defined(WOLFSSL_HAVE_MLDSA)
1323+
{ L"ML-DSA", TestMlDsa },
13241324
#endif
13251325
};
13261326

uefi-library/user_settings.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ extern int uefi_strncmp_wolfssl(const char* s1, const char* s2, size_t n);
5151
#define HAVE_CURVE448
5252
#define HAVE_ED448
5353

54-
/* Post-quantum: Dilithium (ML-DSA) — native wolfSSL implementation */
55-
#define HAVE_DILITHIUM
56-
#define WOLFSSL_WC_DILITHIUM
54+
/* Post-quantum: ML-DSA — native wolfSSL implementation */
55+
#define WOLFSSL_HAVE_MLDSA
5756
/* All levels enabled by default (use WOLFSSL_NO_ML_DSA_44/65/87 to disable) */
5857

5958
/* Falcon requires liboqs; omit unless liboqs is available */

uefi-library/wolfcrypt_api.h

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
#include <wolfssl/wolfcrypt/curve25519.h>
2828
#include <wolfssl/wolfcrypt/ed25519.h>
2929
#include <wolfssl/wolfcrypt/cmac.h>
30-
#ifdef HAVE_DILITHIUM
31-
#include <wolfssl/wolfcrypt/dilithium.h>
30+
#ifdef WOLFSSL_HAVE_MLDSA
31+
#include <wolfssl/wolfcrypt/wc_mldsa.h>
3232
#endif
3333
#ifdef HAVE_FALCON
3434
#include <wolfssl/wolfcrypt/falcon.h>
@@ -371,26 +371,27 @@ typedef int (EFIAPI *wc_MlKemKey_EncodePublicKey_API)(MlKemKey* key,
371371
#endif /* WOLFSSL_HAVE_MLKEM */
372372

373373
/* ------------------------------------------------------------------ */
374-
/* Dilithium (ML-DSA) */
375-
/* ------------------------------------------------------------------ */
376-
#ifdef HAVE_DILITHIUM
377-
typedef int (EFIAPI *wc_dilithium_init_API)(dilithium_key* key);
378-
typedef void (EFIAPI *wc_dilithium_free_API)(dilithium_key* key);
379-
typedef int (EFIAPI *wc_dilithium_set_level_API)(dilithium_key* key, byte level);
380-
typedef int (EFIAPI *wc_dilithium_make_key_API)(dilithium_key* key, WC_RNG* rng);
381-
typedef int (EFIAPI *wc_dilithium_sign_msg_API)(const byte* in, word32 inLen,
382-
byte* out, word32* outLen,
383-
dilithium_key* key, WC_RNG* rng);
384-
typedef int (EFIAPI *wc_dilithium_verify_msg_API)(const byte* sig, word32 sigLen,
385-
const byte* msg, word32 msgLen,
386-
int* res, dilithium_key* key);
387-
typedef int (EFIAPI *wc_dilithium_export_key_API)(dilithium_key* key,
388-
byte* priv, word32* privSz,
389-
byte* pub, word32* pubSz);
390-
typedef int (EFIAPI *wc_dilithium_import_key_API)(const byte* priv, word32 privSz,
391-
const byte* pub, word32 pubSz,
392-
dilithium_key* key);
393-
#endif /* HAVE_DILITHIUM */
374+
/* ML-DSA */
375+
/* ------------------------------------------------------------------ */
376+
#ifdef WOLFSSL_HAVE_MLDSA
377+
typedef int (EFIAPI *wc_MlDsaKey_Init_API)(wc_MlDsaKey* key, void* heap,
378+
int devId);
379+
typedef void (EFIAPI *wc_MlDsaKey_Free_API)(wc_MlDsaKey* key);
380+
typedef int (EFIAPI *wc_MlDsaKey_SetParams_API)(wc_MlDsaKey* key, byte level);
381+
typedef int (EFIAPI *wc_MlDsaKey_MakeKey_API)(wc_MlDsaKey* key, WC_RNG* rng);
382+
typedef int (EFIAPI *wc_MlDsaKey_Sign_API)(wc_MlDsaKey* key, byte* sig,
383+
word32* sigLen, const byte* msg,
384+
word32 msgLen, WC_RNG* rng);
385+
typedef int (EFIAPI *wc_MlDsaKey_Verify_API)(wc_MlDsaKey* key, const byte* sig,
386+
word32 sigLen, const byte* msg,
387+
word32 msgLen, int* res);
388+
typedef int (EFIAPI *wc_MlDsaKey_ExportKey_API)(wc_MlDsaKey* key,
389+
byte* priv, word32* privSz,
390+
byte* pub, word32* pubSz);
391+
typedef int (EFIAPI *wc_MlDsaKey_ImportKey_API)(wc_MlDsaKey* key,
392+
const byte* priv, word32 privSz,
393+
const byte* pub, word32 pubSz);
394+
#endif /* WOLFSSL_HAVE_MLDSA */
394395

395396
/* ------------------------------------------------------------------ */
396397
/* Falcon */
@@ -635,16 +636,16 @@ typedef struct {
635636
wc_MlKemKey_EncodePublicKey_API wc_MlKemKey_EncodePublicKey;
636637
#endif
637638

638-
/* Dilithium */
639-
#ifdef HAVE_DILITHIUM
640-
wc_dilithium_init_API wc_dilithium_init;
641-
wc_dilithium_free_API wc_dilithium_free;
642-
wc_dilithium_set_level_API wc_dilithium_set_level;
643-
wc_dilithium_make_key_API wc_dilithium_make_key;
644-
wc_dilithium_sign_msg_API wc_dilithium_sign_msg;
645-
wc_dilithium_verify_msg_API wc_dilithium_verify_msg;
646-
wc_dilithium_export_key_API wc_dilithium_export_key;
647-
wc_dilithium_import_key_API wc_dilithium_import_key;
639+
/* ML-DSA */
640+
#ifdef WOLFSSL_HAVE_MLDSA
641+
wc_MlDsaKey_Init_API wc_MlDsaKey_Init;
642+
wc_MlDsaKey_Free_API wc_MlDsaKey_Free;
643+
wc_MlDsaKey_SetParams_API wc_MlDsaKey_SetParams;
644+
wc_MlDsaKey_MakeKey_API wc_MlDsaKey_MakeKey;
645+
wc_MlDsaKey_Sign_API wc_MlDsaKey_Sign;
646+
wc_MlDsaKey_Verify_API wc_MlDsaKey_Verify;
647+
wc_MlDsaKey_ExportKey_API wc_MlDsaKey_ExportKey;
648+
wc_MlDsaKey_ImportKey_API wc_MlDsaKey_ImportKey;
648649
#endif
649650

650651
/* Falcon */

0 commit comments

Comments
 (0)