mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-01-10 07:08:03 -05:00
chore(core): add check for polynomial size in schoolbook mul
This commit is contained in:
committed by
Nicolas Sarlin
parent
4b6942a0f8
commit
cc6b074f6d
@@ -14,6 +14,10 @@ use crate::core_crypto::entities::*;
|
||||
/// Computations wrap around (similar to computing modulo $2^{n\_{bits}}$) when exceeding the
|
||||
/// unsigned integer capacity.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This function will panic if `lhs` and `rhs` do not have the same polynomial size.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
@@ -56,6 +60,10 @@ pub fn polynomial_wrapping_add_assign_custom_mod<Scalar, OutputCont, InputCont>(
|
||||
/// Computations wrap around (similar to computing modulo $2^{n\_{bits}}$) when exceeding the
|
||||
/// unsigned integer capacity.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This function will panic if `lhs` and `rhs` do not have the same polynomial size.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
@@ -107,7 +115,9 @@ pub fn polynomial_wrapping_sub_assign_custom_mod<Scalar, OutputCont, InputCont>(
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This function will panic if the lists are not of the same size
|
||||
/// This function will panic in any of these situations:
|
||||
/// - the lists are not of the same size
|
||||
/// - the polynomial sizes are not the same
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
@@ -165,6 +175,17 @@ pub fn polynomial_wrapping_add_multisum_assign_custom_mod<
|
||||
}
|
||||
}
|
||||
|
||||
/// Fill the output polynomial, with the result of the product of two polynomials, reduced modulo
|
||||
/// $(X^{N} + 1)$ with the schoolbook algorithm.
|
||||
///
|
||||
/// # Note
|
||||
///
|
||||
/// Computations wrap around (similar to computing modulo $2^{n\_{bits}}$) when exceeding the
|
||||
/// unsigned integer capacity.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This function will panic if `output`, `lhs` and `rhs` do not have the same polynomial size.
|
||||
fn polynomial_wrapping_add_mul_schoolbook_assign<Scalar, OutputCont, InputCont1, InputCont2>(
|
||||
output: &mut Polynomial<OutputCont>,
|
||||
lhs: &Polynomial<InputCont1>,
|
||||
@@ -175,6 +196,7 @@ fn polynomial_wrapping_add_mul_schoolbook_assign<Scalar, OutputCont, InputCont1,
|
||||
InputCont1: Container<Element = Scalar>,
|
||||
InputCont2: Container<Element = Scalar>,
|
||||
{
|
||||
assert_eq!(lhs.polynomial_size(), rhs.polynomial_size());
|
||||
fn implementation<Scalar: UnsignedInteger>(
|
||||
mut output: Polynomial<&mut [Scalar]>,
|
||||
lhs: Polynomial<&[Scalar]>,
|
||||
@@ -266,6 +288,10 @@ fn polynomial_wrapping_add_mul_schoolbook_assign_custom_mod<
|
||||
/// Computations wrap around (similar to computing modulo $2^{n\_{bits}}$) when exceeding the
|
||||
/// unsigned integer capacity.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This function will panic if `output`, `lhs` and `rhs` do not have the same polynomial size.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
@@ -500,6 +526,10 @@ fn copy_without_neg<Scalar: UnsignedInteger>(dst: &mut [Scalar], src: &[Scalar])
|
||||
/// Computations wrap around (similar to computing modulo $2^{n\_{bits}}$) when exceeding the
|
||||
/// unsigned integer capacity.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This function will panic if `output` and `input` do not have the same polynomial size.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
@@ -560,6 +590,10 @@ pub fn polynomial_wrapping_monic_monomial_div<Scalar, OutputCont, InputCont>(
|
||||
/// Computations wrap around (similar to computing modulo $2^{n\_{bits}}$) when exceeding the
|
||||
/// unsigned integer capacity.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This function will panic if `output` and `input` do not have the same polynomial size.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
@@ -617,6 +651,10 @@ pub fn polynomial_wrapping_monic_monomial_mul<Scalar, OutputCont, InputCont>(
|
||||
///
|
||||
/// output = input * X^degree - input
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This function will panic if `output` and `input` do not have the same polynomial size.
|
||||
///
|
||||
/// # Note
|
||||
///
|
||||
/// Computations wrap around (similar to computing modulo $2^{n\_{bits}}$) when exceeding the
|
||||
@@ -704,7 +742,9 @@ pub(crate) fn polynomial_wrapping_monic_monomial_mul_and_subtract<Scalar, Output
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This function will panic if the lists are not of the same size
|
||||
/// This function will panic in any of these situations:
|
||||
/// - the lists are not of the same size
|
||||
/// - the polynomial sizes are not the same
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
@@ -863,6 +903,10 @@ fn polynomial_wrapping_sub_mul_schoolbook_assign_custom_mod<
|
||||
/// Computations wrap around (similar to computing modulo $2^{n\_{bits}}$) when exceeding the
|
||||
/// unsigned integer capacity.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This function will panic if `output`, `lhs` and `rhs` do not have the same polynomial size.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
@@ -1041,6 +1085,10 @@ pub fn polynomial_wrapping_mul<Scalar, OutputCont, LhsCont, RhsCont>(
|
||||
/// Computations wrap around (similar to computing modulo $2^{n\_{bits}}$) when exceeding the
|
||||
/// unsigned integer capacity.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This function will panic if `output`, `lhs` and `rhs` do not have the same polynomial size.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
|
||||
Reference in New Issue
Block a user