From 40cf1c380f682fd99ebeafae8ae296befb3fb81e Mon Sep 17 00:00:00 2001
From: Piotr Roslaniec
Date: Tue, 31 Oct 2023 15:09:46 +0100
Subject: [PATCH] feat: rename group_threshold_cryptography_pre_release crate
to ferveo_tpke
---
Cargo.lock | 58 +++++++++++++++---------------
ferveo/Cargo.toml | 2 +-
ferveo/src/api.rs | 27 +++++++-------
ferveo/src/bindings_wasm.rs | 8 ++---
ferveo/src/lib.rs | 71 ++++++++++++++++++++++---------------
ferveo/src/pvss.rs | 9 +++--
ferveo/src/refresh.rs | 5 ++-
tpke/Cargo.toml | 2 +-
tpke/benches/tpke.rs | 2 +-
9 files changed, 98 insertions(+), 86 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 604d7deb..f8a43ed7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -771,9 +771,9 @@ dependencies = [
"derive_more",
"digest",
"ferveo-common-pre-release",
+ "ferveo-tpke",
"generic-array",
"getrandom 0.2.9",
- "group-threshold-cryptography-pre-release",
"hex",
"itertools",
"js-sys",
@@ -801,6 +801,34 @@ dependencies = [
"pyo3-build-config",
]
+[[package]]
+name = "ferveo-tpke"
+version = "0.2.0"
+dependencies = [
+ "ark-bls12-381",
+ "ark-ec",
+ "ark-ff",
+ "ark-poly",
+ "ark-serialize",
+ "ark-std",
+ "bincode",
+ "chacha20poly1305",
+ "criterion 0.4.0",
+ "ferveo-common-pre-release",
+ "hex",
+ "itertools",
+ "miracl_core",
+ "rand 0.8.5",
+ "rand_core 0.6.4",
+ "serde",
+ "serde_bytes",
+ "serde_with",
+ "sha2",
+ "subproductdomain-pre-release",
+ "thiserror",
+ "zeroize",
+]
+
[[package]]
name = "ferveo-wasm"
version = "0.1.0"
@@ -879,34 +907,6 @@ version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4"
-[[package]]
-name = "group-threshold-cryptography-pre-release"
-version = "0.2.0"
-dependencies = [
- "ark-bls12-381",
- "ark-ec",
- "ark-ff",
- "ark-poly",
- "ark-serialize",
- "ark-std",
- "bincode",
- "chacha20poly1305",
- "criterion 0.4.0",
- "ferveo-common-pre-release",
- "hex",
- "itertools",
- "miracl_core",
- "rand 0.8.5",
- "rand_core 0.6.4",
- "serde",
- "serde_bytes",
- "serde_with",
- "sha2",
- "subproductdomain-pre-release",
- "thiserror",
- "zeroize",
-]
-
[[package]]
name = "half"
version = "1.8.2"
diff --git a/ferveo/Cargo.toml b/ferveo/Cargo.toml
index bf31f363..6503ff5c 100644
--- a/ferveo/Cargo.toml
+++ b/ferveo/Cargo.toml
@@ -22,7 +22,7 @@ ark-serialize = "0.4"
ark-std = "0.4"
bincode = "1.3"
ferveo-common = { package = "ferveo-common-pre-release", path = "../ferveo-common", version = "^0.1.1" }
-group-threshold-cryptography = { package = "group-threshold-cryptography-pre-release", path = "../tpke", features = ["api", "test-common"], version = "^0.2.0" }
+ferveo-tpke = { package = "ferveo-tpke", path = "../tpke", features = ["api", "test-common"], version = "^0.2.0" }
hex = "0.4.3"
itertools = "0.10.5"
measure_time = "0.8"
diff --git a/ferveo/src/api.rs b/ferveo/src/api.rs
index 3c354bcb..9f83eca0 100644
--- a/ferveo/src/api.rs
+++ b/ferveo/src/api.rs
@@ -5,15 +5,14 @@ use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::UniformRand;
use bincode;
use ferveo_common::serialization;
+pub use ferveo_tpke::api::{
+ prepare_combine_simple, share_combine_precomputed, share_combine_simple,
+ Fr, G1Affine, G1Prepared, G2Affine, SecretBox, E,
+};
use generic_array::{typenum::U48, GenericArray};
-use group_threshold_cryptography as tpke;
use rand::RngCore;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
-pub use tpke::api::{
- prepare_combine_simple, share_combine_precomputed, share_combine_simple,
- Fr, G1Affine, G1Prepared, G2Affine, SecretBox, E,
-};
pub type PublicKey = ferveo_common::PublicKey;
pub type Keypair = ferveo_common::Keypair;
@@ -31,7 +30,8 @@ use crate::{
PubliclyVerifiableSS, Result,
};
-pub type DecryptionSharePrecomputed = tpke::api::DecryptionSharePrecomputed;
+pub type DecryptionSharePrecomputed =
+ ferveo_tpke::api::DecryptionSharePrecomputed;
// Normally, we would use a custom trait for this, but we can't because
// the arkworks will not let us create a blanket implementation for G1Affine
@@ -54,7 +54,8 @@ pub fn encrypt(
pubkey: &DkgPublicKey,
) -> Result {
let mut rng = rand::thread_rng();
- let ciphertext = tpke::api::encrypt(message, aad, &pubkey.0, &mut rng)?;
+ let ciphertext =
+ ferveo_tpke::api::encrypt(message, aad, &pubkey.0, &mut rng)?;
Ok(Ciphertext(ciphertext))
}
@@ -64,7 +65,7 @@ pub fn decrypt_with_shared_secret(
shared_secret: &SharedSecret,
) -> Result> {
let dkg_public_params = DkgPublicParameters::default();
- tpke::api::decrypt_with_shared_secret(
+ ferveo_tpke::api::decrypt_with_shared_secret(
&ciphertext.0,
aad,
&shared_secret.0,
@@ -74,7 +75,7 @@ pub fn decrypt_with_shared_secret(
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Eq)]
-pub struct Ciphertext(tpke::api::Ciphertext);
+pub struct Ciphertext(ferveo_tpke::api::Ciphertext);
impl Ciphertext {
pub fn header(&self) -> Result {
@@ -88,7 +89,7 @@ impl Ciphertext {
#[serde_as]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
-pub struct CiphertextHeader(tpke::api::CiphertextHeader);
+pub struct CiphertextHeader(ferveo_tpke::api::CiphertextHeader);
/// The ferveo variant to use for the decryption share derivation.
#[derive(
@@ -347,7 +348,7 @@ impl AggregatedTranscript {
#[serde_as]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct DecryptionShareSimple {
- share: tpke::api::DecryptionShareSimple,
+ share: ferveo_tpke::api::DecryptionShareSimple,
#[serde_as(as = "serialization::SerdeAs")]
domain_point: Fr,
}
@@ -389,13 +390,13 @@ pub fn combine_shares_simple(shares: &[DecryptionShareSimple]) -> SharedSecret {
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
-pub struct SharedSecret(pub tpke::api::SharedSecret);
+pub struct SharedSecret(pub ferveo_tpke::api::SharedSecret);
#[cfg(test)]
mod test_ferveo_api {
+ use ferveo_tpke::SecretBox;
use itertools::izip;
use rand::{prelude::StdRng, SeedableRng};
- use tpke::SecretBox;
use crate::{api::*, dkg::test_common::*};
diff --git a/ferveo/src/bindings_wasm.rs b/ferveo/src/bindings_wasm.rs
index a8b1f7c7..30defbaa 100644
--- a/ferveo/src/bindings_wasm.rs
+++ b/ferveo/src/bindings_wasm.rs
@@ -1,5 +1,3 @@
-extern crate group_threshold_cryptography as tpke;
-
use std::{
convert::{TryFrom, TryInto},
fmt,
@@ -7,10 +5,10 @@ use std::{
};
use ferveo_common::{FromBytes, ToBytes};
+use ferveo_tpke::SecretBox;
use js_sys::Error;
use rand::thread_rng;
use serde::{Deserialize, Serialize};
-use tpke::SecretBox;
use wasm_bindgen::prelude::*;
use wasm_bindgen_derive::TryFromJsValue;
@@ -202,7 +200,9 @@ generate_common_methods!(DecryptionShareSimple);
#[derive(TryFromJsValue)]
#[wasm_bindgen]
#[derive(Clone, Debug, derive_more::AsRef, derive_more::From)]
-pub struct DecryptionSharePrecomputed(tpke::api::DecryptionSharePrecomputed);
+pub struct DecryptionSharePrecomputed(
+ ferveo_tpke::api::DecryptionSharePrecomputed,
+);
generate_common_methods!(DecryptionSharePrecomputed);
diff --git a/ferveo/src/lib.rs b/ferveo/src/lib.rs
index 41da3ba7..d999ca11 100644
--- a/ferveo/src/lib.rs
+++ b/ferveo/src/lib.rs
@@ -4,7 +4,6 @@
extern crate alloc;
use ark_ec::pairing::Pairing;
-use group_threshold_cryptography as tpke;
use itertools::zip_eq;
#[cfg(feature = "bindings-python")]
@@ -31,7 +30,7 @@ pub use validator::*;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error(transparent)]
- ThresholdEncryptionError(#[from] tpke::Error),
+ ThresholdEncryptionError(#[from] ferveo_tpke::Error),
/// DKG is not in a valid state to deal PVSS shares
#[error("Invalid DKG state to deal PVSS shares")]
@@ -127,9 +126,8 @@ mod test_dkg_full {
use ark_poly::EvaluationDomain;
use ark_std::test_rng;
use ferveo_common::Keypair;
- use group_threshold_cryptography as tpke;
- use group_threshold_cryptography::{
- DecryptionSharePrecomputed, DecryptionShareSimple, SecretBox,
+ use ferveo_tpke::{
+ self, DecryptionSharePrecomputed, DecryptionShareSimple, SecretBox,
SharedSecret,
};
use itertools::izip;
@@ -142,7 +140,7 @@ mod test_dkg_full {
fn make_shared_secret_simple_tdec(
dkg: &PubliclyVerifiableDkg,
aad: &[u8],
- ciphertext_header: &tpke::CiphertextHeader,
+ ciphertext_header: &ferveo_tpke::CiphertextHeader,
validator_keypairs: &[Keypair],
) -> (
PubliclyVerifiableSS,
@@ -178,11 +176,12 @@ mod test_dkg_full {
.collect::>();
assert_eq!(domain_points.len(), decryption_shares.len());
- // TODO: Consider refactor this part into tpke::combine_simple and expose it
- // as a public API in tpke::api
+ // TODO: Consider refactor this part into ferveo_tpke::combine_simple and expose it
+ // as a public API in ferveo_tpke::api
- let lagrange_coeffs = tpke::prepare_combine_simple::(domain_points);
- let shared_secret = tpke::share_combine_simple::(
+ let lagrange_coeffs =
+ ferveo_tpke::prepare_combine_simple::(domain_points);
+ let shared_secret = ferveo_tpke::share_combine_simple::(
&decryption_shares,
&lagrange_coeffs,
);
@@ -202,7 +201,7 @@ mod test_dkg_full {
let msg = "my-msg".as_bytes().to_vec();
let aad: &[u8] = "my-aad".as_bytes();
let public_key = dkg.public_key();
- let ciphertext = tpke::encrypt::(
+ let ciphertext = ferveo_tpke::encrypt::(
SecretBox::new(msg.clone()),
aad,
&public_key,
@@ -217,7 +216,7 @@ mod test_dkg_full {
validator_keypairs.as_slice(),
);
- let plaintext = tpke::decrypt_with_shared_secret(
+ let plaintext = ferveo_tpke::decrypt_with_shared_secret(
&ciphertext,
aad,
&shared_secret,
@@ -241,7 +240,7 @@ mod test_dkg_full {
let msg = "my-msg".as_bytes().to_vec();
let aad: &[u8] = "my-aad".as_bytes();
let public_key = dkg.public_key();
- let ciphertext = tpke::encrypt::(
+ let ciphertext = ferveo_tpke::encrypt::(
SecretBox::new(msg.clone()),
aad,
&public_key,
@@ -279,10 +278,10 @@ mod test_dkg_full {
assert_eq!(domain_points.len(), decryption_shares.len());
let shared_secret =
- tpke::share_combine_precomputed::(&decryption_shares);
+ ferveo_tpke::share_combine_precomputed::(&decryption_shares);
// Combination works, let's decrypt
- let plaintext = tpke::decrypt_with_shared_secret(
+ let plaintext = ferveo_tpke::decrypt_with_shared_secret(
&ciphertext,
aad,
&shared_secret,
@@ -301,9 +300,13 @@ mod test_dkg_full {
let msg = "my-msg".as_bytes().to_vec();
let aad: &[u8] = "my-aad".as_bytes();
let public_key = dkg.public_key();
- let ciphertext =
- tpke::encrypt::(SecretBox::new(msg), aad, &public_key, rng)
- .unwrap();
+ let ciphertext = ferveo_tpke::encrypt::(
+ SecretBox::new(msg),
+ aad,
+ &public_key,
+ rng,
+ )
+ .unwrap();
let (pvss_aggregated, decryption_shares, _) =
make_shared_secret_simple_tdec(
@@ -364,9 +367,13 @@ mod test_dkg_full {
let msg = "my-msg".as_bytes().to_vec();
let aad: &[u8] = "my-aad".as_bytes();
let public_key = &dkg.public_key();
- let ciphertext =
- tpke::encrypt::(SecretBox::new(msg), aad, public_key, rng)
- .unwrap();
+ let ciphertext = ferveo_tpke::encrypt::(
+ SecretBox::new(msg),
+ aad,
+ public_key,
+ rng,
+ )
+ .unwrap();
// Create an initial shared secret
let (_, _, old_shared_secret) = make_shared_secret_simple_tdec(
@@ -496,9 +503,11 @@ mod test_dkg_full {
assert_eq!(domain_points.len(), security_threshold as usize);
assert_eq!(decryption_shares.len(), security_threshold as usize);
- let lagrange = tpke::prepare_combine_simple::(domain_points);
- let new_shared_secret =
- tpke::share_combine_simple::(decryption_shares, &lagrange);
+ let lagrange = ferveo_tpke::prepare_combine_simple::(domain_points);
+ let new_shared_secret = ferveo_tpke::share_combine_simple::(
+ decryption_shares,
+ &lagrange,
+ );
assert_eq!(
old_shared_secret, new_shared_secret,
@@ -517,9 +526,13 @@ mod test_dkg_full {
let msg = "my-msg".as_bytes().to_vec();
let aad: &[u8] = "my-aad".as_bytes();
let public_key = &dkg.public_key();
- let ciphertext =
- tpke::encrypt::(SecretBox::new(msg), aad, public_key, rng)
- .unwrap();
+ let ciphertext = ferveo_tpke::encrypt::(
+ SecretBox::new(msg),
+ aad,
+ public_key,
+ rng,
+ )
+ .unwrap();
// Create an initial shared secret
let (_, _, old_shared_secret) = make_shared_secret_simple_tdec(
@@ -594,10 +607,10 @@ mod test_dkg_full {
})
.collect();
- let lagrange = tpke::prepare_combine_simple::(
+ let lagrange = ferveo_tpke::prepare_combine_simple::(
&domain_points[..security_threshold as usize],
);
- let new_shared_secret = tpke::share_combine_simple::(
+ let new_shared_secret = ferveo_tpke::share_combine_simple::(
&decryption_shares[..security_threshold as usize],
&lagrange,
);
diff --git a/ferveo/src/pvss.rs b/ferveo/src/pvss.rs
index 91976ee9..3e28dd67 100644
--- a/ferveo/src/pvss.rs
+++ b/ferveo/src/pvss.rs
@@ -6,16 +6,15 @@ use ark_poly::{
polynomial::univariate::DensePolynomial, DenseUVPolynomial,
EvaluationDomain,
};
-use group_threshold_cryptography as tpke;
+use ferveo_tpke::{
+ prepare_combine_simple, CiphertextHeader, DecryptionSharePrecomputed,
+ DecryptionShareSimple, PrivateKeyShare,
+};
use itertools::Itertools;
use rand::RngCore;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use subproductdomain::fast_multiexp;
-use tpke::{
- prepare_combine_simple, CiphertextHeader, DecryptionSharePrecomputed,
- DecryptionShareSimple, PrivateKeyShare,
-};
use zeroize::{self, Zeroize, ZeroizeOnDrop};
use crate::{
diff --git a/ferveo/src/refresh.rs b/ferveo/src/refresh.rs
index ce87c81c..9b1ed904 100644
--- a/ferveo/src/refresh.rs
+++ b/ferveo/src/refresh.rs
@@ -3,10 +3,9 @@ use std::{ops::Mul, usize};
use ark_ec::{pairing::Pairing, AffineRepr, CurveGroup};
use ark_ff::Zero;
use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial, Polynomial};
-use group_threshold_cryptography as tpke;
+use ferveo_tpke::{lagrange_basis_at, PrivateKeyShare};
use itertools::zip_eq;
use rand_core::RngCore;
-use tpke::{lagrange_basis_at, PrivateKeyShare};
// SHARE UPDATE FUNCTIONS:
@@ -130,7 +129,7 @@ mod tests_refresh {
type E = ark_bls12_381::Bls12_381;
type ScalarField = ::ScalarField;
- use group_threshold_cryptography::{
+ use ferveo_tpke::{
test_common::setup_simple, PrivateDecryptionContextSimple,
PrivateKeyShare,
};
diff --git a/tpke/Cargo.toml b/tpke/Cargo.toml
index 0e65d20e..0c1bd626 100644
--- a/tpke/Cargo.toml
+++ b/tpke/Cargo.toml
@@ -1,5 +1,5 @@
[package]
-name = "group-threshold-cryptography-pre-release"
+name = "ferveo-tpke"
version = "0.2.0"
edition = "2021"
authors = ["Heliax AG ", "Piotr Roslaniec "]
diff --git a/tpke/benches/tpke.rs b/tpke/benches/tpke.rs
index cb553c27..287ba81d 100644
--- a/tpke/benches/tpke.rs
+++ b/tpke/benches/tpke.rs
@@ -5,7 +5,7 @@ use ark_ec::pairing::Pairing;
use criterion::{
black_box, criterion_group, criterion_main, BenchmarkId, Criterion,
};
-use group_threshold_cryptography_pre_release::{
+use ferveo_tpke::{
test_common::{setup_fast, setup_simple},
*,
};