impl orchard SpendingKey::new()

This commit is contained in:
Deirdre Connolly 2021-03-08 15:43:47 -05:00 committed by Deirdre Connolly
parent 20abeda04b
commit f50d8697d4
2 changed files with 18 additions and 6 deletions

View File

@ -3,8 +3,6 @@
// #[cfg(test)]
// mod test_vectors;
pub mod sinsemilla_hashes;
use std::{convert::TryFrom, fmt, io};
use bitvec::prelude::*;

View File

@ -151,15 +151,29 @@ impl FromStr for SpendingKey {
}
impl SpendingKey {
/// Generate a new _SpendingKey_.
/// Generate a new `SpendingKey`.
///
/// When generating, we check that the corresponding `SpendAuthorizingKey`
/// is not zero, else fail.
///
///
pub fn new<T>(csprng: &mut T) -> Self
where
T: RngCore + CryptoRng,
{
let mut bytes = [0u8; 32];
csprng.fill_bytes(&mut bytes);
loop {
let mut bytes = [0u8; 32];
csprng.fill_bytes(&mut bytes);
Self::from(bytes)
let sk = Self::from(bytes);
// "if ask = 0, discard this key and repeat with a new sk"
if SpendAuthorizingKey::from(sk).0 == pallas::Scalar::zero() {
continue;
}
break sk;
}
}
}