Struct fast_paillier::DecryptionKey
source · 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) -> u32
pub fn bits_length(&self) -> u32
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