1+ use std:: marker:: PhantomData ;
2+
13use tfhe_versionable:: Versionize ;
24
35use crate :: backward_compatibility:: integers:: {
@@ -6,20 +8,20 @@ use crate::backward_compatibility::integers::{
68use crate :: conformance:: ParameterSetConformant ;
79use crate :: core_crypto:: prelude:: SignedNumeric ;
810use crate :: high_level_api:: global_state;
9- use crate :: high_level_api:: integers:: signed:: base:: FheIntConformanceParams ;
1011use crate :: high_level_api:: integers:: { FheInt , FheIntId } ;
1112use crate :: high_level_api:: keys:: InternalServerKey ;
1213use crate :: high_level_api:: re_randomization:: ReRandomizationMetadata ;
1314use crate :: high_level_api:: traits:: Tagged ;
1415use crate :: integer:: block_decomposition:: DecomposableInto ;
1516use crate :: integer:: ciphertext:: {
17+ CompressedModulusSwitchedRadixCiphertextConformanceParams ,
1618 CompressedModulusSwitchedSignedRadixCiphertext ,
1719 CompressedSignedRadixCiphertext as IntegerCompressedSignedRadixCiphertext ,
1820} ;
19- use crate :: integer:: parameters:: RadixCiphertextConformanceParams ;
2021use crate :: named:: Named ;
2122use crate :: prelude:: FheTryEncrypt ;
22- use crate :: { ClientKey , Tag } ;
23+ use crate :: shortint:: AtomicPatternParameters ;
24+ use crate :: { ClientKey , ServerKey , Tag } ;
2325
2426/// Compressed [FheInt]
2527///
@@ -153,10 +155,51 @@ where
153155 }
154156}
155157
158+ #[ derive( Copy , Clone ) ]
159+ pub struct CompressedFheIntConformanceParams < Id : FheIntId > {
160+ pub ( crate ) params : CompressedSignedRadixCiphertextConformanceParams ,
161+ pub ( crate ) id : PhantomData < Id > ,
162+ }
163+
164+ impl < Id : FheIntId , P : Into < AtomicPatternParameters > > From < P >
165+ for CompressedFheIntConformanceParams < Id >
166+ {
167+ fn from ( params : P ) -> Self {
168+ let params = params. into ( ) ;
169+ Self {
170+ params : CompressedSignedRadixCiphertextConformanceParams (
171+ CompressedModulusSwitchedRadixCiphertextConformanceParams {
172+ shortint_params : params. to_compressed_modswitched_conformance_param ( ) ,
173+ num_blocks_per_integer : Id :: num_blocks ( params. message_modulus ( ) ) ,
174+ } ,
175+ ) ,
176+ id : PhantomData ,
177+ }
178+ }
179+ }
180+
181+ impl < Id : FheIntId > From < & ServerKey > for CompressedFheIntConformanceParams < Id > {
182+ fn from ( sk : & ServerKey ) -> Self {
183+ Self {
184+ params : CompressedSignedRadixCiphertextConformanceParams (
185+ CompressedModulusSwitchedRadixCiphertextConformanceParams {
186+ shortint_params : sk
187+ . key
188+ . pbs_key ( )
189+ . key
190+ . compressed_modswitched_conformance_params ( ) ,
191+ num_blocks_per_integer : Id :: num_blocks ( sk. key . pbs_key ( ) . message_modulus ( ) ) ,
192+ } ,
193+ ) ,
194+ id : PhantomData ,
195+ }
196+ }
197+ }
198+
156199impl < Id : FheIntId > ParameterSetConformant for CompressedFheInt < Id > {
157- type ParameterSet = FheIntConformanceParams < Id > ;
200+ type ParameterSet = CompressedFheIntConformanceParams < Id > ;
158201
159- fn is_conformant ( & self , params : & FheIntConformanceParams < Id > ) -> bool {
202+ fn is_conformant ( & self , params : & CompressedFheIntConformanceParams < Id > ) -> bool {
160203 let Self {
161204 ciphertext,
162205 id : _,
@@ -178,12 +221,17 @@ pub enum CompressedSignedRadixCiphertext {
178221 ModulusSwitched ( CompressedModulusSwitchedSignedRadixCiphertext ) ,
179222}
180223
224+ #[ derive( Copy , Clone ) ]
225+ pub struct CompressedSignedRadixCiphertextConformanceParams (
226+ pub ( crate ) CompressedModulusSwitchedRadixCiphertextConformanceParams ,
227+ ) ;
228+
181229impl ParameterSetConformant for CompressedSignedRadixCiphertext {
182- type ParameterSet = RadixCiphertextConformanceParams ;
183- fn is_conformant ( & self , params : & RadixCiphertextConformanceParams ) -> bool {
230+ type ParameterSet = CompressedSignedRadixCiphertextConformanceParams ;
231+ fn is_conformant ( & self , params : & CompressedSignedRadixCiphertextConformanceParams ) -> bool {
184232 match self {
185- Self :: Seeded ( ct) => ct. is_conformant ( params) ,
186- Self :: ModulusSwitched ( ct) => ct. is_conformant ( params) ,
233+ Self :: Seeded ( ct) => ct. is_conformant ( & params. 0 . into ( ) ) ,
234+ Self :: ModulusSwitched ( ct) => ct. is_conformant ( & params. 0 ) ,
187235 }
188236 }
189237}
0 commit comments