Commit 5c16db8cdc for openssl.org
commit 5c16db8cdcd1c1519eb533538fcd6180b40f0fd2
Author: Simo Sorce <simo@redhat.com>
Date: Fri Apr 11 13:38:20 2025 -0400
Make public ml_dsa_mu_.. helpers
Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27342)
diff --git a/crypto/ml_dsa/ml_dsa_sign.c b/crypto/ml_dsa/ml_dsa_sign.c
index bbeb95e2a3..cb375f698c 100644
--- a/crypto/ml_dsa/ml_dsa_sign.c
+++ b/crypto/ml_dsa/ml_dsa_sign.c
@@ -66,8 +66,8 @@ static void signature_init(ML_DSA_SIG *sig,
* @returns an EVP_MD_CTX if the operation is successful, NULL otherwise.
*/
-static EVP_MD_CTX *ml_dsa_mu_init(const ML_DSA_KEY *key, int encode,
- const uint8_t *ctx, size_t ctx_len)
+EVP_MD_CTX *ossl_ml_dsa_mu_init(const ML_DSA_KEY *key, int encode,
+ const uint8_t *ctx, size_t ctx_len)
{
EVP_MD_CTX *md_ctx;
uint8_t itb[2];
@@ -116,8 +116,7 @@ err:
* @param msg_len: The length of the msg buffer to process
* @returns 1 on success, 0 on error
*/
-static int ml_dsa_mu_update(EVP_MD_CTX *md_ctx,
- const uint8_t *msg, size_t msg_len)
+int ossl_ml_dsa_mu_update(EVP_MD_CTX *md_ctx, const uint8_t *msg, size_t msg_len)
{
return EVP_DigestUpdate(md_ctx, msg, msg_len);
}
@@ -130,7 +129,7 @@ static int ml_dsa_mu_update(EVP_MD_CTX *md_ctx,
* @param mu_len: The size of the output buffer
* @returns 1 on success, 0 on error
*/
-static int ml_dsa_mu_finalize(EVP_MD_CTX *md_ctx, uint8_t *mu, size_t mu_len)
+int ossl_ml_dsa_mu_finalize(EVP_MD_CTX *md_ctx, uint8_t *mu, size_t mu_len)
{
if (!ossl_assert(mu_len == ML_DSA_MU_BYTES)) {
ERR_raise(ERR_LIB_PROV, PROV_R_BAD_LENGTH);
@@ -445,14 +444,14 @@ int ossl_ml_dsa_sign(const ML_DSA_KEY *priv, int msg_is_mu,
mu_ptr = msg;
mu_len = msg_len;
} else {
- md_ctx = ml_dsa_mu_init(priv, encode, context, context_len);
+ md_ctx = ossl_ml_dsa_mu_init(priv, encode, context, context_len);
if (md_ctx == NULL)
return 0;
- if (!ml_dsa_mu_update(md_ctx, msg, msg_len))
+ if (!ossl_ml_dsa_mu_update(md_ctx, msg, msg_len))
goto err;
- if (!ml_dsa_mu_finalize(md_ctx, mu, mu_len))
+ if (!ossl_ml_dsa_mu_finalize(md_ctx, mu, mu_len))
goto err;
}
@@ -485,14 +484,14 @@ int ossl_ml_dsa_verify(const ML_DSA_KEY *pub, int msg_is_mu,
mu_ptr = msg;
mu_len = msg_len;
} else {
- md_ctx = ml_dsa_mu_init(pub, encode, context, context_len);
+ md_ctx = ossl_ml_dsa_mu_init(pub, encode, context, context_len);
if (md_ctx == NULL)
return 0;
- if (!ml_dsa_mu_update(md_ctx, msg, msg_len))
+ if (!ossl_ml_dsa_mu_update(md_ctx, msg, msg_len))
goto err;
- if (!ml_dsa_mu_finalize(md_ctx, mu, mu_len))
+ if (!ossl_ml_dsa_mu_finalize(md_ctx, mu, mu_len))
goto err;
}
diff --git a/include/crypto/ml_dsa.h b/include/crypto/ml_dsa.h
index 0df86dfb8c..e8054c6102 100644
--- a/include/crypto/ml_dsa.h
+++ b/include/crypto/ml_dsa.h
@@ -106,6 +106,11 @@ __owur int ossl_ml_dsa_key_public_from_private(ML_DSA_KEY *key);
__owur int ossl_ml_dsa_pk_decode(ML_DSA_KEY *key, const uint8_t *in, size_t in_len);
__owur int ossl_ml_dsa_sk_decode(ML_DSA_KEY *key, const uint8_t *in, size_t in_len);
+EVP_MD_CTX *ossl_ml_dsa_mu_init(const ML_DSA_KEY *key, int encode,
+ const uint8_t *ctx, size_t ctx_len);
+__owur int ossl_ml_dsa_mu_update(EVP_MD_CTX *md_ctx, const uint8_t *msg, size_t msg_len);
+__owur int ossl_ml_dsa_mu_finalize(EVP_MD_CTX *md_ctx, uint8_t *mu, size_t mu_len);
+
__owur int ossl_ml_dsa_sign(const ML_DSA_KEY *priv, int msg_is_mu,
const uint8_t *msg, size_t msg_len,
const uint8_t *context, size_t context_len,