pub struct SecretKey { /* private fields */ }
Expand description

A BFV12 Secret Key

Implementations

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 key
  • rng: the RNG used to generate randomness
use bfv12::SecretKey;

let degree = 4;
let secret_key = SecretKey::generate(degree, &mut rng);

Generate a public key from a secret key.

  • q: the ciphertext modulus
  • std_dev: the standard deviation for error generation
  • rng: 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);

Generate a relinearization key, using the approach in Version 1

  • q: the ciphertext modulus
  • std_dev: the standard deviation for error generation
  • rng: the RNG used to generate randomness
  • base: 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);

Generate a relinearization key, using the approach in Version 2

  • q: the ciphertext modulus
  • std_dev: the standard deviation for error generation
  • rng: the RNG used to generate randomness
  • p: 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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.