1
1
use super :: shortint:: load_params;
2
2
use crate :: { load_and_unversionize, TestedModule } ;
3
3
use std:: path:: Path ;
4
+ #[ cfg( feature = "zk-pok" ) ]
4
5
use tfhe:: integer:: parameters:: DynamicDistribution ;
5
6
use tfhe:: prelude:: { CiphertextList , FheDecrypt , FheEncrypt , ParameterSetConformant } ;
7
+ #[ cfg( feature = "zk-pok" ) ]
6
8
use tfhe:: shortint:: parameters:: {
7
9
CompactCiphertextListExpansionKind , CompactPublicKeyEncryptionParameters ,
8
10
} ;
11
+ #[ cfg( feature = "zk-pok" ) ]
9
12
use tfhe:: shortint:: prelude:: LweDimension ;
10
13
use tfhe:: shortint:: {
11
14
AtomicPatternParameters , CarryModulus , CiphertextModulus , MessageModulus , PBSParameters ,
12
15
} ;
13
16
#[ cfg( feature = "zk-pok" ) ]
14
- use tfhe:: zk:: CompactPkeCrs ;
15
- #[ cfg( feature = "zk-pok" ) ]
16
- use tfhe:: zk:: CompactPkeCrsConformanceParams ;
17
+ use tfhe:: zk:: { CompactPkeCrs , CompactPkeCrsConformanceParams } ;
17
18
use tfhe:: {
18
19
set_server_key, ClientKey , CompactCiphertextList , CompressedCiphertextList ,
19
20
CompressedCompactPublicKey , CompressedFheBool , CompressedFheInt8 , CompressedFheUint8 ,
20
- CompressedPublicKey , CompressedServerKey , FheBool , FheInt8 , FheUint8 , SquashedNoiseFheBool ,
21
- SquashedNoiseFheInt , SquashedNoiseFheUint ,
21
+ CompressedPublicKey , CompressedServerKey , CompressedSquashedNoiseCiphertextList , FheBool ,
22
+ FheInt8 , FheUint8 , SquashedNoiseFheBool , SquashedNoiseFheInt , SquashedNoiseFheUint ,
22
23
} ;
23
24
#[ cfg( feature = "zk-pok" ) ]
24
25
use tfhe:: { CompactPublicKey , ProvenCompactCiphertextList } ;
@@ -27,10 +28,10 @@ use tfhe_backward_compat_data::load::{
27
28
} ;
28
29
use tfhe_backward_compat_data:: {
29
30
DataKind , HlBoolCiphertextTest , HlCiphertextTest , HlClientKeyTest ,
30
- HlHeterogeneousCiphertextListTest , HlPublicKeyTest , HlServerKeyTest , HlSignedCiphertextTest ,
31
- HlSquashedNoiseBoolCiphertextTest , HlSquashedNoiseSignedCiphertextTest ,
32
- HlSquashedNoiseUnsignedCiphertextTest , TestMetadata , TestParameterSet , TestType , Testcase ,
33
- ZkPkePublicParamsTest ,
31
+ HlCompressedSquashedNoiseCiphertextListTest , HlHeterogeneousCiphertextListTest ,
32
+ HlPublicKeyTest , HlServerKeyTest , HlSignedCiphertextTest , HlSquashedNoiseBoolCiphertextTest ,
33
+ HlSquashedNoiseSignedCiphertextTest , HlSquashedNoiseUnsignedCiphertextTest , TestMetadata ,
34
+ TestParameterSet , TestType , Testcase , ZkPkePublicParamsTest ,
34
35
} ;
35
36
use tfhe_versionable:: Unversionize ;
36
37
@@ -495,6 +496,67 @@ pub fn test_hl_squashed_noise_bool_ciphertext(
495
496
}
496
497
}
497
498
499
+ /// Test HL compressed squashed noise ciphertext list:
500
+ /// loads the ciphertext list and compare the decrypted value to the one in the
501
+ /// metadata.
502
+ pub fn test_hl_compressed_squashed_noise_ciphertext_list (
503
+ dir : & Path ,
504
+ test : & HlCompressedSquashedNoiseCiphertextListTest ,
505
+ format : DataFormat ,
506
+ ) -> Result < TestSuccess , TestFailure > {
507
+ let key_file = dir. join ( & * test. key_filename ) ;
508
+ let key = ClientKey :: unversionize (
509
+ load_versioned_auxiliary ( key_file) . map_err ( |e| test. failure ( e, format) ) ?,
510
+ )
511
+ . map_err ( |e| test. failure ( format ! ( "Failed to load key file: {e}" ) , format) ) ?;
512
+
513
+ let list: CompressedSquashedNoiseCiphertextList = load_and_unversionize ( dir, test, format)
514
+ . map_err ( |e| test. failure ( format ! ( "Failed to load list file: {e}" ) , format) ) ?;
515
+
516
+ if list. len ( ) != test. clear_values . len ( ) || list. len ( ) != test. data_kinds . len ( ) {
517
+ return Err ( test. failure (
518
+ format ! (
519
+ "Invalid len for the compressed list, expected {} elements, got {}" ,
520
+ test. clear_values. len( ) ,
521
+ list. len( )
522
+ ) ,
523
+ format,
524
+ ) ) ;
525
+ }
526
+
527
+ for i in 0 ..list. len ( ) {
528
+ let decrypted = match test. data_kinds [ i] {
529
+ DataKind :: Unsigned => {
530
+ let ct: SquashedNoiseFheUint = list. get ( i) . unwrap ( ) . unwrap ( ) ;
531
+ let clear: u64 = ct. decrypt ( & key) ;
532
+ clear
533
+ }
534
+ DataKind :: Signed => {
535
+ let ct: SquashedNoiseFheInt = list. get ( i) . unwrap ( ) . unwrap ( ) ;
536
+ let clear: i64 = ct. decrypt ( & key) ;
537
+ clear as u64
538
+ }
539
+ DataKind :: Bool => {
540
+ let ct: SquashedNoiseFheBool = list. get ( i) . unwrap ( ) . unwrap ( ) ;
541
+ let clear: bool = ct. decrypt ( & key) ;
542
+ clear as u64
543
+ }
544
+ } ;
545
+
546
+ let expected = test. clear_values [ i] ;
547
+ if decrypted != expected {
548
+ return Err ( test. failure (
549
+ format ! (
550
+ "Invalid decryption at index {i}:\n Expected :{expected:?} Got: {decrypted:?}" ,
551
+ ) ,
552
+ format,
553
+ ) ) ;
554
+ }
555
+ }
556
+
557
+ Ok ( test. success ( format) )
558
+ }
559
+
498
560
pub struct Hl ;
499
561
500
562
impl TestedModule for Hl {
@@ -540,6 +602,10 @@ impl TestedModule for Hl {
540
602
TestMetadata :: HlSquashedNoiseBoolCiphertext ( test) => {
541
603
test_hl_squashed_noise_bool_ciphertext ( test_dir. as_ref ( ) , test, format) . into ( )
542
604
}
605
+ TestMetadata :: HlCompressedSquashedNoiseCiphertextList ( test) => {
606
+ test_hl_compressed_squashed_noise_ciphertext_list ( test_dir. as_ref ( ) , test, format)
607
+ . into ( )
608
+ }
543
609
_ => {
544
610
println ! ( "WARNING: missing test: {:?}" , testcase. metadata) ;
545
611
TestResult :: Skipped ( testcase. skip ( ) )
0 commit comments