@@ -8,11 +8,11 @@ use crate::core_crypto::commons::noise_formulas::noise_simulation::traits::{
88} ;
99use crate :: core_crypto:: commons:: noise_formulas:: noise_simulation:: {
1010 NoiseSimulationGlwe , NoiseSimulationLwe , NoiseSimulationModulus ,
11+ NoiseSimulationNoiseDistribution , NoiseSimulationNoiseDistributionKind ,
1112} ;
1213use crate :: core_crypto:: commons:: numeric:: UnsignedInteger ;
1314use crate :: core_crypto:: commons:: parameters:: {
14- DecompositionBaseLog , DecompositionLevelCount , DynamicDistribution , GlweSize , LweDimension ,
15- PolynomialSize ,
15+ DecompositionBaseLog , DecompositionLevelCount , GlweDimension , LweDimension , PolynomialSize ,
1616} ;
1717use crate :: core_crypto:: commons:: traits:: container:: Container ;
1818use crate :: core_crypto:: entities:: lwe_packing_keyswitch_key:: LwePackingKeyswitchKey ;
@@ -22,9 +22,9 @@ pub struct NoiseSimulationLwePackingKeyswitchKey {
2222 input_lwe_dimension : LweDimension ,
2323 decomp_base_log : DecompositionBaseLog ,
2424 decomp_level_count : DecompositionLevelCount ,
25- output_glwe_size : GlweSize ,
25+ output_glwe_dimension : GlweDimension ,
2626 output_polynomial_size : PolynomialSize ,
27- noise_distribution : DynamicDistribution < u128 > ,
27+ noise_distribution : NoiseSimulationNoiseDistribution ,
2828 modulus : NoiseSimulationModulus ,
2929}
3030
@@ -33,16 +33,16 @@ impl NoiseSimulationLwePackingKeyswitchKey {
3333 input_lwe_dimension : LweDimension ,
3434 decomp_base_log : DecompositionBaseLog ,
3535 decomp_level_count : DecompositionLevelCount ,
36- output_glwe_size : GlweSize ,
36+ output_glwe_dimension : GlweDimension ,
3737 output_polynomial_size : PolynomialSize ,
38- noise_distribution : DynamicDistribution < u128 > ,
38+ noise_distribution : NoiseSimulationNoiseDistribution ,
3939 modulus : NoiseSimulationModulus ,
4040 ) -> Self {
4141 Self {
4242 input_lwe_dimension,
4343 decomp_base_log,
4444 decomp_level_count,
45- output_glwe_size ,
45+ output_glwe_dimension ,
4646 output_polynomial_size,
4747 noise_distribution,
4848 modulus,
@@ -57,7 +57,7 @@ impl NoiseSimulationLwePackingKeyswitchKey {
5757 input_lwe_dimension,
5858 decomp_base_log,
5959 decomp_level_count,
60- output_glwe_size ,
60+ output_glwe_dimension ,
6161 output_polynomial_size,
6262 noise_distribution : _,
6363 modulus,
@@ -66,15 +66,15 @@ impl NoiseSimulationLwePackingKeyswitchKey {
6666 let pksk_input_lwe_dimension = pksk. input_key_lwe_dimension ( ) ;
6767 let pksk_decomp_base_log = pksk. decomposition_base_log ( ) ;
6868 let pksk_decomp_level_count = pksk. decomposition_level_count ( ) ;
69- let pksk_output_glwe_size = pksk. output_glwe_size ( ) ;
69+ let pksk_output_glwe_dimension = pksk. output_key_glwe_dimension ( ) ;
7070 let pksk_output_polynomial_size = pksk. output_key_polynomial_size ( ) ;
7171 let pksk_modulus =
7272 NoiseSimulationModulus :: from_ciphertext_modulus ( pksk. ciphertext_modulus ( ) ) ;
7373
7474 input_lwe_dimension == pksk_input_lwe_dimension
7575 && decomp_base_log == pksk_decomp_base_log
7676 && decomp_level_count == pksk_decomp_level_count
77- && output_glwe_size == pksk_output_glwe_size
77+ && output_glwe_dimension == pksk_output_glwe_dimension
7878 && output_polynomial_size == pksk_output_polynomial_size
7979 && modulus == pksk_modulus
8080 }
@@ -91,15 +91,15 @@ impl NoiseSimulationLwePackingKeyswitchKey {
9191 self . decomp_level_count
9292 }
9393
94- pub fn output_glwe_size ( & self ) -> GlweSize {
95- self . output_glwe_size
94+ pub fn output_glwe_dimension ( & self ) -> GlweDimension {
95+ self . output_glwe_dimension
9696 }
9797
9898 pub fn output_polynomial_size ( & self ) -> PolynomialSize {
9999 self . output_polynomial_size
100100 }
101101
102- pub fn noise_distribution ( & self ) -> DynamicDistribution < u128 > {
102+ pub fn noise_distribution ( & self ) -> NoiseSimulationNoiseDistribution {
103103 self . noise_distribution
104104 }
105105
@@ -117,7 +117,7 @@ impl AllocateLwePackingKeyswitchResult for NoiseSimulationLwePackingKeyswitchKey
117117 _side_resources : & mut Self :: SideResources ,
118118 ) -> Self :: Output {
119119 Self :: Output :: new (
120- self . output_glwe_size ( ) . to_glwe_dimension ( ) ,
120+ self . output_glwe_dimension ( ) ,
121121 self . output_polynomial_size ( ) ,
122122 Variance ( f64:: NAN ) ,
123123 self . modulus ,
@@ -137,43 +137,44 @@ impl LwePackingKeyswitch<[&NoiseSimulationLwe], NoiseSimulationGlwe>
137137 _side_resources : & mut Self :: SideResources ,
138138 ) {
139139 let mut input_iter = input. iter ( ) ;
140- let input = input_iter. next ( ) . unwrap ( ) ;
140+ let first_input = input_iter. next ( ) . unwrap ( ) ;
141141
142- let mut lwe_to_pack = 1 ;
142+ // Check first input is compatible with us
143+ assert_eq ! ( first_input. lwe_dimension( ) , self . input_lwe_dimension( ) ) ;
144+ // Check all inputs are the same as first input
145+ assert ! ( input_iter. all( |x| x == first_input) ) ;
143146
144- assert ! ( input_iter . inspect ( |_| lwe_to_pack += 1 ) . all ( |x| x == input ) ) ;
147+ let lwe_to_pack = input . len ( ) as f64 ;
145148
146- assert_eq ! ( input. lwe_dimension( ) , self . input_lwe_dimension( ) ) ;
147-
148- let packing_ks_additive_var = match self . noise_distribution ( ) {
149- DynamicDistribution :: Gaussian ( _) => {
149+ let packing_ks_additive_var = match self . noise_distribution ( ) . kind ( ) {
150+ NoiseSimulationNoiseDistributionKind :: Gaussian => {
150151 packing_keyswitch_additive_variance_132_bits_security_gaussian (
151152 self . input_lwe_dimension ( ) ,
152- self . output_glwe_size ( ) . to_glwe_dimension ( ) ,
153+ self . output_glwe_dimension ( ) ,
153154 self . output_polynomial_size ( ) ,
154155 self . decomp_base_log ( ) ,
155156 self . decomp_level_count ( ) ,
156- lwe_to_pack. into ( ) ,
157+ lwe_to_pack,
157158 self . modulus ( ) . as_f64 ( ) ,
158159 )
159160 }
160- DynamicDistribution :: TUniform ( _ ) => {
161+ NoiseSimulationNoiseDistributionKind :: TUniform => {
161162 packing_keyswitch_additive_variance_132_bits_security_tuniform (
162163 self . input_lwe_dimension ( ) ,
163- self . output_glwe_size ( ) . to_glwe_dimension ( ) ,
164+ self . output_glwe_dimension ( ) ,
164165 self . output_polynomial_size ( ) ,
165166 self . decomp_base_log ( ) ,
166167 self . decomp_level_count ( ) ,
167- lwe_to_pack. into ( ) ,
168+ lwe_to_pack,
168169 self . modulus ( ) . as_f64 ( ) ,
169170 )
170171 }
171172 } ;
172173
173174 * output = NoiseSimulationGlwe :: new (
174- self . output_glwe_size ( ) . to_glwe_dimension ( ) ,
175+ self . output_glwe_dimension ( ) ,
175176 self . output_polynomial_size ( ) ,
176- Variance ( input . variance ( ) . 0 + packing_ks_additive_var. 0 ) ,
177+ Variance ( first_input . variance ( ) . 0 + packing_ks_additive_var. 0 ) ,
177178 self . modulus ( ) ,
178179 ) ;
179180 }
0 commit comments