pub struct SecretKey { /* private fields */ }
Expand description
A BFV12 Secret Key
Implementations
sourceimpl SecretKey
impl SecretKey
sourcepub fn generate<T: RngCore + CryptoRng>(degree: usize, rng: &mut T) -> SecretKey
pub fn generate<T: RngCore + CryptoRng>(degree: usize, rng: &mut T) -> SecretKey
Generate a secret key by sampling the coefficients of s uniformly from R_2, which in this implementation is the set {0, 1}.
degree
: the polynomial degree of the secret keyrng
: the RNG used to generate randomness
use bfv12::SecretKey;
let degree = 4;
let secret_key = SecretKey::generate(degree, &mut rng);
sourcepub fn public_key_gen<T: RngCore + CryptoRng>(
&self,
q: i64,
std_dev: f64,
rng: &mut T
) -> PublicKey
pub fn public_key_gen<T: RngCore + CryptoRng>(
&self,
q: i64,
std_dev: f64,
rng: &mut T
) -> PublicKey
Generate a public key from a secret key.
q
: the ciphertext modulusstd_dev
: the standard deviation for error generationrng
: the RNG used to generate randomness
use bfv12::SecretKey;
let degree = 4;
let std_dev = 3.2;
let q = 65536;
let secret_key = SecretKey::generate(degree, &mut rng);
let public_key = secret_key.public_key_gen(q, std_dev, &mut rng);
sourcepub fn relin_key_gen_1<T: RngCore + CryptoRng>(
&self,
q: i64,
std_dev: f64,
rng: &mut T,
base: i64
) -> RelinearizationKey1
pub fn relin_key_gen_1<T: RngCore + CryptoRng>(
&self,
q: i64,
std_dev: f64,
rng: &mut T,
base: i64
) -> RelinearizationKey1
Generate a relinearization key, using the approach in Version 1
q
: the ciphertext modulusstd_dev
: the standard deviation for error generationrng
: the RNG used to generate randomnessbase
: the decomposition base used for relinearization
Note on base selection: The base can be chosen to trade off relinearisation time and space, for error accumulation. The larger the base, the larger the error. The bounds on the base are discussed in the paper. Choosing T = ceil(sqrt(q)) will minimize relinearisation time and space, at the expense of error. Choosing T = log_2(q) will decrease error at the cost of relinearisation time and space.
use bfv12::SecretKey;
let degree = 4;
let std_dev = 3.2;
let q = 65536;
let rlk_base = (q as f64).log2() as i64;
let secret_key = SecretKey::generate(degree, &mut rng);
let relin_key_1 = secret_key.relin_key_gen_1(q, std_dev, &mut rng, rlk_base);
sourcepub fn relin_key_gen_2<T: RngCore + CryptoRng>(
&self,
q: i64,
std_dev: f64,
rng: &mut T,
p: i64
) -> RelinearizationKey2
pub fn relin_key_gen_2<T: RngCore + CryptoRng>(
&self,
q: i64,
std_dev: f64,
rng: &mut T,
p: i64
) -> RelinearizationKey2
Generate a relinearization key, using the approach in Version 2
q
: the ciphertext modulusstd_dev
: the standard deviation for error generationrng
: the RNG used to generate randomnessp
: the amount to scale the modulus, during modulus switching
Note on p selection: Technically p needs to be >= q^3 for security (see paper discussion on Relinearization Version 2), However, setting p = q^3 results in an overflow when taking p * q. Therefore, in this library we will test with a smaller p, and recommend using Relinearization Version 1.
use bfv12::SecretKey;
let degree = 4;
let std_dev = 3.2;
let q = 65536;
let p = 2_i64.pow(13) * q;
let secret_key = SecretKey::generate(degree, &mut rng);
let relin_key_2 = secret_key.relin_key_gen_2(q, std_dev, &mut rng, p);
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for SecretKey
impl Send for SecretKey
impl Sync for SecretKey
impl Unpin for SecretKey
impl UnwindSafe for SecretKey
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more