mirror of
https://github.com/bitcoin/bips.git
synced 2026-04-27 16:38:39 +00:00
BIP360: Pay to Merkle Root (P2MR) (#1670)
Review comments and assistance by: Armin Sabouri <armins88@gmail.com> D++ <82842780+dplusplus1024@users.noreply.github.com> Jameson Lopp <jameson.lopp@gmail.com> jbride <jbride2001@yahoo.com> Joey Yandle <xoloki@gmail.com> Jon Atack <jon@atack.com> Jonas Nick <jonasd.nick@gmail.com> Kyle Crews <kylecrews@Kyles-Mac-Studio.local> Mark "Murch" Erhardt <murch@murch.one> notmike-5 <notmike-5@users.noreply.github.com> Vojtěch Strnad <43024885+vostrnad@users.noreply.github.com> Co-authored-by: Ethan Heilman <ethan.r.heilman@gmail.com> Co-authored-by: Isabel Foxen Duke <110147802+Isabelfoxenduke@users.noreply.github.com>
This commit is contained in:
33
bip-0360/ref-impl/rust/src/bin/slh_dsa_key_gen.rs
Normal file
33
bip-0360/ref-impl/rust/src/bin/slh_dsa_key_gen.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use std::env;
|
||||
use log::info;
|
||||
use rand::{rng, RngCore};
|
||||
|
||||
use bitcoinpqc::{
|
||||
generate_keypair, public_key_size, secret_key_size, Algorithm, KeyPair,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
let _ = env_logger::try_init();
|
||||
|
||||
/*
|
||||
In SPHINCS+ (underlying algorithm of SLH-DSA), the random data is used to:
|
||||
* Initialize hash function parameters within the key generation
|
||||
* Seed the Merkle tree construction that forms the public key
|
||||
* Generate the secret key components that enable signing
|
||||
*/
|
||||
let random_data = get_random_bytes(128);
|
||||
println!("Generated random data of size {}", random_data.len());
|
||||
|
||||
let keypair: KeyPair = generate_keypair(Algorithm::SLH_DSA_128S, &random_data)
|
||||
.expect("Failed to generate SLH-DSA-128S keypair");
|
||||
|
||||
info!("public key size / value = {}, {}", public_key_size(Algorithm::SLH_DSA_128S), hex::encode(&keypair.public_key.bytes));
|
||||
info!("private key size / value = {}, {}", secret_key_size(Algorithm::SLH_DSA_128S), hex::encode(&keypair.secret_key.bytes));
|
||||
|
||||
}
|
||||
|
||||
fn get_random_bytes(size: usize) -> Vec<u8> {
|
||||
let mut bytes = vec![0u8; size];
|
||||
rng().fill_bytes(&mut bytes);
|
||||
bytes
|
||||
}
|
||||
Reference in New Issue
Block a user