From 2832df2139250496fb2acf5c534c6f6c7e2f3aae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Frauenschl=C3=A4ger?= Date: Mon, 11 May 2026 08:50:41 +0200 Subject: [PATCH] Update C# wrapper to new ML-DSA names --- tests/api.c | 2 +- tests/api/test_mldsa.c | 14 +- wolfcrypt/src/wc_mldsa.c | 146 ++++++++++----------- wolfcrypt/src/wc_pkcs11.c | 28 ++-- wolfssl/wolfcrypt/asn.h | 4 +- wolfssl/wolfcrypt/asn_public.h | 11 +- wolfssl/wolfcrypt/dilithium.h | 55 ++++---- wolfssl/wolfcrypt/wc_mldsa.h | 108 ++++++++------- wrapper/CSharp/wolfSSL_CSharp/wolfCrypt.cs | 64 ++++----- 9 files changed, 223 insertions(+), 209 deletions(-) diff --git a/tests/api.c b/tests/api.c index 3d8d0f5855..7dbc1ce5b6 100644 --- a/tests/api.c +++ b/tests/api.c @@ -1567,7 +1567,7 @@ static int test_dual_alg_ecdsa_mldsa(void) !defined(WOLFSSL_DILITHIUM_NO_SIGN) && \ !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && !defined(WOLFSSL_SMALL_STACK) WOLFSSL_CERT_MANAGER * cm = NULL; - MlDsaKey alt_ca_key; + wc_MlDsaKey alt_ca_key; ecc_key ca_key; WC_RNG rng; int ret = 0; diff --git a/tests/api/test_mldsa.c b/tests/api/test_mldsa.c index a5a1a2bc4c..ad1c6dcefb 100644 --- a/tests/api/test_mldsa.c +++ b/tests/api/test_mldsa.c @@ -30441,7 +30441,7 @@ int test_mldsa_x509_pubkey_sigtype(void) * The two functions below are not runtime tests. Their bodies sit inside * `if (0)` so the compiler parses every reference without emitting any * runtime call. Their job is to fail compilation if the canonical - * wc_MlDsaKey_* / MlDsaKey API in or the + * wc_MlDsaKey_* / wc_MlDsaKey API in or the * legacy alias surface in drifts in a way * that would silently break a downstream consumer. They live in this test * translation unit (rather than wolfcrypt/src/wc_mldsa.c) so the library @@ -30462,20 +30462,20 @@ int test_mldsa_x509_pubkey_sigtype(void) #define WOLFSSL_MLDSA_API_CHECK_INLINE static WC_INLINE #endif -/* Compile-time validation of the canonical wc_MlDsaKey_* / MlDsaKey API. */ +/* Compile-time validation of the canonical wc_MlDsaKey_* / wc_MlDsaKey API. */ WOLFSSL_MLDSA_API_CHECK_INLINE void wc_mldsa_canonical_api_check(void) { if (0) { - MlDsaKey k; - const MlDsaParams *p; + wc_MlDsaKey k; + const wc_MlDsaParams *p; const byte buf[1] = { 0 }; word32 sz = 0; byte level = 0; int res = 0; WC_RNG *rng = NULL; - (void)sizeof(MlDsaKey); - (void)sizeof(MlDsaParams); + (void)sizeof(wc_MlDsaKey); + (void)sizeof(wc_MlDsaParams); /* Lifecycle / parameters. */ (void)wc_MlDsaKey_Init(&k, NULL, INVALID_DEVID); @@ -30589,7 +30589,7 @@ WOLFSSL_MLDSA_API_CHECK_INLINE void wc_mldsa_canonical_api_check(void) WOLFSSL_MLDSA_API_CHECK_INLINE void wc_mldsa_legacy_alias_check(void) { if (0) { - MlDsaKey k; + wc_MlDsaKey k; dilithium_key *kp = (dilithium_key *)0; const wc_dilithium_params *pp = (const wc_dilithium_params *)0; const byte buf[1] = { 0 }; diff --git a/wolfcrypt/src/wc_mldsa.c b/wolfcrypt/src/wc_mldsa.c index 2fd10ea36b..33c51466ba 100644 --- a/wolfcrypt/src/wc_mldsa.c +++ b/wolfcrypt/src/wc_mldsa.c @@ -271,7 +271,7 @@ void print_data(const char* name, const byte* d, int len) /* The ML-DSA parameters sets. */ -static const MlDsaParams mldsa_params[] = { +static const wc_MlDsaParams mldsa_params[] = { #ifndef WOLFSSL_NO_ML_DSA_44 { WC_ML_DSA_44, PARAMS_ML_DSA_44_K, PARAMS_ML_DSA_44_L, PARAMS_ML_DSA_44_ETA, PARAMS_ML_DSA_44_ETA_BITS, @@ -349,7 +349,7 @@ static const MlDsaParams mldsa_params[] = { }; /* Number of ML-DSA parameter sets compiled in. */ #define DILITHIUM_PARAMS_CNT \ - ((unsigned int)(sizeof(mldsa_params) / sizeof(MlDsaParams))) + ((unsigned int)(sizeof(mldsa_params) / sizeof(wc_MlDsaParams))) /* Get the ML-DSA parameters that match the level. * @@ -358,7 +358,7 @@ static const MlDsaParams mldsa_params[] = { * @return 0 on success. * @return NOT_COMPILED_IN when parameters at level are not compiled in. */ -static int mldsa_get_params(int level, const MlDsaParams** params) +static int mldsa_get_params(int level, const wc_MlDsaParams** params) { unsigned int i; int ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN); @@ -379,7 +379,7 @@ static int mldsa_get_params(int level, const MlDsaParams** params) * allocated. Buffer is sized via wc_MlDsaKey_Size(key) and the allocated size * is stored in key->kSz for later use (ForceZero, free). On failure key->k may * remain NULL; callers must not inspect it. */ -static int mldsa_alloc_priv_buf(MlDsaKey* key) +static int mldsa_alloc_priv_buf(wc_MlDsaKey* key) { int ret = 0; @@ -413,7 +413,7 @@ static int mldsa_alloc_priv_buf(MlDsaKey* key) /* Allocate the public key buffer for the current level if not already * allocated. Buffer is sized via wc_MlDsaKey_PubSize(key). On failure, * key->p may remain NULL; callers must not inspect it. */ -static int mldsa_alloc_pub_buf(MlDsaKey* key) +static int mldsa_alloc_pub_buf(wc_MlDsaKey* key) { int ret = 0; @@ -7757,11 +7757,11 @@ static void mldsa_vec_make_pos(sword32* a, byte l) * @return MEMORY_E when memory allocation fails. * @return Other negative when an error occurs. */ -static int mldsa_make_key_from_seed(MlDsaKey* key, const byte* seed) +static int mldsa_make_key_from_seed(wc_MlDsaKey* key, const byte* seed) { #ifndef WOLFSSL_MLDSA_MAKE_KEY_SMALL_MEM int ret = 0; - const MlDsaParams* params = key->params; + const wc_MlDsaParams* params = key->params; sword32* a = NULL; sword32* s1 = NULL; sword32* s2 = NULL; @@ -7932,7 +7932,7 @@ static int mldsa_make_key_from_seed(MlDsaKey* key, const byte* seed) return ret; #else int ret = 0; - const MlDsaParams* params = key->params; + const wc_MlDsaParams* params = key->params; sword32* a = NULL; sword32* s1 = NULL; sword32* s2 = NULL; @@ -8178,7 +8178,7 @@ static int mldsa_make_key_from_seed(MlDsaKey* key, const byte* seed) * @return MEMORY_E when memory allocation fails. * @return Other negative when an error occurs. */ -static int mldsa_make_key(MlDsaKey* key, WC_RNG* rng) +static int mldsa_make_key(wc_MlDsaKey* key, WC_RNG* rng) { int ret; byte seed[DILITHIUM_SEED_SZ]; @@ -8214,10 +8214,10 @@ static int mldsa_make_key(MlDsaKey* key, WC_RNG* rng) * @param [out] s2 Vector of polynomials s2. * @param [out] t0 Vector of polynomials t0. */ -static void mldsa_make_priv_vecs(MlDsaKey* key, sword32* s1, +static void mldsa_make_priv_vecs(wc_MlDsaKey* key, sword32* s1, sword32* s2, sword32* t0) { - const MlDsaParams* params = key->params; + const wc_MlDsaParams* params = key->params; const byte* pubSeed = key->k; const byte* k = pubSeed + DILITHIUM_PUB_SEED_SZ; const byte* tr = k + DILITHIUM_K_SZ; @@ -8301,12 +8301,12 @@ static void mldsa_make_priv_vecs(MlDsaKey* key, sword32* s1, * @return MEMORY_E when memory allocation fails. * @return Other negative when an error occurs. */ -static int mldsa_sign_with_seed_mu(MlDsaKey* key, +static int mldsa_sign_with_seed_mu(wc_MlDsaKey* key, const byte* seedMu, byte* sig, word32 *sigLen) { #ifndef WOLFSSL_MLDSA_SIGN_SMALL_MEM int ret = 0; - const MlDsaParams* params = key->params; + const wc_MlDsaParams* params = key->params; const byte* pub_seed = key->k; const byte* k = pub_seed + DILITHIUM_PUB_SEED_SZ; const byte* mu = seedMu + DILITHIUM_RND_SZ; @@ -8590,7 +8590,7 @@ static int mldsa_sign_with_seed_mu(MlDsaKey* key, return ret; #else int ret = 0; - const MlDsaParams* params = key->params; + const wc_MlDsaParams* params = key->params; const byte* pub_seed = key->k; const byte* k = pub_seed + DILITHIUM_PUB_SEED_SZ; const byte* tr = k + DILITHIUM_K_SZ; @@ -9173,7 +9173,7 @@ static int mldsa_sign_with_seed_mu(MlDsaKey* key, * @return MEMORY_E when memory allocation fails. * @return Other negative when an error occurs. */ -static int mldsa_sign_ctx_msg_with_seed(MlDsaKey* key, +static int mldsa_sign_ctx_msg_with_seed(wc_MlDsaKey* key, const byte* seed, const byte* ctx, byte ctxLen, const byte* msg, word32 msgLen, byte* sig, word32 *sigLen) { @@ -9224,7 +9224,7 @@ static int mldsa_sign_ctx_msg_with_seed(MlDsaKey* key, * @return Other negative when an error occurs. */ #ifdef WOLFSSL_MLDSA_NO_CTX -static int mldsa_sign_msg_with_seed(MlDsaKey* key, const byte* seed, +static int mldsa_sign_msg_with_seed(wc_MlDsaKey* key, const byte* seed, const byte* msg, word32 msgLen, byte* sig, word32 *sigLen) { int ret; @@ -9279,7 +9279,7 @@ static int mldsa_sign_msg_with_seed(MlDsaKey* key, const byte* seed, * @return MEMORY_E when memory allocation fails. * @return Other negative when an error occurs. */ -static int mldsa_sign_ctx_msg(MlDsaKey* key, WC_RNG* rng, +static int mldsa_sign_ctx_msg(wc_MlDsaKey* key, WC_RNG* rng, const byte* ctx, byte ctxLen, const byte* msg, word32 msgLen, byte* sig, word32 *sigLen) { @@ -9343,7 +9343,7 @@ static int mldsa_sign_ctx_msg(MlDsaKey* key, WC_RNG* rng, * @return Other negative when an error occurs. */ #ifdef WOLFSSL_MLDSA_NO_CTX -static int mldsa_sign_msg(MlDsaKey* key, WC_RNG* rng, +static int mldsa_sign_msg(wc_MlDsaKey* key, WC_RNG* rng, const byte* msg, word32 msgLen, byte* sig, word32 *sigLen) { int ret = 0; @@ -9411,7 +9411,7 @@ static int mldsa_sign_msg(MlDsaKey* key, WC_RNG* rng, * @return MEMORY_E when memory allocation fails. * @return Other negative when an error occurs. */ -static int mldsa_sign_ctx_hash_with_seed(MlDsaKey* key, +static int mldsa_sign_ctx_hash_with_seed(wc_MlDsaKey* key, const byte* seed, const byte* ctx, byte ctxLen, int hashAlg, const byte* hash, word32 hashLen, byte* sig, word32 *sigLen) { @@ -9475,7 +9475,7 @@ static int mldsa_sign_ctx_hash_with_seed(MlDsaKey* key, * @return MEMORY_E when memory allocation fails. * @return Other negative when an error occurs. */ -static int mldsa_sign_ctx_hash(MlDsaKey* key, WC_RNG* rng, +static int mldsa_sign_ctx_hash(wc_MlDsaKey* key, WC_RNG* rng, const byte* ctx, byte ctxLen, int hashAlg, const byte* hash, word32 hashLen, byte* sig, word32 *sigLen) { @@ -9511,9 +9511,9 @@ static int mldsa_sign_ctx_hash(MlDsaKey* key, WC_RNG* rng, * @param [in, out] key Key with public key data. * @param [out] t1 Vector in NTT form. */ -static void mldsa_make_pub_vec(MlDsaKey* key, sword32* t1) +static void mldsa_make_pub_vec(wc_MlDsaKey* key, sword32* t1) { - const MlDsaParams* params = key->params; + const wc_MlDsaParams* params = key->params; const byte* t1p = key->p + DILITHIUM_PUB_SEED_SZ; mldsa_vec_decode_t1(t1p, params->k, t1); @@ -9555,12 +9555,12 @@ static void mldsa_make_pub_vec(MlDsaKey* key, sword32* t1) * @return MEMORY_E when memory allocation fails. * @return Other negative when an error occurs. */ -static int mldsa_verify_with_mu(MlDsaKey* key, const byte* mu, +static int mldsa_verify_with_mu(wc_MlDsaKey* key, const byte* mu, const byte* sig, word32 sigLen, int* res) { #ifndef WOLFSSL_MLDSA_VERIFY_SMALL_MEM int ret = 0; - const MlDsaParams* params = key->params; + const wc_MlDsaParams* params = key->params; const byte* pub_seed = key->p; const byte* commit = sig; const byte* ze = sig + params->lambda / 4; @@ -9717,7 +9717,7 @@ static int mldsa_verify_with_mu(MlDsaKey* key, const byte* mu, return ret; #else int ret = 0; - const MlDsaParams* params = key->params; + const wc_MlDsaParams* params = key->params; const byte* pub_seed = key->p; const byte* t1p = pub_seed + DILITHIUM_PUB_SEED_SZ; const byte* commit = sig; @@ -9992,7 +9992,7 @@ static int mldsa_verify_with_mu(MlDsaKey* key, const byte* mu, * @return MEMORY_E when memory allocation fails. * @return Other negative when an error occurs. */ -static int mldsa_verify_ctx_msg(MlDsaKey* key, const byte* ctx, +static int mldsa_verify_ctx_msg(wc_MlDsaKey* key, const byte* ctx, byte ctxLen, const byte* msg, word32 msgLen, const byte* sig, word32 sigLen, int* res) { @@ -10037,7 +10037,7 @@ static int mldsa_verify_ctx_msg(MlDsaKey* key, const byte* ctx, * @return MEMORY_E when memory allocation fails. * @return Other negative when an error occurs. */ -static int mldsa_verify_msg(MlDsaKey* key, const byte* msg, +static int mldsa_verify_msg(wc_MlDsaKey* key, const byte* msg, word32 msgLen, const byte* sig, word32 sigLen, int* res) { int ret = 0; @@ -10084,7 +10084,7 @@ static int mldsa_verify_msg(MlDsaKey* key, const byte* msg, * @return MEMORY_E when memory allocation fails. * @return Other negative when an error occurs. */ -static int mldsa_verify_ctx_hash(MlDsaKey* key, const byte* ctx, +static int mldsa_verify_ctx_hash(wc_MlDsaKey* key, const byte* ctx, byte ctxLen, int hashAlg, const byte* hash, word32 hashLen, const byte* sig, word32 sigLen, int* res) { @@ -10129,7 +10129,7 @@ static int mldsa_verify_ctx_hash(MlDsaKey* key, const byte* ctx, #endif /* WOLFSSL_MLDSA_NO_VERIFY */ #ifndef WOLFSSL_MLDSA_NO_MAKE_KEY -int wc_MlDsaKey_MakeKey(MlDsaKey* key, WC_RNG* rng) +int wc_MlDsaKey_MakeKey(wc_MlDsaKey* key, WC_RNG* rng) { int ret = 0; @@ -10205,7 +10205,7 @@ int wc_MlDsaKey_MakeKey(MlDsaKey* key, WC_RNG* rng) return ret; } -int wc_MlDsaKey_MakeKeyFromSeed(MlDsaKey* key, const byte* seed) +int wc_MlDsaKey_MakeKeyFromSeed(wc_MlDsaKey* key, const byte* seed) { int ret = 0; @@ -10248,7 +10248,7 @@ int wc_MlDsaKey_MakeKeyFromSeed(MlDsaKey* key, const byte* seed) * BUFFER_E when outLen is less than DILITHIUM_LEVEL2_SIG_SIZE, * 0 otherwise. */ -int wc_MlDsaKey_SignCtx(MlDsaKey* key, const byte* ctx, byte ctxLen, +int wc_MlDsaKey_SignCtx(wc_MlDsaKey* key, const byte* ctx, byte ctxLen, byte* sig, word32 *sigLen, const byte* msg, word32 msgLen, WC_RNG* rng) { int ret = 0; @@ -10304,7 +10304,7 @@ int wc_MlDsaKey_SignCtx(MlDsaKey* key, const byte* ctx, byte ctxLen, * NOTE: This is a pre-FIPS 204 API without context support. New code should * use wc_MlDsaKey_SignCtx() with ctx=NULL/ctxLen=0 instead. */ -int wc_MlDsaKey_Sign(MlDsaKey* key, byte* sig, word32 *sigLen, +int wc_MlDsaKey_Sign(wc_MlDsaKey* key, byte* sig, word32 *sigLen, const byte* msg, word32 msgLen, WC_RNG* rng) { int ret = 0; @@ -10355,7 +10355,7 @@ int wc_MlDsaKey_Sign(MlDsaKey* key, byte* sig, word32 *sigLen, * BUFFER_E when outLen is less than DILITHIUM_LEVEL2_SIG_SIZE, * 0 otherwise. */ -int wc_MlDsaKey_SignCtxHash(MlDsaKey* key, const byte* ctx, byte ctxLen, +int wc_MlDsaKey_SignCtxHash(wc_MlDsaKey* key, const byte* ctx, byte ctxLen, byte* sig, word32 *sigLen, const byte* hash, word32 hashLen, int hashAlg, WC_RNG* rng) { @@ -10409,7 +10409,7 @@ int wc_MlDsaKey_SignCtxHash(MlDsaKey* key, const byte* ctx, byte ctxLen, * BUFFER_E when outLen is less than DILITHIUM_LEVEL2_SIG_SIZE, * 0 otherwise. */ -int wc_MlDsaKey_SignCtxWithSeed(MlDsaKey* key, const byte* ctx, byte ctxLen, +int wc_MlDsaKey_SignCtxWithSeed(wc_MlDsaKey* key, const byte* ctx, byte ctxLen, byte* sig, word32 *sigLen, const byte* msg, word32 msgLen, const byte* seed) { @@ -10447,7 +10447,7 @@ int wc_MlDsaKey_SignCtxWithSeed(MlDsaKey* key, const byte* ctx, byte ctxLen, * NOTE: This is a pre-FIPS 204 API without context support. New code should * use wc_MlDsaKey_SignCtxWithSeed() instead. */ -int wc_MlDsaKey_SignWithSeed(MlDsaKey* key, byte* sig, word32 *sigLen, +int wc_MlDsaKey_SignWithSeed(wc_MlDsaKey* key, byte* sig, word32 *sigLen, const byte* msg, word32 msgLen, const byte* seed) { int ret = 0; @@ -10482,7 +10482,7 @@ int wc_MlDsaKey_SignWithSeed(MlDsaKey* key, byte* sig, word32 *sigLen, * BUFFER_E when outLen is less than DILITHIUM_LEVEL2_SIG_SIZE, * 0 otherwise. */ -int wc_MlDsaKey_SignCtxHashWithSeed(MlDsaKey* key, const byte* ctx, +int wc_MlDsaKey_SignCtxHashWithSeed(wc_MlDsaKey* key, const byte* ctx, byte ctxLen, byte* sig, word32 *sigLen, const byte* hash, word32 hashLen, int hashAlg, const byte* seed) { @@ -10523,7 +10523,7 @@ int wc_MlDsaKey_SignCtxHashWithSeed(MlDsaKey* key, const byte* ctx, * BUFFER_E when sigLen is too small, * 0 otherwise. */ -int wc_MlDsaKey_SignMuWithSeed(MlDsaKey* key, byte* sig, word32 *sigLen, +int wc_MlDsaKey_SignMuWithSeed(wc_MlDsaKey* key, byte* sig, word32 *sigLen, const byte* mu, word32 muLen, const byte* seed) { int ret = 0; @@ -10566,7 +10566,7 @@ int wc_MlDsaKey_SignMuWithSeed(MlDsaKey* key, byte* sig, word32 *sigLen, * BUFFER_E when sigLen is less than DILITHIUM_LEVEL2_SIG_SIZE, * 0 otherwise. */ -int wc_MlDsaKey_VerifyCtx(MlDsaKey* key, const byte* sig, word32 sigLen, +int wc_MlDsaKey_VerifyCtx(wc_MlDsaKey* key, const byte* sig, word32 sigLen, const byte* ctx, byte ctxLen, const byte* msg, word32 msgLen, int* res) { int ret = 0; @@ -10623,7 +10623,7 @@ int wc_MlDsaKey_VerifyCtx(MlDsaKey* key, const byte* sig, word32 sigLen, * NOTE: This is a pre-FIPS 204 API without context support. New code should * use wc_MlDsaKey_VerifyCtx() with ctx=NULL/ctxLen=0 instead. */ -int wc_MlDsaKey_Verify(MlDsaKey* key, const byte* sig, word32 sigLen, +int wc_MlDsaKey_Verify(wc_MlDsaKey* key, const byte* sig, word32 sigLen, const byte* msg, word32 msgLen, int* res) { int ret = 0; @@ -10674,7 +10674,7 @@ int wc_MlDsaKey_Verify(MlDsaKey* key, const byte* sig, word32 sigLen, * BUFFER_E when sigLen is less than DILITHIUM_LEVEL2_SIG_SIZE, * 0 otherwise. */ -int wc_MlDsaKey_VerifyCtxHash(MlDsaKey* key, const byte* sig, word32 sigLen, +int wc_MlDsaKey_VerifyCtxHash(wc_MlDsaKey* key, const byte* sig, word32 sigLen, const byte* ctx, byte ctxLen, const byte* hash, word32 hashLen, int hashAlg, int* res) { @@ -10728,7 +10728,7 @@ int wc_MlDsaKey_VerifyCtxHash(MlDsaKey* key, const byte* sig, word32 sigLen, * returns BAD_FUNC_ARG when a parameter is NULL or muLen is not 64, * 0 otherwise. */ -int wc_MlDsaKey_VerifyMu(MlDsaKey* key, const byte* sig, word32 sigLen, +int wc_MlDsaKey_VerifyMu(wc_MlDsaKey* key, const byte* sig, word32 sigLen, const byte* mu, word32 muLen, int* res) { int ret = 0; @@ -10758,10 +10758,10 @@ int wc_MlDsaKey_VerifyMu(MlDsaKey* key, const byte* sig, word32 sigLen, * returns MEMORY_E when dynamic memory allocation fails */ -MlDsaKey* wc_MlDsaKey_New(void* heap, int devId) +wc_MlDsaKey* wc_MlDsaKey_New(void* heap, int devId) { int ret; - MlDsaKey* key = (MlDsaKey*)XMALLOC(sizeof(MlDsaKey), heap, + wc_MlDsaKey* key = (wc_MlDsaKey*)XMALLOC(sizeof(wc_MlDsaKey), heap, DYNAMIC_TYPE_DILITHIUM); if (key != NULL) { ret = wc_MlDsaKey_Init(key, heap, devId); @@ -10782,7 +10782,7 @@ MlDsaKey* wc_MlDsaKey_New(void* heap, int devId) * returns BAD_FUNC_ARG when key is NULL */ -int wc_MlDsaKey_Delete(MlDsaKey* key, MlDsaKey** key_p) +int wc_MlDsaKey_Delete(wc_MlDsaKey* key, wc_MlDsaKey** key_p) { void* heap; if (key == NULL) @@ -10804,7 +10804,7 @@ int wc_MlDsaKey_Delete(MlDsaKey* key, MlDsaKey** key_p) * devId[in] Device ID. * returns BAD_FUNC_ARG when key is NULL */ -int wc_MlDsaKey_Init(MlDsaKey* key, void* heap, int devId) +int wc_MlDsaKey_Init(wc_MlDsaKey* key, void* heap, int devId) { int ret = 0; @@ -10838,7 +10838,7 @@ int wc_MlDsaKey_Init(MlDsaKey* key, void* heap, int devId) } #ifdef WOLF_PRIVATE_KEY_ID -int wc_MlDsaKey_InitId(MlDsaKey* key, const unsigned char* id, int len, +int wc_MlDsaKey_InitId(wc_MlDsaKey* key, const unsigned char* id, int len, void* heap, int devId) { int ret = 0; @@ -10864,7 +10864,7 @@ int wc_MlDsaKey_InitId(MlDsaKey* key, const unsigned char* id, int len, return ret; } -int wc_MlDsaKey_InitLabel(MlDsaKey* key, const char* label, void* heap, +int wc_MlDsaKey_InitLabel(wc_MlDsaKey* key, const char* label, void* heap, int devId) { int ret = 0; @@ -10901,7 +10901,7 @@ int wc_MlDsaKey_InitLabel(MlDsaKey* key, const char* label, void* heap, * level [in] Either 2,3 or 5. * returns BAD_FUNC_ARG when key is NULL or level is a bad values. */ -int wc_MlDsaKey_SetParams(MlDsaKey* key, byte level) +int wc_MlDsaKey_SetParams(wc_MlDsaKey* key, byte level) { int ret = 0; @@ -10977,7 +10977,7 @@ int wc_MlDsaKey_SetParams(MlDsaKey* key, byte level) * level [out] The level. * returns BAD_FUNC_ARG when key is NULL or level has not been set. */ -int wc_MlDsaKey_GetParams(MlDsaKey* key, byte* level) +int wc_MlDsaKey_GetParams(wc_MlDsaKey* key, byte* level) { int ret = 0; @@ -11002,7 +11002,7 @@ int wc_MlDsaKey_GetParams(MlDsaKey* key, byte* level) * * key [in] ML-DSA key. */ -void wc_MlDsaKey_Free(MlDsaKey* key) +void wc_MlDsaKey_Free(wc_MlDsaKey* key) { if (key != NULL) { #if defined(WOLF_CRYPTO_CB) && defined(WOLF_CRYPTO_CB_FREE) @@ -11052,7 +11052,7 @@ void wc_MlDsaKey_Free(MlDsaKey* key) * @return Private key size on success for set level. * @return BAD_FUNC_ARG when key is NULL or level not set, */ -int wc_MlDsaKey_Size(MlDsaKey* key) +int wc_MlDsaKey_Size(wc_MlDsaKey* key) { int ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG); @@ -11093,7 +11093,7 @@ int wc_MlDsaKey_Size(MlDsaKey* key) * @return Private key size on success for set level. * @return BAD_FUNC_ARG when key is NULL or level not set, */ -int wc_MlDsaKey_PrivSize(MlDsaKey* key) +int wc_MlDsaKey_PrivSize(wc_MlDsaKey* key) { int ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG); @@ -11133,7 +11133,7 @@ int wc_MlDsaKey_PrivSize(MlDsaKey* key) * @return 0 on success. * @return BAD_FUNC_ARG when key is NULL or level not set, */ -int wc_MlDsaKey_GetPrivLen(MlDsaKey* key, int* len) +int wc_MlDsaKey_GetPrivLen(wc_MlDsaKey* key, int* len) { int ret = 0; @@ -11154,7 +11154,7 @@ int wc_MlDsaKey_GetPrivLen(MlDsaKey* key, int* len) * @return Public key size on success for set level. * @return BAD_FUNC_ARG when key is NULL or level not set, */ -int wc_MlDsaKey_PubSize(MlDsaKey* key) +int wc_MlDsaKey_PubSize(wc_MlDsaKey* key) { int ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG); @@ -11195,7 +11195,7 @@ int wc_MlDsaKey_PubSize(MlDsaKey* key) * @return 0 on success. * @return BAD_FUNC_ARG when key is NULL or level not set, */ -int wc_MlDsaKey_GetPubLen(MlDsaKey* key, int* len) +int wc_MlDsaKey_GetPubLen(wc_MlDsaKey* key, int* len) { int ret = 0; @@ -11215,7 +11215,7 @@ int wc_MlDsaKey_GetPubLen(MlDsaKey* key, int* len) * @return Signature size on success for set level. * @return BAD_FUNC_ARG when key is NULL or level not set, */ -int wc_MlDsaKey_SigSize(MlDsaKey* key) +int wc_MlDsaKey_SigSize(wc_MlDsaKey* key) { int ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG); @@ -11256,7 +11256,7 @@ int wc_MlDsaKey_SigSize(MlDsaKey* key) * @return 0 on success. * @return BAD_FUNC_ARG when key is NULL or level not set, */ -int wc_MlDsaKey_GetSigLen(MlDsaKey* key, int* len) +int wc_MlDsaKey_GetSigLen(wc_MlDsaKey* key, int* len) { int ret = 0; @@ -11278,10 +11278,10 @@ int wc_MlDsaKey_GetSigLen(MlDsaKey* key, int* len) * @return PUBLIC_KEY_E when the public key is not set or doesn't match, * @return MEMORY_E when dynamic memory allocation fails. */ -int wc_MlDsaKey_CheckKey(MlDsaKey* key) +int wc_MlDsaKey_CheckKey(wc_MlDsaKey* key) { int ret = 0; - const MlDsaParams* params = NULL; + const wc_MlDsaParams* params = NULL; sword32* a = NULL; sword32* s1 = NULL; sword32* s2 = NULL; @@ -11422,7 +11422,7 @@ int wc_MlDsaKey_CheckKey(MlDsaKey* key) * @return BAD_FUNC_ARG when a parameter is NULL. * @return BUFFER_E when outLen is less than DILITHIUM_LEVEL2_PUB_KEY_SIZE. */ -int wc_MlDsaKey_ExportPubRaw(MlDsaKey* key, byte* out, word32* outLen) +int wc_MlDsaKey_ExportPubRaw(wc_MlDsaKey* key, byte* out, word32* outLen) { int ret = 0; word32 inLen; @@ -11517,7 +11517,7 @@ int wc_MlDsaKey_ExportPubRaw(MlDsaKey* key, byte* out, word32* outLen) * @return 0 on success. * @return BAD_FUNC_ARG when in or key is NULL or key format is not supported. */ -int wc_MlDsaKey_ImportPubRaw(MlDsaKey* key, const byte* in, word32 inLen) +int wc_MlDsaKey_ImportPubRaw(wc_MlDsaKey* key, const byte* in, word32 inLen) { int ret = 0; @@ -11655,12 +11655,12 @@ int wc_MlDsaKey_ImportPubRaw(MlDsaKey* key, const byte* in, word32 inLen) * @return Other negative on hash error. */ static int mldsa_set_priv_key(const byte* priv, word32 privSz, - MlDsaKey* key) + wc_MlDsaKey* key) { int ret = 0; int expPrivSz; #ifdef WC_MLDSA_CACHE_MATRIX_A - const MlDsaParams* params = key->params; + const wc_MlDsaParams* params = key->params; #endif /* Validate parameters. privSz must match the expected size for the @@ -11758,7 +11758,7 @@ static int mldsa_set_priv_key(const byte* priv, word32 privSz, * @return BAD_FUNC_ARG when a parameter is NULL or privSz is less than size * required for level, */ -int wc_MlDsaKey_ImportPrivRaw(MlDsaKey* key, const byte* priv, word32 privSz) +int wc_MlDsaKey_ImportPrivRaw(wc_MlDsaKey* key, const byte* priv, word32 privSz) { int ret = 0; @@ -11791,7 +11791,7 @@ int wc_MlDsaKey_ImportPrivRaw(MlDsaKey* key, const byte* priv, word32 privSz) * @return BAD_FUNC_ARG when a required parameter is NULL an invalid * combination of keys/lengths is supplied. */ -int wc_MlDsaKey_ImportKey(MlDsaKey* key, const byte* priv, word32 privSz, +int wc_MlDsaKey_ImportKey(wc_MlDsaKey* key, const byte* priv, word32 privSz, const byte* pub, word32 pubSz) { int ret = 0; @@ -11830,7 +11830,7 @@ int wc_MlDsaKey_ImportKey(MlDsaKey* key, const byte* priv, word32 privSz, * @return BAD_FUNC_ARG when a parameter is NULL. * @return BUFFER_E when outLen is less than DILITHIUM_LEVEL2_KEY_SIZE. */ -int wc_MlDsaKey_ExportPrivRaw(MlDsaKey* key, byte* out, +int wc_MlDsaKey_ExportPrivRaw(wc_MlDsaKey* key, byte* out, word32* outLen) { int ret = 0; @@ -11906,7 +11906,7 @@ int wc_MlDsaKey_ExportPrivRaw(MlDsaKey* key, byte* out, * @return BAD_FUNC_ARG when a key, priv, privSz, pub or pubSz is NULL. * @return BUFFER_E when privSz or pubSz is less than required size. */ -int wc_MlDsaKey_ExportKey(MlDsaKey* key, byte* priv, word32 *privSz, +int wc_MlDsaKey_ExportKey(wc_MlDsaKey* key, byte* priv, word32 *privSz, byte* pub, word32 *pubSz) { int ret; @@ -11950,7 +11950,7 @@ static int mapOidToSecLevel(int oid) } /* Get OID sum from dilithium key */ -int mldsa_get_oid_sum(MlDsaKey* key, int* keyFormat) { +int mldsa_get_oid_sum(wc_MlDsaKey* key, int* keyFormat) { int ret = 0; #if defined(WOLFSSL_MLDSA_FIPS204_DRAFT) @@ -12007,7 +12007,7 @@ int mldsa_get_oid_sum(MlDsaKey* key, int* keyFormat) { * @return BAD_FUNC_ARG when input, inOutIdx or key is NULL or inSz is 0. * @return Other negative on parse error. */ -int wc_MlDsaKey_PrivateKeyDecode(MlDsaKey* key, const byte* input, +int wc_MlDsaKey_PrivateKeyDecode(wc_MlDsaKey* key, const byte* input, word32 inSz, word32* inOutIdx) { int ret = 0; @@ -12321,7 +12321,7 @@ static int mldsa_check_type(const byte* input, word32* inOutIdx, byte type, * @return BAD_FUNC_ARG when level not set. * @return Other negative on parse error. */ -int wc_MlDsaKey_PublicKeyDecode(MlDsaKey* key, const byte* input, +int wc_MlDsaKey_PublicKeyDecode(wc_MlDsaKey* key, const byte* input, word32 inSz, word32* inOutIdx) { int ret = 0; @@ -12516,7 +12516,7 @@ int wc_MlDsaKey_PublicKeyDecode(MlDsaKey* key, const byte* input, * @return BAD_FUNC_ARG when key is NULL. * @return MEMORY_E when dynamic memory allocation failed. */ -int wc_MlDsaKey_PublicKeyToDer(MlDsaKey* key, byte* output, word32 len, +int wc_MlDsaKey_PublicKeyToDer(wc_MlDsaKey* key, byte* output, word32 len, int withAlg) { int ret = 0; @@ -12599,7 +12599,7 @@ int wc_MlDsaKey_PublicKeyToDer(MlDsaKey* key, byte* output, word32 len, * @return BAD_FUNC_ARG when key is NULL. * @return MEMORY_E when dynamic memory allocation failed. */ -int wc_MlDsaKey_KeyToDer(MlDsaKey* key, byte* output, word32 len) +int wc_MlDsaKey_KeyToDer(wc_MlDsaKey* key, byte* output, word32 len) { int ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG); @@ -12653,7 +12653,7 @@ int wc_MlDsaKey_KeyToDer(MlDsaKey* key, byte* output, word32 len) * @return BAD_FUNC_ARG when key is NULL. * @return MEMORY_E when dynamic memory allocation failed. */ -int wc_MlDsaKey_PrivateKeyToDer(MlDsaKey* key, byte* output, word32 len) +int wc_MlDsaKey_PrivateKeyToDer(wc_MlDsaKey* key, byte* output, word32 len) { int ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG); diff --git a/wolfcrypt/src/wc_pkcs11.c b/wolfcrypt/src/wc_pkcs11.c index 1abd674946..73edf279ab 100644 --- a/wolfcrypt/src/wc_pkcs11.c +++ b/wolfcrypt/src/wc_pkcs11.c @@ -1786,7 +1786,7 @@ static int Pkcs11CreateMlKemPrivateKey(CK_OBJECT_HANDLE* privateKey, */ static int Pkcs11CreateMldsaPublicKey(CK_OBJECT_HANDLE* handle, Pkcs11Session* session, - MlDsaKey* key, + wc_MlDsaKey* key, CK_MECHANISM_INFO_PTR mechInfo) { int ret = 0; @@ -1873,7 +1873,7 @@ static int Pkcs11CreateMldsaPublicKey(CK_OBJECT_HANDLE* handle, */ static int Pkcs11CreateMldsaPrivateKey(CK_OBJECT_HANDLE* privateKey, Pkcs11Session* session, - MlDsaKey* key, + wc_MlDsaKey* key, CK_MECHANISM_INFO_PTR mechInfo) { int ret = 0; @@ -2222,7 +2222,7 @@ int wc_Pkcs11StoreKey(Pkcs11Token* token, int type, int clear, void* key) #endif /* WOLFSSL_HAVE_MLKEM */ #if defined(HAVE_DILITHIUM) case PKCS11_KEY_TYPE_MLDSA: { - MlDsaKey* mldsaKey = (MlDsaKey*) key; + wc_MlDsaKey* mldsaKey = (wc_MlDsaKey*) key; CK_MECHANISM_INFO mechInfo; ret = Pkcs11MechAvail(&session, CKM_ML_DSA, &mechInfo); @@ -4763,7 +4763,7 @@ static int Pkcs11PqcKemDecapsulate(Pkcs11Session* session, wc_CryptoInfo* info) static int Pkcs11FindMldsaKey(CK_OBJECT_HANDLE* handle, CK_OBJECT_CLASS keyClass, Pkcs11Session* session, - MlDsaKey* key) + wc_MlDsaKey* key) { int ret = 0; CK_ULONG count = 0; @@ -4810,7 +4810,7 @@ static int Pkcs11FindMldsaKey(CK_OBJECT_HANDLE* handle, * @return MEMORY_E when a memory allocation fails. * @return 0 on success. */ -static int Pkcs11GetMldsaPublicKey(MlDsaKey* key, +static int Pkcs11GetMldsaPublicKey(wc_MlDsaKey* key, Pkcs11Session* session, CK_OBJECT_HANDLE keyHandle) { @@ -4930,7 +4930,7 @@ static int Pkcs11GetMldsaPreHash(int hashType, * @return WC_HW_E when a PKCS#11 library call fails. * @return 0 on success. */ -static int Pkcs11MldsaKeyGen(Pkcs11Session* session, MlDsaKey* key) +static int Pkcs11MldsaKeyGen(Pkcs11Session* session, wc_MlDsaKey* key) { int ret = 0; CK_RV rv; @@ -5057,7 +5057,7 @@ static int Pkcs11MldsaSign(Pkcs11Session* session, wc_CryptoInfo* info) CK_MECHANISM mech; CK_MECHANISM_INFO mechInfo; CK_OBJECT_HANDLE privateKey = NULL_PTR; - MlDsaKey* key = (MlDsaKey*) info->pk.pqc_sign.key; + wc_MlDsaKey* key = (wc_MlDsaKey*) info->pk.pqc_sign.key; union { CK_SIGN_ADDITIONAL_CONTEXT pure; @@ -5200,7 +5200,7 @@ static int Pkcs11MldsaVerify(Pkcs11Session* session, wc_CryptoInfo* info) CK_MECHANISM mech; CK_MECHANISM_INFO mechInfo; CK_OBJECT_HANDLE publicKey = NULL_PTR; - MlDsaKey* key = (MlDsaKey*) info->pk.pqc_verify.key; + wc_MlDsaKey* key = (wc_MlDsaKey*) info->pk.pqc_verify.key; union { CK_SIGN_ADDITIONAL_CONTEXT pure; @@ -5330,10 +5330,10 @@ static int Pkcs11MldsaCheckPrivKey(Pkcs11Session* session, wc_CryptoInfo* info) word32 storedKeySize = 0; word32 idx = 0; CK_OBJECT_HANDLE privKeyHandle; - MlDsaKey* privKey = (MlDsaKey*) info->pk.pqc_sig_check.key; - WC_DECLARE_VAR(pubKey, MlDsaKey, 1, privKey->heap); + wc_MlDsaKey* privKey = (wc_MlDsaKey*) info->pk.pqc_sig_check.key; + WC_DECLARE_VAR(pubKey, wc_MlDsaKey, 1, privKey->heap); - WC_ALLOC_VAR_EX(pubKey, MlDsaKey, 1, privKey->heap, DYNAMIC_TYPE_DILITHIUM, + WC_ALLOC_VAR_EX(pubKey, wc_MlDsaKey, 1, privKey->heap, DYNAMIC_TYPE_DILITHIUM, ret = MEMORY_E); /* Get the ML-DSA public key object. */ @@ -5397,7 +5397,7 @@ static int Pkcs11MldsaCheckPrivKey(Pkcs11Session* session, wc_CryptoInfo* info) * @param [in] key ML-DSA key. * @return 0 on success. */ -static int Pkcs11MldsaDeletePrivKey(Pkcs11Session* session, MlDsaKey* key) +static int Pkcs11MldsaDeletePrivKey(Pkcs11Session* session, wc_MlDsaKey* key) { CK_OBJECT_HANDLE privateKey; @@ -5428,7 +5428,7 @@ static int Pkcs11PqcSigKeyGen(Pkcs11Session* session, wc_CryptoInfo* info) switch (info->pk.pqc_sig_kg.type) { case WC_PQC_SIG_TYPE_DILITHIUM: ret = Pkcs11MldsaKeyGen(session, - (MlDsaKey*)info->pk.pqc_sig_kg.key); + (wc_MlDsaKey*)info->pk.pqc_sig_kg.key); break; default: ret = NOT_COMPILED_IN; @@ -6636,7 +6636,7 @@ int wc_Pkcs11_CryptoDevCb(int devId, wc_CryptoInfo* info, void* ctx) ret = Pkcs11OpenSession(token, &session, readWrite); if (ret == 0) { ret = Pkcs11MldsaDeletePrivKey(&session, - (MlDsaKey*)info->free.obj); + (wc_MlDsaKey*)info->free.obj); Pkcs11CloseSession(token, &session); } } diff --git a/wolfssl/wolfcrypt/asn.h b/wolfssl/wolfcrypt/asn.h index 22346a5c0a..dfcbf8ba6d 100644 --- a/wolfssl/wolfcrypt/asn.h +++ b/wolfssl/wolfcrypt/asn.h @@ -1597,9 +1597,9 @@ struct SignatureCtx { #endif #ifdef HAVE_DILITHIUM #ifdef WOLFSSL_NO_MALLOC - struct dilithium_key dilithium[1]; + dilithium_key dilithium[1]; #else - struct dilithium_key* dilithium; + dilithium_key* dilithium; #endif #endif #ifdef WOLFSSL_HAVE_SLHDSA diff --git a/wolfssl/wolfcrypt/asn_public.h b/wolfssl/wolfcrypt/asn_public.h index c8968cc265..71f976e729 100644 --- a/wolfssl/wolfcrypt/asn_public.h +++ b/wolfssl/wolfcrypt/asn_public.h @@ -78,18 +78,23 @@ This library defines the interface APIs for X509 certificates. #define WC_FALCONKEY_TYPE_DEFINED #endif #ifndef WC_MLDSAKEY_TYPE_DEFINED - typedef struct MlDsaKey MlDsaKey; + typedef struct wc_MlDsaKey wc_MlDsaKey; #define WC_MLDSAKEY_TYPE_DEFINED #endif -/* Legacy typedef alias. Kept until the dilithium.h compatibility shim is +/* Legacy typedef aliases. Kept until the dilithium.h compatibility shim is * removed in a future release. Application code that included only * on master continues to compile. Suppress * with WOLFSSL_NO_DILITHIUM_LEGACY_NAMES. */ #if !defined(WOLFSSL_NO_DILITHIUM_LEGACY_NAMES) && \ !defined(WC_DILITHIUMKEY_TYPE_DEFINED) - typedef struct MlDsaKey dilithium_key; + typedef struct wc_MlDsaKey dilithium_key; #define WC_DILITHIUMKEY_TYPE_DEFINED #endif +#if !defined(WOLFSSL_NO_DILITHIUM_LEGACY_NAMES) && \ + !defined(WC_MLDSAKEY_LEGACY_TYPE_DEFINED) + typedef struct wc_MlDsaKey MlDsaKey; + #define WC_MLDSAKEY_LEGACY_TYPE_DEFINED +#endif #ifndef WC_SLHDSAKEY_TYPE_DEFINED typedef struct SlhDsaKey SlhDsaKey; #define WC_SLHDSAKEY_TYPE_DEFINED diff --git a/wolfssl/wolfcrypt/dilithium.h b/wolfssl/wolfcrypt/dilithium.h index 14531dfd59..45db6d50bd 100644 --- a/wolfssl/wolfcrypt/dilithium.h +++ b/wolfssl/wolfcrypt/dilithium.h @@ -59,7 +59,7 @@ * WOLFSSL_NO_DILITHIUM_LEGACY_NAMES. * * New code must include directly and use - * the MlDsaKey / wc_MlDsaKey_* / WOLFSSL_MLDSA_* names. */ + * the wc_MlDsaKey / wc_MlDsaKey_* / WOLFSSL_MLDSA_* names. */ #ifndef WOLF_CRYPT_DILITHIUM_H #define WOLF_CRYPT_DILITHIUM_H @@ -342,17 +342,12 @@ #if defined(WOLFSSL_HAVE_MLDSA) && !defined(WOLFSSL_NO_DILITHIUM_LEGACY_NAMES) -/* Legacy type aliases. WC_DILITHIUMKEY_TYPE_DEFINED is set so that - * does not emit its own - * `typedef struct MlDsaKey dilithium_key;` (which would expand under this - * macro alias to `typedef struct MlDsaKey MlDsaKey;` -- a typedef - * redefinition that strict C99 / older MSVC reject as a constraint - * violation). */ -#define dilithium_key MlDsaKey -#ifndef WC_DILITHIUMKEY_TYPE_DEFINED - #define WC_DILITHIUMKEY_TYPE_DEFINED -#endif -#define wc_dilithium_params MlDsaParams +/* Legacy type aliases. The wc_MlDsaKey-related typedefs (dilithium_key, + * MlDsaKey) live in so that consumers + * that include only asn_public.h still see them. The wc_MlDsaParams + * legacy typedef (MlDsaParams) lives in + * alongside the canonical struct definition. */ +#define wc_dilithium_params wc_MlDsaParams /* Legacy function aliases - simple symbol redirects. Signature is unchanged * vs the canonical name, so a #define is sufficient: call sites and `&name` @@ -405,29 +400,29 @@ #endif WOLFSSL_DILITHIUM_LEGACY_INLINE -int wc_dilithium_init(MlDsaKey* key) { +int wc_dilithium_init(wc_MlDsaKey* key) { return wc_MlDsaKey_Init(key, NULL, INVALID_DEVID); } #ifdef WOLFSSL_MLDSA_PUBLIC_KEY WOLFSSL_DILITHIUM_LEGACY_INLINE -int wc_dilithium_import_public(const byte* in, word32 inLen, MlDsaKey* key) { +int wc_dilithium_import_public(const byte* in, word32 inLen, wc_MlDsaKey* key) { return wc_MlDsaKey_ImportPubRaw(key, in, inLen); } #endif #ifdef WOLFSSL_MLDSA_PRIVATE_KEY WOLFSSL_DILITHIUM_LEGACY_INLINE -int wc_dilithium_import_private(const byte* priv, word32 privSz, MlDsaKey* key) { +int wc_dilithium_import_private(const byte* priv, word32 privSz, wc_MlDsaKey* key) { return wc_MlDsaKey_ImportPrivRaw(key, priv, privSz); } WOLFSSL_DILITHIUM_LEGACY_INLINE -int wc_dilithium_import_private_only(const byte* in, word32 inLen, MlDsaKey* key) { +int wc_dilithium_import_private_only(const byte* in, word32 inLen, wc_MlDsaKey* key) { return wc_MlDsaKey_ImportPrivRaw(key, in, inLen); } WOLFSSL_DILITHIUM_LEGACY_INLINE int wc_dilithium_import_key(const byte* priv, word32 privSz, const byte* pub, - word32 pubSz, MlDsaKey* key) { + word32 pubSz, wc_MlDsaKey* key) { return wc_MlDsaKey_ImportKey(key, priv, privSz, pub, pubSz); } #endif /* WOLFSSL_MLDSA_PRIVATE_KEY */ @@ -436,12 +431,12 @@ int wc_dilithium_import_key(const byte* priv, word32 privSz, const byte* pub, #ifdef WOLFSSL_MLDSA_NO_CTX WOLFSSL_DILITHIUM_LEGACY_INLINE int wc_dilithium_sign_msg(const byte* msg, word32 msgLen, byte* sig, - word32* sigLen, MlDsaKey* key, WC_RNG* rng) { + word32* sigLen, wc_MlDsaKey* key, WC_RNG* rng) { return wc_MlDsaKey_Sign(key, sig, sigLen, msg, msgLen, rng); } WOLFSSL_DILITHIUM_LEGACY_INLINE int wc_dilithium_sign_msg_with_seed(const byte* msg, word32 msgLen, byte* sig, - word32* sigLen, MlDsaKey* key, + word32* sigLen, wc_MlDsaKey* key, const byte* seed) { return wc_MlDsaKey_SignWithSeed(key, sig, sigLen, msg, msgLen, seed); } @@ -449,13 +444,13 @@ int wc_dilithium_sign_msg_with_seed(const byte* msg, word32 msgLen, byte* sig, WOLFSSL_DILITHIUM_LEGACY_INLINE int wc_dilithium_sign_ctx_msg(const byte* ctx, byte ctxLen, const byte* msg, word32 msgLen, byte* sig, word32* sigLen, - MlDsaKey* key, WC_RNG* rng) { + wc_MlDsaKey* key, WC_RNG* rng) { return wc_MlDsaKey_SignCtx(key, ctx, ctxLen, sig, sigLen, msg, msgLen, rng); } WOLFSSL_DILITHIUM_LEGACY_INLINE int wc_dilithium_sign_ctx_hash(const byte* ctx, byte ctxLen, int hashAlg, const byte* hash, word32 hashLen, byte* sig, - word32* sigLen, MlDsaKey* key, WC_RNG* rng) { + word32* sigLen, wc_MlDsaKey* key, WC_RNG* rng) { return wc_MlDsaKey_SignCtxHash(key, ctx, ctxLen, sig, sigLen, hash, hashLen, hashAlg, rng); } @@ -463,7 +458,7 @@ WOLFSSL_DILITHIUM_LEGACY_INLINE int wc_dilithium_sign_ctx_msg_with_seed(const byte* ctx, byte ctxLen, const byte* msg, word32 msgLen, byte* sig, word32* sigLen, - MlDsaKey* key, const byte* seed) { + wc_MlDsaKey* key, const byte* seed) { return wc_MlDsaKey_SignCtxWithSeed(key, ctx, ctxLen, sig, sigLen, msg, msgLen, seed); } @@ -471,14 +466,14 @@ WOLFSSL_DILITHIUM_LEGACY_INLINE int wc_dilithium_sign_ctx_hash_with_seed(const byte* ctx, byte ctxLen, int hashAlg, const byte* hash, word32 hashLen, byte* sig, - word32* sigLen, MlDsaKey* key, + word32* sigLen, wc_MlDsaKey* key, const byte* seed) { return wc_MlDsaKey_SignCtxHashWithSeed(key, ctx, ctxLen, sig, sigLen, hash, hashLen, hashAlg, seed); } WOLFSSL_DILITHIUM_LEGACY_INLINE int wc_dilithium_sign_mu_with_seed(const byte* mu, word32 muLen, byte* sig, - word32* sigLen, MlDsaKey* key, + word32* sigLen, wc_MlDsaKey* key, const byte* seed) { return wc_MlDsaKey_SignMuWithSeed(key, sig, sigLen, mu, muLen, seed); } @@ -487,27 +482,27 @@ int wc_dilithium_sign_mu_with_seed(const byte* mu, word32 muLen, byte* sig, #ifdef WOLFSSL_MLDSA_NO_CTX WOLFSSL_DILITHIUM_LEGACY_INLINE int wc_dilithium_verify_msg(const byte* sig, word32 sigLen, const byte* msg, - word32 msgLen, int* res, MlDsaKey* key) { + word32 msgLen, int* res, wc_MlDsaKey* key) { return wc_MlDsaKey_Verify(key, sig, sigLen, msg, msgLen, res); } #endif /* WOLFSSL_MLDSA_NO_CTX */ WOLFSSL_DILITHIUM_LEGACY_INLINE int wc_dilithium_verify_ctx_msg(const byte* sig, word32 sigLen, const byte* ctx, byte ctxLen, const byte* msg, word32 msgLen, - int* res, MlDsaKey* key) { + int* res, wc_MlDsaKey* key) { return wc_MlDsaKey_VerifyCtx(key, sig, sigLen, ctx, ctxLen, msg, msgLen, res); } WOLFSSL_DILITHIUM_LEGACY_INLINE int wc_dilithium_verify_ctx_hash(const byte* sig, word32 sigLen, const byte* ctx, byte ctxLen, int hashAlg, const byte* hash, - word32 hashLen, int* res, MlDsaKey* key) { + word32 hashLen, int* res, wc_MlDsaKey* key) { return wc_MlDsaKey_VerifyCtxHash(key, sig, sigLen, ctx, ctxLen, hash, hashLen, hashAlg, res); } WOLFSSL_DILITHIUM_LEGACY_INLINE int wc_dilithium_verify_mu(const byte* sig, word32 sigLen, const byte* mu, - word32 muLen, int* res, MlDsaKey* key) { + word32 muLen, int* res, wc_MlDsaKey* key) { return wc_MlDsaKey_VerifyMu(key, sig, sigLen, mu, muLen, res); } @@ -515,14 +510,14 @@ int wc_dilithium_verify_mu(const byte* sig, word32 sigLen, const byte* mu, #ifdef WOLFSSL_MLDSA_PRIVATE_KEY WOLFSSL_DILITHIUM_LEGACY_INLINE int wc_Dilithium_PrivateKeyDecode(const byte* input, word32* inOutIdx, - MlDsaKey* key, word32 inSz) { + wc_MlDsaKey* key, word32 inSz) { return wc_MlDsaKey_PrivateKeyDecode(key, input, inSz, inOutIdx); } #endif #ifdef WOLFSSL_MLDSA_PUBLIC_KEY WOLFSSL_DILITHIUM_LEGACY_INLINE int wc_Dilithium_PublicKeyDecode(const byte* input, word32* inOutIdx, - MlDsaKey* key, word32 inSz) { + wc_MlDsaKey* key, word32 inSz) { return wc_MlDsaKey_PublicKeyDecode(key, input, inSz, inOutIdx); } #endif diff --git a/wolfssl/wolfcrypt/wc_mldsa.h b/wolfssl/wolfcrypt/wc_mldsa.h index 564084f764..f908505c2a 100644 --- a/wolfssl/wolfcrypt/wc_mldsa.h +++ b/wolfssl/wolfcrypt/wc_mldsa.h @@ -26,7 +26,7 @@ /* Interfaces for ML-DSA (FIPS 204), the NIST-standardized form of the * post-quantum signature algorithm formerly known as Dilithium. * - * This header declares the canonical MlDsaKey / wc_MlDsaKey_* API. New + * This header declares the canonical wc_MlDsaKey / wc_MlDsaKey_* API. New * code must include this header directly. * * Backwards-compatibility for the pre-standardization names is delivered @@ -607,7 +607,7 @@ /* Structs */ -typedef struct MlDsaParams { +typedef struct wc_MlDsaParams { byte level; byte k; byte l; @@ -628,9 +628,13 @@ typedef struct MlDsaParams { word16 zEncSz; word16 pkSz; word16 sigSz; -} MlDsaParams; +} wc_MlDsaParams; -struct MlDsaKey { +#ifndef WOLFSSL_NO_DILITHIUM_LEGACY_NAMES +typedef struct wc_MlDsaParams MlDsaParams; +#endif + +struct wc_MlDsaKey { byte pubKeySet; byte prvKeySet; byte level; /* 2,3 or 5 */ @@ -671,7 +675,7 @@ struct MlDsaKey { const byte* k; #endif - const MlDsaParams* params; + const wc_MlDsaParams* params; wc_Shake shake; #ifndef WC_MLDSA_FIXED_ARRAY #ifdef WC_MLDSA_CACHE_MATRIX_A @@ -721,9 +725,19 @@ struct MlDsaKey { }; #ifndef WC_MLDSAKEY_TYPE_DEFINED - typedef struct MlDsaKey MlDsaKey; + typedef struct wc_MlDsaKey wc_MlDsaKey; #define WC_MLDSAKEY_TYPE_DEFINED #endif +#ifndef WOLFSSL_NO_DILITHIUM_LEGACY_NAMES +#ifndef WC_DILITHIUMKEY_TYPE_DEFINED + typedef struct wc_MlDsaKey dilithium_key; + #define WC_DILITHIUMKEY_TYPE_DEFINED +#endif +#ifndef WC_MLDSAKEY_LEGACY_TYPE_DEFINED + typedef struct wc_MlDsaKey MlDsaKey; + #define WC_MLDSAKEY_LEGACY_TYPE_DEFINED +#endif +#endif /* When WOLFSSL_MLDSA_FIPS204_DRAFT is enabled the legacy (pre-FIPS 204) * no-context sign/verify API is required to handle draft-format signatures. */ @@ -736,9 +750,9 @@ struct MlDsaKey { #ifndef WOLFSSL_MLDSA_VERIFY_ONLY WOLFSSL_API -int wc_MlDsaKey_MakeKey(MlDsaKey* key, WC_RNG* rng); +int wc_MlDsaKey_MakeKey(wc_MlDsaKey* key, WC_RNG* rng); WOLFSSL_API -int wc_MlDsaKey_MakeKeyFromSeed(MlDsaKey* key, const byte* seed); +int wc_MlDsaKey_MakeKeyFromSeed(wc_MlDsaKey* key, const byte* seed); /* Legacy sign API without context parameter (pre-FIPS 204). * Only available when WOLFSSL_MLDSA_NO_CTX is defined. @@ -746,14 +760,14 @@ int wc_MlDsaKey_MakeKeyFromSeed(MlDsaKey* key, const byte* seed); * for FIPS 204 compliant signing with an empty context. */ #ifdef WOLFSSL_MLDSA_NO_CTX WOLFSSL_API -int wc_MlDsaKey_Sign(MlDsaKey* key, byte* sig, word32* sigLen, +int wc_MlDsaKey_Sign(wc_MlDsaKey* key, byte* sig, word32* sigLen, const byte* msg, word32 msgLen, WC_RNG* rng); #endif /* WOLFSSL_MLDSA_NO_CTX */ WOLFSSL_API -int wc_MlDsaKey_SignCtx(MlDsaKey* key, const byte* ctx, byte ctxLen, +int wc_MlDsaKey_SignCtx(wc_MlDsaKey* key, const byte* ctx, byte ctxLen, byte* sig, word32* sigLen, const byte* msg, word32 msgLen, WC_RNG* rng); WOLFSSL_API -int wc_MlDsaKey_SignCtxHash(MlDsaKey* key, const byte* ctx, byte ctxLen, +int wc_MlDsaKey_SignCtxHash(wc_MlDsaKey* key, const byte* ctx, byte ctxLen, byte* sig, word32* sigLen, const byte* hash, word32 hashLen, int hashAlg, WC_RNG* rng); /* Legacy seed-based sign API without context parameter (pre-FIPS 204). @@ -761,19 +775,19 @@ int wc_MlDsaKey_SignCtxHash(MlDsaKey* key, const byte* ctx, byte ctxLen, * New code should use wc_MlDsaKey_SignCtxWithSeed() instead. */ #ifdef WOLFSSL_MLDSA_NO_CTX WOLFSSL_API -int wc_MlDsaKey_SignWithSeed(MlDsaKey* key, byte* sig, word32* sigLen, +int wc_MlDsaKey_SignWithSeed(wc_MlDsaKey* key, byte* sig, word32* sigLen, const byte* msg, word32 msgLen, const byte* seed); #endif /* WOLFSSL_MLDSA_NO_CTX */ WOLFSSL_API -int wc_MlDsaKey_SignCtxWithSeed(MlDsaKey* key, const byte* ctx, byte ctxLen, +int wc_MlDsaKey_SignCtxWithSeed(wc_MlDsaKey* key, const byte* ctx, byte ctxLen, byte* sig, word32* sigLen, const byte* msg, word32 msgLen, const byte* seed); WOLFSSL_API -int wc_MlDsaKey_SignCtxHashWithSeed(MlDsaKey* key, const byte* ctx, +int wc_MlDsaKey_SignCtxHashWithSeed(wc_MlDsaKey* key, const byte* ctx, byte ctxLen, byte* sig, word32* sigLen, const byte* hash, word32 hashLen, int hashAlg, const byte* seed); WOLFSSL_API -int wc_MlDsaKey_SignMuWithSeed(MlDsaKey* key, byte* sig, word32* sigLen, +int wc_MlDsaKey_SignMuWithSeed(wc_MlDsaKey* key, byte* sig, word32* sigLen, const byte* mu, word32 muLen, const byte* seed); #endif /* !WOLFSSL_MLDSA_VERIFY_ONLY */ /* Legacy verify API without context parameter (pre-FIPS 204). @@ -782,121 +796,121 @@ int wc_MlDsaKey_SignMuWithSeed(MlDsaKey* key, byte* sig, word32* sigLen, * for FIPS 204 compliant verification with an empty context. */ #ifdef WOLFSSL_MLDSA_NO_CTX WOLFSSL_API -int wc_MlDsaKey_Verify(MlDsaKey* key, const byte* sig, word32 sigLen, +int wc_MlDsaKey_Verify(wc_MlDsaKey* key, const byte* sig, word32 sigLen, const byte* msg, word32 msgLen, int* res); #endif /* WOLFSSL_MLDSA_NO_CTX */ WOLFSSL_API -int wc_MlDsaKey_VerifyCtx(MlDsaKey* key, const byte* sig, word32 sigLen, +int wc_MlDsaKey_VerifyCtx(wc_MlDsaKey* key, const byte* sig, word32 sigLen, const byte* ctx, byte ctxLen, const byte* msg, word32 msgLen, int* res); WOLFSSL_API -int wc_MlDsaKey_VerifyCtxHash(MlDsaKey* key, const byte* sig, word32 sigLen, +int wc_MlDsaKey_VerifyCtxHash(wc_MlDsaKey* key, const byte* sig, word32 sigLen, const byte* ctx, byte ctxLen, const byte* hash, word32 hashLen, int hashAlg, int* res); WOLFSSL_API -int wc_MlDsaKey_VerifyMu(MlDsaKey* key, const byte* sig, word32 sigLen, +int wc_MlDsaKey_VerifyMu(wc_MlDsaKey* key, const byte* sig, word32 sigLen, const byte* mu, word32 muLen, int* res); #ifndef WC_NO_CONSTRUCTORS WOLFSSL_API -MlDsaKey* wc_MlDsaKey_New(void* heap, int devId); +wc_MlDsaKey* wc_MlDsaKey_New(void* heap, int devId); WOLFSSL_API -int wc_MlDsaKey_Delete(MlDsaKey* key, MlDsaKey** key_p); +int wc_MlDsaKey_Delete(wc_MlDsaKey* key, wc_MlDsaKey** key_p); #endif /* !WC_NO_CONSTRUCTORS */ WOLFSSL_API -int wc_MlDsaKey_Init(MlDsaKey* key, void* heap, int devId); +int wc_MlDsaKey_Init(wc_MlDsaKey* key, void* heap, int devId); #ifdef WOLF_PRIVATE_KEY_ID WOLFSSL_API -int wc_MlDsaKey_InitId(MlDsaKey* key, const unsigned char* id, int len, +int wc_MlDsaKey_InitId(wc_MlDsaKey* key, const unsigned char* id, int len, void* heap, int devId); WOLFSSL_API -int wc_MlDsaKey_InitLabel(MlDsaKey* key, const char* label, void* heap, +int wc_MlDsaKey_InitLabel(wc_MlDsaKey* key, const char* label, void* heap, int devId); #endif WOLFSSL_API -int wc_MlDsaKey_SetParams(MlDsaKey* key, byte level); +int wc_MlDsaKey_SetParams(wc_MlDsaKey* key, byte level); WOLFSSL_API -int wc_MlDsaKey_GetParams(MlDsaKey* key, byte* level); +int wc_MlDsaKey_GetParams(wc_MlDsaKey* key, byte* level); WOLFSSL_API -void wc_MlDsaKey_Free(MlDsaKey* key); +void wc_MlDsaKey_Free(wc_MlDsaKey* key); #ifdef WOLFSSL_MLDSA_PRIVATE_KEY WOLFSSL_API -int wc_MlDsaKey_Size(MlDsaKey* key); +int wc_MlDsaKey_Size(wc_MlDsaKey* key); #endif #if defined(WOLFSSL_MLDSA_PRIVATE_KEY) && \ defined(WOLFSSL_MLDSA_PUBLIC_KEY) WOLFSSL_API -int wc_MlDsaKey_PrivSize(MlDsaKey* key); +int wc_MlDsaKey_PrivSize(wc_MlDsaKey* key); #endif #ifdef WOLFSSL_MLDSA_PUBLIC_KEY WOLFSSL_API -int wc_MlDsaKey_PubSize(MlDsaKey* key); +int wc_MlDsaKey_PubSize(wc_MlDsaKey* key); #endif #if !defined(WOLFSSL_MLDSA_NO_SIGN) || !defined(WOLFSSL_MLDSA_NO_VERIFY) WOLFSSL_API -int wc_MlDsaKey_SigSize(MlDsaKey* key); +int wc_MlDsaKey_SigSize(wc_MlDsaKey* key); #endif #ifdef WOLFSSL_MLDSA_CHECK_KEY WOLFSSL_API -int wc_MlDsaKey_CheckKey(MlDsaKey* key); +int wc_MlDsaKey_CheckKey(wc_MlDsaKey* key); #endif #ifdef WOLFSSL_MLDSA_PUBLIC_KEY WOLFSSL_API -int wc_MlDsaKey_ImportPubRaw(MlDsaKey* key, const byte* in, word32 inLen); +int wc_MlDsaKey_ImportPubRaw(wc_MlDsaKey* key, const byte* in, word32 inLen); #endif #ifdef WOLFSSL_MLDSA_PRIVATE_KEY WOLFSSL_API -int wc_MlDsaKey_ImportPrivRaw(MlDsaKey* key, const byte* priv, word32 privSz); +int wc_MlDsaKey_ImportPrivRaw(wc_MlDsaKey* key, const byte* priv, word32 privSz); WOLFSSL_API -int wc_MlDsaKey_ImportKey(MlDsaKey* key, const byte* priv, word32 privSz, +int wc_MlDsaKey_ImportKey(wc_MlDsaKey* key, const byte* priv, word32 privSz, const byte* pub, word32 pubSz); #endif #ifdef WOLFSSL_MLDSA_PUBLIC_KEY WOLFSSL_API -int wc_MlDsaKey_ExportPubRaw(MlDsaKey* key, byte* out, word32* outLen); +int wc_MlDsaKey_ExportPubRaw(wc_MlDsaKey* key, byte* out, word32* outLen); #endif #ifdef WOLFSSL_MLDSA_PRIVATE_KEY WOLFSSL_API -int wc_MlDsaKey_ExportPrivRaw(MlDsaKey* key, byte* out, word32* outLen); +int wc_MlDsaKey_ExportPrivRaw(wc_MlDsaKey* key, byte* out, word32* outLen); #endif #ifdef WOLFSSL_MLDSA_PRIVATE_KEY WOLFSSL_API -int wc_MlDsaKey_ExportKey(MlDsaKey* key, byte* priv, word32 *privSz, +int wc_MlDsaKey_ExportKey(wc_MlDsaKey* key, byte* priv, word32 *privSz, byte* pub, word32 *pubSz); #endif #ifndef WOLFSSL_MLDSA_NO_ASN1 -WOLFSSL_LOCAL int mldsa_get_oid_sum(MlDsaKey* key, int* keyFormat); +WOLFSSL_LOCAL int mldsa_get_oid_sum(wc_MlDsaKey* key, int* keyFormat); #endif /* WOLFSSL_MLDSA_NO_ASN1 */ #ifndef WOLFSSL_MLDSA_NO_ASN1 #if defined(WOLFSSL_MLDSA_PRIVATE_KEY) -WOLFSSL_API int wc_MlDsaKey_PrivateKeyDecode(MlDsaKey* key, const byte* input, +WOLFSSL_API int wc_MlDsaKey_PrivateKeyDecode(wc_MlDsaKey* key, const byte* input, word32 inSz, word32* inOutIdx); #endif #endif /* WOLFSSL_MLDSA_NO_ASN1 */ #ifdef WOLFSSL_MLDSA_PUBLIC_KEY -WOLFSSL_API int wc_MlDsaKey_PublicKeyDecode(MlDsaKey* key, const byte* input, +WOLFSSL_API int wc_MlDsaKey_PublicKeyDecode(wc_MlDsaKey* key, const byte* input, word32 inSz, word32* inOutIdx); #endif #ifndef WOLFSSL_MLDSA_NO_ASN1 #ifdef WC_ENABLE_ASYM_KEY_EXPORT -WOLFSSL_API int wc_MlDsaKey_PublicKeyToDer(MlDsaKey* key, byte* output, +WOLFSSL_API int wc_MlDsaKey_PublicKeyToDer(wc_MlDsaKey* key, byte* output, word32 inLen, int withAlg); #endif #if defined(WOLFSSL_MLDSA_PRIVATE_KEY) -WOLFSSL_API int wc_MlDsaKey_KeyToDer(MlDsaKey* key, byte* output, +WOLFSSL_API int wc_MlDsaKey_KeyToDer(wc_MlDsaKey* key, byte* output, word32 inLen); #endif #ifdef WOLFSSL_MLDSA_PRIVATE_KEY -WOLFSSL_API int wc_MlDsaKey_PrivateKeyToDer(MlDsaKey* key, byte* output, +WOLFSSL_API int wc_MlDsaKey_PrivateKeyToDer(wc_MlDsaKey* key, byte* output, word32 inLen); #endif #endif /* WOLFSSL_MLDSA_NO_ASN1 */ @@ -1003,9 +1017,9 @@ WOLFSSL_LOCAL void wc_mldsa_poly_make_pos_avx2(sword32* a); (DILITHIUM_ML_DSA_87_PUB_KEY_SIZE + DILITHIUM_ML_DSA_87_KEY_SIZE) -WOLFSSL_API int wc_MlDsaKey_GetPrivLen(MlDsaKey* key, int* len); -WOLFSSL_API int wc_MlDsaKey_GetPubLen(MlDsaKey* key, int* len); -WOLFSSL_API int wc_MlDsaKey_GetSigLen(MlDsaKey* key, int* len); +WOLFSSL_API int wc_MlDsaKey_GetPrivLen(wc_MlDsaKey* key, int* len); +WOLFSSL_API int wc_MlDsaKey_GetPubLen(wc_MlDsaKey* key, int* len); +WOLFSSL_API int wc_MlDsaKey_GetSigLen(wc_MlDsaKey* key, int* len); #if !defined(WOLFSSL_MLDSA_NO_SIGN) || \ !defined(WOLFSSL_MLDSA_NO_VERIFY) diff --git a/wrapper/CSharp/wolfSSL_CSharp/wolfCrypt.cs b/wrapper/CSharp/wolfSSL_CSharp/wolfCrypt.cs index 9355d1137c..8244220728 100644 --- a/wrapper/CSharp/wolfSSL_CSharp/wolfCrypt.cs +++ b/wrapper/CSharp/wolfSSL_CSharp/wolfCrypt.cs @@ -504,25 +504,25 @@ namespace wolfSSL.CSharp */ #if WindowsCE [DllImport(wolfssl_dll)] - private static extern IntPtr wc_dilithium_new(IntPtr heap, int devId); + private static extern IntPtr wc_MlDsaKey_New(IntPtr heap, int devId); [DllImport(wolfssl_dll)] - private static extern int wc_dilithium_delete(IntPtr key, IntPtr key_p); + private static extern int wc_MlDsaKey_Delete(IntPtr key, IntPtr key_p); [DllImport(wolfssl_dll)] - private static extern int wc_dilithium_set_level(IntPtr key, byte level); + private static extern int wc_MlDsaKey_SetParams(IntPtr key, byte level); [DllImport(wolfssl_dll)] - private static extern int wc_dilithium_make_key(IntPtr key, IntPtr rng); + private static extern int wc_MlDsaKey_MakeKey(IntPtr key, IntPtr rng); [DllImport(wolfssl_dll)] - private static extern int wc_dilithium_export_private(IntPtr key, byte[] output, ref uint outLen); + private static extern int wc_MlDsaKey_ExportPrivRaw(IntPtr key, byte[] output, ref uint outLen); [DllImport(wolfssl_dll)] - private static extern int wc_dilithium_import_private(byte[] priv, uint privSz, IntPtr key); + private static extern int wc_MlDsaKey_ImportPrivRaw(IntPtr key, byte[] priv, uint privSz); [DllImport(wolfssl_dll)] - private static extern int wc_dilithium_export_public(IntPtr key, byte[] output, ref uint outLen); + private static extern int wc_MlDsaKey_ExportPubRaw(IntPtr key, byte[] output, ref uint outLen); [DllImport(wolfssl_dll)] - private static extern int wc_dilithium_import_public(byte[] input, uint inputLen, IntPtr key); + private static extern int wc_MlDsaKey_ImportPubRaw(IntPtr key, byte[] input, uint inputLen); [DllImport(wolfssl_dll)] - private static extern int wc_dilithium_sign_ctx_msg(byte[] ctx, byte ctxLen, byte[] msg, uint msgLen, byte[] sig, ref uint sigLen, IntPtr key, IntPtr rng); + private static extern int wc_MlDsaKey_SignCtx(IntPtr key, byte[] ctx, byte ctxLen, byte[] sig, ref uint sigLen, byte[] msg, uint msgLen, IntPtr rng); [DllImport(wolfssl_dll)] - private static extern int wc_dilithium_verify_ctx_msg(byte[] sig, uint sigLen, byte[] ctx, byte ctxLen, byte[] msg, uint msgLen, ref int res, IntPtr key); + private static extern int wc_MlDsaKey_VerifyCtx(IntPtr key, byte[] sig, uint sigLen, byte[] ctx, byte ctxLen, byte[] msg, uint msgLen, ref int res); [DllImport(wolfssl_dll)] private static extern int wc_MlDsaKey_GetPrivLen(IntPtr key, ref int len); [DllImport(wolfssl_dll)] @@ -531,25 +531,25 @@ namespace wolfSSL.CSharp private static extern int wc_MlDsaKey_GetSigLen(IntPtr key, ref int len); #else [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr wc_dilithium_new(IntPtr heap, int devId); + private static extern IntPtr wc_MlDsaKey_New(IntPtr heap, int devId); [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] - private static extern int wc_dilithium_delete(IntPtr key, IntPtr key_p); + private static extern int wc_MlDsaKey_Delete(IntPtr key, IntPtr key_p); [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] - private static extern int wc_dilithium_set_level(IntPtr key, byte level); + private static extern int wc_MlDsaKey_SetParams(IntPtr key, byte level); [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] - private static extern int wc_dilithium_make_key(IntPtr key, IntPtr rng); + private static extern int wc_MlDsaKey_MakeKey(IntPtr key, IntPtr rng); [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] - private static extern int wc_dilithium_export_private(IntPtr key, byte[] output, ref uint outLen); + private static extern int wc_MlDsaKey_ExportPrivRaw(IntPtr key, byte[] output, ref uint outLen); [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] - private static extern int wc_dilithium_import_private(byte[] priv, uint privSz, IntPtr key); + private static extern int wc_MlDsaKey_ImportPrivRaw(IntPtr key, byte[] priv, uint privSz); [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] - private static extern int wc_dilithium_export_public(IntPtr key, byte[] output, ref uint outLen); + private static extern int wc_MlDsaKey_ExportPubRaw(IntPtr key, byte[] output, ref uint outLen); [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] - private static extern int wc_dilithium_import_public(byte[] input, uint inputLen, IntPtr key); + private static extern int wc_MlDsaKey_ImportPubRaw(IntPtr key, byte[] input, uint inputLen); [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] - private static extern int wc_dilithium_sign_ctx_msg(byte[] ctx, byte ctxLen, byte[] msg, uint msgLen, byte[] sig, ref uint sigLen, IntPtr key, IntPtr rng); + private static extern int wc_MlDsaKey_SignCtx(IntPtr key, byte[] ctx, byte ctxLen, byte[] sig, ref uint sigLen, byte[] msg, uint msgLen, IntPtr rng); [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] - private static extern int wc_dilithium_verify_ctx_msg(byte[] sig, uint sigLen, byte[] ctx, byte ctxLen, byte[] msg, uint msgLen, ref int res, IntPtr key); + private static extern int wc_MlDsaKey_VerifyCtx(IntPtr key, byte[] sig, uint sigLen, byte[] ctx, byte ctxLen, byte[] msg, uint msgLen, ref int res); [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] private static extern int wc_MlDsaKey_GetPrivLen(IntPtr key, ref int len); [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] @@ -3370,14 +3370,14 @@ namespace wolfSSL.CSharp try { - key = wc_dilithium_new(heap, devId); + key = wc_MlDsaKey_New(heap, devId); if (key == IntPtr.Zero) { log(ERROR_LOG, "Failed to allocate and initialize ML-DSA key."); return IntPtr.Zero; } - int ret = wc_dilithium_set_level(key, (byte)level); + int ret = wc_MlDsaKey_SetParams(key, (byte)level); if (ret != 0) { log(ERROR_LOG, "Failed to set ML-DSA level. Error code: " + ret); @@ -3421,14 +3421,14 @@ namespace wolfSSL.CSharp try { - key = wc_dilithium_new(heap, devId); + key = wc_MlDsaKey_New(heap, devId); if (key == IntPtr.Zero) { log(ERROR_LOG, "Failed to allocate and initialize ML-DSA key."); return IntPtr.Zero; } - ret = wc_dilithium_set_level(key, (byte)level); + ret = wc_MlDsaKey_SetParams(key, (byte)level); if (ret != 0) { log(ERROR_LOG, "Failed to set ML-DSA level. Error code: " + ret); @@ -3442,7 +3442,7 @@ namespace wolfSSL.CSharp return IntPtr.Zero; } - ret = wc_dilithium_make_key(key, rng); + ret = wc_MlDsaKey_MakeKey(key, rng); if (ret != 0) { log(ERROR_LOG, "Failed to make ML-DSA key. Error code: " + ret); @@ -3488,7 +3488,7 @@ namespace wolfSSL.CSharp return BAD_FUNC_ARG; } - ret = wc_dilithium_delete(key, IntPtr.Zero); + ret = wc_MlDsaKey_Delete(key, IntPtr.Zero); key = IntPtr.Zero; return ret; } @@ -3508,7 +3508,7 @@ namespace wolfSSL.CSharp try { - return wc_dilithium_import_public(publicKey, (uint)publicKey.Length, key); + return wc_MlDsaKey_ImportPubRaw(key, publicKey, (uint)publicKey.Length); } catch (Exception e) { @@ -3532,7 +3532,7 @@ namespace wolfSSL.CSharp try { - return wc_dilithium_import_private(privateKey, (uint)privateKey.Length, key); + return wc_MlDsaKey_ImportPrivRaw(key, privateKey, (uint)privateKey.Length); } catch (Exception e) { @@ -3570,7 +3570,7 @@ namespace wolfSSL.CSharp privateKey = new byte[privLen]; outLen = (uint)privLen; - ret = wc_dilithium_export_private(key, privateKey, ref outLen); + ret = wc_MlDsaKey_ExportPrivRaw(key, privateKey, ref outLen); if (ret != 0) { log(ERROR_LOG, "Failed to export ML-DSA private key. Error code: " + ret); @@ -3620,7 +3620,7 @@ namespace wolfSSL.CSharp publicKey = new byte[pubLen]; outLen = (uint)pubLen; - ret = wc_dilithium_export_public(key, publicKey, ref outLen); + ret = wc_MlDsaKey_ExportPubRaw(key, publicKey, ref outLen); if (ret != 0) { log(ERROR_LOG, "Failed to export ML-DSA public key. Error code: " + ret); @@ -3679,7 +3679,7 @@ namespace wolfSSL.CSharp return MEMORY_E; } /* FIPS 204 sign with empty context (ctx=null, ctxLen=0). */ - ret = wc_dilithium_sign_ctx_msg(null, 0, msg, (uint)msg.Length, sig, ref outLen, key, rng); + ret = wc_MlDsaKey_SignCtx(key, null, 0, sig, ref outLen, msg, (uint)msg.Length, rng); if (ret != 0) { log(ERROR_LOG, "Failed to sign message with ML-DSA key. Error code: " + ret); @@ -3724,7 +3724,7 @@ namespace wolfSSL.CSharp try { /* FIPS 204 verify with empty context (ctx=null, ctxLen=0). */ - ret = wc_dilithium_verify_ctx_msg(sig, (uint)sig.Length, null, 0, msg, (uint)msg.Length, ref res, key); + ret = wc_MlDsaKey_VerifyCtx(key, sig, (uint)sig.Length, null, 0, msg, (uint)msg.Length, ref res); if (ret != 0) { log(ERROR_LOG, "Failed to verify message with ML-DSA key. Error code: " + ret);