Skip to content
Open
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
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repository = "https://github.com/mimblewimble/rust-secp256k1-zkp/"
description = "Grin's fork with Zero-Knowledge extensions of Rust bindings for Pieter Wuille's `libsecp256k1` library. Implements ECDSA for the SECG elliptic curve group secp256k1 and related utilities."
keywords = [ "crypto", "secp256k1", "grin", "bitcoin", "zero-knowledge" ]
readme = "README.md"
edition = "2018"
edition = "2021"

build = "build.rs"
[build-dependencies]
Expand All @@ -30,12 +30,12 @@ dev = ["clippy"]
[dependencies]
arrayvec = "0.7"
clippy = {version = "0.0", optional = true}
rand = "0.5"
rand = "0.9.0"
libc = "0.2"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
zeroize = { version = "1.1", features = ["zeroize_derive"] }

[dev-dependencies]
chrono = "0.4.5"
rand_core = "0.2"
rand_core = "0.9.3"
4 changes: 2 additions & 2 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ name = "grin_secp256k1zkp-fuzz"
version = "0.0.0"
authors = ["Automatically generated"]
publish = false
edition = "2018"
edition = "2021"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.3"
libfuzzer-sys = "0.4.9"

[dependencies.grin_secp256k1zkp]
path = ".."
Expand Down
4 changes: 2 additions & 2 deletions fuzz/fuzz_targets/fuzz_aggsig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ use secp256k1zkp::{
};

use secp256k1zkp::aggsig::AggSigContext;
use secp256k1zkp::rand::{Rng, thread_rng};
use secp256k1zkp::rand::{Rng, rng};

