From: Pauli Date: Wed, 22 Jan 2025 02:08:33 +0000 (+1100) Subject: ml-dsa: add more to internal header X-Git-Tag: openssl-3.5.0-alpha1~583 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=29d14eeb2e71d212476d4f209f0c7976a1a28939;p=thirdparty%2Fopenssl.git ml-dsa: add more to internal header The ossl_ml_dsa_key_get0_libctx() and the various size macros are better in the intneral header Reviewed-by: Tim Hudson Reviewed-by: Shane Lontis Reviewed-by: Viktor Dukhovni (Merged from https://github.com/openssl/openssl/pull/26548) --- diff --git a/crypto/ml_dsa/ml_dsa_key.c b/crypto/ml_dsa/ml_dsa_key.c index 5feb2eb3da4..e34f22cef75 100644 --- a/crypto/ml_dsa/ml_dsa_key.c +++ b/crypto/ml_dsa/ml_dsa_key.c @@ -500,6 +500,11 @@ size_t ossl_ml_dsa_key_get_sig_len(const ML_DSA_KEY *key) return key->params->sig_len; } +OSSL_LIB_CTX *ossl_ml_dsa_key_get0_libctx(const ML_DSA_KEY *key) +{ + return key != NULL ? key->libctx : NULL; +} + const char *ossl_ml_dsa_key_get_name(const ML_DSA_KEY *key) { return key->params->alg; diff --git a/crypto/ml_dsa/ml_dsa_params.c b/crypto/ml_dsa/ml_dsa_params.c index fa56fbb7a30..3057f491d48 100644 --- a/crypto/ml_dsa/ml_dsa_params.c +++ b/crypto/ml_dsa/ml_dsa_params.c @@ -20,9 +20,6 @@ #define ML_DSA_44_BETA 78 #define ML_DSA_44_OMEGA 80 #define ML_DSA_44_SECURITY_CATEGORY 2 -#define ML_DSA_44_PRIV_LEN 2560 -#define ML_DSA_44_PUB_LEN 1312 -#define ML_DSA_44_SIG_LEN 2420 /* See FIPS 204 Section 4 Table 1 & Table 2 */ #define ML_DSA_65_TAU 49 @@ -33,9 +30,6 @@ #define ML_DSA_65_BETA 196 #define ML_DSA_65_OMEGA 55 #define ML_DSA_65_SECURITY_CATEGORY 3 -#define ML_DSA_65_PRIV_LEN 4032 -#define ML_DSA_65_PUB_LEN 1952 -#define ML_DSA_65_SIG_LEN 3309 /* See FIPS 204 Section 4 Table 1 & Table 2 */ #define ML_DSA_87_TAU 60 @@ -46,9 +40,6 @@ #define ML_DSA_87_BETA 120 #define ML_DSA_87_OMEGA 75 #define ML_DSA_87_SECURITY_CATEGORY 5 -#define ML_DSA_87_PRIV_LEN 4896 -#define ML_DSA_87_PUB_LEN 2592 -#define ML_DSA_87_SIG_LEN 4627 static const ML_DSA_PARAMS ml_dsa_params[] = { { "ML-DSA-44", diff --git a/include/crypto/ml_dsa.h b/include/crypto/ml_dsa.h index 7cf446d7d22..709dad9d70b 100644 --- a/include/crypto/ml_dsa.h +++ b/include/crypto/ml_dsa.h @@ -19,6 +19,28 @@ # define ML_DSA_MAX_CONTEXT_STRING_LEN 255 +# define ML_DSA_ENTROPY_LEN 32 + +/* See FIPS 204 Section 4 Table 1 & Table 2 */ +# define ML_DSA_44_PRIV_LEN 2560 +# define ML_DSA_44_PUB_LEN 1312 +# define ML_DSA_44_SIG_LEN 2420 + +/* See FIPS 204 Section 4 Table 1 & Table 2 */ +# define ML_DSA_65_PRIV_LEN 4032 +# define ML_DSA_65_PUB_LEN 1952 +# define ML_DSA_65_SIG_LEN 3309 + +/* See FIPS 204 Section 4 Table 1 & Table 2 */ +# define ML_DSA_87_PRIV_LEN 4896 +# define ML_DSA_87_PUB_LEN 2592 +# define ML_DSA_87_SIG_LEN 4627 + +/* Key and signature size maximums taken from values above */ +# define MAX_ML_DSA_PRIV_LEN ML_DSA_87_PRIV_LEN +# define MAX_ML_DSA_PUB_LEN ML_DSA_87_PUB_LEN +# define MAX_ML_DSA_SIG_LEN ML_DSA_87_SIG_LEN + __owur ML_DSA_KEY *ossl_ml_dsa_key_new(OSSL_LIB_CTX *libctx, const char *propq, const char *alg); __owur int ossl_ml_dsa_key_pub_alloc(ML_DSA_KEY *key); @@ -43,6 +65,8 @@ __owur size_t ossl_ml_dsa_key_get_priv_len(const ML_DSA_KEY *key); __owur size_t ossl_ml_dsa_key_get_sig_len(const ML_DSA_KEY *key); __owur int ossl_ml_dsa_key_matches(const ML_DSA_KEY *key, const char *alg); __owur const char *ossl_ml_dsa_key_get_name(const ML_DSA_KEY *key); +__owur int ossl_ml_dsa_key_to_text(BIO *out, const ML_DSA_KEY *key, int selection); +OSSL_LIB_CTX *ossl_ml_dsa_key_get0_libctx(const ML_DSA_KEY *key); __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); diff --git a/providers/implementations/signature/ml_dsa_sig.c b/providers/implementations/signature/ml_dsa_sig.c index abbdd984681..1f1e9ea2e76 100644 --- a/providers/implementations/signature/ml_dsa_sig.c +++ b/providers/implementations/signature/ml_dsa_sig.c @@ -23,8 +23,6 @@ #include "internal/packet.h" #include "internal/sizes.h" -#define ML_DSA_ENTROPY_LEN 32 - #define ML_DSA_MESSAGE_ENCODE_RAW 0 #define ML_DSA_MESSAGE_ENCODE_PURE 1