[−][src]Struct rust_elgamal::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]
&self,
m: Scalar,
mut rng: R
) -> Ciphertext
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]
&self,
m: RistrettoPoint,
mut rng: R
) -> Ciphertext
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]
&self,
ct: Ciphertext,
mut rng: R
) -> Ciphertext
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]
pub fn as_ref(&self) -> &RistrettoPoint
[src]
impl Clone for EncryptionKey
[src]
pub fn clone(&self) -> EncryptionKey
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for EncryptionKey
[src]
impl Debug for EncryptionKey
[src]
impl Eq for EncryptionKey
[src]
impl From<DecryptionKey> for EncryptionKey
[src]
pub fn from(dk: DecryptionKey) -> Self
[src]
impl From<RistrettoPoint> for EncryptionKey
[src]
pub fn from(y: RistrettoPoint) -> Self
[src]
impl PartialEq<EncryptionKey> for EncryptionKey
[src]
pub fn eq(&self, other: &EncryptionKey) -> bool
[src]
pub fn ne(&self, other: &EncryptionKey) -> bool
[src]
impl StructuralEq for EncryptionKey
[src]
impl StructuralPartialEq for EncryptionKey
[src]
Auto Trait Implementations
impl RefUnwindSafe for EncryptionKey
[src]
impl Send for EncryptionKey
[src]
impl Sync for EncryptionKey
[src]
impl Unpin for EncryptionKey
[src]
impl UnwindSafe for EncryptionKey
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,