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);
}
- 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
ElgamalCipher
constructor
Getter for the gamma public key
Getter for the delta ciphertext
pub fn encrypt(
secret: &JubJubScalar,
public: &JubJubExtended,
generator: &JubJubExtended,
message: &JubJubExtended
) -> Self
pub fn encrypt(
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
.
Perform the decryption with the provided secret.
Trait Implementations
type Output = ElgamalCipher
type Output = ElgamalCipher
The resulting type after applying the +
operator.
Performs the +
operation. Read more
Performs the +=
operation. Read more
Returns the “default value” for a type. Read more
type Output = ElgamalCipher
type Output = ElgamalCipher
The resulting type after applying the *
operator.
Performs the *
operation. Read more
type Output = ElgamalCipher
type Output = ElgamalCipher
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 !=
.
type Output = ElgamalCipher
type Output = ElgamalCipher
The resulting type after applying the -
operator.
Performs the -
operation. Read more
Performs the -=
operation. Read more
Auto Trait Implementations
impl RefUnwindSafe for ElgamalCipher
impl Send for ElgamalCipher
impl Sync for ElgamalCipher
impl Unpin for ElgamalCipher
impl UnwindSafe for ElgamalCipher
Blanket Implementations
Mutably borrows from an owned value. Read more
fn from_hex_str(s: &str) -> Result<Self, Self::Error> where
Self::Error: BadLength,
Self::Error: InvalidChar,
fn from_hex_str(s: &str) -> Result<Self, Self::Error> where
Self::Error: BadLength,
Self::Error: InvalidChar,
Parse a string slice as bytes hex representation and returns `