aws_lc_rs/unstable/signature.rs
1// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0 OR ISC
3
4//! This module contains unstable/experimental APIs.
5//!
6//! # ⚠️ Warning
7//! The APIs under this module are not stable and may change in the future.
8//! They are not covered by semver guarantees.
9//!
10//! # Signing and verifying with MLDSA-44
11//!
12//! ```rust
13//! # use std::error::Error;
14//! # fn main() -> Result<(), Box<dyn Error>> {
15//! use aws_lc_rs::encoding::AsDer;
16//! use aws_lc_rs::signature::{KeyPair, UnparsedPublicKey};
17//! use aws_lc_rs::unstable::signature::{PqdsaKeyPair, MLDSA_44_SIGNING, MLDSA_44};
18//!
19//! let signing_alg = &MLDSA_44_SIGNING;
20//! let key_pair = PqdsaKeyPair::generate(signing_alg)?;
21//!
22//! const MESSAGE: &'static [u8] = b"hello, world";
23//! let mut signature = vec![0; signing_alg.signature_len()];
24//!
25//! let signature_len = key_pair.sign(MESSAGE, &mut signature)?;
26//! assert_eq!(signature_len, signature.len());
27//!
28//! // Verify the signature.
29//! let public_key_bytes = key_pair.public_key().as_der()?;
30//! let public_key = UnparsedPublicKey::new(&MLDSA_44, public_key_bytes.as_ref());
31//!
32//! assert!(public_key.verify(MESSAGE, &signature).is_ok());
33//! # Ok(())
34//! # }
35//! ```
36//!
37
38pub use crate::pqdsa::key_pair::{PqdsaKeyPair, PqdsaPrivateKey};
39pub use crate::pqdsa::signature::{
40 PqdsaSigningAlgorithm, PqdsaVerificationAlgorithm, PublicKey as PqdsaPublicKey,
41};
42
43use crate::pqdsa::AlgorithmID;
44
45/// Verification of MLDSA-44 signatures
46pub static MLDSA_44: PqdsaVerificationAlgorithm = PqdsaVerificationAlgorithm {
47 id: &AlgorithmID::MLDSA_44,
48};
49
50/// Verification of MLDSA-65 signatures
51pub static MLDSA_65: PqdsaVerificationAlgorithm = PqdsaVerificationAlgorithm {
52 id: &AlgorithmID::MLDSA_65,
53};
54
55/// Verification of MLDSA-87 signatures
56pub static MLDSA_87: PqdsaVerificationAlgorithm = PqdsaVerificationAlgorithm {
57 id: &AlgorithmID::MLDSA_87,
58};
59
60/// Sign using MLDSA-44
61pub static MLDSA_44_SIGNING: PqdsaSigningAlgorithm = PqdsaSigningAlgorithm(&MLDSA_44);
62
63/// Sign using MLDSA-65
64pub static MLDSA_65_SIGNING: PqdsaSigningAlgorithm = PqdsaSigningAlgorithm(&MLDSA_65);
65
66/// Sign using MLDSA-87
67pub static MLDSA_87_SIGNING: PqdsaSigningAlgorithm = PqdsaSigningAlgorithm(&MLDSA_87);