pub struct DecryptionKey { /* private fields */ }Expand description
Paillier decryption key
Implementations§
Source§impl DecryptionKey
impl DecryptionKey
Sourcepub fn generate(rng: &mut (impl RngCore + CryptoRng)) -> Result<Self, Error>
pub fn generate(rng: &mut (impl RngCore + CryptoRng)) -> Result<Self, Error>
Generates a paillier key
Samples two safe 1536-bits primes that meets 128 bits security level
Sourcepub fn from_primes(p: Integer, q: Integer) -> Result<Self, Error>
pub fn from_primes(p: Integer, q: Integer) -> Result<Self, Error>
Constructs a paillier key from primes p, q
p and q need to be safe primes sufficiently large to meet security level requirements.
Returns error if p and q do not correspond to a valid paillier key.
Sourcepub fn decrypt(&self, c: &Ciphertext) -> Result<Plaintext, Error>
pub fn decrypt(&self, c: &Ciphertext) -> Result<Plaintext, Error>
Decrypts the ciphertext, returns plaintext in {-N/2, .., N_2}
Sourcepub fn encrypt_with(
&self,
x: &Plaintext,
nonce: &Nonce,
) -> Result<Ciphertext, Error>
pub fn encrypt_with( &self, x: &Plaintext, nonce: &Nonce, ) -> Result<Ciphertext, Error>
Encrypts a plaintext x in {-N/2, .., N/2} with nonce from Z*_n
It uses the fact that factorization of N is known to speed up encryption.
Returns error if inputs are not in specified range
Sourcepub fn encrypt_with_random(
&self,
rng: &mut (impl RngCore + CryptoRng),
x: &Plaintext,
) -> Result<(Ciphertext, Nonce), Error>
pub fn encrypt_with_random( &self, rng: &mut (impl RngCore + CryptoRng), x: &Plaintext, ) -> Result<(Ciphertext, Nonce), Error>
Encrypts the plaintext x in {-N/2, .., N_2}
It’s uses the fact that factorization of N is known to speed up encryption.
Nonce is sampled randomly using rng.
Returns error if plaintext is not in specified range
Sourcepub fn omul(
&self,
scalar: &Integer,
ciphertext: &Ciphertext,
) -> Result<Ciphertext, Error>
pub fn omul( &self, scalar: &Integer, ciphertext: &Ciphertext, ) -> Result<Ciphertext, Error>
Homomorphic multiplication of scalar at ciphertext
It uses the fact that factorization of N is known to speed up an operation.
omul(a, Enc(c)) = Enc(a * c)Sourcepub fn encryption_key(&self) -> &EncryptionKey
pub fn encryption_key(&self) -> &EncryptionKey
Returns a (public) encryption key corresponding to the (secret) decryption key
Sourcepub fn bits_length(&self) -> u64
pub fn bits_length(&self) -> u64
Bits length of smaller prime (p or q)
Trait Implementations§
Source§impl AnyEncryptionKey for DecryptionKey
impl AnyEncryptionKey for DecryptionKey
Source§fn encrypt_with(
&self,
x: &Plaintext,
nonce: &Nonce,
) -> Result<Ciphertext, Error>
fn encrypt_with( &self, x: &Plaintext, nonce: &Nonce, ) -> Result<Ciphertext, Error>
Source§fn oadd(&self, c1: &Ciphertext, c2: &Ciphertext) -> Result<Ciphertext, Error>
fn oadd(&self, c1: &Ciphertext, c2: &Ciphertext) -> Result<Ciphertext, Error>
Source§fn osub(&self, c1: &Ciphertext, c2: &Ciphertext) -> Result<Ciphertext, Error>
fn osub(&self, c1: &Ciphertext, c2: &Ciphertext) -> Result<Ciphertext, Error>
Source§fn omul(
&self,
scalar: &Integer,
ciphertext: &Ciphertext,
) -> Result<Ciphertext, Error>
fn omul( &self, scalar: &Integer, ciphertext: &Ciphertext, ) -> Result<Ciphertext, Error>
Source§fn oneg(&self, ciphertext: &Ciphertext) -> Result<Ciphertext, Error>
fn oneg(&self, ciphertext: &Ciphertext) -> Result<Ciphertext, Error>
Source§fn in_signed_group(&self, x: &Integer) -> bool
fn in_signed_group(&self, x: &Integer) -> bool
x is {-N/2, .., N/2}Source§impl Clone for DecryptionKey
impl Clone for DecryptionKey
Source§fn clone(&self) -> DecryptionKey
fn clone(&self) -> DecryptionKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more