crypto-profile 0.10.0

Named cryptographic profiles over the AWS-LC FIPS module: algorithm types, per-module capabilities and a conformance suite
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
//! The profile golden tables every backend's `resolve` is checked against; literal IANA
//! codepoints and key names. The three rows the option leaves empty (`cnsa1`, `bsi` and `fips1402`
//! with the option) specify the refusal `resolve` gives; their lists are never compared with a
//! resolved profile.
use crate::{
    AeadAlgorithm, Algorithm, CryptoError, Family, HashAlgorithm, KdfAlgorithm,
    KeyAgreementAlgorithm, MacAlgorithm, Module, ModuleLine, Options, Profile, SignatureAlgorithm,
    TlsSignatureScheme,
};

/// One profile's lists, with or without the option.
#[doc(hidden)]
#[derive(Debug, Clone)]
pub struct Golden {
    /// The profile.
    pub profile: Profile,
    /// Whether post-quantum key exchange is required.
    pub pq: bool,
    /// Protocol versions.
    pub versions: &'static [u16],
    /// Cipher suites.
    pub suites: &'static [u16],
    /// Key-exchange groups.
    pub groups: &'static [u16],
    /// Handshake signature schemes.
    pub schemes: &'static [u16],
    /// Key algorithms.
    pub keys: &'static [&'static str],
    /// Entries excluded by the module line, in family and preference order.
    pub excluded: &'static [Algorithm],
}

/// Every handshake scheme, in canonical order.
#[doc(hidden)]
pub const ALL_SCHEMES: &[u16] = &[
    0x0906, 0x0503, 0x0403, 0x0603, 0x0807, 0x0805, 0x0806, 0x0804, 0x0501, 0x0601, 0x0401,
];
/// Every handshake scheme but RSA PKCS#1 v1.5, in canonical order.
#[doc(hidden)]
pub const ALL_SCHEMES_BUT_PKCS1: &[u16] = &[
    0x0906, 0x0503, 0x0403, 0x0603, 0x0807, 0x0805, 0x0806, 0x0804,
];
/// Every key algorithm, in preference order.
#[doc(hidden)]
pub const ALL_KEYS: &[&str] = &[
    "ml-dsa-87",
    "ecdsa-p384-sha384",
    "ecdsa-p256-sha256",
    "ecdsa-p521-sha512",
    "ecdsa-p521-sha384",
    "ed25519",
    "rsa3072-sha384",
    "rsa4096-sha384",
    "rsa2048-sha384",
];
/// The cipher suites of `bsi`, `fips1403` and `fips1402`.
#[doc(hidden)]
pub const FIPS_SUITES: &[u16] = &[0x1302, 0x1301, 0xC02C, 0xC030, 0xC02B, 0xC02F];
/// `preferred`'s handshake schemes.
#[doc(hidden)]
pub const PREFERRED_SCHEMES: &[u16] = &[0x0906, 0x0503, 0x0403, 0x0603, 0x0805, 0x0806, 0x0804];
/// `preferred`'s key algorithms.
#[doc(hidden)]
pub const PREFERRED_KEYS: &[&str] = &[
    "ml-dsa-87",
    "ecdsa-p384-sha384",
    "ecdsa-p256-sha256",
    "ecdsa-p521-sha512",
    "ecdsa-p521-sha384",
    "rsa3072-sha384",
    "rsa4096-sha384",
];

