-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #209 from dusk-network/recipient-params-core
Move elgamal encryption and `RecipientParameters` to `phoenix-core`
- Loading branch information
Showing
13 changed files
with
195 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// 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. | ||
|
||
//! This module implements the ElGamal asymmetric cipher. It allows to | ||
//! encrypt and decrypt. | ||
//! | ||
//! Reference: https://link.springer.com/chapter/10.1007/3-540-39568-7_2 | ||
|
||
use dusk_jubjub::{JubJubExtended, JubJubScalar, GENERATOR}; | ||
|
||
/// Encrypts a JubJubExtended plaintext given a public key and a fresh random | ||
/// number 'r'. | ||
/// | ||
/// ## Return | ||
/// Returns a ciphertext (JubJubExtended, JubJubExtended). | ||
pub fn encrypt( | ||
public_key: &JubJubExtended, | ||
plaintext: &JubJubExtended, | ||
r: &JubJubScalar, | ||
) -> (JubJubExtended, JubJubExtended) { | ||
let ciphertext_1 = GENERATOR * r; | ||
let ciphertext_2 = plaintext + public_key * r; | ||
|
||
(ciphertext_1, ciphertext_2) | ||
} | ||
|
||
/// Decrypts a ciphertext given a secret key. | ||
/// | ||
/// ## Return | ||
/// Returns a JubJubExtended plaintext. | ||
pub fn decrypt( | ||
secret_key: &JubJubScalar, | ||
ciphertext_1: &JubJubExtended, | ||
ciphertext_2: &JubJubExtended, | ||
) -> JubJubExtended { | ||
// return the plaintext | ||
ciphertext_2 - ciphertext_1 * secret_key | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ | |
|
||
/// AES symmetric cipher | ||
pub mod aes; | ||
/// ElGamal asymmetric encryption | ||
pub mod elgamal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.