@@ -13,14 +13,14 @@ use crate::{D, Q};
13
13
///
14
14
/// This is only used in `ml_dsa::key_gen()` and does not involve untrusted input.
15
15
///
16
- /// **Input**: `ρ ∈ {0,1}^256 `, `t1 ∈ R^k` with coefficients in `[0, 2^{bitlen(q−1)−d}-1]`. <br>
16
+ /// **Input**: `ρ ∈ B^{32} `, `t1 ∈ R^k` with coefficients in `[0, 2^{bitlen(q−1)−d}-1]`. <br>
17
17
/// **Output**: Public key `pk ∈ B^{32+32·k·(bitlen(q−1)−d)}`.
18
18
pub ( crate ) fn pk_encode < const K : usize , const PK_LEN : usize > (
19
19
rho : & [ u8 ; 32 ] , t1 : & [ R ; K ] ,
20
20
) -> [ u8 ; PK_LEN ] {
21
- let blqd = bit_length ( Q - 1 ) - D as usize ;
22
- debug_assert ! ( t1. iter( ) . all( |t| is_in_range( t, 0 , ( 1 << blqd ) - 1 ) ) , "Alg 22: t1 out of range" ) ;
23
- debug_assert_eq ! ( PK_LEN , 32 + 32 * K * blqd , "Alg 22: bad pk/config size" ) ;
21
+ const BLQD : usize = bit_length ( Q - 1 ) - D as usize ;
22
+ debug_assert ! ( t1. iter( ) . all( |t| is_in_range( t, 0 , ( 1 << BLQD ) - 1 ) ) , "Alg 22: t1 out of range" ) ;
23
+ debug_assert_eq ! ( PK_LEN , 32 + 32 * K * BLQD , "Alg 22: bad pk/config size" ) ;
24
24
let mut pk = [ 0u8 ; PK_LEN ] ;
25
25
26
26
// 1: pk ← rho
@@ -30,10 +30,10 @@ pub(crate) fn pk_encode<const K: usize, const PK_LEN: usize>(
30
30
// 3: pk ← pk || SimpleBitPack(t1[i], 2^{bitlen(q−1)−d}-1)
31
31
// 4: end for
32
32
pk[ 32 ..]
33
- . chunks_mut ( 32 * blqd )
33
+ . chunks_mut ( 32 * BLQD )
34
34
. enumerate ( )
35
35
. take ( K ) // not strictly needed
36
- . for_each ( |( i, chunk) | simple_bit_pack ( & t1[ i] , ( 1 << blqd ) - 1 , chunk) ) ;
36
+ . for_each ( |( i, chunk) | simple_bit_pack ( & t1[ i] , ( 1 << BLQD ) - 1 , chunk) ) ;
37
37
38
38
// 5: return pk
39
39
pk
@@ -47,7 +47,7 @@ pub(crate) fn pk_encode<const K: usize, const PK_LEN: usize>(
47
47
/// `simple_bit_unpack()` will detect malformed input -- an overly conservative (?) route for now.
48
48
///
49
49
/// **Input**: Public key `pk ∈ B^{32+32·k·(bitlen(q−1)−d)}`. <br>
50
- /// **Output**: `ρ ∈ {0,1}^256 `, `t1 ∈ R^k` with coefficients in `[0, 2^{bitlen(q−1)−d}−1]`).
50
+ /// **Output**: `ρ ∈ B^{32} `, `t1 ∈ R^k` with coefficients in `[0, 2^{bitlen(q−1)−d}−1]`).
51
51
///
52
52
/// # Errors
53
53
/// Returns an error when the internal `simple_bit_unpack()` invocation finds an element of
@@ -85,7 +85,7 @@ pub(crate) fn pk_decode<const K: usize, const PK_LEN: usize>(
85
85
///
86
86
/// This is only used in `ml_dsa::key_gen()` and does not involve untrusted input.
87
87
///
88
- /// **Input**: `ρ ∈ {0,1}^256 `, `K ∈ {0,1}^256 `, `tr ∈ {0,1}^512 `,
88
+ /// **Input**: `ρ ∈ B^{32} `, `K ∈ B^{32} `, `tr ∈ B^{64} `,
89
89
/// `s_1 ∈ R^l` with coefficients in `[−η, η]`,
90
90
/// `s_2 ∈ R^k` with coefficients in `[−η, η]`,
91
91
/// `t_0 ∈ R^k` with coefficients in `[−2^{d-1}+1, 2^{d-1}]`.
@@ -159,7 +159,7 @@ pub(crate) fn sk_encode<const K: usize, const L: usize, const SK_LEN: usize>(
159
159
///
160
160
/// **Input**: Private key, `sk ∈ B^{32+32+64+32·((ℓ+k)·bitlen(2η)+d·k)}`
161
161
/// Security parameter `η` (eta) must be either 2 or 4.<br>
162
- /// **Output**: `ρ ∈ {0,1}^256 `, `K ∈ {0,1}^256 `, `tr ∈ {0,1}^512 `,
162
+ /// **Output**: `ρ ∈ B^{32} `, `K ∈ B^{32} `, `tr ∈ B^{64} `,
163
163
/// `s_1 ∈ R^ℓ`, `s_2 ∈ R^k`, `t_0 ∈ R^k` with coefficients in `[−2^{d−1}+1, 2^{d−1}]`.
164
164
///
165
165
/// # Errors
@@ -168,13 +168,13 @@ pub(crate) fn sk_encode<const K: usize, const L: usize, const SK_LEN: usize>(
168
168
pub ( crate ) fn sk_decode < const K : usize , const L : usize , const SK_LEN : usize > (
169
169
eta : i32 , sk : & [ u8 ; SK_LEN ] ,
170
170
) -> Result < ( & [ u8 ; 32 ] , & [ u8 ; 32 ] , & [ u8 ; 64 ] , [ R ; L ] , [ R ; K ] , [ R ; K ] ) , & ' static str > {
171
+ const TOP : i32 = 1 << ( D - 1 ) ;
171
172
debug_assert ! ( ( eta == 2 ) || ( eta == 4 ) , "Alg 25: incorrect eta" ) ;
172
173
debug_assert_eq ! (
173
174
SK_LEN ,
174
175
128 + 32 * ( ( K + L ) * bit_length( 2 * eta) + D as usize * K ) ,
175
176
"Alg 25: bad sk/config size"
176
177
) ;
177
- let top = 1 << ( D - 1 ) ;
178
178
let ( mut s_1, mut s_2, mut t_0) = ( [ R0 ; L ] , [ R0 ; K ] , [ R0 ; K ] ) ;
179
179
180
180
// 1: (rho, 𝐾, tr, 𝑦0 , … , 𝑦ℓ−1 , 𝑧0 , … , 𝑧𝑘−1 , 𝑤0 , … , 𝑤𝑘−1 ) ∈
@@ -211,7 +211,7 @@ pub(crate) fn sk_decode<const K: usize, const L: usize, const SK_LEN: usize>(
211
211
for i in 0 ..K {
212
212
//
213
213
// 9: t0[i] ← BitUnpack(wi, −2^{d−1} - 1, 2^{d−1}) ▷ This is always in the correct range
214
- t_0[ i] = bit_unpack ( & sk[ start + i * step..start + ( i + 1 ) * step] , top - 1 , top ) ?;
214
+ t_0[ i] = bit_unpack ( & sk[ start + i * step..start + ( i + 1 ) * step] , TOP - 1 , TOP ) ?;
215
215
216
216
// 10: end for
217
217
}
@@ -231,7 +231,7 @@ pub(crate) fn sk_decode<const K: usize, const L: usize, const SK_LEN: usize>(
231
231
/// The `CTEST` generic is only passed through to the `hint_bit_pack()` leaf function
232
232
/// such that this logic becomes constant-time.
233
233
///
234
- /// **Input**: `c_tilde ∈ {0,1}^2λ` (bits) ,
234
+ /// **Input**: `c_tilde ∈ B^{λ/4}` ,
235
235
/// `z ∈ R^ℓ` with coefficients in `[−1*γ_1 + 1, γ_1]`,
236
236
/// `h ∈ R^k_2`. <br>
237
237
/// **Output**: Signature, `σ ∈ B^{λ/4+l·32·(1+bitlen(γ_1-1)+ω+k}`
0 commit comments