/// One row per profile and option value.
#[doc(hidden)]
pub const GOLDEN: &[Golden] = &[
    Golden {
        excluded: &[],
        profile: Profile::Unrestricted,
        pq: false,
        versions: &[0x0304, 0x0303],
        suites: &[
            0x1302, 0x1301, 0x1303, 0xC02C, 0xC030, 0xC02B, 0xC02F, 0xCCA9, 0xCCA8,
        ],
        groups: &[0x0202, 0x11ED, 0x11EC, 0x11EB, 0x0018, 0x0017, 0x001D],
        schemes: ALL_SCHEMES,
        keys: ALL_KEYS,
    },
    Golden {
        excluded: &[],
        profile: Profile::Unrestricted,
        pq: true,
        versions: &[0x0304],
        suites: &[0x1302, 0x1301, 0x1303],
        groups: &[0x0202, 0x11ED, 0x11EC, 0x11EB],
        schemes: ALL_SCHEMES_BUT_PKCS1,
        keys: ALL_KEYS,
    },
    Golden {
        excluded: &[],
        profile: Profile::Preferred,
        pq: false,
        versions: &[0x0304],
        suites: &[0x1302, 0x1301],
        groups: &[0x0202, 0x11ED, 0x11EC, 0x11EB, 0x0018, 0x0017],
        schemes: PREFERRED_SCHEMES,
        keys: PREFERRED_KEYS,
    },
    Golden {
        excluded: &[],
        profile: Profile::Preferred,
        pq: true,
        versions: &[0x0304],
        suites: &[0x1302, 0x1301],
        groups: &[0x0202, 0x11ED, 0x11EC, 0x11EB],
        schemes: PREFERRED_SCHEMES,
        keys: PREFERRED_KEYS,
    },
    Golden {
        excluded: &[],
        profile: Profile::Cnsa2,
        pq: false,
        versions: &[0x0304],
        suites: &[0x1302],
        groups: &[0x0202],
        schemes: &[0x0906],
        keys: &["ml-dsa-87"],
    },
    Golden {
        excluded: &[],
        profile: Profile::Cnsa2,
        pq: true,
        versions: &[0x0304],
        suites: &[0x1302],
        groups: &[0x0202],
        schemes: &[0x0906],
        keys: &["ml-dsa-87"],
    },
    Golden {
        excluded: &[],
        profile: Profile::Cnsa1,
        pq: false,
        versions: &[0x0304, 0x0303],
        suites: &[0x1302, 0xC02C, 0xC030],
        groups: &[0x0018],
        schemes: &[0x0503, 0x0805, 0x0501],
        keys: &["ecdsa-p384-sha384", "rsa3072-sha384", "rsa4096-sha384"],
    },
    Golden {
        excluded: &[],
        profile: Profile::Bsi,
        pq: false,
        versions: &[0x0304, 0x0303],
        suites: FIPS_SUITES,
        groups: &[0x0018, 0x0017],
        schemes: &[0x0503, 0x0403, 0x0603, 0x0805, 0x0806, 0x0804],
        keys: &[
            "ecdsa-p384-sha384",
            "ecdsa-p256-sha256",
            "ecdsa-p521-sha512",
        ],
    },
    Golden {
        excluded: &[],
        profile: Profile::Fips1403,
        pq: false,
        versions: &[0x0304, 0x0303],
        suites: FIPS_SUITES,
        groups: &[0x0202, 0x11ED, 0x11EC, 0x11EB, 0x0018, 0x0017],
        schemes: ALL_SCHEMES,
        keys: ALL_KEYS,
    },
    Golden {
        excluded: &[],
        profile: Profile::Fips1403,
        pq: true,
        versions: &[0x0304],
        suites: &[0x1302, 0x1301],
        groups: &[0x0202, 0x11ED, 0x11EC, 0x11EB],
        schemes: ALL_SCHEMES_BUT_PKCS1,
        keys: ALL_KEYS,
    },
    Golden {
        excluded: &[],
        profile: Profile::Fips1402,
        pq: false,
        versions: &[0x0304, 0x0303],
        suites: FIPS_SUITES,
        groups: &[0x0018, 0x0017],
        schemes: &[
            0x0503, 0x0403, 0x0603, 0x0805, 0x0806, 0x0804, 0x0501, 0x0601, 0x0401,
        ],
        keys: &[
            "ecdsa-p384-sha384",
            "ecdsa-p256-sha256",
            "ecdsa-p521-sha512",
            "ecdsa-p521-sha384",
            "rsa3072-sha384",
            "rsa4096-sha384",
            "rsa2048-sha384",
        ],
    },
    Golden {
        excluded: &[],
        profile: Profile::Cnsa1,
        pq: true,
        versions: &[0x0304],
        suites: &[0x1302],
        groups: &[],
        schemes: &[0x0503, 0x0805],
        keys: &["ecdsa-p384-sha384", "rsa3072-sha384", "rsa4096-sha384"],
    },
    Golden {
        excluded: &[],
        profile: Profile::Bsi,
        pq: true,
        versions: &[0x0304],
        suites: &[0x1302, 0x1301],
        groups: &[],
        schemes: &[0x0503, 0x0403, 0x0603, 0x0805, 0x0806, 0x0804],
        keys: &[
            "ecdsa-p384-sha384",
            "ecdsa-p256-sha256",
            "ecdsa-p521-sha512",
        ],
    },
    Golden {
        excluded: &[],
        profile: Profile::Fips1402,
        pq: true,
        versions: &[0x0304],
        suites: &[0x1302, 0x1301],
        groups: &[],
        schemes: &[0x0503, 0x0403, 0x0603, 0x0805, 0x0806, 0x0804],
        keys: &[
            "ecdsa-p384-sha384",
            "ecdsa-p256-sha256",
            "ecdsa-p521-sha512",
            "ecdsa-p521-sha384",
            "rsa3072-sha384",
            "rsa4096-sha384",
            "rsa2048-sha384",
        ],
    },
];

