use crate::algorithm::{
AeadAlgorithm, Algorithm, CipherSuite as C, HashAlgorithm, KdfAlgorithm, KeyAgreementAlgorithm,
KxGroup as K, MacAlgorithm, SignatureAlgorithm as S, TlsSignatureScheme as T, TlsVersion as V,
};
use crate::capability::{Module, capability};
use crate::error::{CryptoError, Family};
use std::fmt;
use std::str::FromStr;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Profile {
Unrestricted,
Preferred,
Cnsa2,
Cnsa1,
Bsi,
Fips1403,
Fips1402,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum GoverningText {
CrateRecommendation,
Published {
documents: &'static [&'static str],
},
}
impl Profile {
pub const ALL: &'static [Profile] = &[
Profile::Unrestricted,
Profile::Preferred,
Profile::Cnsa2,
Profile::Cnsa1,
Profile::Bsi,
Profile::Fips1403,
Profile::Fips1402,
];
#[cfg(test)]
pub(crate) const fn ordinal(self) -> usize {
match self {
Profile::Unrestricted => 0,
Profile::Preferred => 1,
Profile::Cnsa2 => 2,
Profile::Cnsa1 => 3,
Profile::Bsi => 4,
Profile::Fips1403 => 5,
Profile::Fips1402 => 6,
}
}
pub const fn as_str(self) -> &'static str {
match self {
Profile::Unrestricted => "unrestricted",
Profile::Preferred => "preferred",
Profile::Cnsa2 => "cnsa2",
Profile::Cnsa1 => "cnsa1",
Profile::Bsi => "bsi",
Profile::Fips1403 => "fips1403",
Profile::Fips1402 => "fips1402",
}
}
pub const fn governing_text(self) -> GoverningText {
match self {
Profile::Unrestricted | Profile::Preferred => GoverningText::CrateRecommendation,
Profile::Cnsa2 => GoverningText::Published {
documents: &["CNSSP 15 (December 2024), Annex B, pp. B-1 to B-2"],
},
Profile::Cnsa1 => GoverningText::Published {
documents: &[
"CNSSP 15 (20 October 2016), Annex B, p. B-1",
"RFC 9151 (April 2022)",
],
},
Profile::Bsi => GoverningText::Published {
documents: &[
"BSI TR-02102-2, version 2026-01",
"BSI TR-02102-1, version 2026-01",
],
},
Profile::Fips1403 => GoverningText::Published {
documents: &[
"NIST SP 800-140C r2 and SP 800-140D r2, with the CMVP lists (August 2026)",
"FIPS 140-3 Implementation Guidance (August 2026): IG C.K, D.Q, D.S",
"NIST SP 800-52r2",
"NIST SP 800-131A r2",
],
},
Profile::Fips1402 => GoverningText::Published {
documents: &[
"FIPS 140-2 Annex A and Annex D (2021)",
"FIPS 186-4",
"NIST SP 800-131A r2",
"NIST SP 800-52r2",
],
},
}
}
}
impl fmt::Display for Profile {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct ParseProfileError(pub String);
impl fmt::Display for ParseProfileError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "unknown profile {:?}", self.0)
}
}
impl std::error::Error for ParseProfileError {}
impl FromStr for Profile {
type Err = ParseProfileError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Profile::ALL
.iter()
.copied()
.find(|p| p.as_str() == s)
.ok_or_else(|| ParseProfileError(s.to_string()))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[non_exhaustive]
pub struct Options {
pub pq_key_exchange_required: bool,
pub peer_certificates_match_profile: bool,
pub cnsa1_unclassified_nss: bool,
}
impl fmt::Display for Options {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let names: Vec<&str> = [
(
self.pq_key_exchange_required,
"post-quantum key exchange required",
),
(
self.peer_certificates_match_profile,
"peer certificates match profile",
),
(self.cnsa1_unclassified_nss, "cnsa1 UNCLASSIFIED NSS"),
]
.into_iter()
.filter_map(|(on, name)| on.then_some(name))
.collect();
if names.is_empty() {
f.write_str("no options")
} else {
f.write_str(&names.join(", "))
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub struct ProfileSpec {
pub versions: &'static [V],
pub cipher_suites: &'static [C],
pub kx_groups: &'static [K],
pub signature_schemes: &'static [T],
pub key_algorithms: &'static [S],
pub macs: &'static [MacAlgorithm],
pub kdfs: &'static [KdfAlgorithm],
pub key_agreements: &'static [KeyAgreementAlgorithm],
pub aeads: &'static [AeadAlgorithm],
pub hashes: &'static [HashAlgorithm],
pub signatures: &'static [S],
}
impl Profile {
pub const fn spec(self) -> &'static ProfileSpec {
match self {
Profile::Unrestricted => &UNRESTRICTED,
Profile::Preferred => &PREFERRED,
Profile::Cnsa2 => &CNSA2,
Profile::Cnsa1 => &CNSA1,
Profile::Bsi => &BSI,
Profile::Fips1403 => &FIPS1403,
Profile::Fips1402 => &FIPS1402,
}
}
}
pub const UNRESTRICTED: ProfileSpec = ProfileSpec {
versions: &[V::Tls13, V::Tls12],
cipher_suites: &[
C::Tls13Aes256GcmSha384,
C::Tls13Aes128GcmSha256,
C::Tls13Chacha20Poly1305Sha256,
C::Tls12EcdheEcdsaAes256GcmSha384,
C::Tls12EcdheRsaAes256GcmSha384,
C::Tls12EcdheEcdsaAes128GcmSha256,
C::Tls12EcdheRsaAes128GcmSha256,
C::Tls12EcdheEcdsaChacha20Poly1305Sha256,
C::Tls12EcdheRsaChacha20Poly1305Sha256,
],
kx_groups: &[
K::MlKem1024,
K::Secp384r1MlKem1024,
K::X25519MlKem768,
K::Secp256r1MlKem768,
K::Secp384r1,
K::Secp256r1,
K::X25519,
],
signature_schemes: &[
T::MlDsa87,
T::EcdsaNistp384Sha384,
T::EcdsaNistp256Sha256,
T::EcdsaNistp521Sha512,
T::Ed25519,
T::RsaPssSha384,
T::RsaPssSha512,
T::RsaPssSha256,
T::RsaPkcs1Sha384,
T::RsaPkcs1Sha512,
T::RsaPkcs1Sha256,
],
key_algorithms: &[
S::MlDsa87,
S::EcdsaP384Sha384,
S::EcdsaP256Sha256,
S::EcdsaP521Sha512,
S::EcdsaP521Sha384,
S::Ed25519,
S::Rsa3072Sha384,
S::Rsa4096Sha384,
S::Rsa2048Sha384,
],
macs: &[
MacAlgorithm::HmacSha512,
MacAlgorithm::HmacSha384,
MacAlgorithm::HmacSha256,
],
kdfs: &[
KdfAlgorithm::HkdfSha512,
KdfAlgorithm::HkdfSha384,
KdfAlgorithm::HkdfSha256,
KdfAlgorithm::OneStepSha512,
KdfAlgorithm::OneStepSha384,
KdfAlgorithm::OneStepSha256,
],
key_agreements: &[
KeyAgreementAlgorithm::EcdhP384,
KeyAgreementAlgorithm::EcdhP521,
KeyAgreementAlgorithm::EcdhP256,
KeyAgreementAlgorithm::X25519,
],
aeads: &[
AeadAlgorithm::Aes256Gcm,
AeadAlgorithm::Aes128Gcm,
AeadAlgorithm::Chacha20Poly1305,
],
hashes: &[
HashAlgorithm::Sha512,
HashAlgorithm::Sha384,
HashAlgorithm::Sha256,
HashAlgorithm::Sha3_512,
HashAlgorithm::Sha3_384,
HashAlgorithm::Sha3_256,
],
signatures: &[
S::MlDsa87,
S::EcdsaP384Sha384,
S::EcdsaP521Sha512,
S::EcdsaP521Sha384,
S::EcdsaP256Sha256,
S::Ed25519,
S::Rsa4096Sha384Pss,
S::Rsa3072Sha384Pss,
S::Rsa2048Sha384Pss,
S::Rsa4096Sha384,
S::Rsa3072Sha384,
S::Rsa2048Sha384,
],
};
pub const PREFERRED: ProfileSpec = ProfileSpec {
versions: &[V::Tls13],
cipher_suites: &[C::Tls13Aes256GcmSha384, C::Tls13Aes128GcmSha256],
kx_groups: &[
K::MlKem1024,
K::Secp384r1MlKem1024,
K::X25519MlKem768,
K::Secp256r1MlKem768,
K::Secp384r1,
K::Secp256r1,
],
signature_schemes: &[
T::MlDsa87,
T::EcdsaNistp384Sha384,
T::EcdsaNistp256Sha256,
T::EcdsaNistp521Sha512,
T::RsaPssSha384,
T::RsaPssSha512,
T::RsaPssSha256,
],
key_algorithms: &[
S::MlDsa87,
S::EcdsaP384Sha384,
S::EcdsaP256Sha256,
S::EcdsaP521Sha512,
S::EcdsaP521Sha384,
S::Rsa3072Sha384,
S::Rsa4096Sha384,
],
macs: &[
MacAlgorithm::HmacSha512,
MacAlgorithm::HmacSha384,
MacAlgorithm::HmacSha256,
],
kdfs: &[
KdfAlgorithm::HkdfSha512,
KdfAlgorithm::HkdfSha384,
KdfAlgorithm::HkdfSha256,
KdfAlgorithm::OneStepSha512,
KdfAlgorithm::OneStepSha384,
KdfAlgorithm::OneStepSha256,
],
key_agreements: &[
KeyAgreementAlgorithm::EcdhP384,
KeyAgreementAlgorithm::EcdhP521,
KeyAgreementAlgorithm::EcdhP256,
],
aeads: &[AeadAlgorithm::Aes256Gcm, AeadAlgorithm::Aes128Gcm],
hashes: &[
HashAlgorithm::Sha512,
HashAlgorithm::Sha384,
HashAlgorithm::Sha256,
],
signatures: &[
S::MlDsa87,
S::EcdsaP384Sha384,
S::EcdsaP521Sha512,
S::EcdsaP256Sha256,
S::Rsa4096Sha384Pss,
S::Rsa3072Sha384Pss,
S::Rsa4096Sha384,
S::Rsa3072Sha384,
],
};
pub const CNSA2: ProfileSpec = ProfileSpec {
versions: &[V::Tls13],
cipher_suites: &[C::Tls13Aes256GcmSha384],
kx_groups: &[K::MlKem1024],
signature_schemes: &[T::MlDsa87],
key_algorithms: &[S::MlDsa87],
macs: &[MacAlgorithm::HmacSha384, MacAlgorithm::HmacSha512],
kdfs: &[KdfAlgorithm::HkdfSha384, KdfAlgorithm::HkdfSha512],
key_agreements: &[],
aeads: &[AeadAlgorithm::Aes256Gcm],
hashes: &[HashAlgorithm::Sha384, HashAlgorithm::Sha512],
signatures: &[S::MlDsa87],
};
pub const CNSA1: ProfileSpec = ProfileSpec {
versions: &[V::Tls13, V::Tls12],
cipher_suites: &[
C::Tls13Aes256GcmSha384,
C::Tls12EcdheEcdsaAes256GcmSha384,
C::Tls12EcdheRsaAes256GcmSha384,
],
kx_groups: &[K::Secp384r1],
signature_schemes: &[T::EcdsaNistp384Sha384, T::RsaPssSha384, T::RsaPkcs1Sha384],
key_algorithms: &[S::EcdsaP384Sha384, S::Rsa3072Sha384, S::Rsa4096Sha384],
macs: &[MacAlgorithm::HmacSha384],
kdfs: &[KdfAlgorithm::HkdfSha384],
key_agreements: &[KeyAgreementAlgorithm::EcdhP384],
aeads: &[AeadAlgorithm::Aes256Gcm],
hashes: &[HashAlgorithm::Sha384],
signatures: &[
S::EcdsaP384Sha384,
S::Rsa4096Sha384Pss,
S::Rsa3072Sha384Pss,
S::Rsa4096Sha384,
S::Rsa3072Sha384,
],
};
pub const BSI: ProfileSpec = ProfileSpec {
versions: &[V::Tls13, V::Tls12],
cipher_suites: &[
C::Tls13Aes256GcmSha384,
C::Tls13Aes128GcmSha256,
C::Tls12EcdheEcdsaAes256GcmSha384,
C::Tls12EcdheRsaAes256GcmSha384,
C::Tls12EcdheEcdsaAes128GcmSha256,
C::Tls12EcdheRsaAes128GcmSha256,
],
kx_groups: &[K::Secp384r1, K::Secp256r1],
signature_schemes: &[
T::EcdsaNistp384Sha384,
T::EcdsaNistp256Sha256,
T::EcdsaNistp521Sha512,
T::RsaPssSha384,
T::RsaPssSha512,
T::RsaPssSha256,
],
key_algorithms: &[S::EcdsaP384Sha384, S::EcdsaP256Sha256, S::EcdsaP521Sha512],
macs: &[
MacAlgorithm::HmacSha512,
MacAlgorithm::HmacSha384,
MacAlgorithm::HmacSha256,
],
kdfs: &[
KdfAlgorithm::HkdfSha512,
KdfAlgorithm::HkdfSha384,
KdfAlgorithm::HkdfSha256,
],
key_agreements: &[],
aeads: &[AeadAlgorithm::Aes256Gcm, AeadAlgorithm::Aes128Gcm],
hashes: &[
HashAlgorithm::Sha512,
HashAlgorithm::Sha384,
HashAlgorithm::Sha256,
HashAlgorithm::Sha3_512,
HashAlgorithm::Sha3_384,
HashAlgorithm::Sha3_256,
],
signatures: &[S::Rsa4096Sha384Pss, S::Rsa3072Sha384Pss],
};
pub const FIPS1403: ProfileSpec = ProfileSpec {
versions: &[V::Tls13, V::Tls12],
cipher_suites: &[
C::Tls13Aes256GcmSha384,
C::Tls13Aes128GcmSha256,
C::Tls12EcdheEcdsaAes256GcmSha384,
C::Tls12EcdheRsaAes256GcmSha384,
C::Tls12EcdheEcdsaAes128GcmSha256,
C::Tls12EcdheRsaAes128GcmSha256,
],
kx_groups: &[
K::MlKem1024,
K::Secp384r1MlKem1024,
K::X25519MlKem768,
K::Secp256r1MlKem768,
K::Secp384r1,
K::Secp256r1,
],
signature_schemes: &[
T::MlDsa87,
T::EcdsaNistp384Sha384,
T::EcdsaNistp256Sha256,
T::EcdsaNistp521Sha512,
T::RsaPssSha384,
T::RsaPssSha512,
T::RsaPssSha256,
T::RsaPkcs1Sha384,
T::RsaPkcs1Sha512,
T::RsaPkcs1Sha256,
],
key_algorithms: &[
S::MlDsa87,
S::EcdsaP384Sha384,
S::EcdsaP256Sha256,
S::EcdsaP521Sha512,
S::EcdsaP521Sha384,
S::Rsa3072Sha384,
S::Rsa4096Sha384,
S::Rsa2048Sha384,
],
macs: &[
MacAlgorithm::HmacSha512,
MacAlgorithm::HmacSha384,
MacAlgorithm::HmacSha256,
],
kdfs: &[
KdfAlgorithm::HkdfSha512,
KdfAlgorithm::HkdfSha384,
KdfAlgorithm::HkdfSha256,
KdfAlgorithm::OneStepSha512,
KdfAlgorithm::OneStepSha384,
KdfAlgorithm::OneStepSha256,
],
key_agreements: &[
KeyAgreementAlgorithm::EcdhP384,
KeyAgreementAlgorithm::EcdhP521,
KeyAgreementAlgorithm::EcdhP256,
],
aeads: &[AeadAlgorithm::Aes256Gcm, AeadAlgorithm::Aes128Gcm],
hashes: &[
HashAlgorithm::Sha512,
HashAlgorithm::Sha384,
HashAlgorithm::Sha256,
HashAlgorithm::Sha3_512,
HashAlgorithm::Sha3_384,
HashAlgorithm::Sha3_256,
],
signatures: &[
S::MlDsa87,
S::EcdsaP384Sha384,
S::EcdsaP521Sha512,
S::EcdsaP256Sha256,
S::Ed25519,
S::Rsa4096Sha384Pss,
S::Rsa3072Sha384Pss,
S::Rsa2048Sha384Pss,
S::Rsa4096Sha384,
S::Rsa3072Sha384,
S::Rsa2048Sha384,
],
};
pub const FIPS1402: ProfileSpec = ProfileSpec {
versions: &[V::Tls13, V::Tls12],
cipher_suites: &[
C::Tls13Aes256GcmSha384,
C::Tls13Aes128GcmSha256,
C::Tls12EcdheEcdsaAes256GcmSha384,
C::Tls12EcdheRsaAes256GcmSha384,
C::Tls12EcdheEcdsaAes128GcmSha256,
C::Tls12EcdheRsaAes128GcmSha256,
],
kx_groups: &[K::Secp384r1, K::Secp256r1],
signature_schemes: &[
T::EcdsaNistp384Sha384,
T::EcdsaNistp256Sha256,
T::EcdsaNistp521Sha512,
T::RsaPssSha384,
T::RsaPssSha512,
T::RsaPssSha256,
T::RsaPkcs1Sha384,
T::RsaPkcs1Sha512,
T::RsaPkcs1Sha256,
],
key_algorithms: &[
S::EcdsaP384Sha384,
S::EcdsaP256Sha256,
S::EcdsaP521Sha512,
S::EcdsaP521Sha384,
S::Rsa3072Sha384,
S::Rsa4096Sha384,
S::Rsa2048Sha384,
],
macs: &[
MacAlgorithm::HmacSha512,
MacAlgorithm::HmacSha384,
MacAlgorithm::HmacSha256,
],
kdfs: &[
KdfAlgorithm::HkdfSha512,
KdfAlgorithm::HkdfSha384,
KdfAlgorithm::HkdfSha256,
KdfAlgorithm::OneStepSha512,
KdfAlgorithm::OneStepSha384,
KdfAlgorithm::OneStepSha256,
],
key_agreements: &[
KeyAgreementAlgorithm::EcdhP384,
KeyAgreementAlgorithm::EcdhP521,
KeyAgreementAlgorithm::EcdhP256,
],
aeads: &[AeadAlgorithm::Aes256Gcm, AeadAlgorithm::Aes128Gcm],
hashes: &[
HashAlgorithm::Sha512,
HashAlgorithm::Sha384,
HashAlgorithm::Sha256,
HashAlgorithm::Sha3_512,
HashAlgorithm::Sha3_384,
HashAlgorithm::Sha3_256,
],
signatures: &[
S::EcdsaP384Sha384,
S::EcdsaP521Sha512,
S::EcdsaP521Sha384,
S::EcdsaP256Sha256,
S::Rsa4096Sha384Pss,
S::Rsa3072Sha384Pss,
S::Rsa2048Sha384Pss,
S::Rsa4096Sha384,
S::Rsa3072Sha384,
S::Rsa2048Sha384,
],
};
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct Selection {
pub versions: Vec<V>,
pub cipher_suites: Vec<C>,
pub kx_groups: Vec<K>,
pub signature_schemes: Vec<T>,
pub key_algorithms: Vec<S>,
pub excluded: Vec<Algorithm>,
}
const fn is_tls12_only(t: T) -> bool {
match t {
T::RsaPkcs1Sha256 | T::RsaPkcs1Sha384 | T::RsaPkcs1Sha512 => true,
T::EcdsaNistp256Sha256
| T::EcdsaNistp384Sha384
| T::EcdsaNistp521Sha512
| T::Ed25519
| T::RsaPssSha256
| T::RsaPssSha384
| T::RsaPssSha512
| T::MlDsa87 => false,
}
}
fn keep<X: Copy>(items: &[X], mut wanted: impl FnMut(X) -> bool) -> Vec<X> {
items.iter().copied().filter(|x| wanted(*x)).collect()
}
pub fn select(
profile: Profile,
options: Options,
module: Module,
) -> Result<Selection, CryptoError> {
select_spec(profile, profile.spec(), options, module)
}
fn select_spec(
profile: Profile,
spec: &ProfileSpec,
options: Options,
module: Module,
) -> Result<Selection, CryptoError> {
let pq = options.pq_key_exchange_required;
let versions = keep(spec.versions, |v| !(pq && v == V::Tls12));
let cipher_suites = keep(spec.cipher_suites, |c| versions.contains(&c.version()));
let kx_groups = keep(spec.kx_groups, |k| !pq || k.is_post_quantum());
let signature_schemes = keep(spec.signature_schemes, |t| !(pq && is_tls12_only(t)));
let key_algorithms = spec.key_algorithms.to_vec();
let mut excluded = Vec::new();
let mut available = |a| {
let on = capability(module, a).available;
if !on {
excluded.push(a);
}
on
};
let versions = keep(&versions, |v| available(Algorithm::Protocol(v)));
let cipher_suites = keep(&cipher_suites, |c| available(Algorithm::Cipher(c)));
let kx_groups = keep(&kx_groups, |k| available(Algorithm::Kx(k)));
let signature_schemes = keep(&signature_schemes, |t| available(Algorithm::Scheme(t)));
let key_algorithms = keep(&key_algorithms, |s| available(Algorithm::Signature(s)));
for (empty, category) in [
(versions.is_empty(), Family::Version),
(cipher_suites.is_empty(), Family::CipherSuite),
(kx_groups.is_empty(), Family::KxGroup),
(signature_schemes.is_empty(), Family::SignatureScheme),
(key_algorithms.is_empty(), Family::KeyAlgorithm),
] {
if empty {
return Err(CryptoError::EmptyProfile {
profile,
options,
category,
});
}
}
Ok(Selection {
versions,
cipher_suites,
kx_groups,
signature_schemes,
key_algorithms,
excluded,
})
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct AdmittedSelection {
pub macs: Vec<MacAlgorithm>,
pub kdfs: Vec<KdfAlgorithm>,
pub key_agreements: Vec<KeyAgreementAlgorithm>,
pub aeads: Vec<AeadAlgorithm>,
pub hashes: Vec<HashAlgorithm>,
pub signatures: Vec<S>,
pub excluded: Vec<Algorithm>,
}
pub fn select_admitted(profile: Profile, options: Options, module: Module) -> AdmittedSelection {
select_admitted_with(profile, profile.spec(), options, |a| {
capability(module, a).available
})
}
fn select_admitted_with(
profile: Profile,
spec: &ProfileSpec,
options: Options,
available: impl Fn(Algorithm) -> bool,
) -> AdmittedSelection {
let mut macs = spec.macs.to_vec();
let mut kdfs = spec.kdfs.to_vec();
let mut hashes = spec.hashes.to_vec();
let mut signatures = spec.signatures.to_vec();
if options.cnsa1_unclassified_nss {
macs.extend_from_slice(unclassified_nss_macs(profile));
kdfs.extend_from_slice(unclassified_nss_kdfs(profile));
hashes.extend_from_slice(unclassified_nss_hashes(profile));
signatures.extend_from_slice(unclassified_nss_signatures(profile));
}
let mut key_agreements = spec.key_agreements.to_vec();
let mut aeads = spec.aeads.to_vec();
let mut excluded = Vec::new();
retain_available(&mut macs, Algorithm::Mac, &available, &mut excluded);
retain_available(&mut kdfs, Algorithm::Kdf, &available, &mut excluded);
retain_available(
&mut key_agreements,
Algorithm::KeyAgreement,
&available,
&mut excluded,
);
retain_available(&mut aeads, Algorithm::Aead, &available, &mut excluded);
retain_available(&mut hashes, Algorithm::Hash, &available, &mut excluded);
retain_available(
&mut signatures,
Algorithm::Signature,
&available,
&mut excluded,
);
AdmittedSelection {
macs,
kdfs,
key_agreements,
aeads,
hashes,
signatures,
excluded,
}
}
fn retain_available<X: Copy>(
xs: &mut Vec<X>,
tag: fn(X) -> Algorithm,
available: &impl Fn(Algorithm) -> bool,
excluded: &mut Vec<Algorithm>,
) {
xs.retain(|x| {
let on = available(tag(*x));
if !on {
excluded.push(tag(*x));
}
on
});
}
fn unclassified_nss_macs(p: Profile) -> &'static [MacAlgorithm] {
match p {
Profile::Cnsa1 => &[MacAlgorithm::HmacSha256],
Profile::Unrestricted
| Profile::Preferred
| Profile::Cnsa2
| Profile::Bsi
| Profile::Fips1403
| Profile::Fips1402 => &[],
}
}
fn unclassified_nss_kdfs(p: Profile) -> &'static [KdfAlgorithm] {
match p {
Profile::Cnsa1 => &[KdfAlgorithm::HkdfSha256],
Profile::Unrestricted
| Profile::Preferred
| Profile::Cnsa2
| Profile::Bsi
| Profile::Fips1403
| Profile::Fips1402 => &[],
}
}
fn unclassified_nss_hashes(p: Profile) -> &'static [HashAlgorithm] {
match p {
Profile::Cnsa1 => &[HashAlgorithm::Sha256],
Profile::Unrestricted
| Profile::Preferred
| Profile::Cnsa2
| Profile::Bsi
| Profile::Fips1403
| Profile::Fips1402 => &[],
}
}
fn unclassified_nss_signatures(p: Profile) -> &'static [S] {
match p {
Profile::Cnsa1 => &[S::Rsa2048Sha384Pss, S::Rsa2048Sha384],
Profile::Unrestricted
| Profile::Preferred
| Profile::Cnsa2
| Profile::Bsi
| Profile::Fips1403
| Profile::Fips1402 => &[],
}
}
pub const fn kdf_info_may_be_empty(profile: Profile) -> bool {
match profile {
Profile::Unrestricted => true,
Profile::Preferred
| Profile::Cnsa2
| Profile::Cnsa1
| Profile::Bsi
| Profile::Fips1403
| Profile::Fips1402 => false,
}
}
pub const fn mac_key_floor_bits(profile: Profile) -> usize {
match profile {
Profile::Bsi => 128,
Profile::Unrestricted
| Profile::Preferred
| Profile::Cnsa2
| Profile::Cnsa1
| Profile::Fips1403
| Profile::Fips1402 => 112,
}
}
pub const MAC_KEY_MAX_BITS: usize = 524_288;
#[cfg(test)]
mod tests {
use super::*;
use crate::algorithm::*;
use crate::capability::{Linkage, Module, ModuleLine};
use crate::error::{CryptoError, Family};
#[test]
fn every_profile_lists_its_schemes_in_the_canonical_order() {
assert_eq!(
Profile::Unrestricted.spec().signature_schemes.len(),
TlsSignatureScheme::ALL.len()
);
for &p in Profile::ALL {
let s = p.spec().signature_schemes;
assert!(
s.windows(2).all(|w| w[0].preference() < w[1].preference()),
"{p}"
);
}
}
const M3S: Module = Module {
line: ModuleLine::AwsLcFips3,
linkage: Linkage::Static,
};
const M4S: Module = Module {
line: ModuleLine::AwsLcFips4,
linkage: Linkage::Static,
};
const PQ: Options = Options {
peer_certificates_match_profile: false,
pq_key_exchange_required: true,
cnsa1_unclassified_nss: false,
};
const PKCS1: [TlsSignatureScheme; 3] = [
TlsSignatureScheme::RsaPkcs1Sha256,
TlsSignatureScheme::RsaPkcs1Sha384,
TlsSignatureScheme::RsaPkcs1Sha512,
];
fn no_duplicates<X: PartialEq + std::fmt::Debug>(xs: &[X]) {
for (i, x) in xs.iter().enumerate() {
assert!(!xs[i + 1..].contains(x), "{x:?} twice");
}
}
#[test]
fn every_spec_is_well_formed() {
for &p in Profile::ALL {
let s = p.spec();
no_duplicates(s.versions);
no_duplicates(s.cipher_suites);
no_duplicates(s.kx_groups);
no_duplicates(s.signature_schemes);
no_duplicates(s.key_algorithms);
no_duplicates(s.macs);
no_duplicates(s.kdfs);
no_duplicates(s.key_agreements);
no_duplicates(s.aeads);
no_duplicates(s.hashes);
no_duplicates(s.signatures);
assert!(!s.versions.is_empty() && !s.kx_groups.is_empty(), "{p}");
assert!(
!s.signature_schemes.is_empty() && !s.key_algorithms.is_empty(),
"{p}"
);
assert!(
s.cipher_suites
.iter()
.all(|c| s.versions.contains(&c.version())),
"{p}"
);
let has_pkcs1 = s.signature_schemes.iter().any(|t| PKCS1.contains(t));
assert!(!has_pkcs1 || s.versions.contains(&TlsVersion::Tls12), "{p}");
}
}
#[test]
fn preferred_excludes_what_its_definition_names() {
let s = Profile::Preferred.spec();
assert_eq!(s.versions, &[TlsVersion::Tls13]);
assert!(!s.kx_groups.contains(&KxGroup::X25519));
assert!(
!s.cipher_suites
.contains(&CipherSuite::Tls13Chacha20Poly1305Sha256)
);
assert!(!s.signature_schemes.contains(&TlsSignatureScheme::Ed25519));
assert!(!s.key_algorithms.contains(&SignatureAlgorithm::Ed25519));
assert!(!s.aeads.contains(&AeadAlgorithm::Chacha20Poly1305));
for h in [
HashAlgorithm::Sha3_256,
HashAlgorithm::Sha3_384,
HashAlgorithm::Sha3_512,
] {
assert!(!s.hashes.contains(&h), "{h:?}");
}
for a in [
SignatureAlgorithm::Ed25519,
SignatureAlgorithm::EcdsaP521Sha384,
SignatureAlgorithm::Rsa2048Sha384,
SignatureAlgorithm::Rsa2048Sha384Pss,
] {
assert!(!s.signatures.contains(&a), "{a}");
}
}
#[test]
fn no_tls_key_list_holds_an_rsa_pss_variant() {
for &p in Profile::ALL {
for &k in p.spec().key_algorithms {
assert!(k.tls_scheme().is_some(), "{p} {k}");
}
}
for a in [
S::Rsa2048Sha384Pss,
S::Rsa3072Sha384Pss,
S::Rsa4096Sha384Pss,
] {
assert_eq!(a.tls_scheme(), None, "{a}");
assert!(Profile::Unrestricted.spec().signatures.contains(&a), "{a}");
}
}
#[test]
fn p521_with_sha384_signs_outside_tls_only_where_fips_186_5_does_not_govern() {
for &p in Profile::ALL {
let outside = p.spec().signatures.contains(&S::EcdsaP521Sha384);
let want = match p {
Profile::Unrestricted | Profile::Fips1402 => true,
Profile::Preferred
| Profile::Cnsa2
| Profile::Cnsa1
| Profile::Bsi
| Profile::Fips1403 => false,
};
assert_eq!(outside, want, "{p}");
}
for p in [Profile::Preferred, Profile::Fips1403] {
assert!(p.spec().key_algorithms.contains(&S::EcdsaP521Sha384), "{p}");
}
}
#[test]
fn bsi_signs_with_rsa_pss_only() {
assert_eq!(
Profile::Bsi.spec().signatures,
&[S::Rsa4096Sha384Pss, S::Rsa3072Sha384Pss]
);
}
#[test]
fn bsi_admits_only_ecdsa_keys() {
assert_eq!(
Profile::Bsi.spec().key_algorithms,
&[
SignatureAlgorithm::EcdsaP384Sha384,
SignatureAlgorithm::EcdsaP256Sha256,
SignatureAlgorithm::EcdsaP521Sha512,
]
);
}
#[test]
fn select_records_line_exclusions_after_options() {
for module in [
M3S,
Module {
linkage: Linkage::Dynamic,
..M3S
},
] {
for p in [Profile::Unrestricted, Profile::Preferred, Profile::Fips1403] {
for options in [Options::default(), PQ] {
let s = select(p, options, module).unwrap();
assert_eq!(
s.excluded,
vec![
Algorithm::Scheme(T::MlDsa87),
Algorithm::Signature(S::MlDsa87),
]
);
no_duplicates(&s.excluded);
assert!(!s.signature_schemes.contains(&T::MlDsa87));
assert!(!s.key_algorithms.contains(&S::MlDsa87));
}
}
for options in [Options::default(), PQ] {
assert_eq!(
select(Profile::Cnsa2, options, module),
Err(CryptoError::EmptyProfile {
profile: Profile::Cnsa2,
options,
category: Family::SignatureScheme,
})
);
}
for p in [Profile::Cnsa1, Profile::Bsi, Profile::Fips1402] {
assert!(
select(p, Options::default(), module)
.unwrap()
.excluded
.is_empty()
);
}
}
}
#[test]
fn select_checks_keys_and_options_precede_line_emptiness() {
const KEY_ONLY: ProfileSpec = ProfileSpec {
signature_schemes: &[T::EcdsaNistp384Sha384],
..CNSA2
};
assert_eq!(
select_spec(Profile::Cnsa2, &KEY_ONLY, Options::default(), M3S),
Err(CryptoError::EmptyProfile {
profile: Profile::Cnsa2,
options: Options::default(),
category: Family::KeyAlgorithm,
})
);
const BSI_WITH_ML_DSA: ProfileSpec = ProfileSpec {
signature_schemes: &[T::MlDsa87],
..BSI
};
for spec in [&BSI_WITH_ML_DSA, &BSI] {
assert_eq!(
select_spec(Profile::Bsi, spec, PQ, M3S),
Err(CryptoError::EmptyProfile {
profile: Profile::Bsi,
options: PQ,
category: Family::KxGroup,
})
);
}
}
#[test]
fn select_refuses_each_empty_family_in_order() {
const EMPTY: ProfileSpec = ProfileSpec {
versions: &[],
cipher_suites: &[],
kx_groups: &[],
signature_schemes: &[],
key_algorithms: &[],
macs: &[],
kdfs: &[],
key_agreements: &[],
aeads: &[],
hashes: &[],
signatures: &[],
};
let empty = |category| {
Err(CryptoError::EmptyProfile {
profile: Profile::Bsi,
options: Options::default(),
category,
})
};
let cases: [(ProfileSpec, Family); 5] = [
(EMPTY, Family::Version),
(
ProfileSpec {
versions: BSI.versions,
..EMPTY
},
Family::CipherSuite,
),
(
ProfileSpec {
kx_groups: &[],
signature_schemes: &[],
key_algorithms: &[],
..BSI
},
Family::KxGroup,
),
(
ProfileSpec {
signature_schemes: &[],
key_algorithms: &[],
..BSI
},
Family::SignatureScheme,
),
(
ProfileSpec {
key_algorithms: &[],
..BSI
},
Family::KeyAlgorithm,
),
];
for (spec, category) in cases {
assert_eq!(
select_spec(Profile::Bsi, &spec, Options::default(), M4S),
empty(category),
"{category:?}"
);
}
}
#[test]
fn select_without_options_is_the_spec_on_a_module_that_has_everything() {
for &p in Profile::ALL {
let s = select(p, Options::default(), M4S).unwrap();
let spec = p.spec();
assert!(s.excluded.is_empty());
assert_eq!(s.versions, spec.versions.to_vec(), "{p}");
assert_eq!(s.cipher_suites, spec.cipher_suites.to_vec(), "{p}");
assert_eq!(s.kx_groups, spec.kx_groups.to_vec(), "{p}");
assert_eq!(s.signature_schemes, spec.signature_schemes.to_vec(), "{p}");
assert_eq!(s.key_algorithms, spec.key_algorithms.to_vec(), "{p}");
}
}
#[test]
fn the_option_keeps_post_quantum_groups_tls13_and_no_pkcs1_schemes() {
for &p in Profile::ALL {
let refused = match p {
Profile::Unrestricted | Profile::Preferred | Profile::Cnsa2 | Profile::Fips1403 => {
false
}
Profile::Cnsa1 | Profile::Bsi | Profile::Fips1402 => true,
};
match select(p, PQ, M4S) {
Ok(s) => {
assert!(!refused, "{p}");
let spec = p.spec();
assert_eq!(s.versions, vec![TlsVersion::Tls13], "{p}");
let suites: Vec<_> = spec
.cipher_suites
.iter()
.copied()
.filter(|c| c.version() == TlsVersion::Tls13)
.collect();
assert_eq!(s.cipher_suites, suites, "{p}");
let groups: Vec<_> = spec
.kx_groups
.iter()
.copied()
.filter(|k| k.is_post_quantum())
.collect();
assert_eq!(s.kx_groups, groups, "{p}");
let schemes: Vec<_> = spec
.signature_schemes
.iter()
.copied()
.filter(|t| !PKCS1.contains(t))
.collect();
assert_eq!(s.signature_schemes, schemes, "{p}");
assert_eq!(s.key_algorithms, spec.key_algorithms.to_vec(), "{p}");
}
Err(e) => {
assert!(refused, "{p}");
assert_eq!(
e,
CryptoError::EmptyProfile {
profile: p,
options: PQ,
category: Family::KxGroup
}
);
}
}
}
}
#[test]
fn the_option_removes_every_pkcs1_scheme_from_unrestricted_and_fips1403() {
use TlsSignatureScheme as T;
let unrestricted = vec![
T::MlDsa87,
T::EcdsaNistp384Sha384,
T::EcdsaNistp256Sha256,
T::EcdsaNistp521Sha512,
T::Ed25519,
T::RsaPssSha384,
T::RsaPssSha512,
T::RsaPssSha256,
];
let fips1403 = vec![
T::MlDsa87,
T::EcdsaNistp384Sha384,
T::EcdsaNistp256Sha256,
T::EcdsaNistp521Sha512,
T::RsaPssSha384,
T::RsaPssSha512,
T::RsaPssSha256,
];
for (p, expected) in [
(Profile::Unrestricted, unrestricted),
(Profile::Fips1403, fips1403),
] {
assert_eq!(
select(p, PQ, M4S).unwrap().signature_schemes,
expected,
"{p}"
);
assert_eq!(
select(p, Options::default(), M4S)
.unwrap()
.signature_schemes
.len(),
expected.len() + 3,
"{p}"
);
}
}
#[test]
fn profile_names_are_stable_and_exact() {
assert_eq!(
Profile::ALL
.iter()
.copied()
.map(Profile::as_str)
.collect::<Vec<_>>(),
[
"unrestricted",
"preferred",
"cnsa2",
"cnsa1",
"bsi",
"fips1403",
"fips1402"
]
);
for &p in Profile::ALL {
assert_eq!(p.as_str().parse::<Profile>(), Ok(p));
assert_eq!(p.to_string(), p.as_str());
}
for bad in [
"",
"CNSA2",
"Cnsa2",
"FIPS1403",
"fips140-3",
"fips-140-3",
" fips1403",
"fips1403 ",
"fips1403\n",
" bsi",
"cnsa",
"bsi2026",
"preferred,",
"default",
] {
assert_eq!(
bad.parse::<Profile>(),
Err(ParseProfileError(bad.to_string())),
"{bad:?}"
);
}
assert_eq!(
ParseProfileError("FIPS1403".to_string()).to_string(),
"unknown profile \"FIPS1403\""
);
}
#[test]
fn profile_all_lists_every_variant_in_ordinal_order() {
assert_eq!(
Profile::ALL
.iter()
.copied()
.map(Profile::ordinal)
.collect::<Vec<_>>(),
std::array::from_fn::<usize, 7, _>(|i| i)
);
}
#[test]
fn governing_texts_are_the_published_editions() {
use GoverningText::{CrateRecommendation as Own, Published};
let table: [(Profile, GoverningText); 7] = [
(Profile::Unrestricted, Own),
(Profile::Preferred, Own),
(
Profile::Cnsa2,
Published {
documents: &["CNSSP 15 (December 2024), Annex B, pp. B-1 to B-2"],
},
),
(
Profile::Cnsa1,
Published {
documents: &[
"CNSSP 15 (20 October 2016), Annex B, p. B-1",
"RFC 9151 (April 2022)",
],
},
),
(
Profile::Bsi,
Published {
documents: &[
"BSI TR-02102-2, version 2026-01",
"BSI TR-02102-1, version 2026-01",
],
},
),
(
Profile::Fips1403,
Published {
documents: &[
"NIST SP 800-140C r2 and SP 800-140D r2, with the CMVP lists (August 2026)",
"FIPS 140-3 Implementation Guidance (August 2026): IG C.K, D.Q, D.S",
"NIST SP 800-52r2",
"NIST SP 800-131A r2",
],
},
),
(
Profile::Fips1402,
Published {
documents: &[
"FIPS 140-2 Annex A and Annex D (2021)",
"FIPS 186-4",
"NIST SP 800-131A r2",
"NIST SP 800-52r2",
],
},
),
];
for (p, text) in table {
assert_eq!(p.governing_text(), text, "{p}");
}
}
#[test]
fn options_default_narrows_nothing_and_display_names_the_option() {
assert_eq!(
Options::default(),
Options {
peer_certificates_match_profile: false,
pq_key_exchange_required: false,
cnsa1_unclassified_nss: false,
}
);
assert_eq!(Options::default().to_string(), "no options");
assert_eq!(
Options {
peer_certificates_match_profile: false,
pq_key_exchange_required: true,
cnsa1_unclassified_nss: false,
}
.to_string(),
"post-quantum key exchange required"
);
}
#[test]
fn peer_certificate_options_combinations_preserve_selection() {
for (pq, peer, display) in [
(false, false, "no options"),
(true, false, "post-quantum key exchange required"),
(false, true, "peer certificates match profile"),
(
true,
true,
"post-quantum key exchange required, peer certificates match profile",
),
] {
let options = Options {
pq_key_exchange_required: pq,
peer_certificates_match_profile: peer,
cnsa1_unclassified_nss: false,
};
assert_eq!(options.to_string(), display);
for &profile in Profile::ALL {
for module in [M3S, M4S] {
let baseline = Options {
peer_certificates_match_profile: false,
..options
};
let actual = select(profile, options, module);
let expected = select(profile, baseline, module);
match (actual, expected) {
(Ok(actual), Ok(expected)) => assert_eq!(actual, expected),
(
Err(CryptoError::EmptyProfile {
profile: p,
options: o,
category: f,
}),
Err(CryptoError::EmptyProfile {
profile: ep,
options: eo,
category: ef,
}),
) => {
assert_eq!((p, o, f), (ep, options, ef));
assert_eq!(eo, baseline);
}
(actual, expected) => panic!("{actual:?} != {expected:?}"),
}
}
}
}
}
#[test]
fn cnsa1_unclassified_nss_names_itself_and_leaves_tls_selection_alone() {
let on = Options {
cnsa1_unclassified_nss: true,
..Options::default()
};
assert_eq!(on.to_string(), "cnsa1 UNCLASSIFIED NSS");
assert_eq!(
Options {
pq_key_exchange_required: true,
peer_certificates_match_profile: true,
cnsa1_unclassified_nss: true,
}
.to_string(),
"post-quantum key exchange required, peer certificates match profile, cnsa1 UNCLASSIFIED NSS"
);
for &profile in Profile::ALL {
for module in [M3S, M4S] {
for pq in [false, true] {
let off = Options {
pq_key_exchange_required: pq,
..Options::default()
};
let on = Options {
cnsa1_unclassified_nss: true,
..off
};
match (select(profile, on, module), select(profile, off, module)) {
(Ok(a), Ok(b)) => assert_eq!(a, b),
(
Err(CryptoError::EmptyProfile {
profile: p,
options: o,
category: f,
}),
Err(CryptoError::EmptyProfile {
profile: ep,
options: eo,
category: ef,
}),
) => {
assert_eq!((p, f), (ep, ef));
assert_eq!((o, eo), (on, off));
}
(a, b) => panic!("{a:?} != {b:?}"),
}
}
}
}
}
#[test]
fn select_admitted_never_refuses_an_empty_family() {
let spec = ProfileSpec {
macs: &[],
kdfs: &[],
aeads: &[],
hashes: &[],
signatures: &[],
..BSI
};
assert_eq!(
select_admitted_with(Profile::Bsi, &spec, Options::default(), |_| true),
AdmittedSelection {
macs: vec![],
kdfs: vec![],
key_agreements: vec![],
aeads: vec![],
hashes: vec![],
signatures: vec![],
excluded: vec![],
}
);
}
#[test]
fn select_admitted_records_what_the_module_lacks() {
use AeadAlgorithm as D;
use HashAlgorithm as H;
use KdfAlgorithm as K;
use KeyAgreementAlgorithm as E;
use MacAlgorithm as M;
let lacking = [
Algorithm::Mac(M::HmacSha384),
Algorithm::Kdf(K::HkdfSha512),
Algorithm::Kdf(K::OneStepSha384),
Algorithm::KeyAgreement(E::EcdhP521),
Algorithm::Aead(D::Aes128Gcm),
Algorithm::Hash(H::Sha384),
Algorithm::Hash(H::Sha3_512),
Algorithm::Signature(S::MlDsa87),
Algorithm::Signature(S::Rsa3072Sha384Pss),
];
assert_eq!(
select_admitted_with(Profile::Fips1403, &FIPS1403, Options::default(), |a| {
!lacking.contains(&a)
}),
AdmittedSelection {
macs: vec![M::HmacSha512, M::HmacSha256],
kdfs: vec![
K::HkdfSha384,
K::HkdfSha256,
K::OneStepSha512,
K::OneStepSha256
],
key_agreements: vec![E::EcdhP384, E::EcdhP256],
aeads: vec![D::Aes256Gcm],
hashes: vec![H::Sha512, H::Sha256, H::Sha3_384, H::Sha3_256],
signatures: vec![
S::EcdsaP384Sha384,
S::EcdsaP521Sha512,
S::EcdsaP256Sha256,
S::Ed25519,
S::Rsa4096Sha384Pss,
S::Rsa2048Sha384Pss,
S::Rsa4096Sha384,
S::Rsa3072Sha384,
S::Rsa2048Sha384,
],
excluded: lacking.to_vec(),
}
);
}
fn strength_bits(k: KeyAgreementAlgorithm) -> usize {
match k {
KeyAgreementAlgorithm::EcdhP256 | KeyAgreementAlgorithm::X25519 => 128,
KeyAgreementAlgorithm::EcdhP384 => 192,
KeyAgreementAlgorithm::EcdhP521 => 256,
}
}
#[test]
fn every_admitted_curve_and_kdf_pair_meets_sp_800_56c_section_7() {
let on = Options {
cnsa1_unclassified_nss: true,
..Options::default()
};
let mut pairs = 0;
for &p in Profile::ALL {
for o in [Options::default(), on] {
let s = select_admitted(p, o, M4S);
for &k in &s.key_agreements {
for &d in &s.kdfs {
pairs += 1;
assert!(
8 * d.hash().output_len() >= strength_bits(k),
"{p} {o} {k:?} {d:?}"
);
}
}
}
}
assert_eq!(pairs, 2 * (4 * 6 + 3 * 6 + 3 * 6 + 3 * 6) + 1 + 2);
}
#[test]
fn the_unclassified_nss_option_adds_hmac_sha256_to_cnsa1_only() {
let on = Options {
cnsa1_unclassified_nss: true,
..Options::default()
};
for &p in Profile::ALL {
let mut want = select_admitted(p, Options::default(), M4S).macs;
if p == Profile::Cnsa1 {
want.push(MacAlgorithm::HmacSha256);
}
assert_eq!(select_admitted(p, on, M4S).macs, want, "{p}");
}
}
#[test]
fn the_unclassified_nss_option_adds_hkdf_sha256_to_cnsa1_only() {
let on = Options {
cnsa1_unclassified_nss: true,
..Options::default()
};
for &p in Profile::ALL {
let mut want = select_admitted(p, Options::default(), M4S).kdfs;
if p == Profile::Cnsa1 {
want.push(KdfAlgorithm::HkdfSha256);
}
assert_eq!(select_admitted(p, on, M4S).kdfs, want, "{p}");
}
}
#[test]
fn the_unclassified_nss_option_adds_sha256_hashing_to_cnsa1_only() {
let on = Options {
cnsa1_unclassified_nss: true,
..Options::default()
};
for &p in Profile::ALL {
let mut want = select_admitted(p, Options::default(), M4S).hashes;
if p == Profile::Cnsa1 {
assert_eq!(want, [HashAlgorithm::Sha384]);
want.push(HashAlgorithm::Sha256);
}
assert_eq!(select_admitted(p, on, M4S).hashes, want, "{p}");
assert_eq!(select_admitted(p, on, M3S).hashes, want, "{p}");
}
}
#[test]
fn the_unclassified_nss_option_adds_rsa_2048_signatures_to_cnsa1_only() {
let on = Options {
cnsa1_unclassified_nss: true,
..Options::default()
};
for &p in Profile::ALL {
for m in [M3S, M4S] {
let mut want = select_admitted(p, Options::default(), m).signatures;
if p == Profile::Cnsa1 {
assert_eq!(
want,
[
S::EcdsaP384Sha384,
S::Rsa4096Sha384Pss,
S::Rsa3072Sha384Pss,
S::Rsa4096Sha384,
S::Rsa3072Sha384,
]
);
want.extend([S::Rsa2048Sha384Pss, S::Rsa2048Sha384]);
}
assert_eq!(select_admitted(p, on, m).signatures, want, "{p} {m:?}");
}
}
}
#[test]
fn an_empty_kdf_info_is_admitted_under_unrestricted_only() {
for &p in Profile::ALL {
let may = match p {
Profile::Unrestricted => true,
Profile::Preferred
| Profile::Cnsa2
| Profile::Cnsa1
| Profile::Bsi
| Profile::Fips1403
| Profile::Fips1402 => false,
};
assert_eq!(kdf_info_may_be_empty(p), may, "{p}");
}
}
#[test]
fn mac_keys_are_bounded_by_the_module_and_by_bsi() {
for &p in Profile::ALL {
let floor = match p {
Profile::Bsi => 128,
Profile::Unrestricted
| Profile::Preferred
| Profile::Cnsa2
| Profile::Cnsa1
| Profile::Fips1403
| Profile::Fips1402 => 112,
};
assert_eq!(mac_key_floor_bits(p), floor, "{p}");
}
assert_eq!(MAC_KEY_MAX_BITS, 524_288);
}
}