mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
added basic code for schnorr signatures
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
pub mod diffie_hellman;
|
||||
pub mod mint_proof;
|
||||
pub mod schnorr;
|
||||
pub mod spend_proof;
|
||||
pub mod util;
|
||||
|
||||
use bellman::groth16;
|
||||
use bls12_381::Bls12;
|
||||
|
||||
25
src/crypto/schnorr.rs
Normal file
25
src/crypto/schnorr.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use ff::Field;
|
||||
use group::{Group, GroupEncoding};
|
||||
use rand::rngs::OsRng;
|
||||
|
||||
use super::util::hash_to_scalar;
|
||||
|
||||
#[test]
|
||||
fn test_schnorr() {
|
||||
let secret = jubjub::Fr::random(&mut OsRng);
|
||||
let public = zcash_primitives::constants::SPENDING_KEY_GENERATOR * secret;
|
||||
|
||||
let mask = jubjub::Fr::random(&mut OsRng);
|
||||
let commit = zcash_primitives::constants::SPENDING_KEY_GENERATOR * mask;
|
||||
|
||||
let msg = b"Foo bar";
|
||||
let challenge = hash_to_scalar(b"DarkFi_Schnorr", &commit.to_bytes(), &msg[..]);
|
||||
|
||||
let response = mask + challenge * secret;
|
||||
|
||||
// Verify signature
|
||||
|
||||
assert_eq!(
|
||||
zcash_primitives::constants::SPENDING_KEY_GENERATOR * response - public * challenge, commit);
|
||||
}
|
||||
|
||||
10
src/crypto/util.rs
Normal file
10
src/crypto/util.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
use blake2b_simd::Params;
|
||||
|
||||
pub fn hash_to_scalar(persona: &[u8], a: &[u8], b: &[u8]) -> jubjub::Fr {
|
||||
let mut hasher = Params::new().hash_length(64).personal(persona).to_state();
|
||||
hasher.update(a);
|
||||
hasher.update(b);
|
||||
let ret = hasher.finalize();
|
||||
jubjub::Fr::from_bytes_wide(ret.as_array())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user