/// The independent per-line golden row, or the first empty-family refusal.
#[doc(hidden)]
pub fn expected(module: Module, profile: Profile, options: Options) -> Result<Golden, CryptoError> {
    let mut g = GOLDEN
        .iter()
        .find(|g| g.profile == profile && g.pq == options.pq_key_exchange_required)
        .unwrap_or_else(|| panic!("no golden row for {profile} {options}"))
        .clone();
    match module.line {
        ModuleLine::AwsLcFips4 => {}
        ModuleLine::AwsLcFips3 => {
            match profile {
                Profile::Unrestricted | Profile::Fips1403 => {
                    g.schemes = if options.pq_key_exchange_required {
                        &[0x0503, 0x0403, 0x0603, 0x0807, 0x0805, 0x0806, 0x0804]
                    } else {
                        &[
                            0x0503, 0x0403, 0x0603, 0x0807, 0x0805, 0x0806, 0x0804, 0x0501, 0x0601,
                            0x0401,
                        ]
                    };
                    g.keys = &[
                        "ecdsa-p384-sha384",
                        "ecdsa-p256-sha256",
                        "ecdsa-p521-sha512",
                        "ecdsa-p521-sha384",
                        "ed25519",
                        "rsa3072-sha384",
                        "rsa4096-sha384",
                        "rsa2048-sha384",
                    ];
                }
                Profile::Preferred => {
                    g.schemes = &[0x0503, 0x0403, 0x0603, 0x0805, 0x0806, 0x0804];
                    g.keys = &[
                        "ecdsa-p384-sha384",
                        "ecdsa-p256-sha256",
                        "ecdsa-p521-sha512",
                        "ecdsa-p521-sha384",
                        "rsa3072-sha384",
                        "rsa4096-sha384",
                    ];
                }
                Profile::Cnsa2 => {
                    g.schemes = &[];
                    g.keys = &[];
                }
                Profile::Cnsa1 | Profile::Bsi | Profile::Fips1402 => {}
            }
            match profile {
                Profile::Unrestricted | Profile::Preferred | Profile::Fips1403 | Profile::Cnsa2 => {
                    g.excluded = &[
                        Algorithm::Scheme(TlsSignatureScheme::MlDsa87),
                        Algorithm::Signature(SignatureAlgorithm::MlDsa87),
                    ];
                }
                Profile::Cnsa1 | Profile::Bsi | Profile::Fips1402 => {}
            }
        }
    }
    for (empty, category) in [
        (g.versions.is_empty(), Family::Version),
        (g.suites.is_empty(), Family::CipherSuite),
        (g.groups.is_empty(), Family::KxGroup),
        (g.schemes.is_empty(), Family::SignatureScheme),
        (g.keys.is_empty(), Family::KeyAlgorithm),
    ] {
        if empty {
            return Err(CryptoError::EmptyProfile {
                profile,
                options,
                category,
            });
        }
    }
    Ok(g)
}

/// Each profile's MACs with the `cnsa1_unclassified_nss` option off and on, in preference order.
/// Every MAC cell is available on every module line, so these hold on each one.
#[doc(hidden)]
pub const MAC_GOLDEN: &[(Profile, &[MacAlgorithm], &[MacAlgorithm])] = &{
    use MacAlgorithm::{HmacSha256 as H256, HmacSha384 as H384, HmacSha512 as H512};
    [
        (
            Profile::Unrestricted,
            &[H512, H384, H256],
            &[H512, H384, H256],
        ),
        (Profile::Preferred, &[H512, H384, H256], &[H512, H384, H256]),
        (Profile::Cnsa2, &[H384, H512], &[H384, H512]),
        (Profile::Cnsa1, &[H384], &[H384, H256]),
        (Profile::Bsi, &[H512, H384, H256], &[H512, H384, H256]),
        (Profile::Fips1403, &[H512, H384, H256], &[H512, H384, H256]),
        (Profile::Fips1402, &[H512, H384, H256], &[H512, H384, H256]),
    ]
};

