Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganize features and clean up dependencies #741

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 9 additions & 40 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion fastcrypto-tbls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description = "Threshold BLS and DKG protocols"
repository = "https://github.com/MystenLabs/fastcrypto"

[dependencies]
fastcrypto = { path = "../fastcrypto", features = ["beacon-dkg"]}
fastcrypto = { path = "../fastcrypto", features = ["aes"]}

rand.workspace = true
serde.workspace = true
Expand Down
1 change: 0 additions & 1 deletion fastcrypto-vdf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ num-integer = "0.1.45"
num-prime = { version = "0.4.3", features = ["big-int"] }
rand = "0.8.5"
rand_chacha = "0.3.1"
itertools = { version = "0.12.0", features = [] }

[features]
experimental = []
Expand Down
41 changes: 27 additions & 14 deletions fastcrypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,10 @@ rand.workspace = true
rust_secp256k1 = { version = "0.27.0", package = "secp256k1", features = ["recovery", "rand-std", "bitcoin_hashes", "global-context"] }
serde.workspace = true
serde_with = "2.1.0"
serde-big-array = { version = "0.5.0", optional = true }
signature = { version = "2.0.0" }
tokio = { version = "1.24.1", features = ["sync", "rt", "macros"] }
zeroize.workspace = true
bulletproofs = "4.0.0"
curve25519-dalek-ng = "4.1.1"
merlin = "3.0.0"
aes = "0.8.2"
ctr = "0.9.2"
cbc = { version = "0.1.2", features = ["std"] }
aes-gcm = "0.10.1"
generic-array = { version = "0.14.6", features = ["serde"] }
typenum.workspace = true
auto_ops = "0.3.0"
Expand All @@ -40,19 +33,17 @@ p256 = { version = "0.13.2", features = ["ecdsa"] }
ecdsa = { version = "0.16.6", features = ["rfc6979", "verifying"] }
rfc6979 = "0.4.0"
blake2 = "0.10.6"
blake3 = "1.3.3"
blst = { version = "0.3.10", features = ["no-threads"] }
digest.workspace = true
once_cell = "1.17.0"
readonly = "0.2.3"
sha2 = "0.10.6"
sha3.workspace = true
thiserror = "1.0.38"
twox-hash = { version = "1.6.3", optional = true }
schemars ="0.8.12"
schemars = "0.8.12"
bincode.workspace = true
elliptic-curve = {version = "0.13.2", features = ["hash2curve"]}
rsa = {version = "0.8.2", features = ["sha2"] }
elliptic-curve = { version = "0.13.2", features = ["hash2curve"] }
rsa = { version = "0.8.2", features = ["sha2"] }
static_assertions = "1.1.0"
ark-secp256r1 = "0.4.0"
ark-ec = "0.4.1"
Expand All @@ -64,6 +55,20 @@ serde_json = "1.0.93"
num-bigint = "0.4.4"
bech32 = "0.9.1"

# Required for bulletproofs
bulletproofs = { version = "4.0.0", optional = true }
merlin = { version = "3.0.0", optional = true }

# Required for the unsecure signature and hash schemes
twox-hash = { version = "1.6.3", optional = true }
serde-big-array = { version = "0.5.0", optional = true }

# Required for the aes feature
aes = { version = "0.8.2", optional = true }
ctr = { version = "0.9.2", optional = true }
cbc = { version = "0.1.2", features = ["std"], optional = true }
aes-gcm = { version = "0.10.1", optional = true }

[[bench]]
name = "crypto"
harness = false
Expand Down Expand Up @@ -95,11 +100,19 @@ name = "hash"
harness = false

[features]
beacon-dkg = []
default = []

# Allow copying keys
copy_key = []

# Enable the unsecure signature and hash schemes for benchmarking.
unsecure_schemes = ["dep:twox-hash", "dep:serde-big-array"]
experimental = []

# Used for feature that are not yet audited.
experimental = ["dep:bulletproofs", "dep:merlin"]

# Include AES and its modes.
aes = ["dep:aes", "dep:cbc", "dep:aes-gcm", "dep:ctr"]

[dev-dependencies]
criterion = "0.4.0"
Expand Down
1 change: 0 additions & 1 deletion fastcrypto/benches/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ mod hash_benches {
hash_single::<Sha256, 32, _>("Sha256", &input, &mut group);
hash_single::<Sha3_256, 32, _>("Sha3_256", &input, &mut group);
hash_single::<Blake2b256, 32, _>("Blake2b256", &input, &mut group);
hash_single::<Blake3, 32, _>("Blake3", &input, &mut group);
hash_single::<Keccak256, 32, _>("Keccak256", &input, &mut group);
hash_single::<Sha512, 64, _>("Sha512", &input, &mut group);
hash_single::<Sha3_512, 64, _>("Sha3_512", &input, &mut group);
Expand Down
18 changes: 0 additions & 18 deletions fastcrypto/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,24 +177,6 @@ pub type Keccak256 = HashFunctionWrapper<sha3::Keccak256, 32>;
/// The [BLAKE2-256](https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE2) hash function with 256 bit digests.
pub type Blake2b256 = HashFunctionWrapper<blake2::Blake2b<typenum::U32>, 32>;

/// The [BLAKE3](https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3) hash function with 256 bit digests.
#[derive(Default)]
pub struct Blake3 {
instance: blake3::Hasher,
}

impl HashFunction<32> for Blake3 {
fn update<Data: AsRef<[u8]>>(&mut self, data: Data) {
self.instance.update(data.as_ref());
}

fn finalize(self) -> Digest<32> {
Digest {
digest: self.instance.finalize().into(),
}
}
}

/// A Multiset Hash is a homomorphic hash function, which hashes arbitrary multisets of objects such
/// that the hash of the union of two multisets is easy to compute from the hashes of the two multisets.
///
Expand Down
2 changes: 1 addition & 1 deletion fastcrypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub mod secp256r1_group_tests;

pub mod traits;

#[cfg(any(test, feature = "experimental", feature = "beacon-dkg"))]
#[cfg(any(test, feature = "aes"))]
pub mod aes;
pub mod bls12381;
#[cfg(any(test, feature = "experimental"))]
Expand Down
15 changes: 2 additions & 13 deletions fastcrypto/src/tests/hash_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

use crate::encoding::{Base64, Encoding};
use crate::hash::{
Blake2b256, Blake3, Digest, EllipticCurveMultisetHash, HashFunction, Keccak256, MultisetHash,
Sha256, Sha3_256, Sha3_512, Sha512,
Blake2b256, Digest, EllipticCurveMultisetHash, HashFunction, Keccak256, MultisetHash, Sha256,
Sha3_256, Sha3_512, Sha512,
};
use std::io::Write;

Expand Down Expand Up @@ -138,17 +138,6 @@ fn test_blake2b_256() {
);
}

#[test]
fn test_blake3() {
let data =
hex::decode("301d56460954541aab6dd7ddc0dd08f8cb3ebd884784a0e797905107533cae62").unwrap();
let digest = Blake3::digest(data);
assert_eq!(
digest.as_ref(),
hex::decode("1b6d57a5017077b00cc9ce0641fb8ddcc136fbdb83325b31597fbe9441d9b269").unwrap()
);
}

#[test]
fn test_accumulator() {
let mut accumulator = EllipticCurveMultisetHash::default();
Expand Down
Loading