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);
}
  1. Let p and G = α be defined by the parameters of JubJub.
  2. Let a be Alice’s secret, and A = G · a
  3. Let b be Bob’s secret, and B = G · b

Encryption

Bob should do the following:

  1. Obtain Alice’s authentic public key A.
  2. Represent the message M as a point of JubJub defined such as M = G ·m where m is a scalar in JubJubScalar.
  3. Compute γ = G · b and δ = M + (A ·b).
  4. Send the ciphertext c = (γ; δ) to Alice.

Decryption

To recover plaintext M from c, Alice should do the following:

  1. 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]

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]

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]

type Output = ElgamalCipher

The resulting type after applying the + operator.

impl Add<ElgamalCipher> for ElgamalCipher[src]

type Output = Self

The resulting type after applying the + operator.

impl AddAssign<ElgamalCipher> for ElgamalCipher[src]

impl Clone for ElgamalCipher[src]

impl Copy for ElgamalCipher[src]

impl Debug for ElgamalCipher[src]

impl Default for ElgamalCipher[src]

impl Mul<&'_ Fr> for &ElgamalCipher[src]

type Output = ElgamalCipher

The resulting type after applying the * operator.

impl Mul<Fr> for &ElgamalCipher[src]

type Output = ElgamalCipher

The resulting type after applying the * operator.

impl<'b> MulAssign<&'b Fr> for ElgamalCipher[src]

impl MulAssign<Fr> for ElgamalCipher[src]

impl PartialEq<ElgamalCipher> for ElgamalCipher[src]

impl Serializable<64_usize> for ElgamalCipher[src]

type Error = BytesError

The type returned in the event of a conversion error.

fn to_bytes(&self) -> [u8; 64][src]

Serialize the cipher into bytes

fn from_bytes(bytes: &[u8; 64]) -> Result<Self, Self::Error>[src]

Deserialize from a ElgamalCipher::to_bytes construction

impl StructuralPartialEq for ElgamalCipher[src]

impl Sub<&'_ ElgamalCipher> for &ElgamalCipher[src]

type Output = ElgamalCipher

The resulting type after applying the - operator.

impl Sub<ElgamalCipher> for ElgamalCipher[src]

type Output = Self

The resulting type after applying the - operator.

impl SubAssign<ElgamalCipher> for ElgamalCipher[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, const N: usize> DeserializableSlice<N> for T where
    T: Serializable<N>, 
[src]

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

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

impl<T, const N: usize> ParseHexStr<N> for T where
    T: Serializable<N>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

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.