fuzz_target!(|data: &[u8]| {
let numkeys = 3;
if data.len() < (numkeys + 1) * 32 {
return ();
}

let mut rng = thread_rng();
let mut rng = rng();
let secp = Secp256k1::with_caps(ContextFlag::Full);
let mut pks: Vec<PublicKey> = Vec::with_capacity(numkeys);
let mut keypairs: Vec<(SecretKey, PublicKey)> = Vec::with_capacity(numkeys);
Expand Down
42 changes: 21 additions & 21 deletions src/aggsig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use libc::size_t;
use crate::ffi;
use crate::key::{PublicKey, SecretKey};
use rand::{thread_rng, Rng};
use rand::{rng, Rng};
use std::ptr;
use crate::Secp256k1;
use crate::{AggSigPartialSignature, Error, Message, Signature};
Expand All @@ -34,9 +34,9 @@ pub const ZERO_256: [u8; 32] = [
/// msg: the message to sign
/// seckey: the secret key
pub fn export_secnonce_single(secp: &Secp256k1) -> Result<SecretKey, Error> {
let mut return_key = SecretKey::new(&secp, &mut thread_rng());
let mut return_key = SecretKey::new(&secp, &mut rng());
let mut seed = [0u8; 32];
thread_rng().fill(&mut seed);
rng().fill(&mut seed);
let retval = unsafe {
ffi::secp256k1_aggsig_export_secnonce_single(
secp.ctx,
Expand Down Expand Up @@ -97,7 +97,7 @@ pub fn sign_single(
) -> Result<Signature, Error> {
let mut retsig = Signature::from(ffi::Signature::new());
let mut seed = [0u8; 32];
thread_rng().fill(&mut seed);
rng().fill(&mut seed);

let secnonce = match secnonce {
Some(n) => n.as_ptr(),
Expand Down Expand Up @@ -302,7 +302,7 @@ impl AggSigContext {
/// Creates new aggsig context with a new random seed
pub fn new(secp: &Secp256k1, pubkeys: &Vec<PublicKey>) -> AggSigContext {
let mut seed = [0u8; 32];
thread_rng().fill(&mut seed);
rng().fill(&mut seed);
let pubkeys: Vec<*const ffi::PublicKey> = pubkeys.into_iter().map(|p| p.as_ptr()).collect();
let pubkeys = &pubkeys[..];
unsafe {
Expand Down Expand Up @@ -431,7 +431,7 @@ mod tests {
use crate::aggsig::subtract_partial_signature;
use crate::ffi;
use crate::key::{PublicKey, SecretKey};
use rand::{thread_rng, Rng};
use rand::{rng, Rng};
use crate::ContextFlag;
use crate::{AggSigPartialSignature, Message, Signature};

Expand All @@ -441,7 +441,7 @@ use crate::ffi;
let secp = Secp256k1::with_caps(ContextFlag::Full);
let mut keypairs: Vec<(SecretKey, PublicKey)> = vec![];
for _ in 0..numkeys {
keypairs.push(secp.generate_keypair(&mut thread_rng()).unwrap());
keypairs.push(secp.generate_keypair(&mut rng()).unwrap());
}
let pks: Vec<PublicKey> = keypairs.clone().into_iter().map(|(_, p)| p).collect();
println!(
Expand All @@ -458,7 +458,7 @@ use crate::ffi;
}

let mut msg = [0u8; 32];
thread_rng().fill(&mut msg);
rng().fill(&mut msg);
let msg = Message::from_slice(&msg).unwrap();
let mut partial_sigs: Vec<AggSigPartialSignature> = vec![];
for i in 0..numkeys {
Expand Down Expand Up @@ -498,15 +498,15 @@ use crate::ffi;
#[test]
fn test_aggsig_single() {
let secp = Secp256k1::with_caps(ContextFlag::Full);
let (sk, pk) = secp.generate_keypair(&mut thread_rng()).unwrap();
let (sk, pk) = secp.generate_keypair(&mut rng()).unwrap();

println!(
"Performing aggsig single context with seckey, pubkey: {:?},{:?}",
sk, pk
);

let mut msg = [0u8; 32];
thread_rng().fill(&mut msg);
rng().fill(&mut msg);
let msg = Message::from_slice(&msg).unwrap();
let sig = sign_single(&secp, &msg, &sk, None, None, None, None, None).unwrap();

Expand All @@ -519,7 +519,7 @@ use crate::ffi;
assert!(result == true);

let mut msg = [0u8; 32];
thread_rng().fill(&mut msg);
rng().fill(&mut msg);
let msg = Message::from_slice(&msg).unwrap();
println!(
"Verifying aggsig single: {:?}, msg: {:?}, pk:{:?}",
Expand All @@ -531,9 +531,9 @@ use crate::ffi;

// test optional extra key
let mut msg = [0u8; 32];
thread_rng().fill(&mut msg);
rng().fill(&mut msg);
let msg = Message::from_slice(&msg).unwrap();
let (sk_extra, pk_extra) = secp.generate_keypair(&mut thread_rng()).unwrap();
let (sk_extra, pk_extra) = secp.generate_keypair(&mut rng()).unwrap();
let sig = sign_single(&secp, &msg, &sk, None, Some(&sk_extra), None, None, None).unwrap();
let result = verify_single(&secp, &sig, &msg, None, &pk, None, Some(&pk_extra), false);
assert!(result == true);
Expand All @@ -548,9 +548,9 @@ use crate::ffi;
let mut pub_keys: Vec<PublicKey> = vec![];

for _ in 0..100 {
let (sk, pk) = secp.generate_keypair(&mut thread_rng()).unwrap();
let (sk, pk) = secp.generate_keypair(&mut rng()).unwrap();
let mut msg = [0u8; 32];
thread_rng().fill(&mut msg);
rng().fill(&mut msg);

let msg = Message::from_slice(&msg).unwrap();
let sig = sign_single(&secp, &msg, &sk, None, None, None, Some(&pk), None).unwrap();
Expand All @@ -571,15 +571,15 @@ use crate::ffi;
#[test]
fn test_aggsig_fuzz() {
let secp = Secp256k1::with_caps(ContextFlag::Full);
let (sk, pk) = secp.generate_keypair(&mut thread_rng()).unwrap();
let (sk, pk) = secp.generate_keypair(&mut rng()).unwrap();

println!(
"Performing aggsig single context with seckey, pubkey: {:?},{:?}",
sk, pk
);

let mut msg = [0u8; 32];
thread_rng().fill(&mut msg);
rng().fill(&mut msg);
let msg = Message::from_slice(&msg).unwrap();
let sig = sign_single(&secp, &msg, &sk, None, None, None, None, None).unwrap();

Expand Down Expand Up @@ -677,7 +677,7 @@ use crate::ffi;
assert!(result == false);

let mut msg = [0u8; 32];
thread_rng().fill(&mut msg);
rng().fill(&mut msg);
let msg = Message::from_slice(&msg).unwrap();
if sign_single(
&secp,
Expand All @@ -699,8 +699,8 @@ use crate::ffi;
for _ in 0..20 {
let secp = Secp256k1::with_caps(ContextFlag::Full);
// Generate keys for sender, receiver
let (sk1, pk1) = secp.generate_keypair(&mut thread_rng()).unwrap();
let (sk2, pk2) = secp.generate_keypair(&mut thread_rng()).unwrap();
let (sk1, pk1) = secp.generate_keypair(&mut rng()).unwrap();
let (sk2, pk2) = secp.generate_keypair(&mut rng()).unwrap();

// Generate nonces for sender, receiver
let secnonce_1 = export_secnonce_single(&secp).unwrap();
Expand All @@ -716,7 +716,7 @@ use crate::ffi;

// Random message
let mut msg = [0u8; 32];
thread_rng().fill(&mut msg);
rng().fill(&mut msg);
let msg = Message::from_slice(&msg).unwrap();

// Add public keys (for storing in e)
Expand Down
4 changes: 4 additions & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,19 @@ pub const PEDERSEN_COMMITMENT_SIZE_INTERNAL: usize = 64;
/// The size of a single Bullet proof
pub const SINGLE_BULLET_PROOF_SIZE: usize = 675;

/// The size of a single Bullet proof
#[cfg(feature = "bullet-proof-sizing")]
pub const MAX_PROOF_SIZE: usize = SINGLE_BULLET_PROOF_SIZE;

/// The max size of a range proof
#[cfg(not(feature = "bullet-proof-sizing"))]
pub const MAX_PROOF_SIZE: usize = 5134;

/// The maximum size of a message embedded in a range proof
#[cfg(not(feature = "bullet-proof-sizing"))]
pub const PROOF_MSG_SIZE: usize = 2048;

/// The maximum size of a message embedded in a range proof
#[cfg(feature = "bullet-proof-sizing")]
pub const PROOF_MSG_SIZE: usize = 2048;

Expand Down
10 changes: 5 additions & 5 deletions src/ecdh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ impl ops::Index<ops::RangeFull> for SharedSecret {

#[cfg(test)]
mod tests {
use rand::thread_rng;
use rand::rng;
use super::SharedSecret;
use super::super::Secp256k1;

#[test]
fn ecdh() {
let s = Secp256k1::with_caps(crate::ContextFlag::SignOnly);
let (sk1, pk1) = s.generate_keypair(&mut thread_rng()).unwrap();
let (sk2, pk2) = s.generate_keypair(&mut thread_rng()).unwrap();
let (sk1, pk1) = s.generate_keypair(&mut rng()).unwrap();
let (sk2, pk2) = s.generate_keypair(&mut rng()).unwrap();

let sec1 = SharedSecret::new(&s, &pk1, &sk2);
let sec2 = SharedSecret::new(&s, &pk2, &sk1);
Expand All @@ -112,7 +112,7 @@ mod tests {

#[cfg(all(test, feature = "unstable"))]
mod benches {
use rand::thread_rng;
use rand::rng;
use test::{Bencher, black_box};

use super::SharedSecret;
Expand All @@ -121,7 +121,7 @@ mod benches {
#[bench]
pub fn bench_ecdh(bh: &mut Bencher) {
let s = Secp256k1::with_caps(::ContextFlag::SignOnly);
let (sk, pk) = s.generate_keypair(&mut thread_rng()).unwrap();
let (sk, pk) = s.generate_keypair(&mut rng()).unwrap();

let s = Secp256k1::new();
bh.iter( || {
Expand Down
Loading