From 9c021d3c76bcac258a87bb9aa483ae5d7af4d74a Mon Sep 17 00:00:00 2001 From: Jean-Philippe Bossuat Date: Wed, 22 Jan 2025 11:18:06 +0100 Subject: [PATCH] added a_mul_by_x_pow_b_into_a --- .vscode/launch.json | 16 ++++++++++++++++ math/src/ring/impl_u64/ring.rs | 20 +++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..10efcb2 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "lldb", + "request": "launch", + "name": "Debug", + "program": "${workspaceFolder}/", + "args": [], + "cwd": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/math/src/ring/impl_u64/ring.rs b/math/src/ring/impl_u64/ring.rs index b1e794d..eee5f30 100644 --- a/math/src/ring/impl_u64/ring.rs +++ b/math/src/ring/impl_u64/ring.rs @@ -2,7 +2,7 @@ use crate::dft::ntt::Table; use crate::modulus::barrett::Barrett; use crate::modulus::montgomery::Montgomery; use crate::modulus::prime::Prime; -use crate::modulus::VectorOperations; +use crate::modulus::{VectorOperations, ONCE}; use crate::modulus::{BARRETT, REDUCEMOD}; use crate::poly::Poly; use crate::ring::Ring; @@ -430,4 +430,22 @@ impl Ring { &mut c.0, ); } + + pub fn a_mul_by_x_pow_b_into_a(&self, b: i32, a: &mut Poly) { + let n: usize = self.n(); + let cyclotomic_order: usize = self.cyclotomic_order(); + + let b_0: usize = (b as usize).wrapping_add(cyclotomic_order) & (cyclotomic_order - 1); + let b_1: usize = b as usize & (n - 1); + + a.0.rotate_right(b_1); + + if b_0 > b_1 { + self.modulus + .va_neg_into_va::(&mut a.0[b_1..]) + } else { + self.modulus + .va_neg_into_va::(&mut a.0[..b_1]) + } + } }