[][src]Struct rust_elgamal::EncryptionKey

pub struct EncryptionKey(_);

An ElGamal encryption key (also called a public key in other implementations). To create a new encryption key, see DecryptionKey.

Implementations

impl EncryptionKey[src]

pub fn exp_encrypt<R: RngCore + CryptoRng>(
    &self,
    m: Scalar,
    mut rng: R
) -> Ciphertext
[src]

Encrypt mG with a randomly-generated blinding factor, where G is the group generator.

This is computationally intensive to decrypt to the original scalar, and not relevant to the majority of users. This function takes advantage of a fast implementation for multiple multiplications in curve25519-dalek.

Example

use rand::rngs::StdRng;
use rand::SeedableRng;
use rust_elgamal::{DecryptionKey, GENERATOR_TABLE, Scalar};

let mut rng = StdRng::from_entropy();
let dec_key = DecryptionKey::new(&mut rng);
let enc_key = dec_key.encryption_key();

let m = Scalar::from(5u32);
let encrypted = enc_key.exp_encrypt(m, &mut rng);

pub fn exp_encrypt_with(&self, m: Scalar, r: Scalar) -> Ciphertext[src]

Encrypt mG with the blinding factor r, where G is the group generator.

This is computationally intensive to decrypt to the original scalar, and not relevant to the majority of users. This function takes advantage of a fast implementation for multiple multiplications in curve25519-dalek.

Example

use rand::rngs::StdRng;
use rand::SeedableRng;
use rust_elgamal::{DecryptionKey, GENERATOR_TABLE, Scalar};

let mut rng = StdRng::from_entropy();
let dec_key = DecryptionKey::new(&mut rng);
let enc_key = dec_key.encryption_key();

let m = Scalar::from(5u32);
let r = Scalar::from(10u32);
let encrypted = enc_key.exp_encrypt_with(m, r);

pub fn encrypt<R: RngCore + CryptoRng>(
    &self,
    m: RistrettoPoint,
    mut rng: R
) -> Ciphertext
[src]

Encrypt the curve point m with a randomly-generated blinding factor.

Example

use rand::rngs::StdRng;
use rand::SeedableRng;
use rust_elgamal::{DecryptionKey, GENERATOR_TABLE, Scalar};

let mut rng = StdRng::from_entropy();
let dec_key = DecryptionKey::new(&mut rng);
let enc_key = dec_key.encryption_key();

let m = &Scalar::from(5u32) * &GENERATOR_TABLE;
let encrypted = enc_key.encrypt(m, &mut rng);

pub fn encrypt_with(&self, m: RistrettoPoint, r: Scalar) -> Ciphertext[src]

Encrypt the curve point m with the blinding factor r.

Example

use rand::rngs::StdRng;
use rand::SeedableRng;
use rust_elgamal::{DecryptionKey, GENERATOR_TABLE, Scalar};

let mut rng = StdRng::from_entropy();
let dec_key = DecryptionKey::new(&mut rng);
let enc_key = dec_key.encryption_key();

let m = &Scalar::from(5u32) * &GENERATOR_TABLE;
let r = Scalar::from(10u32);
let encrypted = enc_key.encrypt_with(m, r);

pub fn rerandomise<R: RngCore + CryptoRng>(
    &self,
    ct: Ciphertext,
    mut rng: R
) -> Ciphertext
[src]

Re-randomise the ciphertext ct with a randomly-generated blinding factor. This will generate a new encryption of the same curve point.

Example

use rand::rngs::StdRng;
use rand::SeedableRng;
use rust_elgamal::{DecryptionKey, GENERATOR_TABLE, Scalar};

let mut rng = StdRng::from_entropy();
let dec_key = DecryptionKey::new(&mut rng);
let enc_key = dec_key.encryption_key();

let m = &Scalar::from(5u32) * &GENERATOR_TABLE;
let ct1 = enc_key.encrypt(m, &mut rng);
let ct2 = enc_key.rerandomise(ct1, &mut rng);
assert_eq!(dec_key.decrypt(ct1), dec_key.decrypt(ct2));

pub fn rerandomise_with(&self, ct: Ciphertext, r: Scalar) -> Ciphertext[src]

Re-randomise the ciphertext ct with the provided blinding factor. This will generate a new encryption of the same curve point.

Example

use rand::rngs::StdRng;
use rand::SeedableRng;
use rust_elgamal::{DecryptionKey, GENERATOR_TABLE, Scalar};

let mut rng = StdRng::from_entropy();
let dec_key = DecryptionKey::new(&mut rng);
let enc_key = dec_key.encryption_key();

let m = &Scalar::from(5u32) * &GENERATOR_TABLE;
let ct1 = enc_key.encrypt(m, &mut rng);

let r = Scalar::from(10u32);
let ct2 = enc_key.rerandomise_with(ct1, r);

assert_eq!(dec_key.decrypt(ct1), dec_key.decrypt(ct2));

Trait Implementations

impl AsRef<RistrettoPoint> for EncryptionKey[src]

impl Clone for EncryptionKey[src]

impl Copy for EncryptionKey[src]

impl Debug for EncryptionKey[src]

impl Eq for EncryptionKey[src]

impl From<DecryptionKey> for EncryptionKey[src]

impl From<RistrettoPoint> for EncryptionKey[src]

impl PartialEq<EncryptionKey> for EncryptionKey[src]

impl StructuralEq for EncryptionKey[src]

impl StructuralPartialEq for EncryptionKey[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.