Skip to main content

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
46#[deprecated(note = "Use ML_DSA_44")]
47pub const MLDSA_44: PqdsaVerificationAlgorithm = PqdsaVerificationAlgorithm {
48    id: &AlgorithmID::ML_DSA_44,
49};
50
51/// Verification of MLDSA-65 signatures
52#[deprecated(note = "Use ML_DSA_65")]
53pub const MLDSA_65: PqdsaVerificationAlgorithm = PqdsaVerificationAlgorithm {
54    id: &AlgorithmID::ML_DSA_65,
55};
56
57/// Verification of MLDSA-87 signatures
58#[deprecated(note = "Use ML_DSA_87")]
59pub const MLDSA_87: PqdsaVerificationAlgorithm = PqdsaVerificationAlgorithm {
60    id: &AlgorithmID::ML_DSA_87,
61};
62
63/// Sign using MLDSA-44
64#[deprecated(note = "Use ML_DSA_44_SIGNING")]
65pub const MLDSA_44_SIGNING: PqdsaSigningAlgorithm = PqdsaSigningAlgorithm(&ML_DSA_44);
66
67/// Sign using MLDSA-65
68#[deprecated(note = "Use ML_DSA_65_SIGNING")]
69pub const MLDSA_65_SIGNING: PqdsaSigningAlgorithm = PqdsaSigningAlgorithm(&ML_DSA_65);
70
71/// Sign using MLDSA-87
72#[deprecated(note = "Use ML_DSA_87_SIGNING")]
73pub const MLDSA_87_SIGNING: PqdsaSigningAlgorithm = PqdsaSigningAlgorithm(&ML_DSA_87);
74
75/// Verification of ML-DSA-44 signatures
76pub const ML_DSA_44: PqdsaVerificationAlgorithm = PqdsaVerificationAlgorithm {
77    id: &AlgorithmID::ML_DSA_44,
78};
79
80/// Verification of ML-DSA-65 signatures
81pub const ML_DSA_65: PqdsaVerificationAlgorithm = PqdsaVerificationAlgorithm {
82    id: &AlgorithmID::ML_DSA_65,
83};
84
85/// Verification of ML-DSA-87 signatures
86pub const ML_DSA_87: PqdsaVerificationAlgorithm = PqdsaVerificationAlgorithm {
87    id: &AlgorithmID::ML_DSA_87,
88};
89
90/// Sign using ML-DSA-44
91pub const ML_DSA_44_SIGNING: PqdsaSigningAlgorithm = PqdsaSigningAlgorithm(&ML_DSA_44);
92
93/// Sign using ML-DSA-65
94pub const ML_DSA_65_SIGNING: PqdsaSigningAlgorithm = PqdsaSigningAlgorithm(&ML_DSA_65);
95
96/// Sign using ML-DSA-87
97pub const ML_DSA_87_SIGNING: PqdsaSigningAlgorithm = PqdsaSigningAlgorithm(&ML_DSA_87);