Skip to main content

ToySchnorr

Struct ToySchnorr 

Source
pub struct ToySchnorr {
    pub p: u64,
    pub q: u64,
    pub g: u64,
}
Expand description

Toy Schnorr signature scheme over a finite cyclic group Z_p^*.

§WARNING

Educational only. Parameters are not secure.

Fields§

§p: u64

Prime modulus p

§q: u64

Group order q (should be a prime divisor of p-1)

§g: u64

Generator g of the subgroup of order q

Implementations§

Source§

impl ToySchnorr

Source

pub fn new(p: u64, q: u64, g: u64) -> Self

Create a Schnorr context.

Source

pub fn public_key(&self, x: u64) -> u64

Compute the public key: g^x mod p.

Source

pub fn sign(&self, x: u64, k: u64, h: u64) -> (u64, u64)

Sign a message hash h with private key x and nonce k.

Returns (r, s) where r = g^k mod p mod q, s = (k - x*r) mod q.

§WARNING

Never reuse the nonce k. In practice, k must be uniformly random.

Source

pub fn verify(&self, pk: u64, h: u64, r: u64, s: u64) -> bool

Verify a Schnorr signature (r, s) on hash h with public key pk.

Checks: g^s * pk^h ≡ R and R mod q == r.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.