-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
todo: fix compress to modify buffer
- Loading branch information
Showing
7 changed files
with
205 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#![allow(warnings)] | ||
#[cfg(test)] | ||
|
||
pub(in crate::tests) mod ntt_tests { | ||
use crate::{ | ||
polynomials::*, | ||
params::*, | ||
tests::polynomials::poly_tests::*, | ||
}; | ||
use proptest::prelude::*; | ||
|
||
proptest! { | ||
#[test] | ||
fn ntt_tests(poly in new_poly()) { | ||
let output_1 = poly.normalise().ntt(); | ||
let output_2 = poly.mont_form().ntt(); | ||
let output_3 = poly.barrett_reduce().ntt(); | ||
} | ||
|
||
#[test] | ||
fn inv_ntt_test(poly in new_ntt_poly()) { | ||
let output = poly.inv_ntt(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#![allow(warnings)] | ||
#[cfg(test)] | ||
|
||
mod vec_tests { | ||
use crate::{ | ||
vectors::*, | ||
polynomials::*, | ||
params::*, | ||
tests::polynomials::poly_tests::{ | ||
new_poly, | ||
new_limited_poly, | ||
new_ntt_poly, | ||
}, | ||
tests::params::params_tests::sec_level_strategy, | ||
}; | ||
use proptest::prelude::*; | ||
use tinyvec::ArrayVec; | ||
|
||
prop_compose! { | ||
pub(in crate::tests) fn new_poly_vec() | ||
(sec_level in 2..=4usize, poly_1 in new_poly(), poly_2 in new_poly(), poly_3 in new_poly(), poly_4 in new_poly()) | ||
-> PolyVec<Unreduced> { | ||
PolyVec::from(ArrayVec::<[Poly<Unreduced>; 4]>::from_array_len([poly_1, poly_2, poly_3, poly_4], sec_level)).unwrap() | ||
} | ||
} | ||
|
||
prop_compose! { | ||
// restrict sec_level here so that we can ensure two polyvecs are the same sec_level | ||
pub(in crate::tests) fn new_limited_poly_vec(sec_level: usize) | ||
(poly_1 in new_limited_poly(), poly_2 in new_limited_poly(), poly_3 in new_limited_poly(), poly_4 in new_limited_poly()) | ||
-> PolyVec<Unreduced> { | ||
PolyVec::from(ArrayVec::<[Poly<Unreduced>; 4]>::from_array_len([poly_1, poly_2, poly_3, poly_4], sec_level)).unwrap() | ||
} | ||
} | ||
|
||
prop_compose! { | ||
// restrict sec_level here so that we can ensure two polyvecs are the same sec_level | ||
pub(in crate::tests) fn new_ntt_poly_vec(sec_level: usize) | ||
(poly_1 in new_ntt_poly(), poly_2 in new_ntt_poly(), poly_3 in new_ntt_poly(), poly_4 in new_ntt_poly()) | ||
-> PolyVec<Unreduced> { | ||
PolyVec::from(ArrayVec::<[Poly<Unreduced>; 4]>::from_array_len([poly_1, poly_2, poly_3, poly_4], sec_level)).unwrap() | ||
} | ||
} | ||
|
||
#[test] | ||
#[should_panic] | ||
fn from_test() { | ||
// new should be empty so will fail | ||
let err_result = PolyVec::from(ArrayVec::<[Poly<Unreduced>; 4]>::new()).unwrap(); | ||
} | ||
|
||
proptest! { | ||
#[test] | ||
fn sec_level_test(poly_vec in new_poly_vec()) { | ||
let sec_level = poly_vec.sec_level(); | ||
} | ||
|
||
#[test] | ||
fn polynomials_test(poly_vec in new_poly_vec()) { | ||
let polys = poly_vec.polynomials(); | ||
} | ||
|
||
#[test] | ||
fn add_test(a in new_limited_poly_vec(4), b in new_limited_poly_vec(4)) { | ||
let poly_vec = a.add(&b).unwrap(); | ||
} | ||
|
||
#[test] | ||
#[should_panic] | ||
fn add_test_different_sec_levels(a in new_limited_poly_vec(2), b in new_limited_poly_vec(3)) { | ||
let poly_vec = a.add(&b).unwrap(); | ||
} | ||
|
||
#[test] | ||
fn barrett_reduce_test(poly_vec in new_poly_vec()) { | ||
let output = poly_vec.barrett_reduce(); | ||
} | ||
|
||
#[test] | ||
fn normalise_test(poly_vec in new_poly_vec()) { | ||
let output = poly_vec.normalise(); | ||
} | ||
|
||
#[test] | ||
fn inv_ntt_test(poly_vec in new_ntt_poly_vec(4)) { | ||
let output = poly_vec.inv_ntt(); | ||
} | ||
|
||
#[test] | ||
fn ntt_test(poly_vec in new_poly_vec()) { | ||
let output = poly_vec.normalise().ntt(); | ||
} | ||
|
||
#[test] | ||
fn new_test(sec_level in sec_level_strategy()) { | ||
let output = PolyVec::new(sec_level.k()); | ||
} | ||
|
||
#[test] | ||
fn pack_test(poly_vec in new_poly_vec()) { | ||
let mut buf = [0u8; 4 * POLYBYTES]; // max buf length needed | ||
let k: usize = poly_vec.sec_level().k().into(); | ||
|
||
let output = poly_vec.normalise().pack(&mut buf[..k * POLYBYTES]).unwrap(); | ||
} | ||
|
||
#[test] | ||
fn compress_test(poly_vec in new_poly_vec()) { | ||
let mut buf = [0u8; 4 * 352]; // max poly_vec_compressed_bytes | ||
let end = poly_vec.sec_level().poly_vec_compressed_bytes(); | ||
|
||
let output = poly_vec.normalise().compress(&mut buf[..end]).unwrap(); | ||
assert_eq!(buf, [100u8; 4 * 352]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters