pub trait AnyEncryptionKey: Sealed {
    // Required methods
    fn n(&self) -> &Integer;
    fn nn(&self) -> &Integer;
    fn half_n(&self) -> &Integer;
    fn encrypt_with(
        &self,
        x: &Plaintext,
        nonce: &Nonce
    ) -> Result<Ciphertext, Error>;
    fn oadd(
        &self,
        c1: &Ciphertext,
        c2: &Ciphertext
    ) -> Result<Ciphertext, Error>;
    fn osub(
        &self,
        c1: &Ciphertext,
        c2: &Ciphertext
    ) -> Result<Ciphertext, Error>;
    fn omul(
        &self,
        scalar: &Integer,
        ciphertext: &Ciphertext
    ) -> Result<Ciphertext, Error>;
    fn oneg(&self, ciphertext: &Ciphertext) -> Result<Ciphertext, Error>;
    fn in_signed_group(&self, x: &Integer) -> bool;
}
Expand description

Any key capable of encryption

Both encryption and decryption keys can be used to carry out encryption. Moreover, encryption using decryption key is faster.

Example

This trait can be used, for instance, to accept an encryption key as an argument to the function and benefit from faster encryption if decryption key is provided.

use fast_paillier::{AnyEncryptionKey, Error};
use rug::Integer;

// This function accepts both encryption and decryption key. If decryption key is provided,
// it'll be more efficient
fn some_function(ek: &dyn AnyEncryptionKey) -> Result<Integer, Error> {
    // ...
    let ciphertext = ek.encrypt_with(&x, &r)?;
    Ok(ciphertext)
}

Required Methods§

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

Returns error if inputs are not in specified range

source

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

Homomorphic addition of two ciphertexts

oadd(Enc(a1), Enc(a2)) = Enc(a1 + a2)
source

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

Homomorphic subtraction of two ciphertexts

osub(Enc(a1), Enc(a2)) = Enc(a1 - a2)
source

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

Homomorphic multiplication of scalar at ciphertext

omul(a, Enc(c)) = Enc(a * c)
source

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

Homomorphic negation of a ciphertext

oneg(Enc(a)) = Enc(-a)
source

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

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

Trait Implementations§

source§

impl<'a> Debug for dyn AnyEncryptionKey + 'a

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Implementors§