/// Each profile's KDFs with the `cnsa1_unclassified_nss` option off and on, in preference order.
/// Every KDF cell is available on every module line, so these hold on each one.
#[doc(hidden)]
pub const KDF_GOLDEN: &[(Profile, &[KdfAlgorithm], &[KdfAlgorithm])] = &{
    use KdfAlgorithm::{
        HkdfSha256 as K256, HkdfSha384 as K384, HkdfSha512 as K512, OneStepSha256 as O256,
        OneStepSha384 as O384, OneStepSha512 as O512,
    };
    const ALL: &[KdfAlgorithm] = &[K512, K384, K256, O512, O384, O256];
    [
        (Profile::Unrestricted, ALL, ALL),
        (Profile::Preferred, ALL, ALL),
        (Profile::Cnsa2, &[K384, K512], &[K384, K512]),
        (Profile::Cnsa1, &[K384], &[K384, K256]),
        (Profile::Bsi, &[K512, K384, K256], &[K512, K384, K256]),
        (Profile::Fips1403, ALL, ALL),
        (Profile::Fips1402, ALL, ALL),
    ]
};

/// Each profile's key-agreement curves, in preference order. `cnsa1_unclassified_nss` changes
/// none of them, and every cell is available on every module line.
#[doc(hidden)]
pub const KEY_AGREEMENT_GOLDEN: &[(Profile, &[KeyAgreementAlgorithm])] = &{
    use KeyAgreementAlgorithm::{EcdhP256 as P256, EcdhP384 as P384, EcdhP521 as P521, X25519};
    [
        (Profile::Unrestricted, &[P384, P521, P256, X25519]),
        (Profile::Preferred, &[P384, P521, P256]),
        (Profile::Cnsa2, &[]),
        (Profile::Cnsa1, &[P384]),
        (Profile::Bsi, &[]),
        (Profile::Fips1403, &[P384, P521, P256]),
        (Profile::Fips1402, &[P384, P521, P256]),
    ]
};

/// Each profile's AEADs, in preference order. `cnsa1_unclassified_nss` changes none of them, and
/// every cell is available on every module line.
#[doc(hidden)]
pub const AEAD_GOLDEN: &[(Profile, &[AeadAlgorithm])] = &{
    use AeadAlgorithm::{Aes128Gcm as A128, Aes256Gcm as A256, Chacha20Poly1305 as C20};
    [
        (Profile::Unrestricted, &[A256, A128, C20]),
        (Profile::Preferred, &[A256, A128]),
        (Profile::Cnsa2, &[A256]),
        (Profile::Cnsa1, &[A256]),
        (Profile::Bsi, &[A256, A128]),
        (Profile::Fips1403, &[A256, A128]),
        (Profile::Fips1402, &[A256, A128]),
    ]
};

/// Each profile's hashes with the `cnsa1_unclassified_nss` option off and on, in preference
/// order. Every hash cell is available on every module line, so these hold on each one.
#[doc(hidden)]
pub const HASH_GOLDEN: &[(Profile, &[HashAlgorithm], &[HashAlgorithm])] = &{
    use HashAlgorithm::{
        Sha3_256 as S3_256, Sha3_384 as S3_384, Sha3_512 as S3_512, Sha256 as S256, Sha384 as S384,
        Sha512 as S512,
    };
    const SHA2: &[HashAlgorithm] = &[S512, S384, S256];
    const ALL: &[HashAlgorithm] = &[S512, S384, S256, S3_512, S3_384, S3_256];
    [
        (Profile::Unrestricted, ALL, ALL),
        (Profile::Preferred, SHA2, SHA2),
        (Profile::Cnsa2, &[S384, S512], &[S384, S512]),
        (Profile::Cnsa1, &[S384], &[S384, S256]),
        (Profile::Bsi, ALL, ALL),
        (Profile::Fips1403, ALL, ALL),
        (Profile::Fips1402, ALL, ALL),
    ]
};

