Skip to content

Commit

Permalink
feat: update dependancies (#185)
Browse files Browse the repository at this point in the history
Updates the following dependencies:
tari_utilities
digest
blake2
sha3
bulletproofs_plus
curve25519-dalek
lazy_static
merlin
rand/rand-core
borsh

Some of these like digest and borsh require code changes. 
`Blake256` is now replaced with the raw type `Blake2b<U32>`
  • Loading branch information
SWvheerden committed Jul 18, 2023
1 parent d21cd37 commit 4c2424f
Show file tree
Hide file tree
Showing 22 changed files with 262 additions and 414 deletions.
58 changes: 26 additions & 32 deletions Cargo.toml
Expand Up @@ -11,46 +11,37 @@ version = "0.17.0"
edition = "2018"

[dependencies]
tari_utilities = { version = "0.4.10" }

base64 = "0.10.1"
blake2 = "0.9.1"
borsh = { version = "0.9.3", optional = true }
bulletproofs = { package = "tari_bulletproofs", version= "4.4.1" }
bulletproofs_plus = { package = "tari_bulletproofs_plus", version="0.2.3" }
curve25519-dalek = {package="tari-curve25519-dalek", version = "4.0.2", default-features = false, features = ["serde", "alloc"] }
digest = "0.9.0"
getrandom = { version = "0.2.3", default-features = false, optional = true }
lazy_static = "1.3.0"
log = "0.4.0"
merlin = { version = "2.0.1", default-features = false }
once_cell = "1.8.0"
rand = { version = "0.7.3", default-features = false }
rand_chacha = "0.3.1"
rand_core = "0.6.4"
serde = "1.0"
serde_json = "1.0"
tari_utilities = { version = "0.5", features = ["zero", "std"] }
blake2 = { version = "0.10" }
borsh = { version = "0.10" , optional = true }
bulletproofs_plus = { package = "tari_bulletproofs_plus", version = "0.3.1" }
curve25519-dalek = { package = "tari-curve25519-dalek", version = "4.0.3", default-features = false, features = ["serde", "alloc", "rand_core", "precomputed-tables"] }
digest = { version = "0.10" }
getrandom = { version = "0.2" }
lazy_static = { version = "1.3" }
log = { version = "0.4" }
once_cell = { version = "1.8" }
rand_chacha = { version = "0.3" }
rand_core = { version = "0.6" }
serde = { version = "1.0" }
serde-wasm-bindgen = { version = "0.4", optional = true }
sha3 = "0.9.0"
thiserror = "1.0.20"
sha3 = { version = "0.10" }
thiserror = { version = "1.0" }
wasm-bindgen = { version = "^0.2", features = ["serde-serialize"], optional = true }
zeroize = "1"
zeroize = {version = "1" }
rand = { version = "0.8" }

[dev-dependencies]
bincode = "1.1.4"
criterion = "0.3.4"
rand_chacha = "0.3.1"
sha2 = "0.9.5"
wasm-bindgen-test = "0.3.24"
bincode = { version = "1.1" }
criterion = { version = "0.5", default-features = false }
sha2 = { version = "0.10" }
wasm-bindgen-test = { version = "0.3" }

[build-dependencies]
cbindgen = "0.17.0"
cbindgen = {version = "0.24" }

[features]
default = ["u64_backend"]
u64_backend = ["curve25519-dalek/u64_backend"]
simd_backend = ["curve25519-dalek/simd_backend", "bulletproofs/simd_backend"]
wasm = ["wasm-bindgen", "getrandom/js", "rand/wasm-bindgen", "serde-wasm-bindgen"]
wasm = ["wasm-bindgen", "getrandom/js", "serde-wasm-bindgen"]
ffi = []
musig = []

Expand All @@ -66,3 +57,6 @@ harness = false

[package.metadata.wasm-pack.profile.release]
wasm-opt = ["-Oz"]

[package.metadata.cargo-machete]
ignored = ["getrandom"]
7 changes: 4 additions & 3 deletions src/commitment.rs
Expand Up @@ -37,8 +37,9 @@ pub struct HomomorphicCommitment<P>(pub(crate) P);

#[cfg(feature = "borsh")]
impl<P: borsh::BorshDeserialize> borsh::BorshDeserialize for HomomorphicCommitment<P> {
fn deserialize(buf: &mut &[u8]) -> std::io::Result<Self> {
Ok(Self(P::deserialize(buf)?))
fn deserialize_reader<R>(reader: &mut R) -> Result<Self, std::io::Error>
where R: std::io::Read {
Ok(Self(P::deserialize_reader(reader)?))
}
}

Expand Down Expand Up @@ -80,7 +81,7 @@ impl<P> PartialOrd for HomomorphicCommitment<P>
where P: PublicKey
{
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.0.cmp(&other.0))
Some(self.cmp(other))
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/errors.rs
Expand Up @@ -45,13 +45,19 @@ pub enum HashingError {
#[error("The input to the hashing function is too short.")]
InputTooShort,
/// Converting a byte string into a secret key failed
#[error("Converting a byte string into a secret key failed. {0}")]
ConversionFromBytes(#[from] ByteArrayError),
#[error("Converting a byte string into a secret key failed: {0}")]
ConversionFromBytes(String),
/// The digest does not produce enough output
#[error("The digest does produce enough output. {0} bytes are required.")]
DigestTooShort(usize),
}

impl From<ByteArrayError> for HashingError {
fn from(byte_error: ByteArrayError) -> Self {
HashingError::ConversionFromBytes(byte_error.to_string())
}
}

/// Errors encountered when copying to a buffer
#[derive(Debug, Clone, Error, PartialEq, Eq, Serialize, Deserialize)]
pub enum SliceError {
Expand Down
16 changes: 8 additions & 8 deletions src/ffi/keys.rs
Expand Up @@ -6,14 +6,14 @@ use std::{
os::raw::{c_char, c_int},
};

use digest::Digest;
use blake2::Blake2b;
use digest::{consts::U32, Digest};
use rand::rngs::OsRng;
use tari_utilities::ByteArray;

use crate::{
commitment::{HomomorphicCommitment, HomomorphicCommitmentFactory},
ffi::error::{INVALID_SECRET_KEY_SER, NULL_POINTER, OK, SIGNING_ERROR, STR_CONV_ERR},
hash::blake2::Blake256,
keys::{PublicKey, SecretKey},
ristretto::{
pedersen::commitment_factory::PedersenCommitmentFactory,
Expand Down Expand Up @@ -79,7 +79,7 @@ pub unsafe extern "C" fn sign(
Ok(s) => s,
_ => return STR_CONV_ERR,
};
let e = RistrettoSchnorr::construct_domain_separated_challenge::<_, Blake256>(&pub_r, &pubkey, msg.as_bytes());
let e = RistrettoSchnorr::construct_domain_separated_challenge::<_, Blake2b<U32>>(&pub_r, &pubkey, msg.as_bytes());
let sig = match RistrettoSchnorr::sign_raw(&k, r, e.as_ref()) {
Ok(sig) => sig,
_ => return SIGNING_ERROR,
Expand Down Expand Up @@ -200,7 +200,7 @@ pub unsafe extern "C" fn sign_comsig(
Ok(s) => s,
_ => return STR_CONV_ERR,
};
let challenge = Blake256::digest(msg.as_bytes()).to_vec();
let challenge = Blake2b::<U32>::digest(msg.as_bytes()).to_vec();
let factory = PedersenCommitmentFactory::default();
let sig = match RistrettoComSig::sign(&secret_a, &secret_x, &nonce_a, &nonce_x, &challenge, &factory) {
Ok(sig) => sig,
Expand Down Expand Up @@ -254,7 +254,7 @@ pub unsafe extern "C" fn verify_comsig(
_ => return false,
};
let sig = RistrettoComSig::new(r_pub, u, v);
let challenge = Blake256::digest(msg.as_bytes());
let challenge = Blake2b::<U32>::digest(msg.as_bytes());
let challenge = match RistrettoSecretKey::from_bytes(challenge.as_slice()) {
Ok(e) => e,
_ => return false,
Expand Down Expand Up @@ -314,7 +314,7 @@ pub unsafe extern "C" fn sign_comandpubsig(
Ok(s) => s,
_ => return STR_CONV_ERR,
};
let challenge = Blake256::digest(msg.as_bytes()).to_vec();
let challenge = Blake2b::<U32>::digest(msg.as_bytes()).to_vec();
let factory = PedersenCommitmentFactory::default();
let sig = match RistrettoComAndPubSig::sign(&a, &x, &y, &r_a, &r_x, &r_y, &challenge, &factory) {
Ok(sig) => sig,
Expand Down Expand Up @@ -394,7 +394,7 @@ pub unsafe extern "C" fn verify_comandpubsig(
_ => return false,
};
let sig = RistrettoComAndPubSig::new(ephemeral_commitment, ephemeral_pubkey, u_a, u_x, u_y);
let challenge = Blake256::digest(msg.as_bytes());
let challenge = Blake2b::<U32>::digest(msg.as_bytes());
let challenge = match RistrettoSecretKey::from_bytes(challenge.as_slice()) {
Ok(e) => e,
_ => return false,
Expand Down Expand Up @@ -438,7 +438,7 @@ mod test {
}
assert_ne!(priv_key, priv_key_before);
assert_eq!(
RistrettoPublicKey::from_secret_key(&RistrettoSecretKey(Scalar::from_bits(priv_key))).as_bytes(),
RistrettoPublicKey::from_secret_key(&RistrettoSecretKey(Scalar::from_bytes_mod_order(priv_key))).as_bytes(),
pub_key
);
}
Expand Down
189 changes: 0 additions & 189 deletions src/hash/blake2.rs

This file was deleted.

14 changes: 0 additions & 14 deletions src/hash/error.rs

This file was deleted.

0 comments on commit 4c2424f

Please sign in to comment.