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, GLWECiphertext, GLWESwitchingKey, GLWEToLWESwitchingKey,
  5    LWECiphertext, LWESwitchingKey, LWEToGLWESwitchingKey, Rank, TensorKey, TorusPrecision,
  6    compressed::{
  7        AutomorphismKeyCompressed, GGLWECiphertextCompressed, GGSWCiphertextCompressed, GLWECiphertextCompressed,
  8        GLWESwitchingKeyCompressed, GLWEToLWESwitchingKeyCompressed, LWECiphertextCompressed, LWESwitchingKeyCompressed,
  9        LWEToGLWESwitchingKeyCompressed, 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: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc_with(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: GLWECiphertextCompressed<Vec<u8>> = GLWECiphertextCompressed::alloc_with(N_GLWE, BASE2K, K, RANK);
 30    test_reader_writer_interface(original);
 31}
 32
 33#[test]
 34fn lwe_serialization() {
 35    let original: LWECiphertext<Vec<u8>> = LWECiphertext::alloc_with(N_LWE, BASE2K, K);
 36    test_reader_writer_interface(original);
 37}
 38
 39#[test]
 40fn lwe_compressed_serialization() {
 41    let original: LWECiphertextCompressed<Vec<u8>> = LWECiphertextCompressed::alloc_with(BASE2K, K);
 42    test_reader_writer_interface(original);
 43}
 44
 45#[test]
 46fn test_gglwe_serialization() {
 47    let original: GGLWE<Vec<u8>> = GGLWE::alloc_with(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: GGLWECiphertextCompressed<Vec<u8>> =
 54        GGLWECiphertextCompressed::alloc_with(N_GLWE, BASE2K, K, RANK, RANK, DNUM, DSIZE);
 55    test_reader_writer_interface(original);
 56}
 57
 58#[test]
 59fn test_glwe_switching_key_serialization() {
 60    let original: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc_with(N_GLWE, BASE2K, K, RANK, RANK, DNUM, DSIZE);
 61    test_reader_writer_interface(original);
 62}
 63
 64#[test]
 65fn test_glwe_switching_key_compressed_serialization() {
 66    let original: GLWESwitchingKeyCompressed<Vec<u8>> =
 67        GLWESwitchingKeyCompressed::alloc_with(N_GLWE, BASE2K, K, RANK, RANK, DNUM, DSIZE);
 68    test_reader_writer_interface(original);
 69}
 70
 71#[test]
 72fn test_automorphism_key_serialization() {
 73    let original: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE);
 74    test_reader_writer_interface(original);
 75}
 76
 77#[test]
 78fn test_automorphism_key_compressed_serialization() {
 79    let original: AutomorphismKeyCompressed<Vec<u8>> =
 80        AutomorphismKeyCompressed::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE);
 81    test_reader_writer_interface(original);
 82}
 83
 84#[test]
 85fn test_tensor_key_serialization() {
 86    let original: TensorKey<Vec<u8>> = TensorKey::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE);
 87    test_reader_writer_interface(original);
 88}
 89
 90#[test]
 91fn test_tensor_key_compressed_serialization() {
 92    let original: TensorKeyCompressed<Vec<u8>> = TensorKeyCompressed::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE);
 93    test_reader_writer_interface(original);
 94}
 95
 96#[test]
 97fn glwe_to_lwe_switching_key_serialization() {
 98    let original: GLWEToLWESwitchingKey<Vec<u8>> = GLWEToLWESwitchingKey::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM);
 99    test_reader_writer_interface(original);
100}
101
102#[test]
103fn glwe_to_lwe_switching_key_compressed_serialization() {
104    let original: GLWEToLWESwitchingKeyCompressed<Vec<u8>> =
105        GLWEToLWESwitchingKeyCompressed::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM);
106    test_reader_writer_interface(original);
107}
108
109#[test]
110fn lwe_to_glwe_switching_key_serialization() {
111    let original: LWEToGLWESwitchingKey<Vec<u8>> = LWEToGLWESwitchingKey::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM);
112    test_reader_writer_interface(original);
113}
114
115#[test]
116fn lwe_to_glwe_switching_key_compressed_serialization() {
117    let original: LWEToGLWESwitchingKeyCompressed<Vec<u8>> =
118        LWEToGLWESwitchingKeyCompressed::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM);
119    test_reader_writer_interface(original);
120}
121
122#[test]
123fn lwe_switching_key_serialization() {
124    let original: LWESwitchingKey<Vec<u8>> = LWESwitchingKey::alloc_with(N_GLWE, BASE2K, K, DNUM);
125    test_reader_writer_interface(original);
126}
127
128#[test]
129fn lwe_switching_key_compressed_serialization() {
130    let original: LWESwitchingKeyCompressed<Vec<u8>> = LWESwitchingKeyCompressed::alloc_with(N_GLWE, BASE2K, K, DNUM);
131    test_reader_writer_interface(original);
132}
133
134#[test]
135fn ggsw_serialization() {
136    let original: GGSW<Vec<u8>> = GGSW::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE);
137    test_reader_writer_interface(original);
138}
139
140#[test]
141fn ggsw_compressed_serialization() {
142    let original: GGSWCiphertextCompressed<Vec<u8>> = GGSWCiphertextCompressed::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE);
143    test_reader_writer_interface(original);
144}