/// Each profile's signature algorithms outside TLS with the `cnsa1_unclassified_nss` option off
/// and on, in preference order, on a module that has every one; a 3.x module lacks ML-DSA-87, and
/// `select_admitted` records it in `excluded`.
#[doc(hidden)]
pub const SIGNATURE_GOLDEN: &[(Profile, &[SignatureAlgorithm], &[SignatureAlgorithm])] = &{
    use SignatureAlgorithm::{
        EcdsaP256Sha256 as P256, EcdsaP384Sha384 as P384, EcdsaP521Sha384 as P521_384,
        EcdsaP521Sha512 as P521_512, Ed25519 as Ed, MlDsa87 as Ml, Rsa2048Sha384 as R2048,
        Rsa2048Sha384Pss as P2048, Rsa3072Sha384 as R3072, Rsa3072Sha384Pss as P3072,
        Rsa4096Sha384 as R4096, Rsa4096Sha384Pss as P4096,
    };
    const ALL: &[SignatureAlgorithm] = &[
        Ml, P384, P521_512, P521_384, P256, Ed, P4096, P3072, P2048, R4096, R3072, R2048,
    ];
    const PREFERRED: &[SignatureAlgorithm] =
        &[Ml, P384, P521_512, P256, P4096, P3072, R4096, R3072];
    const CNSA1: &[SignatureAlgorithm] = &[P384, P4096, P3072, R4096, R3072];
    const CNSA1_UNCLASSIFIED: &[SignatureAlgorithm] =
        &[P384, P4096, P3072, R4096, R3072, P2048, R2048];
    const FIPS1403: &[SignatureAlgorithm] = &[
        Ml, P384, P521_512, P256, Ed, P4096, P3072, P2048, R4096, R3072, R2048,
    ];
    const FIPS1402: &[SignatureAlgorithm] = &[
        P384, P521_512, P521_384, P256, P4096, P3072, P2048, R4096, R3072, R2048,
    ];
    [
        (Profile::Unrestricted, ALL, ALL),
        (Profile::Preferred, PREFERRED, PREFERRED),
        (Profile::Cnsa2, &[Ml], &[Ml]),
        (Profile::Cnsa1, CNSA1, CNSA1_UNCLASSIFIED),
        (Profile::Bsi, &[P4096, P3072], &[P4096, P3072]),
        (Profile::Fips1403, FIPS1403, FIPS1403),
        (Profile::Fips1402, FIPS1402, FIPS1402),
    ]
};

#[cfg(test)]
mod tests {
    use super::*;
    use crate::capability::{Linkage, ModuleLine};
    use crate::error::Family;
    use crate::profile::select;
    use crate::{Algorithm, TlsSignatureScheme};

    const M3S: Module = Module {
        line: ModuleLine::AwsLcFips3,
        linkage: Linkage::Static,
    };
    const M3D: Module = Module {
        line: ModuleLine::AwsLcFips3,
        linkage: Linkage::Dynamic,
    };
    const M4S: Module = Module {
        line: ModuleLine::AwsLcFips4,
        linkage: Linkage::Static,
    };
    const M4D: Module = Module {
        line: ModuleLine::AwsLcFips4,
        linkage: Linkage::Dynamic,
    };

    fn admitted_excluded(m: Module, p: Profile) -> Vec<Algorithm> {
        let ml_dsa = Algorithm::Signature(SignatureAlgorithm::MlDsa87);
        match m.line {
            ModuleLine::AwsLcFips3
                if p.spec().signatures.contains(&SignatureAlgorithm::MlDsa87) =>
            {
                vec![ml_dsa]
            }
            ModuleLine::AwsLcFips3 | ModuleLine::AwsLcFips4 => vec![],
        }
    }

    #[test]
    fn select_admitted_agrees_with_the_signature_golden_rows_on_every_module() {
        assert_eq!(SIGNATURE_GOLDEN.len(), Profile::ALL.len());
        for (i, p) in Profile::ALL.iter().copied().enumerate() {
            assert_eq!(SIGNATURE_GOLDEN[i].0, p);
        }
        for m in [M3S, M3D, M4S, M4D] {
            for &(p, off, on) in SIGNATURE_GOLDEN {
                for (unclassified, golden) in [(false, off), (true, on)] {
                    let o = Options {
                        cnsa1_unclassified_nss: unclassified,
                        ..Options::default()
                    };
                    let s = crate::profile::select_admitted(p, o, m);
                    let want: Vec<SignatureAlgorithm> = golden
                        .iter()
                        .copied()
                        .filter(|a| {
                            m.line == ModuleLine::AwsLcFips4 || *a != SignatureAlgorithm::MlDsa87
                        })
                        .collect();
                    assert_eq!(s.signatures, want, "{m:?} {p} {unclassified}");
                    assert_eq!(
                        s.excluded,
                        admitted_excluded(m, p),
                        "{m:?} {p} {unclassified}"
                    );
                }
            }
        }
        assert_eq!(
            admitted_excluded(M3D, Profile::Cnsa2),
            [Algorithm::Signature(SignatureAlgorithm::MlDsa87)]
        );
        assert_eq!(admitted_excluded(M3S, Profile::Bsi), []);
        assert_eq!(admitted_excluded(M4S, Profile::Unrestricted), []);
    }

