@@ -42,15 +42,12 @@ pub trait CbdSamplingSize: ArraySize {
4242 const ONES : Array < Elem , Self :: OnesSize > ;
4343}
4444
45- // To speed up CBD sampling, we pre-compute all the bit-manipulations:
46- //
47- // * Splitting a sampled integer into two parts
48- // * Counting the ones in each part
49- // * Taking the difference between the two counts mod q
50- //
51- // We have to allow the use of `as` here because we can't use our nice Truncate trait, because
52- // const functions don't support traits.
53- #[ allow( clippy:: cast_possible_truncation) ]
45+ /// To speed up CBD sampling, we pre-compute all the bit-manipulations:
46+ ///
47+ /// * Splitting a sampled integer into two parts
48+ /// * Counting the ones in each part
49+ /// * Taking the difference between the two counts mod q
50+ #[ allow( clippy:: integer_division_remainder_used, reason = "constant" ) ]
5451const fn ones_array < const B : usize , const N : usize , U > ( ) -> Array < Elem , U >
5552where
5653 U : ArraySize < ArrayType < Elem > = [ Elem ; N ] > ,
6158 let mut x = 0usize ;
6259 while x < max {
6360 let mut y = 0usize ;
64- #[ allow( clippy:: integer_division_remainder_used) ]
6561 while y < max {
66- let x_ones = x. count_ones ( ) as u16 ;
67- let y_ones = y. count_ones ( ) as u16 ;
62+ let x_ones = ( x. count_ones ( ) & 0xFFFF ) as u16 ;
63+ let y_ones = ( y. count_ones ( ) & 0xFFFF ) as u16 ;
6864 let i = x + ( y << B ) ;
6965 out[ i] = Elem :: new ( ( x_ones + BaseField :: Q - y_ones) % BaseField :: Q ) ;
7066
@@ -87,8 +83,9 @@ impl CbdSamplingSize for U3 {
8783 const ONES : Array < Elem , U64 > = ones_array :: < 3 , 64 , U64 > ( ) ;
8884}
8985
90- /// A `ParameterSet` captures the parameters that describe a particular instance of ML-KEM. There
91- /// are three variants, corresponding to three different security levels.
86+ /// A `ParameterSet` captures the parameters that describe a particular instance of ML-KEM.
87+ ///
88+ /// There are three variants, corresponding to three different security levels.
9289pub trait ParameterSet : Default + Clone + Debug + PartialEq {
9390 /// The dimensionality of vectors and arrays
9491 type K : ArraySize ;
0 commit comments