Skip to main content

lib_q_types/
fndsa.rs

1//! FN-DSA object sizes (bytes) shared across the workspace.
2//!
3//! Unlike the other families in this crate, these ARE genuinely derived at compile time from
4//! `lib-q-fn-dsa-comm`'s own `const fn` formulas (`sign_key_size` / `vrfy_key_size` /
5//! `signature_size`), not hand-maintained literals. `lib-q-fn-dsa-comm` has no dependency on
6//! `lib-q-types` or `lib-q-core` (only `rand_core` / `cpufeatures`), so this edge is acyclic.
7//!
8//! This closes the exact bug class that motivated this module: `lib-q-core`'s
9//! `SecurityConstants` once hand-copied `sign_key_size(10)` as the literal `2561`, which is
10//! `sign_key_size` evaluated with logn=9's `nbits_fg` branch instead of logn=10's -- the real
11//! value is `2305`. A hand-copied literal can silently drift from the formula; a `const`
12//! initialized directly by calling the formula cannot.
13
14use fn_dsa_comm::{
15    sign_key_size,
16    signature_size,
17    vrfy_key_size,
18};
19
20/// FN-DSA-512 (logn = 9) secret (signing) key length.
21pub const FNDSA512_SECRET_KEY_BYTES: usize = sign_key_size(9);
22/// FN-DSA-512 (logn = 9) public (verifying) key length.
23pub const FNDSA512_PUBLIC_KEY_BYTES: usize = vrfy_key_size(9);
24/// FN-DSA-512 (logn = 9) signature length.
25pub const FNDSA512_SIGNATURE_BYTES: usize = signature_size(9);
26
27/// FN-DSA-1024 (logn = 10) secret (signing) key length.
28pub const FNDSA1024_SECRET_KEY_BYTES: usize = sign_key_size(10);
29/// FN-DSA-1024 (logn = 10) public (verifying) key length.
30pub const FNDSA1024_PUBLIC_KEY_BYTES: usize = vrfy_key_size(10);
31/// FN-DSA-1024 (logn = 10) signature length.
32pub const FNDSA1024_SIGNATURE_BYTES: usize = signature_size(10);
33
34#[cfg(test)]
35mod tests {
36    use super::*;
37
38    /// Self-evident by construction (these are `const fn` calls, not literals) -- kept as a
39    /// readable regression pin for the historical 2561-vs-2305 bug.
40    #[test]
41    fn fn_dsa_1024_secret_key_matches_the_historical_correction() {
42        assert_eq!(FNDSA1024_SECRET_KEY_BYTES, 2305);
43        assert_eq!(FNDSA1024_PUBLIC_KEY_BYTES, 1793);
44        assert_eq!(FNDSA1024_SIGNATURE_BYTES, 1280);
45        assert_eq!(FNDSA512_SECRET_KEY_BYTES, 1281);
46        assert_eq!(FNDSA512_PUBLIC_KEY_BYTES, 897);
47        assert_eq!(FNDSA512_SIGNATURE_BYTES, 666);
48    }
49}