    #[test]
    fn select_admitted_agrees_with_the_mac_golden_rows_on_every_module() {
        assert_eq!(MAC_GOLDEN.len(), Profile::ALL.len());
        for (i, p) in Profile::ALL.iter().copied().enumerate() {
            assert_eq!(MAC_GOLDEN[i].0, p);
        }
        for m in [M3S, M3D, M4S, M4D] {
            for &(p, off, on) in MAC_GOLDEN {
                for (unclassified, want) in [(false, off), (true, on)] {
                    let o = Options {
                        cnsa1_unclassified_nss: unclassified,
                        ..Options::default()
                    };
                    let s = crate::profile::select_admitted(p, o, m);
                    assert_eq!(s.macs, want, "{m:?} {p} {unclassified}");
                    assert_eq!(
                        s.excluded,
                        admitted_excluded(m, p),
                        "{m:?} {p} {unclassified}"
                    );
                }
            }
        }
    }

    #[test]
    fn select_admitted_agrees_with_the_kdf_golden_rows_on_every_module() {
        assert_eq!(KDF_GOLDEN.len(), Profile::ALL.len());
        for (i, p) in Profile::ALL.iter().copied().enumerate() {
            assert_eq!(KDF_GOLDEN[i].0, p);
        }
        for m in [M3S, M3D, M4S, M4D] {
            for &(p, off, on) in KDF_GOLDEN {
                for (unclassified, want) in [(false, off), (true, on)] {
                    let o = Options {
                        cnsa1_unclassified_nss: unclassified,
                        ..Options::default()
                    };
                    let s = crate::profile::select_admitted(p, o, m);
                    assert_eq!(s.kdfs, want, "{m:?} {p} {unclassified}");
                    assert_eq!(
                        s.excluded,
                        admitted_excluded(m, p),
                        "{m:?} {p} {unclassified}"
                    );
                }
            }
        }
    }

    #[test]
    fn select_admitted_agrees_with_the_key_agreement_golden_rows_on_every_module() {
        assert_eq!(KEY_AGREEMENT_GOLDEN.len(), Profile::ALL.len());
        for (i, p) in Profile::ALL.iter().copied().enumerate() {
            assert_eq!(KEY_AGREEMENT_GOLDEN[i].0, p);
        }
        for m in [M3S, M3D, M4S, M4D] {
            for &(p, want) in KEY_AGREEMENT_GOLDEN {
                for unclassified in [false, true] {
                    let o = Options {
                        cnsa1_unclassified_nss: unclassified,
                        ..Options::default()
                    };
                    let s = crate::profile::select_admitted(p, o, m);
                    assert_eq!(s.key_agreements, want, "{m:?} {p} {unclassified}");
                    assert_eq!(
                        s.excluded,
                        admitted_excluded(m, p),
                        "{m:?} {p} {unclassified}"
                    );
                }
            }
        }
    }

    #[test]
    fn select_admitted_agrees_with_the_aead_golden_rows_on_every_module() {
        assert_eq!(AEAD_GOLDEN.len(), Profile::ALL.len());
        for (i, p) in Profile::ALL.iter().copied().enumerate() {
            assert_eq!(AEAD_GOLDEN[i].0, p);
        }
        for m in [M3S, M3D, M4S, M4D] {
            for &(p, want) in AEAD_GOLDEN {
                for unclassified in [false, true] {
                    let o = Options {
                        cnsa1_unclassified_nss: unclassified,
                        ..Options::default()
                    };
                    let s = crate::profile::select_admitted(p, o, m);
                    assert_eq!(s.aeads, want, "{m:?} {p} {unclassified}");
                    assert_eq!(
                        s.excluded,
                        admitted_excluded(m, p),
                        "{m:?} {p} {unclassified}"
                    );
                }
            }
        }
    }

