crypto_profile_awslc3/lib.rs
1//! The crypto-profile backend on the AWS-LC FIPS 3.x module (aws-lc-rs 1.17, `fips`).
2//! `rustls` is re-exported because its types are this crate's API; `aws-lc-rs` is not.
3#![deny(missing_docs)]
4
5pub use crypto_profile::*;
6#[cfg(feature = "test-support")]
7pub use rcgen;
8pub use rustls;
9
10/// `Admitted` is built only by `admit`, and its lists are read-only:
11///
12/// ```
13/// use crypto_profile_awslc3::{KdfAlgorithm, MacAlgorithm, Options, Profile, admit};
14/// let a = admit(Profile::Cnsa2, Options::default());
15/// assert!(!a.macs().contains(&MacAlgorithm::HmacSha256));
16/// assert!(!a.kdfs().contains(&KdfAlgorithm::HkdfSha256));
17/// ```
18///
19/// ```
20/// use crypto_profile_awslc3::{Options, Profile, admit};
21/// let mut a = admit(Profile::Cnsa2, Options::default());
22/// let x = a.macs()[0];
23/// let _ = (&mut a, x);
24/// ```
25///
26/// ```compile_fail,E0616
27/// use crypto_profile_awslc3::{Options, Profile, admit};
28/// let mut a = admit(Profile::Cnsa2, Options::default());
29/// let x = a.macs()[0];
30/// a.macs.push(x);
31/// ```
32///
33/// ```
34/// use crypto_profile_awslc3::{Options, Profile, admit};
35/// let mut a = admit(Profile::Cnsa2, Options::default());
36/// let x = a.kdfs()[0];
37/// let _ = (&mut a, x);
38/// ```
39///
40/// ```compile_fail,E0616
41/// use crypto_profile_awslc3::{Options, Profile, admit};
42/// let mut a = admit(Profile::Cnsa2, Options::default());
43/// let x = a.kdfs()[0];
44/// a.kdfs.push(x);
45/// ```
46#[allow(dead_code)]
47mod admitted_is_read_only {}
48
49/// An `ecdh::EphemeralKey` agrees once: `agree` consumes it.
50///
51/// ```
52/// use crypto_profile_awslc3::{KdfAlgorithm, KeyAgreementAlgorithm, Options, Profile, admit, ecdh, kdf};
53/// let a = admit(Profile::Fips1403, Options::default());
54/// let peer = ecdh::EphemeralKey::generate(&a, KeyAgreementAlgorithm::EcdhP384).unwrap();
55/// let spec = kdf::Spec::Hkdf { algorithm: KdfAlgorithm::HkdfSha384, salt: None, info: b"doc" };
56/// let mine = ecdh::EphemeralKey::generate(&a, KeyAgreementAlgorithm::EcdhP384).unwrap();
57/// let key = mine.agree(peer.public_key(), &spec, 32).unwrap();
58/// assert_eq!(key.as_bytes().len(), 32);
59/// ```
60///
61/// ```compile_fail,E0382
62/// use crypto_profile_awslc3::{KdfAlgorithm, KeyAgreementAlgorithm, Options, Profile, admit, ecdh, kdf};
63/// let a = admit(Profile::Fips1403, Options::default());
64/// let peer = ecdh::EphemeralKey::generate(&a, KeyAgreementAlgorithm::EcdhP384).unwrap();
65/// let spec = kdf::Spec::Hkdf { algorithm: KdfAlgorithm::HkdfSha384, salt: None, info: b"doc" };
66/// let mine = ecdh::EphemeralKey::generate(&a, KeyAgreementAlgorithm::EcdhP384).unwrap();
67/// let key = mine.agree(peer.public_key(), &spec, 32).unwrap();
68/// let again = mine.agree(peer.public_key(), &spec, 32).unwrap();
69/// ```
70#[allow(dead_code)]
71mod ephemeral_keys_agree_once {}
72
73/// An `aead::Key` is not `Clone`, so its seal count cannot be copied:
74///
75/// ```
76/// use crypto_profile_awslc3::{AeadAlgorithm, Options, Profile, admit, aead};
77/// let a = admit(Profile::Fips1403, Options::default());
78/// let key = aead::Key::new(&a, AeadAlgorithm::Aes256Gcm, &[7; 32]).unwrap();
79/// assert_eq!(key.algorithm(), AeadAlgorithm::Aes256Gcm);
80/// ```
81///
82/// ```compile_fail,E0599
83/// use crypto_profile_awslc3::{AeadAlgorithm, Options, Profile, admit, aead};
84/// let a = admit(Profile::Fips1403, Options::default());
85/// let key = aead::Key::new(&a, AeadAlgorithm::Aes256Gcm, &[7; 32]).unwrap();
86/// let copy = key.clone();
87/// ```
88#[allow(dead_code)]
89mod aead_keys_are_not_clone {}
90
91/// A `digest::Hasher` is not `Clone`, so a partial hash cannot be forked:
92///
93/// ```
94/// use crypto_profile_awslc3::{HashAlgorithm, Options, Profile, admit, digest};
95/// let a = admit(Profile::Fips1403, Options::default());
96/// let hasher = digest::Hasher::new(&a, HashAlgorithm::Sha384).unwrap();
97/// assert_eq!(hasher.algorithm(), HashAlgorithm::Sha384);
98/// ```
99///
100/// ```compile_fail,E0599
101/// use crypto_profile_awslc3::{HashAlgorithm, Options, Profile, admit, digest};
102/// let a = admit(Profile::Fips1403, Options::default());
103/// let hasher = digest::Hasher::new(&a, HashAlgorithm::Sha384).unwrap();
104/// let copy = hasher.clone();
105/// ```
106#[allow(dead_code)]
107mod hashers_are_not_clone {}
108
109/// A `signature::KeyPair` is not `Clone`, so its private key is held once:
110///
111/// ```
112/// use crypto_profile_awslc3::{Options, Profile, SignatureAlgorithm, admit, signature};
113/// let a = admit(Profile::Fips1403, Options::default());
114/// let key = signature::KeyPair::generate(&a, SignatureAlgorithm::EcdsaP384Sha384).unwrap();
115/// assert_eq!(key.algorithm(), SignatureAlgorithm::EcdsaP384Sha384);
116/// ```
117///
118/// ```compile_fail,E0599
119/// use crypto_profile_awslc3::{Options, Profile, SignatureAlgorithm, admit, signature};
120/// let a = admit(Profile::Fips1403, Options::default());
121/// let key = signature::KeyPair::generate(&a, SignatureAlgorithm::EcdsaP384Sha384).unwrap();
122/// let copy = key.clone();
123/// ```
124#[allow(dead_code)]
125mod signature_key_pairs_are_not_clone {}
126
127crypto_profile::provider!(crate::provider_arms);
128mod provider_arms;
129
130crypto_profile::backend_body!(crate::backend_arms);
131mod backend_arms;
132#[cfg(any(test, feature = "test-support"))]
133pub use backend_body::test_support;
134pub use backend_body::{
135 Admitted, Resolved, admit, assert_admitted_approved, assert_module_approves, resolve,
136};
137pub use backend_body::{aead, csr, digest, ecdh, fips, hmac, kdf, random, sealbox, signature, tls};
138
139/// The AWS-LC FIPS module (line and linkage) this build links. Its certificate status is
140/// [`fips::certificate()`]; for 3.x the certified release is 3.1.0.
141pub const MODULE: Module = Module {
142 line: ModuleLine::AwsLcFips3,
143 linkage: if cfg!(crypto_profile_static) {
144 Linkage::Static
145 } else {
146 Linkage::Dynamic
147 },
148};
149
150/// Returns the exact runtime-linked AWS-LC release, independently of its certificate release.
151///
152/// This initializes the linked library and also reflects its version with dynamic linkage.
153pub fn awslc_version() -> &'static str {
154 aws_lc_rs::awslc_version()
155}
156
157pub(crate) fn ensure(alg: Algorithm) -> Result<(), CryptoError> {
158 ensure_available(MODULE, alg)
159}
160
161#[cfg(test)]
162mod tests {
163 use super::*;
164
165 #[test]
166 fn ensure_refuses_unavailable_keys_and_schemes() {
167 for algorithm in [
168 Algorithm::Signature(SignatureAlgorithm::MlDsa87),
169 Algorithm::Scheme(TlsSignatureScheme::MlDsa87),
170 ] {
171 assert_eq!(ensure(algorithm), Err(CryptoError::Unavailable(algorithm)));
172 }
173 assert_eq!(
174 ensure(Algorithm::Signature(SignatureAlgorithm::EcdsaP384Sha384)),
175 Ok(())
176 );
177 }
178}