Skip to content

Commit

Permalink
adds matrix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
supinie committed Apr 16, 2024
1 parent 218b94d commit 0136f69
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 93 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ mod tests {
// mod buffer;
mod field_operations;
mod indcpa;
// mod matrix;
mod matrix;
mod ntt;
mod sample;
mod params;
Expand Down
92 changes: 0 additions & 92 deletions src/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,95 +105,3 @@ impl Matrix<Montgomery> {
})
}
}

// pub type Mat512 = [PolyVec512; 2];
// pub type Mat768 = [PolyVec768; 3];
// pub type Mat1024 = [PolyVec1024; 4];

// pub trait New {
// fn new() -> Self;
// }

// pub trait MatOperations {
// // seed length 32
// fn derive(seed: &[u8], transpose: bool) -> Self;
// fn transpose(&mut self);
// }

// impl New for Mat512 {
// fn new() -> Self {
// [PolyVec512::from([Poly::new(); 2]); 2]
// }
// }

// impl New for Mat768 {
// fn new() -> Self {
// [PolyVec768::from([Poly::new(); 3]); 3]
// }
// }

// impl New for Mat1024 {
// fn new() -> Self {
// [PolyVec1024::from([Poly::new(); 4]); 4]
// }
// }

// impl GetSecLevel for Mat512 {
// fn sec_level() -> SecurityLevel {
// SecurityLevel::new(K::Two)
// }
// }

// impl GetSecLevel for Mat768 {
// fn sec_level() -> SecurityLevel {
// SecurityLevel::new(K::Three)
// }
// }

// impl GetSecLevel for Mat1024 {
// fn sec_level() -> SecurityLevel {
// SecurityLevel::new(K::Four)
// }
// }

// macro_rules! impl_matrix {
// ($variant:ty) => {
// impl MatOperations for $variant {
// fn derive(seed: &[u8], transpose: bool) -> Self {
// let mut matrix = Self::new();
// match transpose {
// true => {
// for (i, vector) in matrix.iter_mut().enumerate() {
// for (j, polynomial) in vector.iter_mut().enumerate() {
// polynomial.derive_uniform(seed, i as u8, j as u8);
// }
// }
// }
// false => {
// for (i, vector) in matrix.iter_mut().enumerate() {
// for (j, polynomial) in vector.iter_mut().enumerate() {
// polynomial.derive_uniform(seed, j as u8, i as u8);
// }
// }
// }
// }
// matrix
// }

// fn transpose(&mut self) {
// let k: u8 = <$variant as GetSecLevel>::sec_level().k().into();
// for i in 0..usize::from(k - 1) {
// for j in i + 1..usize::from(k) {
// let temp = self[i][j];
// self[i][j] = self[j][i];
// self[j][i] = temp;
// }
// }
// }
// }
// };
// }

// impl_matrix!(Mat512);
// impl_matrix!(Mat768);
// impl_matrix!(Mat1024);
50 changes: 50 additions & 0 deletions src/tests/matrix.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#![allow(warnings)]
#[cfg(test)]

mod matrix_tests {
use crate::{
matrix::*, params::*, polynomials::Montgomery, tests::params::params_tests::sec_level_strategy
};
use proptest::prelude::*;
use tinyvec::ArrayVec;

prop_compose! {
pub(in crate::tests) fn new_matrix()
(sec_level in sec_level_strategy(), seed in prop::array::uniform32(u8::MIN..u8::MAX), transpose in prop::bool::ANY)
-> Matrix<Montgomery> {
Matrix::derive(&seed, transpose, sec_level.k()).unwrap()
}
}

proptest! {
#[test]
fn derive_test(
sec_level in sec_level_strategy(),
seed in prop::array::uniform32(u8::MIN..u8::MAX),
transpose in prop::bool::ANY,
) {
let matrix = Matrix::derive(&seed, transpose, sec_level.k()).unwrap();
}

#[test]
fn sec_level_test(mat in new_matrix()) {
let sec_level = mat.sec_level();
}

#[test]
fn vectors_test(mat in new_matrix()) {
let vecs = mat.vectors();
}

#[test]
fn transpose_test(
sec_level in sec_level_strategy(),
seed in prop::array::uniform32(u8::MIN..u8::MAX),
) {
let matrix_1 = Matrix::derive(&seed, false, sec_level.k()).unwrap().transpose().unwrap();
let matrix_2 = Matrix::derive(&seed, true, sec_level.k()).unwrap();

assert_eq!(matrix_1, matrix_2);
}
}
}

0 comments on commit 0136f69

Please sign in to comment.