poulpy/poulpy-core/src/tests/serialization.rs
poulpy-core/src/tests/serialization.rsRaw
1use poulpy_backend::FFT64Ref;
2use poulpy_hal::{api::ModuleNew, layouts::Module, test_suite::serialization::test_reader_writer_interface};
3
4use crate::layouts::{
5 AutomorphismKey, Base2K, Degree, Dnum, Dsize, GGLWE, GGSW, GLWE, GLWESwitchingKey, GLWEToLWESwitchingKey, LWE,
6 LWESwitchingKey, LWEToGLWESwitchingKey, Rank, TensorKey, TorusPrecision,
7 compressed::{
8 AutomorphismKeyCompressed, GGLWECompressed, GGSWCompressed, GLWECompressed, GLWESwitchingKeyCompressed,
9 GLWEToLWESwitchingKeyCompressed, LWECompressed, LWESwitchingKeyCompressed, LWEToGLWESwitchingKeyCompressed,
10 TensorKeyCompressed,
11 },
12};
13
14const N_GLWE: Degree = Degree(64);
15const N_LWE: Degree = Degree(32);
16const BASE2K: Base2K = Base2K(12);
17const K: TorusPrecision = TorusPrecision(33);
18const DNUM: Dnum = Dnum(3);
19const RANK: Rank = Rank(2);
20const DSIZE: Dsize = Dsize(1);
21
22#[test]
23fn glwe_serialization() {
24 let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
25 let original: GLWE<Vec<u8>> = GLWE::alloc(&module, BASE2K, K, RANK);
26 poulpy_hal::test_suite::serialization::test_reader_writer_interface(original);
27}
28
29#[test]
30fn glwe_compressed_serialization() {
31 let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
32 let original: GLWECompressed<Vec<u8>> = GLWECompressed::alloc(&module, BASE2K, K, RANK);
33 test_reader_writer_interface(original);
34}
35
36#[test]
37fn lwe_serialization() {
38 let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
39 let original: LWE<Vec<u8>> = LWE::alloc(&module, N_LWE, BASE2K, K);
40 test_reader_writer_interface(original);
41}
42
43#[test]
44fn lwe_compressed_serialization() {
45 let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
46 let original: LWECompressed<Vec<u8>> = LWECompressed::alloc(&module, BASE2K, K);
47 test_reader_writer_interface(original);
48}
49
50#[test]
51fn test_gglwe_serialization() {
52 let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
53 let original: GGLWE<Vec<u8>> = GGLWE::alloc(&module, BASE2K, K, RANK, RANK, DNUM, DSIZE);
54 test_reader_writer_interface(original);
55}
56
57#[test]
58fn test_gglwe_compressed_serialization() {
59 let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
60 let original: GGLWECompressed<Vec<u8>> = GGLWECompressed::alloc(&module, BASE2K, K, RANK, RANK, DNUM, DSIZE);
61 test_reader_writer_interface(original);
62}
63
64#[test]
65fn test_glwe_switching_key_serialization() {
66 let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
67 let original: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&module, BASE2K, K, RANK, RANK, DNUM, DSIZE);
68 test_reader_writer_interface(original);
69}
70
71#[test]
72fn test_glwe_switching_key_compressed_serialization() {
73 let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
74 let original: GLWESwitchingKeyCompressed<Vec<u8>> =
75 GLWESwitchingKeyCompressed::alloc(&module, BASE2K, K, RANK, RANK, DNUM, DSIZE);
76 test_reader_writer_interface(original);
77}
78
79#[test]
80fn test_automorphism_key_serialization() {
81 let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
82 let original: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_with(&module, BASE2K, K, RANK, DNUM, DSIZE);
83 test_reader_writer_interface(original);
84}
85
86#[test]
87fn test_automorphism_key_compressed_serialization() {
88 let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
89 let original: AutomorphismKeyCompressed<Vec<u8>> = AutomorphismKeyCompressed::alloc(&module, BASE2K, K, RANK, DNUM, DSIZE);
90 test_reader_writer_interface(original);
91}
92
93#[test]
94fn test_tensor_key_serialization() {
95 let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
96 let original: TensorKey<Vec<u8>> = TensorKey::alloc(&module, BASE2K, K, RANK, DNUM, DSIZE);
97 test_reader_writer_interface(original);
98}
99
100#[test]
101fn test_tensor_key_compressed_serialization() {
102 let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
103 let original: TensorKeyCompressed<Vec<u8>> = TensorKeyCompressed::alloc(&module, BASE2K, K, RANK, DNUM, DSIZE);
104 test_reader_writer_interface(original);
105}
106
107#[test]
108fn glwe_to_lwe_switching_key_serialization() {
109 let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
110 let original: GLWEToLWESwitchingKey<Vec<u8>> = GLWEToLWESwitchingKey::alloc(&module, BASE2K, K, RANK, DNUM);
111 test_reader_writer_interface(original);
112}
113
114#[test]
115fn glwe_to_lwe_switching_key_compressed_serialization() {
116 let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
117 let original: GLWEToLWESwitchingKeyCompressed<Vec<u8>> =
118 GLWEToLWESwitchingKeyCompressed::alloc(&module, BASE2K, K, RANK, DNUM);
119 test_reader_writer_interface(original);
120}
121
122#[test]
123fn lwe_to_glwe_switching_key_serialization() {
124 let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
125 let original: LWEToGLWESwitchingKey<Vec<u8>> = LWEToGLWESwitchingKey::alloc(&module, BASE2K, K, RANK, DNUM);
126 test_reader_writer_interface(original);
127}
128
129#[test]
130fn lwe_to_glwe_switching_key_compressed_serialization() {
131 let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
132 let original: LWEToGLWESwitchingKeyCompressed<Vec<u8>> =
133 LWEToGLWESwitchingKeyCompressed::alloc_with(&module, BASE2K, K, RANK, DNUM);
134 test_reader_writer_interface(original);
135}
136
137#[test]
138fn lwe_switching_key_serialization() {
139 let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
140 let original: LWESwitchingKey<Vec<u8>> = LWESwitchingKey::alloc(&module, BASE2K, K, DNUM);
141 test_reader_writer_interface(original);
142}
143
144#[test]
145fn lwe_switching_key_compressed_serialization() {
146 let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
147 let original: LWESwitchingKeyCompressed<Vec<u8>> = LWESwitchingKeyCompressed::alloc(&module, BASE2K, K, DNUM);
148 test_reader_writer_interface(original);
149}
150
151#[test]
152fn ggsw_serialization() {
153 let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
154 let original: GGSW<Vec<u8>> = GGSW::alloc(&module, BASE2K, K, RANK, DNUM, DSIZE);
155 test_reader_writer_interface(original);
156}
157
158#[test]
159fn ggsw_compressed_serialization() {
160 let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
161 let original: GGSWCompressed<Vec<u8>> = GGSWCompressed::alloc(&module, BASE2K, K, RANK, DNUM, DSIZE);
162 test_reader_writer_interface(original);
163}