Crates.io | schnorr-rs |
lib.rs | schnorr-rs |
version | 0.1.0 |
source | src |
created_at | 2024-07-09 05:36:42.384129 |
updated_at | 2024-07-09 05:36:42.384129 |
description | Schnorr Protocols |
homepage | |
repository | https://github.com/AlvinHon/schnorr |
max_upload_size | |
id | 1296653 |
size | 39,116 |
This repository contains the rust implementation of various Schnorr protocols by Dr. Claus-Peter Schnorr:
It is a light-weight library that implements the protocol in simpliest way where minimal number of APIs are used, though the protocols are highly interactive. While there are some limitations for you to consider before using it:
secp256r1
, prime256v1
) to use.Welcome to contribute to remove (any) limitations (e.g. to make it more flexible) while keeping the prinicple of simplicity.
The protocol involves user
, issuer
and verifier
, who share the same parameters that can be instantiated by Identification::<Hash>::from_str
. In following example, the variable schnorr
is its instantiation while i
is the identify in type BigUInt
.
// user interacts with issuer to get a certificate
let (iss_secret, iss_params) = schnorr.issue_params::<Rand>(i.clone());
let cert = schnorr.issue_certificate(iss_params);
// user presents the certificate to the verifier
let (ver_secret, ver_req) = schnorr.verification_request::<Rand>(cert);
// verifier challenges the user's knowledge of the secret
let challenge = schnorr
.verification_challenge::<Rand>(ver_req.clone())
.unwrap();
// user responds to the challenge
let ver_res = schnorr.verification_response(challenge.clone(), iss_secret, ver_secret);
// verifier verifies the response
assert!(schnorr.verification(ver_req, challenge, ver_res));
The scheme starts with the struct SignatureScheme<Hash>
. It can be instantiated by method from_str
. In following example, the variable schnorr
is its instantiation.
let (key, public_key) = scheme.generate_key::<Rand>();
let message = "hello world".as_bytes();
let signature = scheme.sign::<Rand, _>(&key, &public_key, message);
assert!(scheme.verify(&public_key, message, &signature));
For the ECC-based scheme, use struct SignatureSchemeECP256
which is instantiated by new
or default
(because the generator used is fixed).