Skip to content
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
2 changes: 0 additions & 2 deletions mux_circuits/src/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,6 @@ mod tests {
fn case(n: usize, m: usize) {
let circuit = unsigned_multiplier(n, m);

dbg!(circuit.metrics());

for _ in 0..100 {
let a_raw = rng().next_u64() % (0x1 << n) as u64;
let b_raw = rng().next_u64() % (0x1 << m) as u64;
Expand Down
2 changes: 0 additions & 2 deletions sunscreen_gpu_runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,8 +900,6 @@ mod tests {

let z_gpu = z_gpu.as_slice();

dbg!(z_gpu);

for (z, (x, y)) in z_gpu.iter().zip(x.iter().zip(y.iter())) {
assert_eq!(*z, *x + *y);
}
Expand Down
11 changes: 11 additions & 0 deletions sunscreen_math/src/misc_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ where
fn one() -> Self;
}

impl Zero for Complex<f64> {
fn zero() -> Self {
Self::new(0.0, 0.0)
}

fn vartime_is_zero(&self) -> bool {
self.re == 0.0 && self.im == 0.0
}
}

/// Methods for switching elements between finite rings.
pub trait ModSwitch<R> {
/// Treat the input value as unsigned in the current Ring and produce
Expand All @@ -31,4 +41,5 @@ pub trait ModSwitch<R> {
fn mod_switch_signed(&self) -> R;
}

use num::Complex;
pub use num::traits::ToBytes;
4 changes: 2 additions & 2 deletions sunscreen_tfhe/src/dst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ macro_rules! dst {
}
}

impl<T> $ref_t<T> where T: Clone $(+ $t_bounds)*, $wrapper<T>: num::Zero {
impl<T> $ref_t<T> where T: Clone $(+ $t_bounds)*, $wrapper<T>: sunscreen_math::Zero {
#[allow(unused)]
/// Clears the contents of self to contain zero
pub fn clear(&mut self) {
use crate::dst::AsMutSlice;

for x in self.as_mut_slice() {
*x = <$wrapper<T> as num::Zero>::zero();
*x = <$wrapper<T> as sunscreen_math::Zero>::zero();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion sunscreen_tfhe/src/entities/ggsw_ciphertext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ where

GgswCiphertext {
data: dst_from_iter(std::iter::repeat_n(
Torus::from(<S as num::Zero>::zero()),
Torus::from(<S as sunscreen_math::Zero>::zero()),
len,
)),
}
Expand Down
2 changes: 1 addition & 1 deletion sunscreen_tfhe/src/entities/glev_ciphertext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ where

GlevCiphertext {
data: dst_from_iter(std::iter::repeat_n(
Torus::from(<S as num::Zero>::zero()),
Torus::from(<S as sunscreen_math::Zero>::zero()),
len,
)),
}
Expand Down
6 changes: 3 additions & 3 deletions sunscreen_tfhe/src/entities/glwe_ciphertext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ where
.nth(index)
.unwrap()
.coeffs_mut()
.fill(Torus::from(<S as num::Zero>::zero()));
.fill(Torus::from(<S as sunscreen_math::Zero>::zero()));
}

/// Copies the coefficients from the provided polynomial into the GLWE
Expand Down Expand Up @@ -243,7 +243,7 @@ where
} else {
// Zero out all other positions
poly.coeffs_mut()
.fill(Torus::from(<S as num::Zero>::zero()));
.fill(Torus::from(<S as sunscreen_math::Zero>::zero()));
}
}
}
Expand All @@ -257,7 +257,7 @@ where
// should be zero.
GlweCiphertext {
data: dst_from_iter(std::iter::repeat_n(
Torus::from(<S as num::Zero>::zero()),
Torus::from(<S as sunscreen_math::Zero>::zero()),
len,
)),
}
Expand Down
15 changes: 14 additions & 1 deletion sunscreen_tfhe/src/entities/glwe_secret_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};

use crate::{
GlweDef, GlweDimension, PlaintextBits, RadixDecomposition, Torus, TorusOps,
dst::{FromSlice, NoWrapper, OverlaySize, dst_from_iter},
dst::{FromSlice, NoWrapper, OverlaySize, dst_allocate, dst_from_iter},
entities::{
DstIterator, DstIteratorMut, GgswCiphertext, ParallelDstIterator, ParallelDstIteratorMut,
},
Expand Down Expand Up @@ -48,6 +48,19 @@ impl<S> GlweSecretKey<S>
where
S: TorusOps,
{
/// Create an empty secret key.
///
/// # Security
/// The key is zero, which is insecure. You must initialize the key with an appropriate
/// distribution.
pub(crate) fn insecure_zero(params: &GlweDef) -> Self {
let len = GlweSecretKeyRef::<S>::size(params.dim);

Self {
data: dst_allocate(len),
}
}

fn generate(params: &GlweDef, torus_element_generator: impl Fn() -> S) -> GlweSecretKey<S> {
params.assert_valid();

Expand Down
2 changes: 1 addition & 1 deletion sunscreen_tfhe/src/entities/lwe_ciphertext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl<S: TorusOps> LweCiphertextRef<S> {

LweCiphertext {
data: dst_from_iter(std::iter::repeat_n(
Torus::from(<S as num::Zero>::zero()),
Torus::from(<S as sunscreen_math::Zero>::zero()),
len,
)),
}
Expand Down
2 changes: 1 addition & 1 deletion sunscreen_tfhe/src/entities/lwe_public_key.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use num::Zero;
use serde::{Deserialize, Serialize};
use sunscreen_math::Zero;

use crate::{
LweDef, LweDimension, PlaintextBits, Torus, TorusOps,
Expand Down
2 changes: 1 addition & 1 deletion sunscreen_tfhe/src/entities/lwe_secret_key.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use num::Zero;
use serde::{Deserialize, Serialize};
use sunscreen_math::Zero;

use crate::{
LweDef, LweDimension, PlaintextBits, Torus, TorusOps,
Expand Down
4 changes: 3 additions & 1 deletion sunscreen_tfhe/src/entities/polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
};

use bytemuck::Pod;
use num::{Complex, Zero};
use num::Complex;
use serde::{Deserialize, Serialize};

use crate::{
Expand All @@ -20,6 +20,8 @@ use crate::{

use super::PolynomialFftRef;

use sunscreen_math::Zero;

dst! {
/// A type representing a polynomial.
Polynomial,
Expand Down
3 changes: 0 additions & 3 deletions sunscreen_tfhe/src/gpu/tests/bootstrapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ fn can_programmable_bootstrap() {

encrypt_lwe_ciphertext(ct, &lwe_sk, msg, &lwe);
// trivially_encrypt_lwe_ciphertext(ct, &msg, &lwe);

dbg!(ct.a_b(&lwe).1);
}

// Fill the LUT with nonsense and we'll overwrite it with
Expand Down Expand Up @@ -83,7 +81,6 @@ fn can_programmable_bootstrap() {
let mut dbg_msg = Polynomial::zero(glwe.dim.polynomial_degree.0);
decrypt_glwe_ciphertext(&mut dbg_msg, &out, &glwe_sk, &glwe);

dbg!(i);
for c in dbg_msg.coeffs().iter().take(8) {
println!("pt {:0>64b}", c.inner());
}
Expand Down
2 changes: 2 additions & 0 deletions sunscreen_tfhe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ pub use error::*;
#[cfg(feature = "gpu")]
/// GPU acceleraton for TFHE
pub mod gpu;

mod zkp;
Loading
Loading