From f924db914726fd97b4c285f0d62667ac8c0fc076 Mon Sep 17 00:00:00 2001 From: asherli <444649358@qq.com> Date: Wed, 30 Oct 2024 14:15:44 +0800 Subject: [PATCH] remove rand private key --- crypto/vrf/secp256k1/src/lib.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/crypto/vrf/secp256k1/src/lib.rs b/crypto/vrf/secp256k1/src/lib.rs index d5cedfe..cffa8bd 100644 --- a/crypto/vrf/secp256k1/src/lib.rs +++ b/crypto/vrf/secp256k1/src/lib.rs @@ -6,7 +6,7 @@ extern crate k256; use k256::{ elliptic_curve::{ - generic_array::GenericArray, rand_core::OsRng, sec1::FromEncodedPoint, + generic_array::GenericArray, sec1::FromEncodedPoint, PrimeField, }, AffinePoint, EncodedPoint, Scalar, @@ -119,14 +119,14 @@ impl Vrf for WedprSecp256k1Vrf { } fn prove>( - private_key: &T, + private_key_vec: &T, message: &T, ) -> Result where Self: Sized, { let private_key_result = - k256::SecretKey::from_slice(private_key.as_ref()); + k256::SecretKey::from_slice(private_key_vec.as_ref()); let private_key = match private_key_result { Ok(private_key) => private_key, @@ -157,9 +157,11 @@ impl Vrf for WedprSecp256k1Vrf { let gamma = h_point * private_key_scalar; - let blinding_k = k256::Scalar::random(&mut OsRng); - - let scalar_k = private_key_scalar * blinding_k; + // let blinding_k = k256::Scalar::random(&mut OsRng); + let scalar_k = match hash_to_scalar(&private_key_vec.as_ref().to_vec()) { + Ok(scalar_k) => scalar_k, + Err(_) => return Err(WedprError::FormatError), + }; let point_k = base_point * scalar_k; @@ -300,6 +302,8 @@ impl Vrf for WedprSecp256k1Vrf { #[cfg(test)] mod tests { + use k256::elliptic_curve::rand_core::OsRng; + use super::*; #[test] @@ -318,7 +322,7 @@ mod tests { proof.verify(&public_key.as_affine().to_bytes().to_vec(), &message), true ); - // println!("proof hash : {:?}", proof.proof_to_hash().unwrap()); + println!("proof hash : {:?}", proof.proof_to_hash().unwrap()); } #[test]