schnorr_rs/
lib.rs

1#![doc = include_str!("../README.md")]
2
3use digest::Digest;
4
5pub mod group;
6pub use group::{Group, SchnorrGroup, SchnorrP256Group};
7
8pub mod public_key;
9pub use public_key::PublicKey;
10
11pub mod signature;
12pub use signature::Signature;
13
14pub mod signature_scheme;
15pub use signature_scheme::SignatureScheme;
16
17pub mod signing_key;
18pub use signing_key::SigningKey;
19
20pub mod signer;
21pub use signer::Signer;
22
23pub mod verifier;
24pub use verifier::Verifier;
25
26pub mod identification;
27pub use identification::Identification;
28
29/// Instantiate a Schnorr Signature Protocol from string representation of p, q, and a:
30/// - p is a large prime
31/// - q is a large prime divisor of p-1
32/// - a is a generator of the group of order q, i.e., a^q mod p = 1 by Fermat's Little Theorem.
33///
34/// Return None if a is not a valid generator (i.e. a^q mod p != 1)
35pub fn signature_scheme<H: Digest>(
36    p: &str,
37    q: &str,
38    a: &str,
39) -> Option<SignatureScheme<SchnorrGroup, H>> {
40    let group = SchnorrGroup::from_str(p, q, a)?;
41    Some(SignatureScheme {
42        group,
43        _phantom: std::marker::PhantomData,
44    })
45}
46
47/// Instantiate a Schnorr Identification Protocol from string representation of p, q, and a:
48/// - p is a large prime
49/// - q is a large prime divisor of p-1
50/// - a is a generator of the group of order q, i.e., a^q mod p = 1 by Fermat's Little Theorem.
51///
52/// Return None if a is not a valid generator (i.e. a^q mod p != 1)
53pub fn identification_protocol(p: &str, q: &str, a: &str) -> Option<Identification<SchnorrGroup>> {
54    SchnorrGroup::from_str(p, q, a).map(|group| Identification { group })
55}
56
57/// Instantiate a Schnorr Signature Protocol based on elliptic curve p256. The generator point is provided by crate [p256].
58pub fn signature_scheme_p256<H: Digest>() -> SignatureScheme<SchnorrP256Group, H> {
59    let group = SchnorrP256Group;
60    SignatureScheme {
61        group,
62        _phantom: std::marker::PhantomData,
63    }
64}
65
66/// Instantiate a Schnorr Identification Protocol based on elliptic curve p256. The generator point is provided by crate [p256].
67pub fn identification_protocol_p256() -> Identification<SchnorrP256Group> {
68    Identification {
69        group: SchnorrP256Group,
70    }
71}