Skip to main content

crypto_profile/
capability.rs

1//! What each AWS-LC FIPS module can do and what the published evidence says about each
2//! algorithm: the module's security policy, cited by table for every sourced cell, or, for a
3//! module with none published, one CAVP certificate, which is never an approval (decision 0004).
4use crate::algorithm::*;
5use crate::error::CryptoError;
6
7/// An AWS-LC FIPS module line.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
9#[non_exhaustive]
10pub enum ModuleLine {
11    /// AWS-LC FIPS 3.x (aws-lc-rs 1.17).
12    AwsLcFips3,
13    /// AWS-LC FIPS 4.x (aws-lc-rs 1.18 and later).
14    AwsLcFips4,
15}
16
17/// How the FIPS module is linked; each linkage is a separate module, with its own certificate or
18/// submission.
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20#[non_exhaustive]
21pub enum Linkage {
22    /// Linked into the binary.
23    Static,
24    /// Loaded as a shared library.
25    Dynamic,
26}
27
28/// An AWS-LC FIPS module: a line and a linkage.
29#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
30pub struct Module {
31    /// The module line.
32    pub line: ModuleLine,
33    /// The linkage.
34    pub linkage: Linkage,
35}
36
37/// A certificate's CMVP status as recorded when this crate version was released.
38#[derive(Debug, Clone, Copy, PartialEq, Eq)]
39#[non_exhaustive]
40pub enum CertStatus {
41    /// On the CMVP validated list.
42    Validated,
43    /// Submitted and in CMVP review, on the CMVP Modules In Process list; not validated.
44    InProcess,
45    /// Moved to the CMVP historical list.
46    Historical,
47}
48
49/// The certificate a module carries.
50#[derive(Debug, Clone, Copy, PartialEq, Eq)]
51pub struct Certificate {
52    /// The module's name, with the release for a 3.x line.
53    pub module_name: &'static str,
54    /// The certificate number, absent while in review.
55    pub number: Option<u32>,
56    /// The status when this crate version was released; the CMVP list is authoritative.
57    pub status: CertStatus,
58    /// The security policy URL, absent while none is published.
59    pub policy: Option<&'static str>,
60}
61
62/// A module's approval status for one algorithm, as its published evidence settles it.
63#[derive(Debug, Clone, Copy, PartialEq, Eq)]
64pub enum Approval {
65    /// Listed as approved; `source` cites the table.
66    Approved {
67        /// The security-policy citation.
68        source: &'static str,
69    },
70    /// Not approved; `source` cites where the policy says so or omits it.
71    NotApproved {
72        /// The security-policy citation.
73        source: &'static str,
74    },
75    /// One published CAVP certificate for this module shows every operation the cell needs, with
76    /// the parameters `cavp` names, but no security policy lists it as approved. Never approved.
77    /// It covers only those parameters: rustls verifies a `Scheme` cell's signatures over a wider
78    /// range of keys (decision 0004 §5). Tested on that certificate's processor variant; which
79    /// variant a build uses depends on the CPU.
80    AlgorithmTested {
81        /// The certificate, and the capabilities and parameters it shows.
82        cavp: &'static str,
83    },
84    /// No published source settles it: no security policy, and no single CAVP certificate under
85    /// decision 0004. Treated as not approved everywhere.
86    Unverified,
87}
88
89impl Approval {
90    /// Whether the cell is approved. Only `Approved` is; `AlgorithmTested` and `Unverified` are not.
91    pub const fn is_approved(self) -> bool {
92        matches!(self, Approval::Approved { .. })
93    }
94}
95
96/// One cell of the capability table. A cipher suite cell speaks only to the suite's algorithms;
97/// whether its protocol version is approved is the `Protocol` cell.
98#[derive(Debug, Clone, Copy, PartialEq, Eq)]
99pub struct Capability {
100    /// The backend for this module implements the algorithm.
101    pub available: bool,
102    /// The module's approval status for it.
103    pub approval: Approval,
104}
105
106const POLICY_5314: &str = "https://csrc.nist.gov/CSRC/media/projects/cryptographic-module-validation-program/documents/security-policies/140sp5314.pdf";
107const POLICY_5298: &str = "https://csrc.nist.gov/CSRC/media/projects/cryptographic-module-validation-program/documents/security-policies/140sp5298.pdf";
108
109/// The certificate for a module.
110pub const fn certificate(m: Module) -> Certificate {
111    match (m.line, m.linkage) {
112        (ModuleLine::AwsLcFips3, Linkage::Static) => Certificate {
113            module_name: "AWS-LC 3 Cryptographic Module (static), AWS-LC FIPS 3.1.0",
114            number: Some(5314),
115            status: CertStatus::Validated,
116            policy: Some(POLICY_5314),
117        },
118        (ModuleLine::AwsLcFips3, Linkage::Dynamic) => Certificate {
119            module_name: "AWS-LC 3 Cryptographic Module (dynamic), AWS-LC FIPS 3.1.0",
120            number: Some(5298),
121            status: CertStatus::Validated,
122            policy: Some(POLICY_5298),
123        },
124        (ModuleLine::AwsLcFips4, Linkage::Static) => Certificate {
125            module_name: "AWS-LC 4 Cryptographic Module (static)",
126            number: None,
127            status: CertStatus::InProcess,
128            policy: None,
129        },
130        (ModuleLine::AwsLcFips4, Linkage::Dynamic) => Certificate {
131            module_name: "AWS-LC 4 Cryptographic Module (dynamic)",
132            number: None,
133            status: CertStatus::InProcess,
134            policy: None,
135        },
136    }
137}
138
139const fn table5(l: Linkage) -> &'static str {
140    match l {
141        Linkage::Static => {
142            "AWS-LC FIPS 3.1.0 Security Policy, cert #5314 (static), Table 5, pp. 8-11"
143        }
144        Linkage::Dynamic => {
145            "AWS-LC FIPS 3.1.0 Security Policy, cert #5298 (dynamic), Table 5, pp. 8-11"
146        }
147    }
148}
149
150const fn absent(l: Linkage) -> &'static str {
151    match l {
152        Linkage::Static => {
153            "AWS-LC FIPS 3.1.0 Security Policy, cert #5314 (static): not listed in Tables 5-8"
154        }
155        Linkage::Dynamic => {
156            "AWS-LC FIPS 3.1.0 Security Policy, cert #5298 (dynamic): not listed in Tables 5-8"
157        }
158    }
159}
160
161const fn ecdh_outside_tls(l: Linkage) -> &'static str {
162    match l {
163        Linkage::Static => {
164            "AWS-LC FIPS 3.1.0 Security Policy, cert #5314 (static), p. 20: the SP 800-56Ar3 assurances hold only with an application that implements the TLS protocol, for ephemeral keys from the module's key pair generation; \"The module does not support static keys\""
165        }
166        Linkage::Dynamic => {
167            "AWS-LC FIPS 3.1.0 Security Policy, cert #5298 (dynamic), p. 20: the SP 800-56Ar3 assurances hold only with an application that implements the TLS protocol, for ephemeral keys from the module's key pair generation; \"The module does not support static keys\""
168        }
169    }
170}
171
172const fn x25519_absent(l: Linkage) -> &'static str {
173    match l {
174        Linkage::Static => {
175            "AWS-LC FIPS 3.1.0 Security Policy, cert #5314 (static): not listed in Tables 5-8; FIPS 140-3 IG C.K Resolution 5 (p. 160)"
176        }
177        Linkage::Dynamic => {
178            "AWS-LC FIPS 3.1.0 Security Policy, cert #5298 (dynamic): not listed in Tables 5-8; FIPS 140-3 IG C.K Resolution 5 (p. 160)"
179        }
180    }
181}
182
183const fn gcm_scenario_2(l: Linkage) -> &'static str {
184    match l {
185        Linkage::Static => {
186            "AWS-LC FIPS 3.1.0 Security Policy, cert #5314 (static), Table 5, p. 8 (AES-GCM: IV Generation Internal, IV Generation Mode 8.2.2, Key Length 128, 256); §2.7 GCM IV, Scenario 2, pp. 18-19 (EVP_aead_aes_128_gcm_randnonce, EVP_aead_aes_256_gcm_randnonce)"
187        }
188        Linkage::Dynamic => {
189            "AWS-LC FIPS 3.1.0 Security Policy, cert #5298 (dynamic), Table 5, p. 8 (AES-GCM: IV Generation Internal, IV Generation Mode 8.2.2, Key Length 128, 256); §2.7 GCM IV, Scenario 2, p. 19 (EVP_aead_aes_128_gcm_randnonce, EVP_aead_aes_256_gcm_randnonce)"
190        }
191    }
192}
193
194const fn tls12_ems(l: Linkage) -> &'static str {
195    match l {
196        Linkage::Static => {
197            "AWS-LC FIPS 3.1.0 Security Policy, cert #5314 (static), Table 5, p. 10 (KDF TLS (CVL), SP 800-135: TLS v1.0/1.1, v1.2, no TLS v1.2 KDF RFC7627) and Table 8, p. 12 (TLS KDF using non-extended master secret: not allowed), though Table 12 (Approved Services), p. 25, lists Key Derivation with TLS KDF; FIPS 140-3 IG D.Q (April 9, 2026 edition, p. 205): the TLS 1.2 KDF shall use the extended master secret (RFC 7627), and a version not tested by the CAVP shall not be used in the approved mode; IG 2.4.B item 6 (p. 31) denotes that test separately, as TLS v1.2 KDF RFC7627"
198        }
199        Linkage::Dynamic => {
200            "AWS-LC FIPS 3.1.0 Security Policy, cert #5298 (dynamic), Table 5, p. 10 (KDF TLS (CVL), SP 800-135: TLS v1.0/1.1, v1.2, no TLS v1.2 KDF RFC7627) and Table 8, p. 12 (TLS KDF using non-extended master secret: not allowed), though Table 12 (Approved Services), p. 26, lists Key Derivation with TLS KDF; FIPS 140-3 IG D.Q (April 9, 2026 edition, p. 205): the TLS 1.2 KDF shall use the extended master secret (RFC 7627), and a version not tested by the CAVP shall not be used in the approved mode; IG 2.4.B item 6 (p. 31) denotes that test separately, as TLS v1.2 KDF RFC7627"
201        }
202    }
203}
204
205const ED25519_5314: Approval = Approval::NotApproved {
206    source: "AWS-LC FIPS 3.1.0 Security Policy, cert #5314 (static), Table 12 (Approved Services), pp. 24-25: Signature Generation and Signature Verification list RSA and ECDSA, not EdDSA",
207};
208
209const fn ed25519_3x(l: Linkage) -> Approval {
210    match l {
211        Linkage::Static => ED25519_5314,
212        Linkage::Dynamic => Approval::Approved { source: table5(l) },
213    }
214}
215
216/// X25519, in key agreement and as a TLS group, on a module with no security policy: IG C.K
217/// settles it for every module.
218const X25519_NOT_APPROVED: Approval = Approval::NotApproved {
219    source: "FIPS 140-3 IG C.K Resolution 5 (p. 160): X25519 is not an SP 800-56Ar3 key-agreement curve",
220};
221
222const fn three_x(l: Linkage, a: Algorithm) -> Capability {
223    let yes = Approval::Approved { source: table5(l) };
224    let no = Approval::NotApproved { source: absent(l) };
225    let (available, approval) = match a {
226        Algorithm::Signature(s) => match s {
227            SignatureAlgorithm::MlDsa87 => (false, no),
228            SignatureAlgorithm::Ed25519 => (true, ed25519_3x(l)),
229            SignatureAlgorithm::EcdsaP256Sha256
230            | SignatureAlgorithm::EcdsaP384Sha384
231            | SignatureAlgorithm::EcdsaP521Sha384
232            | SignatureAlgorithm::EcdsaP521Sha512
233            | SignatureAlgorithm::Rsa2048Sha384
234            | SignatureAlgorithm::Rsa3072Sha384
235            | SignatureAlgorithm::Rsa4096Sha384
236            | SignatureAlgorithm::Rsa2048Sha384Pss
237            | SignatureAlgorithm::Rsa3072Sha384Pss
238            | SignatureAlgorithm::Rsa4096Sha384Pss => (true, yes),
239        },
240        Algorithm::Scheme(s) => match s {
241            TlsSignatureScheme::MlDsa87 => (false, no),
242            TlsSignatureScheme::Ed25519 => (true, ed25519_3x(l)),
243            TlsSignatureScheme::EcdsaNistp256Sha256
244            | TlsSignatureScheme::EcdsaNistp384Sha384
245            | TlsSignatureScheme::EcdsaNistp521Sha512
246            | TlsSignatureScheme::RsaPssSha256
247            | TlsSignatureScheme::RsaPssSha384
248            | TlsSignatureScheme::RsaPssSha512
249            | TlsSignatureScheme::RsaPkcs1Sha256
250            | TlsSignatureScheme::RsaPkcs1Sha384
251            | TlsSignatureScheme::RsaPkcs1Sha512 => (true, yes),
252        },
253        Algorithm::Kx(k) => match k {
254            KxGroup::MlKem1024 | KxGroup::Secp384r1 | KxGroup::Secp256r1 => (true, yes),
255            KxGroup::X25519 => (
256                true,
257                Approval::NotApproved {
258                    source: x25519_absent(l),
259                },
260            ),
261            KxGroup::X25519MlKem768 | KxGroup::Secp256r1MlKem768 | KxGroup::Secp384r1MlKem1024 => {
262                (true, Approval::Unverified)
263            }
264        },
265        Algorithm::Cipher(c) => match c {
266            CipherSuite::Tls13Aes256GcmSha384
267            | CipherSuite::Tls13Aes128GcmSha256
268            | CipherSuite::Tls12EcdheEcdsaAes256GcmSha384
269            | CipherSuite::Tls12EcdheEcdsaAes128GcmSha256
270            | CipherSuite::Tls12EcdheRsaAes256GcmSha384
271            | CipherSuite::Tls12EcdheRsaAes128GcmSha256 => (true, yes),
272            CipherSuite::Tls13Chacha20Poly1305Sha256
273            | CipherSuite::Tls12EcdheEcdsaChacha20Poly1305Sha256
274            | CipherSuite::Tls12EcdheRsaChacha20Poly1305Sha256 => (true, no),
275        },
276        Algorithm::Hash(h) => match h {
277            HashAlgorithm::Sha256
278            | HashAlgorithm::Sha384
279            | HashAlgorithm::Sha512
280            | HashAlgorithm::Sha3_256
281            | HashAlgorithm::Sha3_384
282            | HashAlgorithm::Sha3_512 => (true, yes),
283        },
284        Algorithm::Protocol(v) => match v {
285            TlsVersion::Tls12 => (
286                true,
287                Approval::NotApproved {
288                    source: tls12_ems(l),
289                },
290            ),
291            TlsVersion::Tls13 => (true, Approval::Unverified),
292        },
293        Algorithm::Mac(m) => match m {
294            MacAlgorithm::HmacSha256 | MacAlgorithm::HmacSha384 | MacAlgorithm::HmacSha512 => {
295                (true, yes)
296            }
297        },
298        Algorithm::Kdf(k) => match k {
299            KdfAlgorithm::HkdfSha256
300            | KdfAlgorithm::HkdfSha384
301            | KdfAlgorithm::HkdfSha512
302            | KdfAlgorithm::OneStepSha256
303            | KdfAlgorithm::OneStepSha384
304            | KdfAlgorithm::OneStepSha512 => (true, yes),
305        },
306        Algorithm::KeyAgreement(k) => match k {
307            KeyAgreementAlgorithm::EcdhP256
308            | KeyAgreementAlgorithm::EcdhP384
309            | KeyAgreementAlgorithm::EcdhP521 => (
310                true,
311                Approval::NotApproved {
312                    source: ecdh_outside_tls(l),
313                },
314            ),
315            KeyAgreementAlgorithm::X25519 => (
316                true,
317                Approval::NotApproved {
318                    source: x25519_absent(l),
319                },
320            ),
321        },
322        Algorithm::Aead(d) => match d {
323            AeadAlgorithm::Aes128Gcm | AeadAlgorithm::Aes256Gcm => (
324                true,
325                Approval::Approved {
326                    source: gcm_scenario_2(l),
327                },
328            ),
329            AeadAlgorithm::Chacha20Poly1305 => (true, no),
330        },
331    };
332    Capability {
333        available,
334        approval,
335    }
336}
337
338const fn four_x(l: Linkage, a: Algorithm) -> Capability {
339    Capability {
340        available: true,
341        approval: four_x_cell(l, a),
342    }
343}
344
345const fn tested_on(l: Linkage, dynamic: &'static str, static_build: &'static str) -> Approval {
346    Approval::AlgorithmTested {
347        cavp: match l {
348            Linkage::Dynamic => dynamic,
349            Linkage::Static => static_build,
350        },
351    }
352}
353
354/// Each `AlgorithmTested` cell cites the lowest-numbered AWS-LC FIPS 4.0.0 CAVP certificate of its
355/// linkage (A7839-A7876 dynamic build, A7886-A7923 static build) that alone shows every operation
356/// the cell needs, with the parameters the citation names (decision 0004).
357const fn four_x_cell(l: Linkage, a: Algorithm) -> Approval {
358    match a {
359        Algorithm::Signature(s) => match s {
360            SignatureAlgorithm::MlDsa87 => tested_on(
361                l,
362                "A7855 (ML-DSA KeyGen, SigGen, SigVer: ML-DSA-87)",
363                "A7902 (ML-DSA KeyGen, SigGen, SigVer: ML-DSA-87)",
364            ),
365            SignatureAlgorithm::Ed25519 => tested_on(
366                l,
367                "A7855 (EDDSA KeyGen, SigGen, SigVer: ED-25519)",
368                "A7902 (EDDSA KeyGen, SigGen, SigVer: ED-25519)",
369            ),
370            SignatureAlgorithm::Rsa2048Sha384 => tested_on(
371                l,
372                "A7873 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pkcs1v1.5, pss, 2048, SHA2-384)",
373                "A7912 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pkcs1v1.5, pss, 2048, SHA2-384)",
374            ),
375            SignatureAlgorithm::Rsa3072Sha384 => tested_on(
376                l,
377                "A7873 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pkcs1v1.5, pss, 3072, SHA2-384)",
378                "A7912 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pkcs1v1.5, pss, 3072, SHA2-384)",
379            ),
380            SignatureAlgorithm::Rsa4096Sha384 => tested_on(
381                l,
382                "A7873 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pkcs1v1.5, pss, 4096, SHA2-384)",
383                "A7912 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pkcs1v1.5, pss, 4096, SHA2-384)",
384            ),
385            SignatureAlgorithm::Rsa2048Sha384Pss => tested_on(
386                l,
387                "A7873 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pss, mgf1, 2048, SHA2-384, salt 48)",
388                "A7912 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pss, mgf1, 2048, SHA2-384, salt 48)",
389            ),
390            SignatureAlgorithm::Rsa3072Sha384Pss => tested_on(
391                l,
392                "A7873 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pss, mgf1, 3072, SHA2-384, salt 48)",
393                "A7912 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pss, mgf1, 3072, SHA2-384, salt 48)",
394            ),
395            SignatureAlgorithm::Rsa4096Sha384Pss => tested_on(
396                l,
397                "A7873 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pss, mgf1, 4096, SHA2-384, salt 48)",
398                "A7912 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pss, mgf1, 4096, SHA2-384, salt 48)",
399            ),
400            SignatureAlgorithm::EcdsaP256Sha256
401            | SignatureAlgorithm::EcdsaP384Sha384
402            | SignatureAlgorithm::EcdsaP521Sha384
403            | SignatureAlgorithm::EcdsaP521Sha512 => Approval::Unverified,
404        },
405        Algorithm::Scheme(t) => match t {
406            TlsSignatureScheme::EcdsaNistp256Sha256 => tested_on(
407                l,
408                "A7856 (ECDSA SigVer (FIPS186-5): P-256, SHA2-256)",
409                "A7903 (ECDSA SigVer (FIPS186-5): P-256, SHA2-256)",
410            ),
411            TlsSignatureScheme::EcdsaNistp384Sha384 => tested_on(
412                l,
413                "A7856 (ECDSA SigVer (FIPS186-5): P-384, SHA2-384)",
414                "A7903 (ECDSA SigVer (FIPS186-5): P-384, SHA2-384)",
415            ),
416            TlsSignatureScheme::EcdsaNistp521Sha512 => tested_on(
417                l,
418                "A7856 (ECDSA SigVer (FIPS186-5): P-521, SHA2-512)",
419                "A7903 (ECDSA SigVer (FIPS186-5): P-521, SHA2-512)",
420            ),
421            TlsSignatureScheme::Ed25519 => tested_on(
422                l,
423                "A7855 (EDDSA SigVer: ED-25519)",
424                "A7902 (EDDSA SigVer: ED-25519)",
425            ),
426            TlsSignatureScheme::RsaPssSha256 => tested_on(
427                l,
428                "A7856 (RSA SigVer (FIPS186-5): pss, 2048, 3072, 4096, SHA2-256)",
429                "A7903 (RSA SigVer (FIPS186-5): pss, 2048, 3072, 4096, SHA2-256)",
430            ),
431            TlsSignatureScheme::RsaPssSha384 => tested_on(
432                l,
433                "A7856 (RSA SigVer (FIPS186-5): pss, 2048, 3072, 4096, SHA2-384)",
434                "A7903 (RSA SigVer (FIPS186-5): pss, 2048, 3072, 4096, SHA2-384)",
435            ),
436            TlsSignatureScheme::RsaPssSha512 => tested_on(
437                l,
438                "A7856 (RSA SigVer (FIPS186-5): pss, 2048, 3072, 4096, SHA2-512)",
439                "A7903 (RSA SigVer (FIPS186-5): pss, 2048, 3072, 4096, SHA2-512)",
440            ),
441            TlsSignatureScheme::RsaPkcs1Sha256 => tested_on(
442                l,
443                "A7856 (RSA SigVer (FIPS186-5): pkcs1v1.5, 2048, 3072, 4096, SHA2-256)",
444                "A7903 (RSA SigVer (FIPS186-5): pkcs1v1.5, 2048, 3072, 4096, SHA2-256)",
445            ),
446            TlsSignatureScheme::RsaPkcs1Sha384 => tested_on(
447                l,
448                "A7856 (RSA SigVer (FIPS186-5): pkcs1v1.5, 2048, 3072, 4096, SHA2-384)",
449                "A7903 (RSA SigVer (FIPS186-5): pkcs1v1.5, 2048, 3072, 4096, SHA2-384)",
450            ),
451            TlsSignatureScheme::RsaPkcs1Sha512 => tested_on(
452                l,
453                "A7856 (RSA SigVer (FIPS186-5): pkcs1v1.5, 2048, 3072, 4096, SHA2-512)",
454                "A7903 (RSA SigVer (FIPS186-5): pkcs1v1.5, 2048, 3072, 4096, SHA2-512)",
455            ),
456            TlsSignatureScheme::MlDsa87 => tested_on(
457                l,
458                "A7855 (ML-DSA SigVer: ML-DSA-87)",
459                "A7902 (ML-DSA SigVer: ML-DSA-87)",
460            ),
461        },
462        Algorithm::Kx(k) => match k {
463            KxGroup::MlKem1024 => tested_on(
464                l,
465                "A7855 (ML-KEM KeyGen, EncapDecap: ML-KEM-1024)",
466                "A7902 (ML-KEM KeyGen, EncapDecap: ML-KEM-1024)",
467            ),
468            KxGroup::Secp384r1 => tested_on(
469                l,
470                "A7864 (KAS-ECC-SSC Sp800-56Ar3: ephemeralUnified, P-384; ECDSA KeyGen (FIPS186-5): P-384)",
471                "A7919 (KAS-ECC-SSC Sp800-56Ar3: ephemeralUnified, P-384; ECDSA KeyGen (FIPS186-5): P-384)",
472            ),
473            KxGroup::Secp256r1 => tested_on(
474                l,
475                "A7864 (KAS-ECC-SSC Sp800-56Ar3: ephemeralUnified, P-256; ECDSA KeyGen (FIPS186-5): P-256)",
476                "A7919 (KAS-ECC-SSC Sp800-56Ar3: ephemeralUnified, P-256; ECDSA KeyGen (FIPS186-5): P-256)",
477            ),
478            KxGroup::X25519 => X25519_NOT_APPROVED,
479            KxGroup::X25519MlKem768 | KxGroup::Secp256r1MlKem768 | KxGroup::Secp384r1MlKem1024 => {
480                Approval::Unverified
481            }
482        },
483        Algorithm::Cipher(c) => match c {
484            CipherSuite::Tls13Aes256GcmSha384
485            | CipherSuite::Tls12EcdheEcdsaAes256GcmSha384
486            | CipherSuite::Tls12EcdheRsaAes256GcmSha384
487            | CipherSuite::Tls13Aes128GcmSha256
488            | CipherSuite::Tls12EcdheEcdsaAes128GcmSha256
489            | CipherSuite::Tls12EcdheRsaAes128GcmSha256
490            | CipherSuite::Tls13Chacha20Poly1305Sha256
491            | CipherSuite::Tls12EcdheEcdsaChacha20Poly1305Sha256
492            | CipherSuite::Tls12EcdheRsaChacha20Poly1305Sha256 => Approval::Unverified,
493        },
494        Algorithm::Hash(h) => match h {
495            HashAlgorithm::Sha256 => tested_on(l, "A7855 (SHA2-256)", "A7902 (SHA2-256)"),
496            HashAlgorithm::Sha384 => tested_on(l, "A7855 (SHA2-384)", "A7902 (SHA2-384)"),
497            HashAlgorithm::Sha512 => tested_on(l, "A7855 (SHA2-512)", "A7902 (SHA2-512)"),
498            HashAlgorithm::Sha3_256 => tested_on(l, "A7855 (SHA3-256)", "A7902 (SHA3-256)"),
499            HashAlgorithm::Sha3_384 => tested_on(l, "A7855 (SHA3-384)", "A7902 (SHA3-384)"),
500            HashAlgorithm::Sha3_512 => tested_on(l, "A7855 (SHA3-512)", "A7902 (SHA3-512)"),
501        },
502        Algorithm::Protocol(v) => match v {
503            TlsVersion::Tls12 | TlsVersion::Tls13 => Approval::Unverified,
504        },
505        Algorithm::Mac(m) => match m {
506            MacAlgorithm::HmacSha256 => tested_on(
507                l,
508                "A7855 (HMAC-SHA2-256: MAC 256, key 112-524288)",
509                "A7902 (HMAC-SHA2-256: MAC 256, key 112-524288)",
510            ),
511            MacAlgorithm::HmacSha384 => tested_on(
512                l,
513                "A7855 (HMAC-SHA2-384: MAC 384, key 112-524288)",
514                "A7902 (HMAC-SHA2-384: MAC 384, key 112-524288)",
515            ),
516            MacAlgorithm::HmacSha512 => tested_on(
517                l,
518                "A7855 (HMAC-SHA2-512: MAC 512, key 112-524288)",
519                "A7902 (HMAC-SHA2-512: MAC 512, key 112-524288)",
520            ),
521        },
522        Algorithm::Kdf(k) => match k {
523            KdfAlgorithm::HkdfSha256 => tested_on(
524                l,
525                "A7855 (KDA HKDF Sp800-56Cr1: HMAC SHA2-256, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo||l)",
526                "A7902 (KDA HKDF Sp800-56Cr1: HMAC SHA2-256, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo||l)",
527            ),
528            KdfAlgorithm::HkdfSha384 => tested_on(
529                l,
530                "A7855 (KDA HKDF Sp800-56Cr1: HMAC SHA2-384, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo||l)",
531                "A7902 (KDA HKDF Sp800-56Cr1: HMAC SHA2-384, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo||l)",
532            ),
533            KdfAlgorithm::HkdfSha512 => tested_on(
534                l,
535                "A7855 (KDA HKDF Sp800-56Cr1: HMAC SHA2-512, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo||l)",
536                "A7902 (KDA HKDF Sp800-56Cr1: HMAC SHA2-512, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo||l)",
537            ),
538            KdfAlgorithm::OneStepSha256 => tested_on(
539                l,
540                "A7856 (KDA OneStep SP800-56Cr2: SHA2-256, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo)",
541                "A7903 (KDA OneStep SP800-56Cr2: SHA2-256, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo)",
542            ),
543            KdfAlgorithm::OneStepSha384 => tested_on(
544                l,
545                "A7856 (KDA OneStep SP800-56Cr2: SHA2-384, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo)",
546                "A7903 (KDA OneStep SP800-56Cr2: SHA2-384, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo)",
547            ),
548            KdfAlgorithm::OneStepSha512 => tested_on(
549                l,
550                "A7856 (KDA OneStep SP800-56Cr2: SHA2-512, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo)",
551                "A7903 (KDA OneStep SP800-56Cr2: SHA2-512, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo)",
552            ),
553        },
554        Algorithm::KeyAgreement(k) => match k {
555            KeyAgreementAlgorithm::EcdhP256 => tested_on(
556                l,
557                "A7864 (KAS-ECC-SSC Sp800-56Ar3: ephemeralUnified, initiator and responder, P-256; ECDSA KeyGen (FIPS186-5): P-256)",
558                "A7919 (KAS-ECC-SSC Sp800-56Ar3: ephemeralUnified, initiator and responder, P-256; ECDSA KeyGen (FIPS186-5): P-256)",
559            ),
560            KeyAgreementAlgorithm::EcdhP384 => tested_on(
561                l,
562                "A7864 (KAS-ECC-SSC Sp800-56Ar3: ephemeralUnified, initiator and responder, P-384; ECDSA KeyGen (FIPS186-5): P-384)",
563                "A7919 (KAS-ECC-SSC Sp800-56Ar3: ephemeralUnified, initiator and responder, P-384; ECDSA KeyGen (FIPS186-5): P-384)",
564            ),
565            KeyAgreementAlgorithm::EcdhP521 => tested_on(
566                l,
567                "A7864 (KAS-ECC-SSC Sp800-56Ar3: ephemeralUnified, initiator and responder, P-521; ECDSA KeyGen (FIPS186-5): P-521)",
568                "A7919 (KAS-ECC-SSC Sp800-56Ar3: ephemeralUnified, initiator and responder, P-521; ECDSA KeyGen (FIPS186-5): P-521)",
569            ),
570            KeyAgreementAlgorithm::X25519 => X25519_NOT_APPROVED,
571        },
572        Algorithm::Aead(d) => match d {
573            AeadAlgorithm::Aes128Gcm => tested_on(
574                l,
575                "A7840 (AES-GCM: Encrypt, IV Generation Internal, 8.2.2; Decrypt, IV Generation External; key 128, IV 96, tag 128)",
576                "A7887 (AES-GCM: Encrypt, IV Generation Internal, 8.2.2; Decrypt, IV Generation External; key 128, IV 96, tag 128)",
577            ),
578            AeadAlgorithm::Aes256Gcm => tested_on(
579                l,
580                "A7840 (AES-GCM: Encrypt, IV Generation Internal, 8.2.2; Decrypt, IV Generation External; key 256, IV 96, tag 128)",
581                "A7887 (AES-GCM: Encrypt, IV Generation Internal, 8.2.2; Decrypt, IV Generation External; key 256, IV 96, tag 128)",
582            ),
583            AeadAlgorithm::Chacha20Poly1305 => Approval::Unverified,
584        },
585    }
586}
587
588/// What the backend for `m` can do for `a`, and what that module's published evidence says about
589/// it: its security policy, or one CAVP certificate (decision 0004).
590pub const fn capability(m: Module, a: Algorithm) -> Capability {
591    match m.line {
592        ModuleLine::AwsLcFips3 => three_x(m.linkage, a),
593        ModuleLine::AwsLcFips4 => four_x(m.linkage, a),
594    }
595}
596
597/// Refuses an algorithm the module's backend does not implement.
598pub fn ensure_available(m: Module, a: Algorithm) -> Result<(), CryptoError> {
599    if capability(m, a).available {
600        Ok(())
601    } else {
602        Err(CryptoError::Unavailable(a))
603    }
604}
605
606#[cfg(test)]
607mod tests {
608    use super::*;
609
610    const M3S: Module = Module {
611        line: ModuleLine::AwsLcFips3,
612        linkage: Linkage::Static,
613    };
614    const M3D: Module = Module {
615        line: ModuleLine::AwsLcFips3,
616        linkage: Linkage::Dynamic,
617    };
618    const M4S: Module = Module {
619        line: ModuleLine::AwsLcFips4,
620        linkage: Linkage::Static,
621    };
622    const M4D: Module = Module {
623        line: ModuleLine::AwsLcFips4,
624        linkage: Linkage::Dynamic,
625    };
626
627    fn modules() -> [Module; 4] {
628        [M3S, M3D, M4S, M4D]
629    }
630
631    const X25519: Algorithm = Algorithm::KeyAgreement(KeyAgreementAlgorithm::X25519);
632    const KX_X25519: Algorithm = Algorithm::Kx(KxGroup::X25519);
633
634    #[test]
635    fn certificates_name_their_module() {
636        let c = certificate(M3S);
637        assert_eq!((c.number, c.status), (Some(5314), CertStatus::Validated));
638        assert!(c.policy.unwrap().ends_with("140sp5314.pdf"));
639        let c = certificate(M3D);
640        assert_eq!((c.number, c.status), (Some(5298), CertStatus::Validated));
641        assert!(c.policy.unwrap().ends_with("140sp5298.pdf"));
642        for m in [M4S, M4D] {
643            let c = certificate(m);
644            assert_eq!(
645                (c.number, c.status, c.policy),
646                (None, CertStatus::InProcess, None)
647            );
648        }
649    }
650
651    #[test]
652    fn every_sourced_cell_cites_its_own_certificate() {
653        for m in modules() {
654            for a in Algorithm::all() {
655                match capability(m, a).approval {
656                    Approval::Approved { source } | Approval::NotApproved { source } => {
657                        assert!(!source.is_empty(), "{m:?} {a:?}");
658                        let want = match (m.line, m.linkage) {
659                            (ModuleLine::AwsLcFips3, Linkage::Static) => "#5314",
660                            (ModuleLine::AwsLcFips3, Linkage::Dynamic) => "#5298",
661                            (ModuleLine::AwsLcFips4, Linkage::Static | Linkage::Dynamic) => {
662                                assert!(a == X25519 || a == KX_X25519, "{m:?} {a:?}");
663                                "FIPS 140-3 IG C.K Resolution 5"
664                            }
665                        };
666                        assert!(source.contains(want), "{m:?} {a:?} cites {source}");
667                    }
668                    Approval::AlgorithmTested { cavp } => {
669                        let range = match (m.line, m.linkage) {
670                            (ModuleLine::AwsLcFips4, Linkage::Dynamic) => 7839..=7876,
671                            (ModuleLine::AwsLcFips4, Linkage::Static) => 7886..=7923,
672                            (ModuleLine::AwsLcFips3, _) => panic!("{m:?} {a:?} cites {cavp}"),
673                        };
674                        let number: u32 = cavp[1..5].parse().unwrap();
675                        assert!(
676                            cavp.starts_with('A') && range.contains(&number),
677                            "{m:?} {a:?} cites {cavp}"
678                        );
679                        assert_eq!(cavp.matches("A7").count(), 1, "{a:?} cites {cavp}");
680                    }
681                    Approval::Unverified => {}
682                }
683            }
684        }
685    }
686
687    #[test]
688    fn x25519_is_not_approved_on_any_module() {
689        for m in modules() {
690            for a in [X25519, KX_X25519] {
691                let c = capability(m, a);
692                assert!(c.available, "{m:?} {a:?}");
693                match c.approval {
694                    Approval::NotApproved { source } => {
695                        assert!(
696                            source.contains("IG C.K Resolution 5 (p. 160)"),
697                            "{m:?} {a:?}"
698                        )
699                    }
700                    other => panic!("{m:?} {a:?}: {other:?}"),
701                }
702            }
703        }
704    }
705
706    #[test]
707    fn three_x_approves_aes_gcm_outside_tls_on_scenario_2() {
708        for (m, cert, scenario) in [
709            (M3S, "#5314 (static)", "Scenario 2, pp. 18-19"),
710            (M3D, "#5298 (dynamic)", "Scenario 2, p. 19"),
711        ] {
712            for d in [AeadAlgorithm::Aes128Gcm, AeadAlgorithm::Aes256Gcm] {
713                let c = capability(m, Algorithm::Aead(d));
714                assert_eq!(
715                    c,
716                    Capability {
717                        available: true,
718                        approval: Approval::Approved {
719                            source: gcm_scenario_2(m.linkage)
720                        }
721                    },
722                    "{m:?} {d:?}"
723                );
724                for want in [
725                    cert,
726                    "Table 5, p. 8",
727                    "IV Generation Internal, IV Generation Mode 8.2.2",
728                    scenario,
729                    "EVP_aead_aes_128_gcm_randnonce, EVP_aead_aes_256_gcm_randnonce",
730                ] {
731                    assert!(gcm_scenario_2(m.linkage).contains(want), "{m:?} {want}");
732                }
733            }
734            assert_eq!(
735                capability(m, Algorithm::Aead(AeadAlgorithm::Chacha20Poly1305)),
736                Capability {
737                    available: true,
738                    approval: Approval::NotApproved {
739                        source: absent(m.linkage)
740                    }
741                },
742                "{m:?}"
743            );
744        }
745    }
746
747    #[test]
748    fn every_hash_cell_is_pinned_to_its_citation() {
749        for (m, cert) in [(M3S, "#5314 (static)"), (M3D, "#5298 (dynamic)")] {
750            for &h in HashAlgorithm::ALL {
751                assert_eq!(
752                    capability(m, Algorithm::Hash(h)),
753                    Capability {
754                        available: true,
755                        approval: Approval::Approved {
756                            source: table5(m.linkage)
757                        }
758                    },
759                    "{m:?} {h:?}"
760                );
761            }
762            assert!(table5(m.linkage).contains(cert), "{m:?}");
763            assert!(table5(m.linkage).contains("Table 5, pp. 8-11"), "{m:?}");
764        }
765        for (m, cert) in [(M4D, "A7855"), (M4S, "A7902")] {
766            for (h, name) in [
767                (HashAlgorithm::Sha256, "SHA2-256"),
768                (HashAlgorithm::Sha384, "SHA2-384"),
769                (HashAlgorithm::Sha512, "SHA2-512"),
770                (HashAlgorithm::Sha3_256, "SHA3-256"),
771                (HashAlgorithm::Sha3_384, "SHA3-384"),
772                (HashAlgorithm::Sha3_512, "SHA3-512"),
773            ] {
774                let want = format!("{cert} ({name})");
775                match capability(m, Algorithm::Hash(h)) {
776                    Capability {
777                        available: true,
778                        approval: Approval::AlgorithmTested { cavp },
779                    } => assert_eq!(cavp, want, "{m:?} {h:?}"),
780                    other => panic!("{m:?} {h:?}: {other:?}"),
781                }
782            }
783        }
784    }
785
786    #[test]
787    fn three_x_does_not_approve_ecdh_outside_tls() {
788        for (m, cert) in [(M3S, "#5314 (static)"), (M3D, "#5298 (dynamic)")] {
789            for k in [
790                KeyAgreementAlgorithm::EcdhP256,
791                KeyAgreementAlgorithm::EcdhP384,
792                KeyAgreementAlgorithm::EcdhP521,
793            ] {
794                let c = capability(m, Algorithm::KeyAgreement(k));
795                assert_eq!(
796                    c,
797                    Capability {
798                        available: true,
799                        approval: Approval::NotApproved {
800                            source: ecdh_outside_tls(m.linkage)
801                        }
802                    },
803                    "{m:?} {k:?}"
804                );
805                let Approval::NotApproved { source } = c.approval else {
806                    panic!("{m:?} {k:?}")
807                };
808                assert!(source.contains(cert), "{source}");
809                assert!(source.contains("p. 20"), "{source}");
810                assert!(source.contains("does not support static keys"), "{source}");
811            }
812        }
813    }
814
815    #[test]
816    fn three_x_static_does_not_approve_ed25519_and_dynamic_does() {
817        for a in [
818            Algorithm::Signature(SignatureAlgorithm::Ed25519),
819            Algorithm::Scheme(TlsSignatureScheme::Ed25519),
820        ] {
821            assert_eq!(
822                capability(M3S, a),
823                Capability {
824                    available: true,
825                    approval: ED25519_5314
826                },
827                "{a:?}"
828            );
829            assert_eq!(
830                capability(M3D, a),
831                Capability {
832                    available: true,
833                    approval: Approval::Approved {
834                        source: table5(Linkage::Dynamic)
835                    }
836                },
837                "{a:?}"
838            );
839        }
840        let Approval::NotApproved { source } = ED25519_5314 else {
841            panic!("{ED25519_5314:?}")
842        };
843        for want in [
844            "#5314 (static)",
845            "Table 12",
846            "pp. 24-25",
847            "RSA and ECDSA",
848            "not EdDSA",
849        ] {
850            assert!(source.contains(want), "{want}");
851        }
852    }
853
854    #[test]
855    fn every_rsa_signature_cell_is_pinned_to_its_citation() {
856        use SignatureAlgorithm as S;
857        for m in [M3S, M3D] {
858            for a in [
859                S::Rsa2048Sha384,
860                S::Rsa3072Sha384,
861                S::Rsa4096Sha384,
862                S::Rsa2048Sha384Pss,
863                S::Rsa3072Sha384Pss,
864                S::Rsa4096Sha384Pss,
865            ] {
866                assert_eq!(
867                    capability(m, Algorithm::Signature(a)),
868                    Capability {
869                        available: true,
870                        approval: Approval::Approved {
871                            source: table5(m.linkage)
872                        }
873                    },
874                    "{m:?} {a}"
875                );
876            }
877        }
878        for (m, cert) in [(M4D, "A7873"), (M4S, "A7912")] {
879            for (a, padding, bits) in [
880                (S::Rsa2048Sha384, "pkcs1v1.5, pss", 2048),
881                (S::Rsa3072Sha384, "pkcs1v1.5, pss", 3072),
882                (S::Rsa4096Sha384, "pkcs1v1.5, pss", 4096),
883                (S::Rsa2048Sha384Pss, "pss, mgf1", 2048),
884                (S::Rsa3072Sha384Pss, "pss, mgf1", 3072),
885                (S::Rsa4096Sha384Pss, "pss, mgf1", 4096),
886            ] {
887                let salt = if padding.starts_with("pss") {
888                    ", salt 48"
889                } else {
890                    ""
891                };
892                let want = format!(
893                    "{cert} (RSA KeyGen, SigGen, SigVer (FIPS186-5): {padding}, {bits}, SHA2-384{salt})"
894                );
895                match capability(m, Algorithm::Signature(a)) {
896                    Capability {
897                        available: true,
898                        approval: Approval::AlgorithmTested { cavp },
899                    } => assert_eq!(cavp, want, "{m:?} {a}"),
900                    other => panic!("{m:?} {a}: {other:?}"),
901                }
902            }
903        }
904    }
905
906    fn four_x_citations() -> [(Algorithm, Option<(&'static str, &'static str)>); 63] {
907        use Algorithm as A;
908        use CipherSuite as C;
909        use HashAlgorithm as H;
910        use KxGroup as K;
911        use SignatureAlgorithm as S;
912        use TlsSignatureScheme as T;
913        use TlsVersion as V;
914        [
915            (
916                A::Signature(S::MlDsa87),
917                Some((
918                    "A7855 (ML-DSA KeyGen, SigGen, SigVer: ML-DSA-87)",
919                    "A7902 (ML-DSA KeyGen, SigGen, SigVer: ML-DSA-87)",
920                )),
921            ),
922            (A::Signature(S::EcdsaP256Sha256), None),
923            (A::Signature(S::EcdsaP384Sha384), None),
924            (A::Signature(S::EcdsaP521Sha384), None),
925            (A::Signature(S::EcdsaP521Sha512), None),
926            (
927                A::Signature(S::Ed25519),
928                Some((
929                    "A7855 (EDDSA KeyGen, SigGen, SigVer: ED-25519)",
930                    "A7902 (EDDSA KeyGen, SigGen, SigVer: ED-25519)",
931                )),
932            ),
933            (
934                A::Signature(S::Rsa2048Sha384),
935                Some((
936                    "A7873 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pkcs1v1.5, pss, 2048, SHA2-384)",
937                    "A7912 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pkcs1v1.5, pss, 2048, SHA2-384)",
938                )),
939            ),
940            (
941                A::Signature(S::Rsa3072Sha384),
942                Some((
943                    "A7873 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pkcs1v1.5, pss, 3072, SHA2-384)",
944                    "A7912 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pkcs1v1.5, pss, 3072, SHA2-384)",
945                )),
946            ),
947            (
948                A::Signature(S::Rsa4096Sha384),
949                Some((
950                    "A7873 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pkcs1v1.5, pss, 4096, SHA2-384)",
951                    "A7912 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pkcs1v1.5, pss, 4096, SHA2-384)",
952                )),
953            ),
954            (
955                A::Signature(S::Rsa2048Sha384Pss),
956                Some((
957                    "A7873 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pss, mgf1, 2048, SHA2-384, salt 48)",
958                    "A7912 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pss, mgf1, 2048, SHA2-384, salt 48)",
959                )),
960            ),
961            (
962                A::Signature(S::Rsa3072Sha384Pss),
963                Some((
964                    "A7873 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pss, mgf1, 3072, SHA2-384, salt 48)",
965                    "A7912 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pss, mgf1, 3072, SHA2-384, salt 48)",
966                )),
967            ),
968            (
969                A::Signature(S::Rsa4096Sha384Pss),
970                Some((
971                    "A7873 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pss, mgf1, 4096, SHA2-384, salt 48)",
972                    "A7912 (RSA KeyGen, SigGen, SigVer (FIPS186-5): pss, mgf1, 4096, SHA2-384, salt 48)",
973                )),
974            ),
975            (
976                A::Scheme(T::EcdsaNistp256Sha256),
977                Some((
978                    "A7856 (ECDSA SigVer (FIPS186-5): P-256, SHA2-256)",
979                    "A7903 (ECDSA SigVer (FIPS186-5): P-256, SHA2-256)",
980                )),
981            ),
982            (
983                A::Scheme(T::EcdsaNistp384Sha384),
984                Some((
985                    "A7856 (ECDSA SigVer (FIPS186-5): P-384, SHA2-384)",
986                    "A7903 (ECDSA SigVer (FIPS186-5): P-384, SHA2-384)",
987                )),
988            ),
989            (
990                A::Scheme(T::EcdsaNistp521Sha512),
991                Some((
992                    "A7856 (ECDSA SigVer (FIPS186-5): P-521, SHA2-512)",
993                    "A7903 (ECDSA SigVer (FIPS186-5): P-521, SHA2-512)",
994                )),
995            ),
996            (
997                A::Scheme(T::Ed25519),
998                Some((
999                    "A7855 (EDDSA SigVer: ED-25519)",
1000                    "A7902 (EDDSA SigVer: ED-25519)",
1001                )),
1002            ),
1003            (
1004                A::Scheme(T::RsaPssSha256),
1005                Some((
1006                    "A7856 (RSA SigVer (FIPS186-5): pss, 2048, 3072, 4096, SHA2-256)",
1007                    "A7903 (RSA SigVer (FIPS186-5): pss, 2048, 3072, 4096, SHA2-256)",
1008                )),
1009            ),
1010            (
1011                A::Scheme(T::RsaPssSha384),
1012                Some((
1013                    "A7856 (RSA SigVer (FIPS186-5): pss, 2048, 3072, 4096, SHA2-384)",
1014                    "A7903 (RSA SigVer (FIPS186-5): pss, 2048, 3072, 4096, SHA2-384)",
1015                )),
1016            ),
1017            (
1018                A::Scheme(T::RsaPssSha512),
1019                Some((
1020                    "A7856 (RSA SigVer (FIPS186-5): pss, 2048, 3072, 4096, SHA2-512)",
1021                    "A7903 (RSA SigVer (FIPS186-5): pss, 2048, 3072, 4096, SHA2-512)",
1022                )),
1023            ),
1024            (
1025                A::Scheme(T::RsaPkcs1Sha256),
1026                Some((
1027                    "A7856 (RSA SigVer (FIPS186-5): pkcs1v1.5, 2048, 3072, 4096, SHA2-256)",
1028                    "A7903 (RSA SigVer (FIPS186-5): pkcs1v1.5, 2048, 3072, 4096, SHA2-256)",
1029                )),
1030            ),
1031            (
1032                A::Scheme(T::RsaPkcs1Sha384),
1033                Some((
1034                    "A7856 (RSA SigVer (FIPS186-5): pkcs1v1.5, 2048, 3072, 4096, SHA2-384)",
1035                    "A7903 (RSA SigVer (FIPS186-5): pkcs1v1.5, 2048, 3072, 4096, SHA2-384)",
1036                )),
1037            ),
1038            (
1039                A::Scheme(T::RsaPkcs1Sha512),
1040                Some((
1041                    "A7856 (RSA SigVer (FIPS186-5): pkcs1v1.5, 2048, 3072, 4096, SHA2-512)",
1042                    "A7903 (RSA SigVer (FIPS186-5): pkcs1v1.5, 2048, 3072, 4096, SHA2-512)",
1043                )),
1044            ),
1045            (
1046                A::Scheme(T::MlDsa87),
1047                Some((
1048                    "A7855 (ML-DSA SigVer: ML-DSA-87)",
1049                    "A7902 (ML-DSA SigVer: ML-DSA-87)",
1050                )),
1051            ),
1052            (
1053                A::Kx(K::MlKem1024),
1054                Some((
1055                    "A7855 (ML-KEM KeyGen, EncapDecap: ML-KEM-1024)",
1056                    "A7902 (ML-KEM KeyGen, EncapDecap: ML-KEM-1024)",
1057                )),
1058            ),
1059            (A::Kx(K::Secp384r1MlKem1024), None),
1060            (A::Kx(K::X25519MlKem768), None),
1061            (A::Kx(K::Secp256r1MlKem768), None),
1062            (
1063                A::Kx(K::Secp384r1),
1064                Some((
1065                    "A7864 (KAS-ECC-SSC Sp800-56Ar3: ephemeralUnified, P-384; ECDSA KeyGen (FIPS186-5): P-384)",
1066                    "A7919 (KAS-ECC-SSC Sp800-56Ar3: ephemeralUnified, P-384; ECDSA KeyGen (FIPS186-5): P-384)",
1067                )),
1068            ),
1069            (
1070                A::Kx(K::Secp256r1),
1071                Some((
1072                    "A7864 (KAS-ECC-SSC Sp800-56Ar3: ephemeralUnified, P-256; ECDSA KeyGen (FIPS186-5): P-256)",
1073                    "A7919 (KAS-ECC-SSC Sp800-56Ar3: ephemeralUnified, P-256; ECDSA KeyGen (FIPS186-5): P-256)",
1074                )),
1075            ),
1076            (A::Kx(K::X25519), None),
1077            (A::Cipher(C::Tls13Aes256GcmSha384), None),
1078            (A::Cipher(C::Tls13Aes128GcmSha256), None),
1079            (A::Cipher(C::Tls13Chacha20Poly1305Sha256), None),
1080            (A::Cipher(C::Tls12EcdheEcdsaAes256GcmSha384), None),
1081            (A::Cipher(C::Tls12EcdheEcdsaAes128GcmSha256), None),
1082            (A::Cipher(C::Tls12EcdheEcdsaChacha20Poly1305Sha256), None),
1083            (A::Cipher(C::Tls12EcdheRsaAes256GcmSha384), None),
1084            (A::Cipher(C::Tls12EcdheRsaAes128GcmSha256), None),
1085            (A::Cipher(C::Tls12EcdheRsaChacha20Poly1305Sha256), None),
1086            (
1087                A::Hash(H::Sha256),
1088                Some(("A7855 (SHA2-256)", "A7902 (SHA2-256)")),
1089            ),
1090            (
1091                A::Hash(H::Sha384),
1092                Some(("A7855 (SHA2-384)", "A7902 (SHA2-384)")),
1093            ),
1094            (
1095                A::Hash(H::Sha512),
1096                Some(("A7855 (SHA2-512)", "A7902 (SHA2-512)")),
1097            ),
1098            (
1099                A::Hash(H::Sha3_256),
1100                Some(("A7855 (SHA3-256)", "A7902 (SHA3-256)")),
1101            ),
1102            (
1103                A::Hash(H::Sha3_384),
1104                Some(("A7855 (SHA3-384)", "A7902 (SHA3-384)")),
1105            ),
1106            (
1107                A::Hash(H::Sha3_512),
1108                Some(("A7855 (SHA3-512)", "A7902 (SHA3-512)")),
1109            ),
1110            (A::Protocol(V::Tls12), None),
1111            (A::Protocol(V::Tls13), None),
1112            (
1113                A::Mac(MacAlgorithm::HmacSha256),
1114                Some((
1115                    "A7855 (HMAC-SHA2-256: MAC 256, key 112-524288)",
1116                    "A7902 (HMAC-SHA2-256: MAC 256, key 112-524288)",
1117                )),
1118            ),
1119            (
1120                A::Mac(MacAlgorithm::HmacSha384),
1121                Some((
1122                    "A7855 (HMAC-SHA2-384: MAC 384, key 112-524288)",
1123                    "A7902 (HMAC-SHA2-384: MAC 384, key 112-524288)",
1124                )),
1125            ),
1126            (
1127                A::Mac(MacAlgorithm::HmacSha512),
1128                Some((
1129                    "A7855 (HMAC-SHA2-512: MAC 512, key 112-524288)",
1130                    "A7902 (HMAC-SHA2-512: MAC 512, key 112-524288)",
1131                )),
1132            ),
1133            (
1134                A::Kdf(KdfAlgorithm::HkdfSha256),
1135                Some((
1136                    "A7855 (KDA HKDF Sp800-56Cr1: HMAC SHA2-256, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo||l)",
1137                    "A7902 (KDA HKDF Sp800-56Cr1: HMAC SHA2-256, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo||l)",
1138                )),
1139            ),
1140            (
1141                A::Kdf(KdfAlgorithm::HkdfSha384),
1142                Some((
1143                    "A7855 (KDA HKDF Sp800-56Cr1: HMAC SHA2-384, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo||l)",
1144                    "A7902 (KDA HKDF Sp800-56Cr1: HMAC SHA2-384, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo||l)",
1145                )),
1146            ),
1147            (
1148                A::Kdf(KdfAlgorithm::HkdfSha512),
1149                Some((
1150                    "A7855 (KDA HKDF Sp800-56Cr1: HMAC SHA2-512, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo||l)",
1151                    "A7902 (KDA HKDF Sp800-56Cr1: HMAC SHA2-512, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo||l)",
1152                )),
1153            ),
1154            (
1155                A::Kdf(KdfAlgorithm::OneStepSha256),
1156                Some((
1157                    "A7856 (KDA OneStep SP800-56Cr2: SHA2-256, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo)",
1158                    "A7903 (KDA OneStep SP800-56Cr2: SHA2-256, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo)",
1159                )),
1160            ),
1161            (
1162                A::Kdf(KdfAlgorithm::OneStepSha384),
1163                Some((
1164                    "A7856 (KDA OneStep SP800-56Cr2: SHA2-384, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo)",
1165                    "A7903 (KDA OneStep SP800-56Cr2: SHA2-384, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo)",
1166                )),
1167            ),
1168            (
1169                A::Kdf(KdfAlgorithm::OneStepSha512),
1170                Some((
1171                    "A7856 (KDA OneStep SP800-56Cr2: SHA2-512, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo)",
1172                    "A7903 (KDA OneStep SP800-56Cr2: SHA2-512, shared secret 224-2048, derived key 2048, fixed info uPartyInfo||vPartyInfo)",
1173                )),
1174            ),
1175            (
1176                A::KeyAgreement(KeyAgreementAlgorithm::EcdhP256),
1177                Some((
1178                    "A7864 (KAS-ECC-SSC Sp800-56Ar3: ephemeralUnified, initiator and responder, P-256; ECDSA KeyGen (FIPS186-5): P-256)",
1179                    "A7919 (KAS-ECC-SSC Sp800-56Ar3: ephemeralUnified, initiator and responder, P-256; ECDSA KeyGen (FIPS186-5): P-256)",
1180                )),
1181            ),
1182            (
1183                A::KeyAgreement(KeyAgreementAlgorithm::EcdhP384),
1184                Some((
1185                    "A7864 (KAS-ECC-SSC Sp800-56Ar3: ephemeralUnified, initiator and responder, P-384; ECDSA KeyGen (FIPS186-5): P-384)",
1186                    "A7919 (KAS-ECC-SSC Sp800-56Ar3: ephemeralUnified, initiator and responder, P-384; ECDSA KeyGen (FIPS186-5): P-384)",
1187                )),
1188            ),
1189            (
1190                A::KeyAgreement(KeyAgreementAlgorithm::EcdhP521),
1191                Some((
1192                    "A7864 (KAS-ECC-SSC Sp800-56Ar3: ephemeralUnified, initiator and responder, P-521; ECDSA KeyGen (FIPS186-5): P-521)",
1193                    "A7919 (KAS-ECC-SSC Sp800-56Ar3: ephemeralUnified, initiator and responder, P-521; ECDSA KeyGen (FIPS186-5): P-521)",
1194                )),
1195            ),
1196            (X25519, None),
1197            (
1198                A::Aead(AeadAlgorithm::Aes128Gcm),
1199                Some((
1200                    "A7840 (AES-GCM: Encrypt, IV Generation Internal, 8.2.2; Decrypt, IV Generation External; key 128, IV 96, tag 128)",
1201                    "A7887 (AES-GCM: Encrypt, IV Generation Internal, 8.2.2; Decrypt, IV Generation External; key 128, IV 96, tag 128)",
1202                )),
1203            ),
1204            (
1205                A::Aead(AeadAlgorithm::Aes256Gcm),
1206                Some((
1207                    "A7840 (AES-GCM: Encrypt, IV Generation Internal, 8.2.2; Decrypt, IV Generation External; key 256, IV 96, tag 128)",
1208                    "A7887 (AES-GCM: Encrypt, IV Generation Internal, 8.2.2; Decrypt, IV Generation External; key 256, IV 96, tag 128)",
1209                )),
1210            ),
1211            (A::Aead(AeadAlgorithm::Chacha20Poly1305), None),
1212        ]
1213    }
1214
1215    fn four_x_cells_are_pinned(m: Module) {
1216        let expected = four_x_citations();
1217        assert_eq!(expected.len(), Algorithm::all().len());
1218        assert!(
1219            Algorithm::all()
1220                .iter()
1221                .all(|a| expected.iter().any(|(b, _)| b == a))
1222        );
1223        assert_eq!(expected.iter().filter(|(_, c)| c.is_some()).count(), 42);
1224        for (a, cavp) in expected {
1225            let approval = match (cavp, m.linkage) {
1226                (Some((cavp, _)), Linkage::Dynamic) | (Some((_, cavp)), Linkage::Static) => {
1227                    Approval::AlgorithmTested { cavp }
1228                }
1229                (None, _) if a == X25519 || a == KX_X25519 => X25519_NOT_APPROVED,
1230                (None, _) => Approval::Unverified,
1231            };
1232            assert_eq!(
1233                capability(m, a),
1234                Capability {
1235                    available: true,
1236                    approval
1237                },
1238                "{m:?} {a:?}"
1239            );
1240            assert!(!approval.is_approved(), "{a:?}");
1241        }
1242    }
1243
1244    #[test]
1245    fn four_x_dynamic_cells_are_pinned_to_their_cavp_certificates() {
1246        four_x_cells_are_pinned(M4D);
1247    }
1248
1249    #[test]
1250    fn four_x_static_cells_are_pinned_to_their_cavp_certificates() {
1251        four_x_cells_are_pinned(M4S);
1252    }
1253
1254    #[test]
1255    fn each_static_certificate_is_the_dynamic_ones_counterpart() {
1256        let pairs = [
1257            ("A7855", "A7902"),
1258            ("A7856", "A7903"),
1259            ("A7873", "A7912"),
1260            ("A7864", "A7919"),
1261            ("A7840", "A7887"),
1262        ];
1263        for (a, cavp) in four_x_citations() {
1264            if let Some((dynamic, static_build)) = cavp {
1265                assert!(
1266                    pairs.contains(&(&dynamic[..5], &static_build[..5])),
1267                    "{a:?}: {dynamic} / {static_build}"
1268                );
1269                assert_eq!(dynamic[5..], static_build[5..], "{a:?}");
1270            }
1271        }
1272    }
1273
1274    #[test]
1275    fn three_x_lacks_only_ml_dsa() {
1276        for m in [M3S, M3D] {
1277            for a in Algorithm::all() {
1278                let ml_dsa = matches!(
1279                    a,
1280                    Algorithm::Signature(SignatureAlgorithm::MlDsa87)
1281                        | Algorithm::Scheme(TlsSignatureScheme::MlDsa87)
1282                );
1283                assert_eq!(capability(m, a).available, !ml_dsa, "{m:?} {a:?}");
1284            }
1285        }
1286    }
1287
1288    #[test]
1289    fn three_x_tls12_is_not_approved_without_an_ems_kdf_test() {
1290        for (m, module_label, services) in [
1291            (M3S, "#5314 (static)", "p. 25"),
1292            (M3D, "#5298 (dynamic)", "p. 26"),
1293        ] {
1294            let Approval::NotApproved { source } =
1295                capability(m, Algorithm::Protocol(TlsVersion::Tls12)).approval
1296            else {
1297                panic!("{m:?}: TLS 1.2 is not NotApproved");
1298            };
1299            for part in [
1300                module_label,
1301                services,
1302                "Table 5",
1303                "Table 8",
1304                "IG D.Q",
1305                "p. 205",
1306                "RFC 7627",
1307                "IG 2.4.B item 6",
1308            ] {
1309                assert!(source.contains(part), "{m:?}: {part} missing from {source}");
1310            }
1311        }
1312    }
1313
1314    #[test]
1315    fn three_x_approval_matches_the_security_policies() {
1316        use Algorithm as A;
1317        let approved = |a| capability(M3S, a).approval.is_approved();
1318        assert!(approved(A::Signature(SignatureAlgorithm::Rsa2048Sha384)));
1319        assert!(approved(A::Signature(SignatureAlgorithm::Rsa4096Sha384Pss)));
1320        assert!(approved(A::Signature(SignatureAlgorithm::EcdsaP521Sha384)));
1321        assert!(approved(A::Kx(KxGroup::MlKem1024)));
1322        assert!(approved(A::Kx(KxGroup::Secp384r1)));
1323        assert!(approved(A::Cipher(CipherSuite::Tls13Aes128GcmSha256)));
1324        assert!(approved(A::Hash(HashAlgorithm::Sha512)));
1325        assert!(approved(A::Hash(HashAlgorithm::Sha3_256)));
1326        assert!(approved(A::Mac(MacAlgorithm::HmacSha384)));
1327        assert!(approved(A::Kdf(KdfAlgorithm::HkdfSha512)));
1328        assert!(approved(A::Kdf(KdfAlgorithm::OneStepSha256)));
1329        assert!(approved(A::Aead(AeadAlgorithm::Aes128Gcm)));
1330        assert!(approved(A::Aead(AeadAlgorithm::Aes256Gcm)));
1331        for a in [
1332            A::Signature(SignatureAlgorithm::MlDsa87),
1333            A::Scheme(TlsSignatureScheme::MlDsa87),
1334            A::Kx(KxGroup::X25519),
1335            A::Cipher(CipherSuite::Tls13Chacha20Poly1305Sha256),
1336            A::Cipher(CipherSuite::Tls12EcdheRsaChacha20Poly1305Sha256),
1337            A::Aead(AeadAlgorithm::Chacha20Poly1305),
1338            A::Protocol(TlsVersion::Tls12),
1339        ] {
1340            assert!(
1341                matches!(capability(M3S, a).approval, Approval::NotApproved { .. }),
1342                "{a:?}"
1343            );
1344        }
1345        for a in [
1346            A::Kx(KxGroup::X25519MlKem768),
1347            A::Kx(KxGroup::Secp256r1MlKem768),
1348            A::Protocol(TlsVersion::Tls13),
1349        ] {
1350            assert_eq!(capability(M3S, a).approval, Approval::Unverified, "{a:?}");
1351        }
1352    }
1353
1354    #[test]
1355    fn unverified_is_never_approved() {
1356        assert!(!Approval::Unverified.is_approved());
1357        assert!(!Approval::AlgorithmTested { cavp: "A7855" }.is_approved());
1358        assert!(!Approval::NotApproved { source: "x" }.is_approved());
1359        assert!(Approval::Approved { source: "x" }.is_approved());
1360    }
1361
1362    #[test]
1363    fn ensure_available_refuses_ml_dsa_on_3x() {
1364        let a = Algorithm::Signature(SignatureAlgorithm::MlDsa87);
1365        assert_eq!(ensure_available(M3S, a), Err(CryptoError::Unavailable(a)));
1366        assert_eq!(ensure_available(M4S, a), Ok(()));
1367    }
1368
1369    #[test]
1370    fn three_x_table_is_pinned_cell_by_cell() {
1371        use Algorithm as A;
1372        use SignatureAlgorithm as S;
1373        use TlsSignatureScheme as T;
1374        #[derive(Debug, Clone, Copy, PartialEq)]
1375        enum K {
1376            Approved,
1377            NotApproved,
1378            Unverified,
1379            StaticNotApproved,
1380        }
1381        use K::{Approved as Y, NotApproved as N, StaticNotApproved as E, Unverified as U};
1382        let expected: [(Algorithm, bool, K); 63] = [
1383            (A::Signature(S::MlDsa87), false, N),
1384            (A::Signature(S::EcdsaP256Sha256), true, Y),
1385            (A::Signature(S::EcdsaP384Sha384), true, Y),
1386            (A::Signature(S::EcdsaP521Sha384), true, Y),
1387            (A::Signature(S::EcdsaP521Sha512), true, Y),
1388            (A::Signature(S::Ed25519), true, E),
1389            (A::Signature(S::Rsa2048Sha384), true, Y),
1390            (A::Signature(S::Rsa3072Sha384), true, Y),
1391            (A::Signature(S::Rsa4096Sha384), true, Y),
1392            (A::Signature(S::Rsa2048Sha384Pss), true, Y),
1393            (A::Signature(S::Rsa3072Sha384Pss), true, Y),
1394            (A::Signature(S::Rsa4096Sha384Pss), true, Y),
1395            (A::Scheme(T::EcdsaNistp256Sha256), true, Y),
1396            (A::Scheme(T::EcdsaNistp384Sha384), true, Y),
1397            (A::Scheme(T::EcdsaNistp521Sha512), true, Y),
1398            (A::Scheme(T::Ed25519), true, E),
1399            (A::Scheme(T::RsaPssSha256), true, Y),
1400            (A::Scheme(T::RsaPssSha384), true, Y),
1401            (A::Scheme(T::RsaPssSha512), true, Y),
1402            (A::Scheme(T::RsaPkcs1Sha256), true, Y),
1403            (A::Scheme(T::RsaPkcs1Sha384), true, Y),
1404            (A::Scheme(T::RsaPkcs1Sha512), true, Y),
1405            (A::Scheme(T::MlDsa87), false, N),
1406            (A::Kx(KxGroup::MlKem1024), true, Y),
1407            (A::Kx(KxGroup::Secp384r1MlKem1024), true, U),
1408            (A::Kx(KxGroup::X25519MlKem768), true, U),
1409            (A::Kx(KxGroup::Secp256r1MlKem768), true, U),
1410            (A::Kx(KxGroup::Secp384r1), true, Y),
1411            (A::Kx(KxGroup::Secp256r1), true, Y),
1412            (A::Kx(KxGroup::X25519), true, N),
1413            (A::Cipher(CipherSuite::Tls13Aes256GcmSha384), true, Y),
1414            (A::Cipher(CipherSuite::Tls13Aes128GcmSha256), true, Y),
1415            (A::Cipher(CipherSuite::Tls13Chacha20Poly1305Sha256), true, N),
1416            (
1417                A::Cipher(CipherSuite::Tls12EcdheEcdsaAes256GcmSha384),
1418                true,
1419                Y,
1420            ),
1421            (
1422                A::Cipher(CipherSuite::Tls12EcdheEcdsaAes128GcmSha256),
1423                true,
1424                Y,
1425            ),
1426            (
1427                A::Cipher(CipherSuite::Tls12EcdheEcdsaChacha20Poly1305Sha256),
1428                true,
1429                N,
1430            ),
1431            (
1432                A::Cipher(CipherSuite::Tls12EcdheRsaAes256GcmSha384),
1433                true,
1434                Y,
1435            ),
1436            (
1437                A::Cipher(CipherSuite::Tls12EcdheRsaAes128GcmSha256),
1438                true,
1439                Y,
1440            ),
1441            (
1442                A::Cipher(CipherSuite::Tls12EcdheRsaChacha20Poly1305Sha256),
1443                true,
1444                N,
1445            ),
1446            (A::Hash(HashAlgorithm::Sha256), true, Y),
1447            (A::Hash(HashAlgorithm::Sha384), true, Y),
1448            (A::Hash(HashAlgorithm::Sha512), true, Y),
1449            (A::Hash(HashAlgorithm::Sha3_256), true, Y),
1450            (A::Hash(HashAlgorithm::Sha3_384), true, Y),
1451            (A::Hash(HashAlgorithm::Sha3_512), true, Y),
1452            (A::Protocol(TlsVersion::Tls12), true, N),
1453            (A::Protocol(TlsVersion::Tls13), true, U),
1454            (A::Mac(MacAlgorithm::HmacSha256), true, Y),
1455            (A::Mac(MacAlgorithm::HmacSha384), true, Y),
1456            (A::Mac(MacAlgorithm::HmacSha512), true, Y),
1457            (A::Kdf(KdfAlgorithm::HkdfSha256), true, Y),
1458            (A::Kdf(KdfAlgorithm::HkdfSha384), true, Y),
1459            (A::Kdf(KdfAlgorithm::HkdfSha512), true, Y),
1460            (A::Kdf(KdfAlgorithm::OneStepSha256), true, Y),
1461            (A::Kdf(KdfAlgorithm::OneStepSha384), true, Y),
1462            (A::Kdf(KdfAlgorithm::OneStepSha512), true, Y),
1463            (A::KeyAgreement(KeyAgreementAlgorithm::EcdhP256), true, N),
1464            (A::KeyAgreement(KeyAgreementAlgorithm::EcdhP384), true, N),
1465            (A::KeyAgreement(KeyAgreementAlgorithm::EcdhP521), true, N),
1466            (X25519, true, N),
1467            (A::Aead(AeadAlgorithm::Aes128Gcm), true, Y),
1468            (A::Aead(AeadAlgorithm::Aes256Gcm), true, Y),
1469            (A::Aead(AeadAlgorithm::Chacha20Poly1305), true, N),
1470        ];
1471        assert_eq!(expected.len(), Algorithm::all().len());
1472        for m in [M3S, M3D] {
1473            for (a, available, kind) in &expected {
1474                let c = capability(m, *a);
1475                let got = match c.approval {
1476                    Approval::Approved { .. } => K::Approved,
1477                    Approval::NotApproved { .. } => K::NotApproved,
1478                    Approval::Unverified => K::Unverified,
1479                    Approval::AlgorithmTested { cavp } => panic!("{m:?} {a:?}: 3.x cites {cavp}"),
1480                };
1481                let want = match (kind, m.linkage) {
1482                    (K::StaticNotApproved, Linkage::Static) => K::NotApproved,
1483                    (K::StaticNotApproved, Linkage::Dynamic) => K::Approved,
1484                    (other, _) => *other,
1485                };
1486                assert_eq!((c.available, got), (*available, want), "{m:?} {a:?}");
1487            }
1488        }
1489    }
1490}