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