Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ntt): avoid panicking on non prime inputs #13

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/prime32.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
bit_rev,
fastdiv::{Div32, Div64},
prime::is_prime64,
roots::find_primitive_root64,
};
use aligned_vec::{avec, ABox};
Expand Down Expand Up @@ -632,6 +633,8 @@ impl Plan {
// as SIMD registers can contain at most 16*u32
// and the implementation assumes that SIMD registers are full
if polynomial_size < 32
|| !polynomial_size.is_power_of_two()
|| !is_prime64(modulus as u64)
|| find_primitive_root64(Div64::new(modulus as u64), 2 * polynomial_size as u64)
.is_none()
{
Expand Down
9 changes: 8 additions & 1 deletion src/prime64.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{bit_rev, fastdiv::Div64, roots::find_primitive_root64};
use crate::{bit_rev, fastdiv::Div64, prime::is_prime64, roots::find_primitive_root64};
use aligned_vec::{avec, ABox};

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Expand Down Expand Up @@ -707,6 +707,8 @@ impl Plan {
// as SIMD registers can contain at most 8*u64
// and the implementation assumes that SIMD registers are full
if polynomial_size < 16
|| !polynomial_size.is_power_of_two()
|| !is_prime64(modulus)
|| find_primitive_root64(p_div, 2 * polynomial_size as u64).is_none()
{
None
Expand Down Expand Up @@ -1869,4 +1871,9 @@ mod x86_tests {
assert_eq!(val, val_target);
}
}

#[test]
fn test_plan_crash_github_11() {
assert!(Plan::try_new(2048, 1024).is_none());
}
}
Loading