    #[test]
    fn select_admitted_agrees_with_the_hash_golden_rows_on_every_module() {
        assert_eq!(HASH_GOLDEN.len(), Profile::ALL.len());
        for (i, p) in Profile::ALL.iter().copied().enumerate() {
            assert_eq!(HASH_GOLDEN[i].0, p);
        }
        for m in [M3S, M3D, M4S, M4D] {
            for &(p, off, on) in HASH_GOLDEN {
                for (unclassified, want) in [(false, off), (true, on)] {
                    let o = Options {
                        cnsa1_unclassified_nss: unclassified,
                        ..Options::default()
                    };
                    let s = crate::profile::select_admitted(p, o, m);
                    assert_eq!(s.hashes, want, "{m:?} {p} {unclassified}");
                    assert_eq!(
                        s.excluded,
                        admitted_excluded(m, p),
                        "{m:?} {p} {unclassified}"
                    );
                }
            }
        }
    }

    const PQ: Options = Options {
        peer_certificates_match_profile: false,
        pq_key_exchange_required: true,
        cnsa1_unclassified_nss: false,
    };

    type Lists = (
        Vec<u16>,
        Vec<u16>,
        Vec<u16>,
        Vec<u16>,
        Vec<&'static str>,
        Vec<Algorithm>,
    );

    #[test]
    fn every_profile_and_option_has_exactly_one_golden_row() {
        assert_eq!(GOLDEN.len(), 14);
        for &p in Profile::ALL {
            for pq in [false, true] {
                let n = GOLDEN
                    .iter()
                    .filter(|g| g.profile == p && g.pq == pq)
                    .count();
                assert_eq!(n, 1, "{p} {pq}");
            }
        }
    }

    #[test]
    fn select_agrees_with_the_golden_rows_on_every_module() {
        for m in [M3S, M3D, M4S, M4D] {
            let mut successes = 0;
            for &p in Profile::ALL {
                for pq in [false, true] {
                    let o = Options {
                        peer_certificates_match_profile: false,
                        pq_key_exchange_required: pq,
                        cnsa1_unclassified_nss: false,
                    };
                    let got: Result<Lists, CryptoError> = select(p, o, m).map(|s| {
                        (
                            s.versions.iter().map(|x| x.iana()).collect(),
                            s.cipher_suites.iter().map(|x| x.iana()).collect(),
                            s.kx_groups.iter().map(|x| x.iana()).collect(),
                            s.signature_schemes.iter().map(|x| x.iana()).collect(),
                            s.key_algorithms.iter().map(|x| x.as_str()).collect(),
                            s.excluded,
                        )
                    });
                    let want: Result<Lists, CryptoError> = expected(m, p, o).map(|g| {
                        (
                            g.versions.to_vec(),
                            g.suites.to_vec(),
                            g.groups.to_vec(),
                            g.schemes.to_vec(),
                            g.keys.to_vec(),
                            g.excluded.to_vec(),
                        )
                    });
                    assert_eq!(got, want, "{m:?} {p} {o}");
                    successes += usize::from(got.is_ok());
                }
            }
            assert_eq!(
                successes,
                match m.line {
                    ModuleLine::AwsLcFips3 => 9,
                    ModuleLine::AwsLcFips4 => 11,
                }
            );
        }
    }

    #[test]
    fn expected_records_the_3x_refusals() {
        let d = Options::default();
        assert_eq!(
            expected(M3S, Profile::Cnsa2, d).map(|_| ()),
            Err(CryptoError::EmptyProfile {
                profile: Profile::Cnsa2,
                options: d,
                category: Family::SignatureScheme,
            })
        );
        assert_eq!(
            expected(M3S, Profile::Preferred, PQ).unwrap().excluded,
            &[
                Algorithm::Scheme(TlsSignatureScheme::MlDsa87),
                Algorithm::Signature(SignatureAlgorithm::MlDsa87)
            ]
        );
        assert!(expected(M3S, Profile::Cnsa1, d).is_ok());
        assert_eq!(
            expected(M3S, Profile::Fips1402, PQ).map(|_| ()),
            Err(CryptoError::EmptyProfile {
                profile: Profile::Fips1402,
                options: PQ,
                category: Family::KxGroup,
            })
        );
        assert!(expected(M4S, Profile::Cnsa2, d).is_ok());
    }
}