Struct dusk_jubjub::elgamal::ElgamalCipher [−][src]
pub struct ElgamalCipher { /* fields omitted */ }
Tuple for assymetric encryption using ElGamal algorithm.
Example
use dusk_jubjub::elgamal::ElgamalCipher; use dusk_jubjub::{JubJubScalar, GENERATOR_EXTENDED}; fn main() { // Bob's (sender) secret and message let bob_secret = JubJubScalar::random(&mut rand::thread_rng()); let message = JubJubScalar::random(&mut rand::thread_rng()); let message = GENERATOR_EXTENDED * message; // Alice's (receiver) secret and public let alice_secret = JubJubScalar::random(&mut rand::thread_rng()); let alice_public = GENERATOR_EXTENDED * alice_secret; let cipher = ElgamalCipher::encrypt( &bob_secret, &alice_public, &GENERATOR_EXTENDED, &message, ); let decrypt = cipher.decrypt(&alice_secret); assert_eq!(message, decrypt); }
- Let
p
andG = α
be defined by the parameters of JubJub. - Let
a
be Alice’s secret, andA = G · a
- Let
b
be Bob’s secret, andB = G · b
Encryption
Bob should do the following:
- Obtain Alice’s authentic public key
A
. - Represent the message
M
as a point of JubJub defined such asM = G ·m
wherem
is a scalar inJubJubScalar
. - Compute
γ = G · b
andδ = M + (A ·b)
. - Send the ciphertext
c = (γ; δ)
to Alice.
Decryption
To recover plaintext M
from c
, Alice should do the following:
- Recover
M
by computingδ - γ · a
.
Homomorphism
A function f
is homomorphic when f(a · b) = f(a) · f(b)
.
This implementation extends the homomorphic property of ElGamal to addition, subtraction and multiplication.
The addition and subtraction are homomorphic with other ElgamalCipher
structures.
The multiplication is homomorphic with JubJubScalar
scalars.
Being E
the encrypt and D
the decrypt functions, here follows an
example: D{E[x * (a + b)]} == D{x * [E(a) + E(b)]}
Implementations
impl ElgamalCipher
[src]
impl ElgamalCipher
[src]pub fn new(gamma: JubJubExtended, delta: JubJubExtended) -> Self
[src]
ElgamalCipher
constructor
pub fn gamma(&self) -> &JubJubExtended
[src]
Getter for the gamma public key
pub fn delta(&self) -> &JubJubExtended
[src]
Getter for the delta ciphertext
pub fn encrypt(
secret: &JubJubScalar,
public: &JubJubExtended,
generator: &JubJubExtended,
message: &JubJubExtended
) -> Self
[src]
secret: &JubJubScalar,
public: &JubJubExtended,
generator: &JubJubExtended,
message: &JubJubExtended
) -> Self
Uses assymetric encryption to return a cipher construction.
The decryption will expect the secret of public
.
pub fn decrypt(&self, secret: &JubJubScalar) -> JubJubExtended
[src]
Perform the decryption with the provided secret.
Trait Implementations
impl Add<&'_ ElgamalCipher> for &ElgamalCipher
[src]
impl Add<&'_ ElgamalCipher> for &ElgamalCipher
[src]type Output = ElgamalCipher
The resulting type after applying the +
operator.
fn add(self, other: &ElgamalCipher) -> ElgamalCipher
[src]
impl Add<ElgamalCipher> for ElgamalCipher
[src]
impl Add<ElgamalCipher> for ElgamalCipher
[src]impl AddAssign<ElgamalCipher> for ElgamalCipher
[src]
impl AddAssign<ElgamalCipher> for ElgamalCipher
[src]fn add_assign(&mut self, other: Self)
[src]
impl Clone for ElgamalCipher
[src]
impl Clone for ElgamalCipher
[src]fn clone(&self) -> ElgamalCipher
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for ElgamalCipher
[src]
impl Copy for ElgamalCipher
[src]impl Default for ElgamalCipher
[src]
impl Default for ElgamalCipher
[src]fn default() -> ElgamalCipher
[src]
impl Mul<&'_ Fr> for &ElgamalCipher
[src]
impl Mul<&'_ Fr> for &ElgamalCipher
[src]type Output = ElgamalCipher
The resulting type after applying the *
operator.
fn mul(self, rhs: &JubJubScalar) -> ElgamalCipher
[src]
impl Mul<Fr> for &ElgamalCipher
[src]
impl Mul<Fr> for &ElgamalCipher
[src]type Output = ElgamalCipher
The resulting type after applying the *
operator.
fn mul(self, rhs: JubJubScalar) -> ElgamalCipher
[src]
impl<'b> MulAssign<&'b Fr> for ElgamalCipher
[src]
impl<'b> MulAssign<&'b Fr> for ElgamalCipher
[src]fn mul_assign(&mut self, rhs: &'b JubJubScalar)
[src]
impl MulAssign<Fr> for ElgamalCipher
[src]
impl MulAssign<Fr> for ElgamalCipher
[src]fn mul_assign(&mut self, rhs: JubJubScalar)
[src]
impl PartialEq<ElgamalCipher> for ElgamalCipher
[src]
impl PartialEq<ElgamalCipher> for ElgamalCipher
[src]fn eq(&self, other: &ElgamalCipher) -> bool
[src]
fn ne(&self, other: &ElgamalCipher) -> bool
[src]
impl Serializable<64_usize> for ElgamalCipher
[src]
impl Serializable<64_usize> for ElgamalCipher
[src]impl StructuralPartialEq for ElgamalCipher
[src]
impl StructuralPartialEq for ElgamalCipher
[src]impl Sub<&'_ ElgamalCipher> for &ElgamalCipher
[src]
impl Sub<&'_ ElgamalCipher> for &ElgamalCipher
[src]type Output = ElgamalCipher
The resulting type after applying the -
operator.
fn sub(self, other: &ElgamalCipher) -> ElgamalCipher
[src]
impl Sub<ElgamalCipher> for ElgamalCipher
[src]
impl Sub<ElgamalCipher> for ElgamalCipher
[src]impl SubAssign<ElgamalCipher> for ElgamalCipher
[src]
impl SubAssign<ElgamalCipher> for ElgamalCipher
[src]fn sub_assign(&mut self, other: Self)
[src]
Auto Trait Implementations
impl RefUnwindSafe for ElgamalCipher
impl RefUnwindSafe for ElgamalCipher
impl Send for ElgamalCipher
impl Send for ElgamalCipher
impl Sync for ElgamalCipher
impl Sync for ElgamalCipher
impl Unpin for ElgamalCipher
impl Unpin for ElgamalCipher
impl UnwindSafe for ElgamalCipher
impl UnwindSafe for ElgamalCipher
Blanket Implementations
impl<T, const N: usize> DeserializableSlice<N> for T where
T: Serializable<N>,
[src]
impl<T, const N: usize> DeserializableSlice<N> for T where
T: Serializable<N>,
[src]impl<T, const N: usize> ParseHexStr<N> for T where
T: Serializable<N>,
[src]
impl<T, const N: usize> ParseHexStr<N> for T where
T: Serializable<N>,
[src]pub fn from_hex_str(s: &str) -> Result<Self, Self::Error> where
Self::Error: BadLength,
Self::Error: InvalidChar,
[src]
Self::Error: BadLength,
Self::Error: InvalidChar,