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

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 copy 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> Az for T

source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
source§

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

§

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>,

§

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>,

§

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.
source§

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.