Type Definition tari_crypto::ristretto::ristretto_sig::RistrettoSchnorr [−][src]
type RistrettoSchnorr = SchnorrSignature<RistrettoPublicKey, RistrettoSecretKey>;
A Schnorr signature implementation on Ristretto
Find out more about Schnorr signatures.
RistrettoSchnorr
utilises the curve25519-dalek
implementation of ristretto255
to provide Schnorr signature functionality.
In short, a Schnorr sig is made up of the pair (R, s), where R is a public key (of a secret nonce) and s is the signature.
Creating signatures
You can create a RisrettoSchnorr
from it’s component parts:
ⓘ
let public_r = RistrettoPublicKey::from_hex("6a493210f7499cd17fecb510ae0cea23a110e8d5b901f8acadd3095c73a3b919").unwrap(); let s = RistrettoSecretKey::from_bytes(b"10000000000000000000000000000000").unwrap(); let sig = RistrettoSchnorr::new(public_r, s);
or you can create a signature by signing a message:
fn get_keypair() -> (RistrettoSecretKey, RistrettoPublicKey) { let mut rng = rand::thread_rng(); let k = RistrettoSecretKey::random(&mut rng); let pk = RistrettoPublicKey::from_secret_key(&k); (k, pk) } #[allow(non_snake_case)] let (k, P) = get_keypair(); let (r, R) = get_keypair(); let e = Blake256::digest(b"Small Gods"); let sig = RistrettoSchnorr::sign(k, r, &e);
Verifying signatures
Given a signature, (R,s) and a Challenge, e, you can verify that the signature is valid by calling the verify
method:
ⓘ
let P = RistrettoPublicKey::from_hex("74896a30c89186b8194e25f8c1382f8d3081c5a182fb8f8a6d34f27fbefbfc70").unwrap(); let R = RistrettoPublicKey::from_hex("fa14cb581ce5717248444721242e6b195a482d503a853dea4acb513074d8d803").unwrap(); let s = RistrettoSecretKey::from_hex("bd0b253a619310340a4fa2de54cdd212eac7d088ee1dc47e305c3f6cbd020908").unwrap(); let sig = RistrettoSchnorr::new(R, s); let e = Blake256::digest(b"Maskerade"); assert!(sig.verify_challenge(&P, &e));