Trait fast_paillier::AnyEncryptionKey
source · 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§
sourcefn encrypt_with(
&self,
x: &Plaintext,
nonce: &Nonce
) -> Result<Ciphertext, Error>
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
sourcefn oadd(&self, c1: &Ciphertext, c2: &Ciphertext) -> Result<Ciphertext, Error>
fn oadd(&self, c1: &Ciphertext, c2: &Ciphertext) -> Result<Ciphertext, Error>
Homomorphic addition of two ciphertexts
oadd(Enc(a1), Enc(a2)) = Enc(a1 + a2)
sourcefn osub(&self, c1: &Ciphertext, c2: &Ciphertext) -> Result<Ciphertext, Error>
fn osub(&self, c1: &Ciphertext, c2: &Ciphertext) -> Result<Ciphertext, Error>
Homomorphic subtraction of two ciphertexts
osub(Enc(a1), Enc(a2)) = Enc(a1 - a2)
sourcefn omul(
&self,
scalar: &Integer,
ciphertext: &Ciphertext
) -> Result<Ciphertext, Error>
fn omul( &self, scalar: &Integer, ciphertext: &Ciphertext ) -> Result<Ciphertext, Error>
Homomorphic multiplication of scalar at ciphertext
omul(a, Enc(c)) = Enc(a * c)
sourcefn oneg(&self, ciphertext: &Ciphertext) -> Result<Ciphertext, Error>
fn oneg(&self, ciphertext: &Ciphertext) -> Result<Ciphertext, Error>
Homomorphic negation of a ciphertext
oneg(Enc(a)) = Enc(-a)
sourcefn in_signed_group(&self, x: &Integer) -> bool
fn in_signed_group(&self, x: &Integer) -> bool
Checks whether x
is {-N/2, .., N/2}