add modulus switching to GLWE ciphertexts (and Zq,Rq)

This commit is contained in:
2025-07-16 18:15:51 +02:00
parent c73ff20931
commit 4a082b9187
8 changed files with 60 additions and 16 deletions

View File

@@ -49,9 +49,6 @@ impl<const Q: u64, const N: usize> Ring for Rq<Q, N> {
}
}
// TODO define a trait "PolynomialRingTrait" or similar, so that when other structs use it can just
// use the trait and not need to add '<Q, N>' to their params
impl<const Q: u64, const N: usize> From<crate::ring::R<N>> for Rq<Q, N> {
fn from(r: crate::ring::R<N>) -> Self {
Self::from_vec(
@@ -165,7 +162,7 @@ impl<const Q: u64, const N: usize> Rq<Q, N> {
}
/// perform the mod switch operation from Q to Q', where Q2=Q'
fn mod_switch<const Q2: u64>(&self) -> Rq<Q2, N> {
pub fn mod_switch<const Q2: u64>(&self) -> Rq<Q2, N> {
Rq::<Q2, N> {
coeffs: array::from_fn(|i| self.coeffs[i].mod_switch::<Q2>()),
evals: None,

View File

@@ -4,7 +4,7 @@ use std::fmt::Debug;
use std::iter::Sum;
use std::ops::{Add, AddAssign, Mul, Sub, SubAssign};
/// represents a ring element
/// Represents a ring element. Currently implemented by ring.rs#R and ringq.rs#Rq.
pub trait Ring:
Sized
+ Add<Output = Self>
@@ -25,6 +25,6 @@ pub trait Ring:
fn coeffs(&self) -> Vec<Self::C>;
fn zero() -> Self;
fn rand(rng: impl Rng, dist: impl Distribution<f64>) -> Self;
// note/wip/warning: dist (0,q) with f64, will output more '0=q' elements than other values
fn rand(rng: impl Rng, dist: impl Distribution<f64>) -> Self;
}