Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bypass rand_hack to build for no_std #55

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,14 @@ pub trait SigningTranscript {
/// Produce a secret witness scalar `k`, aka nonce, from the protocol
/// transcript and any "nonce seeds" kept with the secret keys.
fn witness_scalar(&self, label: &'static [u8], nonce_seeds: &[&[u8]]) -> Scalar {
self.witness_scalar_rng(label, nonce_seeds, super::rand_hack())
}

/// Produce a secret witness scalar `k`, aka nonce, from the protocol
/// transcript and any "nonce seeds" kept with the secret keys, while passing an rng.
fn witness_scalar_rng<R: RngCore+CryptoRng>(&self, label: &'static [u8], nonce_seeds: &[&[u8]], rng: R) -> Scalar {
let mut scalar_bytes = [0u8; 64];
self.witness_bytes(label, &mut scalar_bytes, nonce_seeds);
self.witness_bytes_rng(label, &mut scalar_bytes, nonce_seeds, rng);
Scalar::from_bytes_mod_order_wide(&scalar_bytes)
}

Expand Down
13 changes: 12 additions & 1 deletion src/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,17 @@ impl SecretKey {
/// fails and the function gets called with the wrong public key.
#[allow(non_snake_case)]
pub fn sign<T: SigningTranscript>(&self, mut t: T, public_key: &PublicKey) -> Signature
{
self.sign_rng(t, public_key, super::rand_hack())
}

#[allow(non_snake_case)]
pub fn sign_rng<T: SigningTranscript, R: RngCore+CryptoRng>(&self, mut t: T, public_key: &PublicKey, rng: R) -> Signature
{
t.proto_name(b"Schnorr-sig");
t.commit_point(b"sign:pk",public_key.as_compressed());

let mut r = t.witness_scalar(b"signing",&[&self.nonce]); // context, message, A/public_key
let mut r = t.witness_scalar_rng(b"signing",&[&self.nonce], rng); // context, message, A/public_key
let R = (&r * &constants::RISTRETTO_BASEPOINT_TABLE).compress();

t.commit_point(b"sign:R",&R);
Expand Down Expand Up @@ -351,6 +357,11 @@ impl Keypair {
self.secret.sign_simple(ctx, msg, &self.public)
}

pub fn sign_rng<T: SigningTranscript, R: CryptoRng + RngCore>(&self, t: T, mut rng: R) -> Signature
{
self.secret.sign_rng(t,&self.public, &mut rng)
}

/// Verify a signature by keypair's public key on a transcript.
///
/// Requires a `SigningTranscript`, normally created from a
Expand Down