#![expect(dead_code)]
#![expect(unused_imports)]
use super::*;
use bindings::{dispatch_table_entry, OSSL_DISPATCH};
use bindings::{OSSL_FUNC_keymgmt_export_fn, OSSL_FUNC_KEYMGMT_EXPORT};
use bindings::{OSSL_FUNC_keymgmt_export_types_ex_fn, OSSL_FUNC_KEYMGMT_EXPORT_TYPES_EX};
use bindings::{OSSL_FUNC_keymgmt_free_fn, OSSL_FUNC_KEYMGMT_FREE};
use bindings::{OSSL_FUNC_keymgmt_gen_cleanup_fn, OSSL_FUNC_KEYMGMT_GEN_CLEANUP};
use bindings::{OSSL_FUNC_keymgmt_gen_fn, OSSL_FUNC_KEYMGMT_GEN};
use bindings::{OSSL_FUNC_keymgmt_gen_init_fn, OSSL_FUNC_KEYMGMT_GEN_INIT};
use bindings::{OSSL_FUNC_keymgmt_gen_set_params_fn, OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS};
use bindings::{OSSL_FUNC_keymgmt_gen_settable_params_fn, OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS};
use bindings::{OSSL_FUNC_keymgmt_get_params_fn, OSSL_FUNC_KEYMGMT_GET_PARAMS};
use bindings::{OSSL_FUNC_keymgmt_gettable_params_fn, OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS};
use bindings::{OSSL_FUNC_keymgmt_has_fn, OSSL_FUNC_KEYMGMT_HAS};
use bindings::{OSSL_FUNC_keymgmt_import_fn, OSSL_FUNC_KEYMGMT_IMPORT};
use bindings::{OSSL_FUNC_keymgmt_import_types_ex_fn, OSSL_FUNC_KEYMGMT_IMPORT_TYPES_EX};
use bindings::{OSSL_FUNC_keymgmt_load_fn, OSSL_FUNC_KEYMGMT_LOAD};
use bindings::{OSSL_FUNC_keymgmt_match_fn, OSSL_FUNC_KEYMGMT_MATCH};
use bindings::{OSSL_FUNC_keymgmt_new_fn, OSSL_FUNC_KEYMGMT_NEW};
use bindings::{OSSL_FUNC_keymgmt_set_params_fn, OSSL_FUNC_KEYMGMT_SET_PARAMS};
use bindings::{OSSL_FUNC_keymgmt_settable_params_fn, OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS};
use bindings::{OSSL_FUNC_signature_digest_sign_fn, OSSL_FUNC_SIGNATURE_DIGEST_SIGN};
use bindings::{OSSL_FUNC_signature_digest_sign_init_fn, OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT};
use bindings::{OSSL_FUNC_signature_digest_verify_fn, OSSL_FUNC_SIGNATURE_DIGEST_VERIFY};
use bindings::{OSSL_FUNC_signature_digest_verify_init_fn, OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT};
use bindings::{OSSL_FUNC_signature_freectx_fn, OSSL_FUNC_SIGNATURE_FREECTX};
use bindings::{OSSL_FUNC_signature_get_ctx_params_fn, OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS};
use bindings::{
OSSL_FUNC_signature_gettable_ctx_params_fn, OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS,
};
use bindings::{OSSL_FUNC_signature_newctx_fn, OSSL_FUNC_SIGNATURE_NEWCTX};
use bindings::{OSSL_FUNC_signature_set_ctx_params_fn, OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS};
use bindings::{
OSSL_FUNC_signature_settable_ctx_params_fn, OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS,
};
use bindings::{OSSL_FUNC_signature_sign_fn, OSSL_FUNC_SIGNATURE_SIGN};
use bindings::{OSSL_FUNC_signature_sign_init_fn, OSSL_FUNC_SIGNATURE_SIGN_INIT};
use bindings::{OSSL_FUNC_signature_verify_fn, OSSL_FUNC_SIGNATURE_VERIFY};
use bindings::{OSSL_FUNC_signature_verify_init_fn, OSSL_FUNC_SIGNATURE_VERIFY_INIT};
mod decoder_functions;
mod encoder_functions;
mod keymgmt_functions;
#[path = "../common/signature.rs"]
mod signature;
#[path = "../common/signature_functions.rs"]
mod signature_functions;
pub(crate) type OurError = anyhow::Error;
pub(crate) use anyhow::anyhow;
pub(super) const NAMES: &CStr = c"ML-DSA-44:2.16.840.1.101.3.4.3.17:id-ml-dsa-44:mldsa44";
pub(crate) const NAME: &CStr = c"ML-DSA-44";
pub(crate) const LONG_NAME: &CStr = c"id-ml-dsa-44";
pub(crate) const OID: asn1::ObjectIdentifier = asn1::oid!(2, 16, 840, 1, 101, 3, 4, 3, 17);
pub(crate) const OID_PKCS8: pkcs8::ObjectIdentifier =
pkcs8::ObjectIdentifier::new_unwrap("2.16.840.1.101.3.4.3.17");
pub(crate) const SIGALG_OID: Option<&CStr> = Some(c"2.16.840.1.101.3.4.3.17");
crate::adapters::common::keymgmt_functions::oid_consistency_tests!();
use std::sync::LazyLock;
pub(crate) static ALGORITHM_ID_DER: LazyLock<Vec<u8>> = LazyLock::new(|| {
asn1::write(|w| {
w.write_element(&asn1::SequenceWriter::new(&|w| {
w.write_element(&OID)?;
Ok(())
}))
})
.expect("OID should be encodable as AlgorithmIdentifier")
});
pub(super) const DESCRIPTION: &CStr = c"ML-DSA-44 from pqclean";
pub(crate) const SECURITY_BITS: u32 = 128;
pub(crate) const OBJ_SIGID: ObjSigId = ObjSigId {
oid: SIGALG_OID.unwrap(),
short_name: NAME,
long_name: LONG_NAME,
digest_name: None,
};
#[allow(unused_imports)]
pub(crate) use keymgmt_functions::{PUBKEY_LEN, SECRETKEY_LEN, SIGNATURE_LEN};
pub(crate) mod capabilities {
pub(crate) mod tls_sigalg {
use super::super::forge;
use forge::capabilities::tls_sigalg;
use forge::osslparams::CONST_OSSL_PARAM;
use tls_sigalg::*;
pub(crate) struct TLSSigAlgCap;
impl TLSSigAlg for TLSSigAlgCap {
const SIGALG_IANA_NAME: &CStr = c"mldsa44";
const SIGALG_CODEPOINT: u32 = 0x0904;
const SIGALG_NAME: &CStr = c"ML-DSA-44";
const SIGALG_OID: Option<&CStr> = super::super::SIGALG_OID;
const SECURITY_BITS: u32 = super::super::SECURITY_BITS;
const MIN_TLS: TLSVersion = TLSVersion::TLSv1_3;
}
pub(crate) static OSSL_PARAM_ARRAY: &[CONST_OSSL_PARAM] =
tls_sigalg::as_params!(TLSSigAlgCap);
pub(crate) struct OQScompatCap;
impl TLSSigAlg for OQScompatCap {
const SIGALG_NAME: &CStr = c"mldsa44";
const SIGALG_IANA_NAME: &CStr = TLSSigAlgCap::SIGALG_IANA_NAME;
const SIGALG_CODEPOINT: u32 = TLSSigAlgCap::SIGALG_CODEPOINT;
const SECURITY_BITS: u32 = TLSSigAlgCap::SECURITY_BITS;
const SIGALG_OID: Option<&CStr> = None;
const SIGALG_SIG_OID: Option<&CStr> = None;
const SIGALG_HASH_OID: Option<&CStr> = None;
const SIGALG_KEYTYPE_OID: Option<&CStr> = None;
const SIGALG_SIG_NAME: Option<&CStr> = TLSSigAlgCap::SIGALG_SIG_NAME;
const SIGALG_HASH_NAME: Option<&CStr> = TLSSigAlgCap::SIGALG_HASH_NAME;
const SIGALG_KEYTYPE: Option<&CStr> = TLSSigAlgCap::SIGALG_KEYTYPE;
const MIN_TLS: TLSVersion = TLSSigAlgCap::MIN_TLS;
const MAX_TLS: TLSVersion = TLSSigAlgCap::MAX_TLS;
const MIN_DTLS: DTLSVersion = TLSSigAlgCap::MIN_DTLS;
const MAX_DTLS: DTLSVersion = TLSSigAlgCap::MAX_DTLS;
}
pub(crate) static OSSL_PARAM_ARRAY_OQSCOMP: &[CONST_OSSL_PARAM] =
tls_sigalg::as_params!(OQScompatCap);
}
}
pub(super) const SIG_FUNCTIONS: &[OSSL_DISPATCH] = &[
dispatch_table_entry!(
OSSL_FUNC_SIGNATURE_NEWCTX,
OSSL_FUNC_signature_newctx_fn,
signature_functions::newctx
),
dispatch_table_entry!(
OSSL_FUNC_SIGNATURE_FREECTX,
OSSL_FUNC_signature_freectx_fn,
signature_functions::freectx
),
dispatch_table_entry!(
OSSL_FUNC_SIGNATURE_SIGN_INIT,
OSSL_FUNC_signature_sign_init_fn,
signature_functions::sign_init
),
dispatch_table_entry!(
OSSL_FUNC_SIGNATURE_SIGN,
OSSL_FUNC_signature_sign_fn,
signature_functions::sign
),
dispatch_table_entry!(
OSSL_FUNC_SIGNATURE_VERIFY_INIT,
OSSL_FUNC_signature_verify_init_fn,
signature_functions::verify_init
),
dispatch_table_entry!(
OSSL_FUNC_SIGNATURE_VERIFY,
OSSL_FUNC_signature_verify_fn,
signature_functions::verify
),
dispatch_table_entry!(
OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT,
OSSL_FUNC_signature_digest_verify_init_fn,
signature_functions::digest_verify_init
),
dispatch_table_entry!(
OSSL_FUNC_SIGNATURE_DIGEST_VERIFY,
OSSL_FUNC_signature_digest_verify_fn,
signature_functions::digest_verify
),
dispatch_table_entry!(
OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT,
OSSL_FUNC_signature_digest_sign_init_fn,
signature_functions::digest_sign_init
),
dispatch_table_entry!(
OSSL_FUNC_SIGNATURE_DIGEST_SIGN,
OSSL_FUNC_signature_digest_sign_fn,
signature_functions::digest_sign
),
dispatch_table_entry!(
OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS,
OSSL_FUNC_signature_gettable_ctx_params_fn,
signature_functions::gettable_ctx_params
),
dispatch_table_entry!(
OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS,
OSSL_FUNC_signature_get_ctx_params_fn,
signature_functions::get_ctx_params
),
#[cfg(any())]
dispatch_table_entry!(
OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS,
OSSL_FUNC_signature_settable_ctx_params_fn,
signature_functions::settable_ctx_params
),
#[cfg(any())]
dispatch_table_entry!(
OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS,
OSSL_FUNC_signature_set_ctx_params_fn,
signature_functions::set_ctx_params
),
OSSL_DISPATCH::END,
];
pub(super) const KMGMT_FUNCTIONS: &[OSSL_DISPATCH] = &[
dispatch_table_entry!(
OSSL_FUNC_KEYMGMT_NEW,
OSSL_FUNC_keymgmt_new_fn,
keymgmt_functions::new
),
dispatch_table_entry!(
OSSL_FUNC_KEYMGMT_FREE,
OSSL_FUNC_keymgmt_free_fn,
keymgmt_functions::free
),
dispatch_table_entry!(
OSSL_FUNC_KEYMGMT_HAS,
OSSL_FUNC_keymgmt_has_fn,
keymgmt_functions::has
),
dispatch_table_entry!(
OSSL_FUNC_KEYMGMT_GEN,
OSSL_FUNC_keymgmt_gen_fn,
keymgmt_functions::gen
),
dispatch_table_entry!(
OSSL_FUNC_KEYMGMT_GEN_CLEANUP,
OSSL_FUNC_keymgmt_gen_cleanup_fn,
keymgmt_functions::gen_cleanup
),
dispatch_table_entry!(
OSSL_FUNC_KEYMGMT_GEN_INIT,
OSSL_FUNC_keymgmt_gen_init_fn,
keymgmt_functions::gen_init
),
dispatch_table_entry!(
OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS,
OSSL_FUNC_keymgmt_gen_set_params_fn,
keymgmt_functions::gen_set_params
),
dispatch_table_entry!(
OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS,
OSSL_FUNC_keymgmt_gen_settable_params_fn,
keymgmt_functions::gen_settable_params
),
dispatch_table_entry!(
OSSL_FUNC_KEYMGMT_GET_PARAMS,
OSSL_FUNC_keymgmt_get_params_fn,
keymgmt_functions::get_params
),
dispatch_table_entry!(
OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS,
OSSL_FUNC_keymgmt_gettable_params_fn,
keymgmt_functions::gettable_params
),
dispatch_table_entry!(
OSSL_FUNC_KEYMGMT_SET_PARAMS,
OSSL_FUNC_keymgmt_set_params_fn,
keymgmt_functions::set_params
),
dispatch_table_entry!(
OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS,
OSSL_FUNC_keymgmt_settable_params_fn,
keymgmt_functions::settable_params
),
dispatch_table_entry!(
OSSL_FUNC_KEYMGMT_IMPORT,
OSSL_FUNC_keymgmt_import_fn,
keymgmt_functions::import
),
dispatch_table_entry!(
OSSL_FUNC_KEYMGMT_EXPORT,
OSSL_FUNC_keymgmt_export_fn,
keymgmt_functions::export
),
dispatch_table_entry!(
OSSL_FUNC_KEYMGMT_IMPORT_TYPES_EX,
OSSL_FUNC_keymgmt_import_types_ex_fn,
keymgmt_functions::import_types_ex
),
dispatch_table_entry!(
OSSL_FUNC_KEYMGMT_EXPORT_TYPES_EX,
OSSL_FUNC_keymgmt_export_types_ex_fn,
keymgmt_functions::export_types_ex
),
dispatch_table_entry!(
OSSL_FUNC_KEYMGMT_LOAD,
OSSL_FUNC_keymgmt_load_fn,
keymgmt_functions::load
),
dispatch_table_entry!(
OSSL_FUNC_KEYMGMT_MATCH,
OSSL_FUNC_keymgmt_match_fn,
keymgmt_functions::match_
),
OSSL_DISPATCH::END,
];
pub(super) use decoder_functions::DER2PrivateKeyInfo as DECODER_DER2PrivateKeyInfo;
pub(super) use decoder_functions::DER2SubjectPublicKeyInfo as DECODER_DER2SubjectPublicKeyInfo;
pub(super) use encoder_functions::PrivateKeyInfo2DER as ENCODER_PrivateKeyInfo2DER;
pub(super) use encoder_functions::PrivateKeyInfo2PEM as ENCODER_PrivateKeyInfo2PEM;
pub(super) use encoder_functions::PrivateKeyInfo2Text as ENCODER_PrivateKeyInfo2Text;
pub(super) use encoder_functions::PubKeyStructureless2Text as ENCODER_PubKeyStructureless2Text;
pub(super) use encoder_functions::SubjectPublicKeyInfo2DER as ENCODER_SubjectPublicKeyInfo2DER;
pub(super) use encoder_functions::SubjectPublicKeyInfo2PEM as ENCODER_SubjectPublicKeyInfo2PEM;
pub(super) use super::helpers::MlDsaSeed;
pub(super) use keymgmt_functions::{PrivateKey, PublicKey};
pub(super) use signature::{Signature, SignerWithCtx, VerifierWithCtx};
#[cfg(test)]
mod tests {
use super::*;
use crate::adapters::common::wycheproof::*;
use signature::{Verifier, VerifierWithCtx};
use wycheproof::mldsa_verify;
struct Mldsa44;
impl_sigalg_verify_variant!(Mldsa44, keymgmt_functions::PublicKey, signature::Signature);
#[test]
fn test_mldsa_44_verify_from_wycheproof() {
crate::tests::common::setup().expect("Failed to initialize test setup");
run_mldsa_wycheproof_verify_tests::<Mldsa44>(mldsa_verify::TestName::MlDsa44Verify);
}
use signature::{SignatureBytes, SignatureEncoding, Signer, SignerWithCtx};
use wycheproof::mldsa_sign;
impl_sigalg_sign_variant!(Mldsa44, keymgmt_functions::PrivateKey, signature::Signature);
#[test]
fn test_mldsa_44_sign_seed_from_wycheproof() {
crate::tests::common::setup().expect("Failed to initialize test setup");
run_mldsa_wycheproof_sign_tests::<Mldsa44>(
mldsa_sign::TestName::MlDsa44SignSeed,
false,
);
}
#[test]
fn test_mldsa_44_sign_noseed_from_wycheproof() {
crate::tests::common::setup().expect("Failed to initialize test setup");
run_mldsa_wycheproof_sign_tests::<Mldsa44>(
mldsa_sign::TestName::MlDsa44SignNoSeed,
false,
);
}
}