Crates.io | jubjub-elgamal |
lib.rs | jubjub-elgamal |
version | 0.1.0 |
source | src |
created_at | 2024-11-25 15:49:25.399084 |
updated_at | 2024-11-25 15:49:25.399084 |
description | ElGamal encryption scheme implemented on the JubJub curve with support for zero-knowledge circuits |
homepage | |
repository | https://github.com/dusk-network/jubjub-elgamal |
max_upload_size | |
id | 1460441 |
size | 31,933 |
This crate provides a Rust implementation of the ElGamal encryption scheme implemented for elements of the JubJub elliptic curve to be used natively and as part of a Zero-Knowledge circuit using plonk. This implementation is designed by the Dusk team.
The ElGamal encryption system is an asymmetric key encryption algorithm for public-key cryptography based on the Diffie-Hellman key exchange.
Its security relies on the difficulty of computing discrete logarithms over finite fields.
The implementation has been created using the field elements of the jubjub
elliptic curve.
In the following:
Since we implement our ElGamal encryption scheme on the jubjub elliptic curve we have:
Suppose Alice wants to send Bob an encrypted message $m \in \mathbb{F}_q^×$. To encrypt the message Alice will use Bob's public-key $PK_B$:
To decrypt the ciphertext $(c_1, c_2)$ Bob will use his secret-key $sk_B$:
This is true because:
c_2 - c_1 * sk_B = m + PK_B * r - (r * G * sk_B) = m + PK_B * r - PK_B * r = m
A basic example demonstrating how to encrypt and decrypt a message using ElGamal:
use dusk_jubjub::{JubJubScalar, GENERATOR_EXTENDED};
use ff::Field;
use jubjub_elgamal::{decrypt, encrypt};
use rand::rngs::StdRng;
use rand::SeedableRng;
let mut rng = StdRng::seed_from_u64(0xc0b);
let sk = JubJubScalar::random(&mut rng);
let pk = GENERATOR_EXTENDED * &sk;
let message = GENERATOR_EXTENDED * JubJubScalar::from(1234u64);
// Encrypt using a fresh random value 'blinder'
let r = JubJubScalar::random(&mut rng);
let (c1, c2) = encrypt(&pk, &message, &r);
// Assert decryption
let dec_message = decrypt(&sk, &(c1, c2));
assert_eq!(message, dec_message);
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
Copyright (c) DUSK NETWORK. All rights reserved.