From 436dde3013aeb8db9edf45ae96a58da0618834a9 Mon Sep 17 00:00:00 2001 From: Jake Massimo Date: Tue, 24 Dec 2024 11:22:09 -0800 Subject: [PATCH] consistency in naming --- crypto/dilithium/ml_dsa.c | 60 ++++---- .../pqcrystals_dilithium_ref_common/sign.c | 134 +++++++++--------- .../pqcrystals_dilithium_ref_common/sign.h | 84 +++++------ 3 files changed, 139 insertions(+), 139 deletions(-) diff --git a/crypto/dilithium/ml_dsa.c b/crypto/dilithium/ml_dsa.c index 6bc2f53ae5..96be7a035f 100644 --- a/crypto/dilithium/ml_dsa.c +++ b/crypto/dilithium/ml_dsa.c @@ -27,7 +27,7 @@ int ml_dsa_44_keypair(uint8_t *public_key /* OUT */, uint8_t *private_key /* OUT */) { ml_dsa_params params; ml_dsa_44_params_init(¶ms); - return (mldsa_keypair(¶ms, public_key, private_key) == 0); + return (ml_dsa_keypair(¶ms, public_key, private_key) == 0); } int ml_dsa_44_keypair_internal(uint8_t *public_key /* OUT */, @@ -35,7 +35,7 @@ int ml_dsa_44_keypair_internal(uint8_t *public_key /* OUT */, const uint8_t *seed /* IN */) { ml_dsa_params params; ml_dsa_44_params_init(¶ms); - return mldsa_keypair_internal(¶ms, public_key, private_key, seed) == 0; + return ml_dsa_keypair_internal(¶ms, public_key, private_key, seed) == 0; } int ml_dsa_44_sign(const uint8_t *private_key /* IN */, @@ -47,8 +47,8 @@ int ml_dsa_44_sign(const uint8_t *private_key /* IN */, size_t ctx_string_len /* IN */) { ml_dsa_params params; ml_dsa_44_params_init(¶ms); - return mldsa_signature(¶ms, sig, sig_len, message, message_len, - ctx_string, ctx_string_len, private_key) == 0; + return ml_dsa_signature(¶ms, sig, sig_len, message, message_len, + ctx_string, ctx_string_len, private_key) == 0; } int ml_dsa_44_sign_internal(const uint8_t *private_key /* IN */, @@ -61,8 +61,8 @@ int ml_dsa_44_sign_internal(const uint8_t *private_key /* IN */, uint8_t *rnd /* IN */) { ml_dsa_params params; ml_dsa_44_params_init(¶ms); - return mldsa_signature_internal(¶ms, sig, sig_len, message, message_len, - pre, pre_len, rnd, private_key) == 0; + return ml_dsa_signature_internal(¶ms, sig, sig_len, message, message_len, + pre, pre_len, rnd, private_key) == 0; } int ml_dsa_44_verify(const uint8_t *public_key /* IN */, @@ -74,8 +74,8 @@ int ml_dsa_44_verify(const uint8_t *public_key /* IN */, size_t ctx_string_len /* IN */) { ml_dsa_params params; ml_dsa_44_params_init(¶ms); - return mldsa_verify(¶ms, sig, sig_len, message, message_len, - ctx_string, ctx_string_len, public_key) == 0; + return ml_dsa_verify(¶ms, sig, sig_len, message, message_len, + ctx_string, ctx_string_len, public_key) == 0; } int ml_dsa_44_verify_internal(const uint8_t *public_key /* IN */, @@ -87,15 +87,15 @@ int ml_dsa_44_verify_internal(const uint8_t *public_key /* IN */, size_t pre_len /* IN */) { ml_dsa_params params; ml_dsa_44_params_init(¶ms); - return mldsa_verify_internal(¶ms, sig, sig_len, message, message_len, - pre, pre_len, public_key) == 0; + return ml_dsa_verify_internal(¶ms, sig, sig_len, message, message_len, + pre, pre_len, public_key) == 0; } int ml_dsa_65_keypair(uint8_t *public_key /* OUT */, uint8_t *private_key /* OUT */) { ml_dsa_params params; ml_dsa_65_params_init(¶ms); - return (mldsa_keypair(¶ms, public_key, private_key) == 0); + return (ml_dsa_keypair(¶ms, public_key, private_key) == 0); } int ml_dsa_65_keypair_internal(uint8_t *public_key /* OUT */, @@ -103,7 +103,7 @@ int ml_dsa_65_keypair_internal(uint8_t *public_key /* OUT */, const uint8_t *seed /* IN */) { ml_dsa_params params; ml_dsa_65_params_init(¶ms); - return mldsa_keypair_internal(¶ms, public_key, private_key, seed) == 0; + return ml_dsa_keypair_internal(¶ms, public_key, private_key, seed) == 0; } int ml_dsa_65_sign(const uint8_t *private_key /* IN */, @@ -115,8 +115,8 @@ int ml_dsa_65_sign(const uint8_t *private_key /* IN */, size_t ctx_string_len /* IN */) { ml_dsa_params params; ml_dsa_65_params_init(¶ms); - return mldsa_signature(¶ms, sig, sig_len, message, message_len, - ctx_string, ctx_string_len, private_key) == 0; + return ml_dsa_signature(¶ms, sig, sig_len, message, message_len, + ctx_string, ctx_string_len, private_key) == 0; } int ml_dsa_65_sign_internal(const uint8_t *private_key /* IN */, @@ -129,8 +129,8 @@ int ml_dsa_65_sign_internal(const uint8_t *private_key /* IN */, uint8_t *rnd /* IN */) { ml_dsa_params params; ml_dsa_65_params_init(¶ms); - return mldsa_signature_internal(¶ms, sig, sig_len, message, message_len, - pre, pre_len, rnd, private_key) == 0; + return ml_dsa_signature_internal(¶ms, sig, sig_len, message, message_len, + pre, pre_len, rnd, private_key) == 0; } int ml_dsa_65_verify(const uint8_t *public_key /* IN */, @@ -142,8 +142,8 @@ int ml_dsa_65_verify(const uint8_t *public_key /* IN */, size_t ctx_string_len /* IN */) { ml_dsa_params params; ml_dsa_65_params_init(¶ms); - return mldsa_verify(¶ms, sig, sig_len, message, message_len, - ctx_string, ctx_string_len, public_key) == 0; + return ml_dsa_verify(¶ms, sig, sig_len, message, message_len, + ctx_string, ctx_string_len, public_key) == 0; } int ml_dsa_65_verify_internal(const uint8_t *public_key /* IN */, @@ -155,15 +155,15 @@ int ml_dsa_65_verify_internal(const uint8_t *public_key /* IN */, size_t pre_len /* IN */) { ml_dsa_params params; ml_dsa_65_params_init(¶ms); - return mldsa_verify_internal(¶ms, sig, sig_len, message, message_len, - pre, pre_len, public_key) == 0; + return ml_dsa_verify_internal(¶ms, sig, sig_len, message, message_len, + pre, pre_len, public_key) == 0; } int ml_dsa_87_keypair(uint8_t *public_key /* OUT */, uint8_t *private_key /* OUT */) { ml_dsa_params params; ml_dsa_87_params_init(¶ms); - return (mldsa_keypair(¶ms, public_key, private_key) == 0); + return (ml_dsa_keypair(¶ms, public_key, private_key) == 0); } int ml_dsa_87_keypair_internal(uint8_t *public_key /* OUT */, @@ -171,7 +171,7 @@ int ml_dsa_87_keypair_internal(uint8_t *public_key /* OUT */, const uint8_t *seed /* IN */) { ml_dsa_params params; ml_dsa_87_params_init(¶ms); - return mldsa_keypair_internal(¶ms, public_key, private_key, seed) == 0; + return ml_dsa_keypair_internal(¶ms, public_key, private_key, seed) == 0; } int ml_dsa_87_sign(const uint8_t *private_key /* IN */, @@ -183,8 +183,8 @@ int ml_dsa_87_sign(const uint8_t *private_key /* IN */, size_t ctx_string_len /* IN */) { ml_dsa_params params; ml_dsa_87_params_init(¶ms); - return mldsa_signature(¶ms, sig, sig_len, message, message_len, - ctx_string, ctx_string_len, private_key) == 0; + return ml_dsa_signature(¶ms, sig, sig_len, message, message_len, + ctx_string, ctx_string_len, private_key) == 0; } int ml_dsa_87_sign_internal(const uint8_t *private_key /* IN */, @@ -197,8 +197,8 @@ int ml_dsa_87_sign_internal(const uint8_t *private_key /* IN */, uint8_t *rnd /* IN */) { ml_dsa_params params; ml_dsa_87_params_init(¶ms); - return mldsa_signature_internal(¶ms, sig, sig_len, message, message_len, - pre, pre_len, rnd, private_key) == 0; + return ml_dsa_signature_internal(¶ms, sig, sig_len, message, message_len, + pre, pre_len, rnd, private_key) == 0; } int ml_dsa_87_verify(const uint8_t *public_key /* IN */, @@ -210,8 +210,8 @@ int ml_dsa_87_verify(const uint8_t *public_key /* IN */, size_t ctx_string_len /* IN */) { ml_dsa_params params; ml_dsa_87_params_init(¶ms); - return mldsa_verify(¶ms, sig, sig_len, message, message_len, - ctx_string, ctx_string_len, public_key) == 0; + return ml_dsa_verify(¶ms, sig, sig_len, message, message_len, + ctx_string, ctx_string_len, public_key) == 0; } int ml_dsa_87_verify_internal(const uint8_t *public_key /* IN */, @@ -223,6 +223,6 @@ int ml_dsa_87_verify_internal(const uint8_t *public_key /* IN */, size_t pre_len /* IN */) { ml_dsa_params params; ml_dsa_87_params_init(¶ms); - return mldsa_verify_internal(¶ms, sig, sig_len, message, message_len, - pre, pre_len, public_key) == 0; + return ml_dsa_verify_internal(¶ms, sig, sig_len, message, message_len, + pre, pre_len, public_key) == 0; } diff --git a/crypto/dilithium/pqcrystals_dilithium_ref_common/sign.c b/crypto/dilithium/pqcrystals_dilithium_ref_common/sign.c index 5f69a380dd..1d31c58340 100644 --- a/crypto/dilithium/pqcrystals_dilithium_ref_common/sign.c +++ b/crypto/dilithium/pqcrystals_dilithium_ref_common/sign.c @@ -9,7 +9,7 @@ /************************************************* - * Name: mldsa_keypair_internal + * Name: ml_dsa_keypair_internal * * Description: FIPS 204: Algorithm 6 ML-DSA.KeyGen_internal. * Generates public and private key. Internal API. @@ -23,10 +23,10 @@ * * Returns 0 (success) **************************************************/ -int mldsa_keypair_internal(ml_dsa_params *params, - uint8_t *pk, - uint8_t *sk, - const uint8_t *seed) { +int ml_dsa_keypair_internal(ml_dsa_params *params, + uint8_t *pk, + uint8_t *sk, + const uint8_t *seed) { uint8_t seedbuf[2 * ML_DSA_SEEDBYTES + ML_DSA_CRHBYTES]; uint8_t tr[ML_DSA_TRBYTES]; const uint8_t *rho, *rhoprime, *key; @@ -83,7 +83,7 @@ int mldsa_keypair_internal(ml_dsa_params *params, } /************************************************* -* Name: mldsa_keypair +* Name: ml_dsa_keypair * * Description: FIPS 204: Algorithm 1 ML-DSA.KeyGen * Generates public and private key. @@ -96,18 +96,18 @@ int mldsa_keypair_internal(ml_dsa_params *params, * * Returns 0 (success) -1 on failure **************************************************/ -int mldsa_keypair(ml_dsa_params *params, uint8_t *pk, uint8_t *sk) { +int ml_dsa_keypair(ml_dsa_params *params, uint8_t *pk, uint8_t *sk) { uint8_t seed[ML_DSA_SEEDBYTES]; if (!RAND_bytes(seed, ML_DSA_SEEDBYTES)) { return -1; } - mldsa_keypair_internal(params, pk, sk, seed); + ml_dsa_keypair_internal(params, pk, sk, seed); OPENSSL_cleanse(seed, sizeof(seed)); return 0; } /************************************************* -* Name: mldsa_signature_internal +* Name: ml_dsa_signature_internal * * Description: FIPS 204: Algorithm 7 ML-DSA.Sign_internal. * Computes signature. Internal API. @@ -124,15 +124,15 @@ int mldsa_keypair(ml_dsa_params *params, uint8_t *pk, uint8_t *sk) { * * Returns 0 (success) or -1 (context string too long) **************************************************/ -int mldsa_signature_internal(ml_dsa_params *params, - uint8_t *sig, - size_t *siglen, - const uint8_t *m, - size_t mlen, - const uint8_t *pre, - size_t prelen, - const uint8_t *rnd, - const uint8_t *sk) +int ml_dsa_signature_internal(ml_dsa_params *params, + uint8_t *sig, + size_t *siglen, + const uint8_t *m, + size_t mlen, + const uint8_t *pre, + size_t prelen, + const uint8_t *rnd, + const uint8_t *sk) { unsigned int n; uint8_t seedbuf[2*ML_DSA_SEEDBYTES + ML_DSA_TRBYTES + 2*ML_DSA_CRHBYTES]; @@ -253,7 +253,7 @@ int mldsa_signature_internal(ml_dsa_params *params, } /************************************************* -* Name: mldsa_signature +* Name: ml_dsa_signature * * Description: FIPS 204: Algorithm 2 ML-DSA.Sign. * Computes signature in hedged mode. @@ -268,14 +268,14 @@ int mldsa_signature_internal(ml_dsa_params *params, * * Returns 0 (success) or -1 (context string too long) **************************************************/ -int mldsa_signature(ml_dsa_params *params, - uint8_t *sig, - size_t *siglen, - const uint8_t *m, - size_t mlen, - const uint8_t *ctx, - size_t ctxlen, - const uint8_t *sk) +int ml_dsa_signature(ml_dsa_params *params, + uint8_t *sig, + size_t *siglen, + const uint8_t *m, + size_t mlen, + const uint8_t *ctx, + size_t ctxlen, + const uint8_t *sk) { uint8_t pre[257]; uint8_t rnd[ML_DSA_RNDBYTES]; @@ -291,7 +291,7 @@ int mldsa_signature(ml_dsa_params *params, if (!RAND_bytes(rnd, ML_DSA_RNDBYTES)) { return -1; } - mldsa_signature_internal(params, sig, siglen, m, mlen, pre, 2 + ctxlen, rnd, sk); + ml_dsa_signature_internal(params, sig, siglen, m, mlen, pre, 2 + ctxlen, rnd, sk); /* FIPS 204. Section 3.6.3 Destruction of intermediate values. */ OPENSSL_cleanse(pre, sizeof(pre)); @@ -300,7 +300,7 @@ int mldsa_signature(ml_dsa_params *params, } /************************************************* -* Name: mldsa_sign_message +* Name: ml_dsa_sign_message * * Description: Compute signed message. * @@ -318,14 +318,14 @@ int mldsa_signature(ml_dsa_params *params, * * Returns 0 (success) or -1 (context string too long) **************************************************/ -int mldsa_sign_message(ml_dsa_params *params, - uint8_t *sm, - size_t *smlen, - const uint8_t *m, - size_t mlen, - const uint8_t *ctx, - size_t ctxlen, - const uint8_t *sk) +int ml_dsa_sign_message(ml_dsa_params *params, + uint8_t *sm, + size_t *smlen, + const uint8_t *m, + size_t mlen, + const uint8_t *ctx, + size_t ctxlen, + const uint8_t *sk) { int ret; size_t i; @@ -333,13 +333,13 @@ int mldsa_sign_message(ml_dsa_params *params, for(i = 0; i < mlen; ++i) { sm[params->bytes + mlen - 1 - i] = m[mlen - 1 - i]; } - ret = mldsa_signature(params, sm, smlen, sm + params->bytes, mlen, ctx, ctxlen, sk); + ret = ml_dsa_signature(params, sm, smlen, sm + params->bytes, mlen, ctx, ctxlen, sk); *smlen += mlen; return ret; } /************************************************* -* Name: mldsa_verify_internal +* Name: ml_dsa_verify_internal * * Description: FIPS 204: Algorithm 8 ML-DSA.Verify_internal. * Verifies signature. Internal API. @@ -355,14 +355,14 @@ int mldsa_sign_message(ml_dsa_params *params, * * Returns 0 if signature could be verified correctly and -1 otherwise **************************************************/ -int mldsa_verify_internal(ml_dsa_params *params, - const uint8_t *sig, - size_t siglen, - const uint8_t *m, - size_t mlen, - const uint8_t *pre, - size_t prelen, - const uint8_t *pk) +int ml_dsa_verify_internal(ml_dsa_params *params, + const uint8_t *sig, + size_t siglen, + const uint8_t *m, + size_t mlen, + const uint8_t *pre, + size_t prelen, + const uint8_t *pk) { unsigned int i; uint8_t buf[ML_DSA_K_MAX*ML_DSA_POLYW1_PACKEDBYTES_MAX]; @@ -449,7 +449,7 @@ int mldsa_verify_internal(ml_dsa_params *params, } /************************************************* -* Name: mldsa_verify +* Name: ml_dsa_verify * * Description: FIPS 204: Algorithm 3 ML-DSA.Verify. * Verifies signature. @@ -465,14 +465,14 @@ int mldsa_verify_internal(ml_dsa_params *params, * * Returns 0 if signature could be verified correctly and -1 otherwise **************************************************/ -int mldsa_verify(ml_dsa_params *params, - const uint8_t *sig, - size_t siglen, - const uint8_t *m, - size_t mlen, - const uint8_t *ctx, - size_t ctxlen, - const uint8_t *pk) +int ml_dsa_verify(ml_dsa_params *params, + const uint8_t *sig, + size_t siglen, + const uint8_t *m, + size_t mlen, + const uint8_t *ctx, + size_t ctxlen, + const uint8_t *pk) { uint8_t pre[257]; @@ -483,11 +483,11 @@ int mldsa_verify(ml_dsa_params *params, pre[0] = 0; pre[1] = ctxlen; OPENSSL_memcpy(pre + 2 , ctx, ctxlen); - return mldsa_verify_internal(params, sig, siglen, m, mlen, pre, 2 + ctxlen, pk); + return ml_dsa_verify_internal(params, sig, siglen, m, mlen, pre, 2 + ctxlen, pk); } /************************************************* -* Name: mldsa_verify_message +* Name: ml_dsa_verify_message * * Description: Verify signed message. * @@ -503,14 +503,14 @@ int mldsa_verify(ml_dsa_params *params, * * Returns 0 if signed message could be verified correctly and -1 otherwise **************************************************/ -int mldsa_verify_message(ml_dsa_params *params, - uint8_t *m, - size_t *mlen, - const uint8_t *sm, - size_t smlen, - const uint8_t *ctx, - size_t ctxlen, - const uint8_t *pk) +int ml_dsa_verify_message(ml_dsa_params *params, + uint8_t *m, + size_t *mlen, + const uint8_t *sm, + size_t smlen, + const uint8_t *ctx, + size_t ctxlen, + const uint8_t *pk) { if(smlen < params->bytes) { @@ -518,7 +518,7 @@ int mldsa_verify_message(ml_dsa_params *params, } *mlen = smlen - params->bytes; - if(mldsa_verify(params,sm, params->bytes, sm + params->bytes, *mlen, ctx, ctxlen, pk)) { + if(ml_dsa_verify(params,sm, params->bytes, sm + params->bytes, *mlen, ctx, ctxlen, pk)) { goto badsig; } else { diff --git a/crypto/dilithium/pqcrystals_dilithium_ref_common/sign.h b/crypto/dilithium/pqcrystals_dilithium_ref_common/sign.h index c04e85ba23..bc21a45bd1 100644 --- a/crypto/dilithium/pqcrystals_dilithium_ref_common/sign.h +++ b/crypto/dilithium/pqcrystals_dilithium_ref_common/sign.h @@ -5,48 +5,48 @@ #include #include "params.h" -int mldsa_keypair(ml_dsa_params *params, uint8_t *pk, uint8_t *sk); - -int mldsa_keypair_internal(ml_dsa_params *params, - uint8_t *pk, - uint8_t *sk, - const uint8_t *seed); - -int mldsa_signature(ml_dsa_params *params, - uint8_t *sig, size_t *siglen, - const uint8_t *m, size_t mlen, - const uint8_t *ctx, size_t ctxlen, - const uint8_t *sk); - -int mldsa_signature_internal(ml_dsa_params *params, - uint8_t *sig, size_t *siglen, - const uint8_t *m, size_t mlen, - const uint8_t *pre, size_t prelen, - const uint8_t *rnd, - const uint8_t *sk); - -int mldsa_sign_message(ml_dsa_params *params, - uint8_t *sm, size_t *smlen, - const uint8_t *m, size_t mlen, - const uint8_t *ctx, size_t ctxlen, - const uint8_t *sk); - -int mldsa_verify(ml_dsa_params *params, - const uint8_t *sig, size_t siglen, - const uint8_t *m, size_t mlen, - const uint8_t *ctx, size_t ctxlen, - const uint8_t *pk); - -int mldsa_verify_internal(ml_dsa_params *params, - const uint8_t *sig, size_t siglen, - const uint8_t *m, size_t mlen, - const uint8_t *pre, size_t prelen, +int ml_dsa_keypair(ml_dsa_params *params, uint8_t *pk, uint8_t *sk); + +int ml_dsa_keypair_internal(ml_dsa_params *params, + uint8_t *pk, + uint8_t *sk, + const uint8_t *seed); + +int ml_dsa_signature(ml_dsa_params *params, + uint8_t *sig, size_t *siglen, + const uint8_t *m, size_t mlen, + const uint8_t *ctx, size_t ctxlen, + const uint8_t *sk); + +int ml_dsa_signature_internal(ml_dsa_params *params, + uint8_t *sig, size_t *siglen, + const uint8_t *m, size_t mlen, + const uint8_t *pre, size_t prelen, + const uint8_t *rnd, + const uint8_t *sk); + +int ml_dsa_sign_message(ml_dsa_params *params, + uint8_t *sm, size_t *smlen, + const uint8_t *m, size_t mlen, + const uint8_t *ctx, size_t ctxlen, + const uint8_t *sk); + +int ml_dsa_verify(ml_dsa_params *params, + const uint8_t *sig, size_t siglen, + const uint8_t *m, size_t mlen, + const uint8_t *ctx, size_t ctxlen, + const uint8_t *pk); + +int ml_dsa_verify_internal(ml_dsa_params *params, + const uint8_t *sig, size_t siglen, + const uint8_t *m, size_t mlen, + const uint8_t *pre, size_t prelen, + const uint8_t *pk); + +int ml_dsa_verify_message(ml_dsa_params *params, + uint8_t *m, size_t *mlen, + const uint8_t *sm, size_t smlen, + const uint8_t *ctx, size_t ctxlen, const uint8_t *pk); -int mldsa_verify_message(ml_dsa_params *params, - uint8_t *m, size_t *mlen, - const uint8_t *sm, size_t smlen, - const uint8_t *ctx, size_t ctxlen, - const uint8_t *pk); - #endif