diff --git a/libcrux-ml-dsa/src/simd/portable/ntt.rs b/libcrux-ml-dsa/src/simd/portable/ntt.rs index 1674c9c66..ac40a9c1c 100644 --- a/libcrux-ml-dsa/src/simd/portable/ntt.rs +++ b/libcrux-ml-dsa/src/simd/portable/ntt.rs @@ -1,4 +1,4 @@ -use super::arithmetic; +use super::arithmetic::{self, montgomery_multiply_fe_by_fer}; use crate::simd::{ portable::PortableSIMDUnit, traits::{ @@ -15,19 +15,19 @@ pub fn simd_unit_ntt_at_layer_0( zeta2: i32, zeta3: i32, ) -> PortableSIMDUnit { - let t = arithmetic::montgomery_multiply_fe_by_fer(simd_unit.coefficients[1], zeta0); + let t = montgomery_multiply_fe_by_fer(simd_unit.coefficients[1], zeta0); simd_unit.coefficients[1] = simd_unit.coefficients[0] - t; simd_unit.coefficients[0] = simd_unit.coefficients[0] + t; - let t = arithmetic::montgomery_multiply_fe_by_fer(simd_unit.coefficients[3], zeta1); + let t = montgomery_multiply_fe_by_fer(simd_unit.coefficients[3], zeta1); simd_unit.coefficients[3] = simd_unit.coefficients[2] - t; simd_unit.coefficients[2] = simd_unit.coefficients[2] + t; - let t = arithmetic::montgomery_multiply_fe_by_fer(simd_unit.coefficients[5], zeta2); + let t = montgomery_multiply_fe_by_fer(simd_unit.coefficients[5], zeta2); simd_unit.coefficients[5] = simd_unit.coefficients[4] - t; simd_unit.coefficients[4] = simd_unit.coefficients[4] + t; - let t = arithmetic::montgomery_multiply_fe_by_fer(simd_unit.coefficients[7], zeta3); + let t = montgomery_multiply_fe_by_fer(simd_unit.coefficients[7], zeta3); simd_unit.coefficients[7] = simd_unit.coefficients[6] - t; simd_unit.coefficients[6] = simd_unit.coefficients[6] + t; @@ -39,19 +39,19 @@ pub fn simd_unit_ntt_at_layer_1( zeta1: i32, zeta2: i32, ) -> PortableSIMDUnit { - let t = arithmetic::montgomery_multiply_fe_by_fer(simd_unit.coefficients[2], zeta1); + let t = montgomery_multiply_fe_by_fer(simd_unit.coefficients[2], zeta1); simd_unit.coefficients[2] = simd_unit.coefficients[0] - t; simd_unit.coefficients[0] = simd_unit.coefficients[0] + t; - let t = arithmetic::montgomery_multiply_fe_by_fer(simd_unit.coefficients[3], zeta1); + let t = montgomery_multiply_fe_by_fer(simd_unit.coefficients[3], zeta1); simd_unit.coefficients[3] = simd_unit.coefficients[1] - t; simd_unit.coefficients[1] = simd_unit.coefficients[1] + t; - let t = arithmetic::montgomery_multiply_fe_by_fer(simd_unit.coefficients[6], zeta2); + let t = montgomery_multiply_fe_by_fer(simd_unit.coefficients[6], zeta2); simd_unit.coefficients[6] = simd_unit.coefficients[4] - t; simd_unit.coefficients[4] = simd_unit.coefficients[4] + t; - let t = arithmetic::montgomery_multiply_fe_by_fer(simd_unit.coefficients[7], zeta2); + let t = montgomery_multiply_fe_by_fer(simd_unit.coefficients[7], zeta2); simd_unit.coefficients[7] = simd_unit.coefficients[5] - t; simd_unit.coefficients[5] = simd_unit.coefficients[5] + t; @@ -59,19 +59,19 @@ pub fn simd_unit_ntt_at_layer_1( } #[inline(always)] pub fn simd_unit_ntt_at_layer_2(mut simd_unit: PortableSIMDUnit, zeta: i32) -> PortableSIMDUnit { - let t = arithmetic::montgomery_multiply_fe_by_fer(simd_unit.coefficients[4], zeta); + let t = montgomery_multiply_fe_by_fer(simd_unit.coefficients[4], zeta); simd_unit.coefficients[4] = simd_unit.coefficients[0] - t; simd_unit.coefficients[0] = simd_unit.coefficients[0] + t; - let t = arithmetic::montgomery_multiply_fe_by_fer(simd_unit.coefficients[5], zeta); + let t = montgomery_multiply_fe_by_fer(simd_unit.coefficients[5], zeta); simd_unit.coefficients[5] = simd_unit.coefficients[1] - t; simd_unit.coefficients[1] = simd_unit.coefficients[1] + t; - let t = arithmetic::montgomery_multiply_fe_by_fer(simd_unit.coefficients[6], zeta); + let t = montgomery_multiply_fe_by_fer(simd_unit.coefficients[6], zeta); simd_unit.coefficients[6] = simd_unit.coefficients[2] - t; simd_unit.coefficients[2] = simd_unit.coefficients[2] + t; - let t = arithmetic::montgomery_multiply_fe_by_fer(simd_unit.coefficients[7], zeta); + let t = montgomery_multiply_fe_by_fer(simd_unit.coefficients[7], zeta); simd_unit.coefficients[7] = simd_unit.coefficients[3] - t; simd_unit.coefficients[3] = simd_unit.coefficients[3] + t; @@ -88,19 +88,19 @@ pub fn invert_ntt_at_layer_0( ) -> PortableSIMDUnit { let a_minus_b = simd_unit.coefficients[1] - simd_unit.coefficients[0]; simd_unit.coefficients[0] = simd_unit.coefficients[0] + simd_unit.coefficients[1]; - simd_unit.coefficients[1] = arithmetic::montgomery_multiply_fe_by_fer(a_minus_b, zeta0); + simd_unit.coefficients[1] = montgomery_multiply_fe_by_fer(a_minus_b, zeta0); let a_minus_b = simd_unit.coefficients[3] - simd_unit.coefficients[2]; simd_unit.coefficients[2] = simd_unit.coefficients[2] + simd_unit.coefficients[3]; - simd_unit.coefficients[3] = arithmetic::montgomery_multiply_fe_by_fer(a_minus_b, zeta1); + simd_unit.coefficients[3] = montgomery_multiply_fe_by_fer(a_minus_b, zeta1); let a_minus_b = simd_unit.coefficients[5] - simd_unit.coefficients[4]; simd_unit.coefficients[4] = simd_unit.coefficients[4] + simd_unit.coefficients[5]; - simd_unit.coefficients[5] = arithmetic::montgomery_multiply_fe_by_fer(a_minus_b, zeta2); + simd_unit.coefficients[5] = montgomery_multiply_fe_by_fer(a_minus_b, zeta2); let a_minus_b = simd_unit.coefficients[7] - simd_unit.coefficients[6]; simd_unit.coefficients[6] = simd_unit.coefficients[6] + simd_unit.coefficients[7]; - simd_unit.coefficients[7] = arithmetic::montgomery_multiply_fe_by_fer(a_minus_b, zeta3); + simd_unit.coefficients[7] = montgomery_multiply_fe_by_fer(a_minus_b, zeta3); simd_unit } @@ -112,19 +112,19 @@ pub fn invert_ntt_at_layer_1( ) -> PortableSIMDUnit { let a_minus_b = simd_unit.coefficients[2] - simd_unit.coefficients[0]; simd_unit.coefficients[0] = simd_unit.coefficients[0] + simd_unit.coefficients[2]; - simd_unit.coefficients[2] = arithmetic::montgomery_multiply_fe_by_fer(a_minus_b, zeta0); + simd_unit.coefficients[2] = montgomery_multiply_fe_by_fer(a_minus_b, zeta0); let a_minus_b = simd_unit.coefficients[3] - simd_unit.coefficients[1]; simd_unit.coefficients[1] = simd_unit.coefficients[1] + simd_unit.coefficients[3]; - simd_unit.coefficients[3] = arithmetic::montgomery_multiply_fe_by_fer(a_minus_b, zeta0); + simd_unit.coefficients[3] = montgomery_multiply_fe_by_fer(a_minus_b, zeta0); let a_minus_b = simd_unit.coefficients[6] - simd_unit.coefficients[4]; simd_unit.coefficients[4] = simd_unit.coefficients[4] + simd_unit.coefficients[6]; - simd_unit.coefficients[6] = arithmetic::montgomery_multiply_fe_by_fer(a_minus_b, zeta1); + simd_unit.coefficients[6] = montgomery_multiply_fe_by_fer(a_minus_b, zeta1); let a_minus_b = simd_unit.coefficients[7] - simd_unit.coefficients[5]; simd_unit.coefficients[5] = simd_unit.coefficients[5] + simd_unit.coefficients[7]; - simd_unit.coefficients[7] = arithmetic::montgomery_multiply_fe_by_fer(a_minus_b, zeta1); + simd_unit.coefficients[7] = montgomery_multiply_fe_by_fer(a_minus_b, zeta1); simd_unit } @@ -132,19 +132,19 @@ pub fn invert_ntt_at_layer_1( pub fn invert_ntt_at_layer_2(mut simd_unit: PortableSIMDUnit, zeta: i32) -> PortableSIMDUnit { let a_minus_b = simd_unit.coefficients[4] - simd_unit.coefficients[0]; simd_unit.coefficients[0] = simd_unit.coefficients[0] + simd_unit.coefficients[4]; - simd_unit.coefficients[4] = arithmetic::montgomery_multiply_fe_by_fer(a_minus_b, zeta); + simd_unit.coefficients[4] = montgomery_multiply_fe_by_fer(a_minus_b, zeta); let a_minus_b = simd_unit.coefficients[5] - simd_unit.coefficients[1]; simd_unit.coefficients[1] = simd_unit.coefficients[1] + simd_unit.coefficients[5]; - simd_unit.coefficients[5] = arithmetic::montgomery_multiply_fe_by_fer(a_minus_b, zeta); + simd_unit.coefficients[5] = montgomery_multiply_fe_by_fer(a_minus_b, zeta); let a_minus_b = simd_unit.coefficients[6] - simd_unit.coefficients[2]; simd_unit.coefficients[2] = simd_unit.coefficients[2] + simd_unit.coefficients[6]; - simd_unit.coefficients[6] = arithmetic::montgomery_multiply_fe_by_fer(a_minus_b, zeta); + simd_unit.coefficients[6] = montgomery_multiply_fe_by_fer(a_minus_b, zeta); let a_minus_b = simd_unit.coefficients[7] - simd_unit.coefficients[3]; simd_unit.coefficients[3] = simd_unit.coefficients[3] + simd_unit.coefficients[7]; - simd_unit.coefficients[7] = arithmetic::montgomery_multiply_fe_by_fer(a_minus_b, zeta); + simd_unit.coefficients[7] = montgomery_multiply_fe_by_fer(a_minus_b, zeta); simd_unit }