Rename ElGamal::keygen to ElGamal::new

This commit is contained in:
Michael Vines 2021-10-04 08:48:11 -07:00
parent 94a96670e8
commit a622ee4b8d
6 changed files with 26 additions and 26 deletions

View File

@ -23,15 +23,15 @@ pub struct ElGamal;
impl ElGamal { impl ElGamal {
/// Generates the public and secret keys for ElGamal encryption. /// Generates the public and secret keys for ElGamal encryption.
#[cfg(not(target_arch = "bpf"))] #[cfg(not(target_arch = "bpf"))]
pub fn keygen() -> (ElGamalPubkey, ElGamalSecretKey) { pub fn new() -> (ElGamalPubkey, ElGamalSecretKey) {
ElGamal::keygen_with(&mut OsRng) // using OsRng for now ElGamal::with(&mut OsRng) // using OsRng for now
} }
/// On input a randomness generator, the function generates the public and /// On input a randomness generator, the function generates the public and
/// secret keys for ElGamal encryption. /// secret keys for ElGamal encryption.
#[cfg(not(target_arch = "bpf"))] #[cfg(not(target_arch = "bpf"))]
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn keygen_with<T: RngCore + CryptoRng>(rng: &mut T) -> (ElGamalPubkey, ElGamalSecretKey) { pub fn with<T: RngCore + CryptoRng>(rng: &mut T) -> (ElGamalPubkey, ElGamalSecretKey) {
// sample a non-zero scalar // sample a non-zero scalar
let mut s: Scalar; let mut s: Scalar;
loop { loop {
@ -356,7 +356,7 @@ mod tests {
#[test] #[test]
fn test_encrypt_decrypt_correctness() { fn test_encrypt_decrypt_correctness() {
let (pk, sk) = ElGamal::keygen(); let (pk, sk) = ElGamal::new();
let msg: u32 = 57; let msg: u32 = 57;
let ct = ElGamal::encrypt(&pk, msg); let ct = ElGamal::encrypt(&pk, msg);
@ -373,8 +373,8 @@ mod tests {
#[test] #[test]
fn test_decrypt_handle() { fn test_decrypt_handle() {
let (pk_1, sk_1) = ElGamal::keygen(); let (pk_1, sk_1) = ElGamal::new();
let (pk_2, sk_2) = ElGamal::keygen(); let (pk_2, sk_2) = ElGamal::new();
let msg: u32 = 77; let msg: u32 = 77;
let (comm, open) = Pedersen::commit(msg); let (comm, open) = Pedersen::commit(msg);
@ -400,7 +400,7 @@ mod tests {
#[test] #[test]
fn test_homomorphic_addition() { fn test_homomorphic_addition() {
let (pk, _) = ElGamal::keygen(); let (pk, _) = ElGamal::new();
let msg_0: u64 = 57; let msg_0: u64 = 57;
let msg_1: u64 = 77; let msg_1: u64 = 77;
@ -425,7 +425,7 @@ mod tests {
#[test] #[test]
fn test_homomorphic_subtraction() { fn test_homomorphic_subtraction() {
let (pk, _) = ElGamal::keygen(); let (pk, _) = ElGamal::new();
let msg_0: u64 = 77; let msg_0: u64 = 77;
let msg_1: u64 = 55; let msg_1: u64 = 55;
@ -450,7 +450,7 @@ mod tests {
#[test] #[test]
fn test_homomorphic_multiplication() { fn test_homomorphic_multiplication() {
let (pk, _) = ElGamal::keygen(); let (pk, _) = ElGamal::new();
let msg_0: u64 = 57; let msg_0: u64 = 57;
let msg_1: u64 = 77; let msg_1: u64 = 77;
@ -466,7 +466,7 @@ mod tests {
#[test] #[test]
fn test_homomorphic_division() { fn test_homomorphic_division() {
let (pk, _) = ElGamal::keygen(); let (pk, _) = ElGamal::new();
let msg_0: u64 = 55; let msg_0: u64 = 55;
let msg_1: u64 = 5; let msg_1: u64 = 5;
@ -482,7 +482,7 @@ mod tests {
#[test] #[test]
fn test_serde_ciphertext() { fn test_serde_ciphertext() {
let (pk, _) = ElGamal::keygen(); let (pk, _) = ElGamal::new();
let msg: u64 = 77; let msg: u64 = 77;
let ct = pk.encrypt(msg); let ct = pk.encrypt(msg);
@ -494,7 +494,7 @@ mod tests {
#[test] #[test]
fn test_serde_pubkey() { fn test_serde_pubkey() {
let (pk, _) = ElGamal::keygen(); let (pk, _) = ElGamal::new();
let encoded = bincode::serialize(&pk).unwrap(); let encoded = bincode::serialize(&pk).unwrap();
let decoded: ElGamalPubkey = bincode::deserialize(&encoded).unwrap(); let decoded: ElGamalPubkey = bincode::deserialize(&encoded).unwrap();
@ -504,7 +504,7 @@ mod tests {
#[test] #[test]
fn test_serde_secretkey() { fn test_serde_secretkey() {
let (_, sk) = ElGamal::keygen(); let (_, sk) = ElGamal::new();
let encoded = bincode::serialize(&sk).unwrap(); let encoded = bincode::serialize(&sk).unwrap();
let decoded: ElGamalSecretKey = bincode::deserialize(&encoded).unwrap(); let decoded: ElGamalSecretKey = bincode::deserialize(&encoded).unwrap();

View File

@ -141,7 +141,7 @@ mod test {
#[test] #[test]
fn test_close_account_correctness() { fn test_close_account_correctness() {
let (source_pk, source_sk) = ElGamal::keygen(); let (source_pk, source_sk) = ElGamal::new();
// If account balance is 0, then the proof should succeed // If account balance is 0, then the proof should succeed
let balance = source_pk.encrypt(0_u64); let balance = source_pk.encrypt(0_u64);

View File

@ -517,9 +517,9 @@ mod test {
#[test] #[test]
fn test_transfer_correctness() { fn test_transfer_correctness() {
// ElGamal keys for source, destination, and auditor accounts // ElGamal keys for source, destination, and auditor accounts
let (source_pk, source_sk) = ElGamal::keygen(); let (source_pk, source_sk) = ElGamal::new();
let (dest_pk, _) = ElGamal::keygen(); let (dest_pk, _) = ElGamal::new();
let (auditor_pk, _) = ElGamal::keygen(); let (auditor_pk, _) = ElGamal::new();
// create source account spendable ciphertext // create source account spendable ciphertext
let spendable_balance: u64 = 77; let spendable_balance: u64 = 77;

View File

@ -218,8 +218,8 @@ mod test {
#[test] #[test]
fn test_update_account_public_key_correctness() { fn test_update_account_public_key_correctness() {
let (current_pk, current_sk) = ElGamal::keygen(); let (current_pk, current_sk) = ElGamal::new();
let (new_pk, new_sk) = ElGamal::keygen(); let (new_pk, new_sk) = ElGamal::new();
// If current_ct and new_ct encrypt same values, then the proof verification should succeed // If current_ct and new_ct encrypt same values, then the proof verification should succeed
let balance: u64 = 77; let balance: u64 = 77;

View File

@ -179,7 +179,7 @@ mod test {
#[ignore] #[ignore]
fn test_withdraw_correctness() { fn test_withdraw_correctness() {
// generate and verify proof for the proper setting // generate and verify proof for the proper setting
let (source_pk, source_sk) = ElGamal::keygen(); let (source_pk, source_sk) = ElGamal::new();
let current_balance: u64 = 77; let current_balance: u64 = 77;
let current_balance_ct = source_pk.encrypt(current_balance); let current_balance_ct = source_pk.encrypt(current_balance);

View File

@ -252,7 +252,7 @@ mod tests {
// spendable_ct should be an encryption of 0 for any public key when // spendable_ct should be an encryption of 0 for any public key when
// `PedersenOpen::default()` is used // `PedersenOpen::default()` is used
let (pk, _) = ElGamal::keygen(); let (pk, _) = ElGamal::new();
let balance: u64 = 0; let balance: u64 = 0;
assert_eq!( assert_eq!(
spendable_ct, spendable_ct,
@ -276,7 +276,7 @@ mod tests {
let added_ct = ops::add_to(&spendable_balance, 55).unwrap(); let added_ct = ops::add_to(&spendable_balance, 55).unwrap();
let (pk, _) = ElGamal::keygen(); let (pk, _) = ElGamal::new();
let expected: pod::ElGamalCiphertext = let expected: pod::ElGamalCiphertext =
pk.encrypt_with(55_u64, &PedersenOpen::default()).into(); pk.encrypt_with(55_u64, &PedersenOpen::default()).into();
@ -286,7 +286,7 @@ mod tests {
#[test] #[test]
fn test_subtract_from() { fn test_subtract_from() {
let amount = 77_u64; let amount = 77_u64;
let (pk, _) = ElGamal::keygen(); let (pk, _) = ElGamal::new();
let open = PedersenOpen::random(&mut OsRng); let open = PedersenOpen::random(&mut OsRng);
let encrypted_amount: pod::ElGamalCiphertext = pk.encrypt_with(amount, &open).into(); let encrypted_amount: pod::ElGamalCiphertext = pk.encrypt_with(amount, &open).into();
@ -312,9 +312,9 @@ mod tests {
let (amount_lo, amount_hi) = split_u64_into_u32(transfer_amount); let (amount_lo, amount_hi) = split_u64_into_u32(transfer_amount);
// generate public keys // generate public keys
let (source_pk, _) = ElGamal::keygen(); let (source_pk, _) = ElGamal::new();
let (dest_pk, _) = ElGamal::keygen(); let (dest_pk, _) = ElGamal::new();
let (auditor_pk, _) = ElGamal::keygen(); let (auditor_pk, _) = ElGamal::new();
// commitments associated with TransferRangeProof // commitments associated with TransferRangeProof
let (comm_lo, open_lo) = Pedersen::commit(amount_lo); let (comm_lo, open_lo) = Pedersen::commit(amount_lo);