Crate bgv

Source
Expand description

An efficient FHE library

§Example

 use rand::prelude::*;
 use bgv::{math, BGV};

 const T: u64 = 65537;
 const N: usize = 1024;
 const L: usize = 15;
 const NBITS: u8 = 50;
 const MU: f64 = 0.0;
 const SIGMA: f64 = 3.19;

 let mut rng = rand::rng();
 let b = BGV::new(N, L, NBITS, MU, SIGMA, T);
 let k = b.key_gen();

 let m1: Vec<u64> = (0..N).map(|_| rng.random_range(0..T) as u64).collect();
 let m2: Vec<u64> = (0..N).map(|_| rng.random_range(0..T) as u64).collect();
 let sum: Vec<u64> = (0..N).map(|i| math::modadd(m1[i], m2[i], T)).collect();

 let x = b.encrypt(&m1, &k.pk);
 let y = b.encrypt(&m2, &k.pk);
 let c = b.add(&x, &y);

 let m3 = b.decrypt(&c, &k.s);
 assert_eq!(m3, sum);

Modules§

math
rq

Structs§

BGV
Implements the BGV scheme
BGVKey
Represents a BGV key pair
Ciphertext
KeyPair
Generic Key pair