DecryptionKey

Struct DecryptionKey 

Source
pub struct DecryptionKey { /* private fields */ }
Expand description

Paillier decryption key

Implementations§

Source§

impl DecryptionKey

Source

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

Source

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.

Source

pub fn decrypt(&self, c: &Ciphertext) -> Result<Plaintext, Error>

Decrypts the ciphertext, returns plaintext in {-N/2, .., N_2}

Source

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

Source

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

Source

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)
Source

pub fn encryption_key(&self) -> &EncryptionKey

Returns a (public) encryption key corresponding to the (secret) decryption key

Source

pub fn n(&self) -> &Integer

The Paillier modulus

Source

pub fn lambda(&self) -> &Integer

The Paillier lambda

Source

pub fn mu(&self) -> &Integer

The Paillier mu

Source

pub fn p(&self) -> &Integer

Prime p

Source

pub fn q(&self) -> &Integer

Prime q

Source

pub fn bits_length(&self) -> u64

Bits length of smaller prime (p or q)

Trait Implementations§

Source§

impl AnyEncryptionKey for DecryptionKey

Source§

fn n(&self) -> &Integer

Returns N
Source§

fn nn(&self) -> &Integer

Returns N^2
Source§

fn half_n(&self) -> &Integer

Returns N/2
Source§

fn encrypt_with( &self, x: &Plaintext, nonce: &Nonce, ) -> Result<Ciphertext, Error>

Encrypts the plaintext x in {-N/2, .., N_2} with nonce in Z*_n Read more
Source§

fn oadd(&self, c1: &Ciphertext, c2: &Ciphertext) -> Result<Ciphertext, Error>

Homomorphic addition of two ciphertexts Read more
Source§

fn osub(&self, c1: &Ciphertext, c2: &Ciphertext) -> Result<Ciphertext, Error>

Homomorphic subtraction of two ciphertexts Read more
Source§

fn omul( &self, scalar: &Integer, ciphertext: &Ciphertext, ) -> Result<Ciphertext, Error>

Homomorphic multiplication of scalar at ciphertext Read more
Source§

fn oneg(&self, ciphertext: &Ciphertext) -> Result<Ciphertext, Error>

Homomorphic negation of a ciphertext Read more
Source§

fn in_signed_group(&self, x: &Integer) -> bool

Checks whether x is {-N/2, .., N/2}
Source§

impl Clone for DecryptionKey

Source§

fn clone(&self) -> DecryptionKey

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<E> AnyEncryptionKeyExt for E

Source§

fn encrypt_with_random( &self, rng: &mut (impl RngCore + CryptoRng), x: &Integer, ) -> Result<(Integer, Integer), Error>

Encrypts the plaintext x in {-N/2, .., N_2} Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.