Struct dusk_jubjub::elgamal::ElgamalCipher[][src]

pub struct ElgamalCipher { /* fields omitted */ }
Expand description

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

ElgamalCipher constructor

Getter for the gamma public key

Getter for the delta ciphertext

Uses assymetric encryption to return a cipher construction.

The decryption will expect the secret of public.

Perform the decryption with the provided secret.

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

Performs the *= operation. Read more

Performs the *= operation. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize the cipher into bytes

Deserialize from a ElgamalCipher::to_bytes construction

The type returned in the event of a conversion error.

The size of

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Performs the -= operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Deserialize a slice of u8 into Self

Deserialize the type reading the bytes from a reader. The bytes read are removed from the reader. Read more

Performs the conversion.

Performs the conversion.

Parse a string slice as bytes hex representation and returns `

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.