mirror of https://github.com/zcash/halo2.git
Use orchard::redpallas types in orchard::keys implementation
This commit is contained in:
parent
eaa7158751
commit
27501702d5
|
@ -11,6 +11,7 @@ use subtle::CtOption;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
address::Address,
|
address::Address,
|
||||||
|
primitives::redpallas::{self, SpendAuth},
|
||||||
spec::{
|
spec::{
|
||||||
commit_ivk, diversify_hash, extract_p, ka_orchard, prf_expand, prf_expand_vec, to_base,
|
commit_ivk, diversify_hash, extract_p, ka_orchard, prf_expand, prf_expand_vec, to_base,
|
||||||
to_scalar,
|
to_scalar,
|
||||||
|
@ -43,7 +44,7 @@ impl SpendingKey {
|
||||||
///
|
///
|
||||||
/// [§4.2.3]: https://zips.z.cash/protocol/nu5.pdf#orchardkeycomponents
|
/// [§4.2.3]: https://zips.z.cash/protocol/nu5.pdf#orchardkeycomponents
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct SpendAuthorizingKey(reddsa::SigningKey<reddsa::orchard::SpendAuth>);
|
pub(crate) struct SpendAuthorizingKey(redpallas::SigningKey<SpendAuth>);
|
||||||
|
|
||||||
impl SpendAuthorizingKey {
|
impl SpendAuthorizingKey {
|
||||||
/// Derives ask from sk. Internal use only, does not enforce all constraints.
|
/// Derives ask from sk. Internal use only, does not enforce all constraints.
|
||||||
|
@ -70,7 +71,7 @@ impl From<&SpendingKey> for SpendAuthorizingKey {
|
||||||
|
|
||||||
/// TODO: This is its protocol spec name for Sapling, but I'd prefer a different name.
|
/// TODO: This is its protocol spec name for Sapling, but I'd prefer a different name.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct AuthorizingKey(reddsa::VerificationKey<reddsa::orchard::SpendAuth>);
|
pub(crate) struct AuthorizingKey(redpallas::VerificationKey<SpendAuth>);
|
||||||
|
|
||||||
impl From<&SpendAuthorizingKey> for AuthorizingKey {
|
impl From<&SpendAuthorizingKey> for AuthorizingKey {
|
||||||
fn from(ask: &SpendAuthorizingKey) -> Self {
|
fn from(ask: &SpendAuthorizingKey) -> Self {
|
||||||
|
@ -121,7 +122,7 @@ impl FullViewingKey {
|
||||||
/// [§4.2.3]: https://zips.z.cash/protocol/nu5.pdf#orchardkeycomponents
|
/// [§4.2.3]: https://zips.z.cash/protocol/nu5.pdf#orchardkeycomponents
|
||||||
fn derive_dk_ovk(&self) -> (DiversifierKey, OutgoingViewingKey) {
|
fn derive_dk_ovk(&self) -> (DiversifierKey, OutgoingViewingKey) {
|
||||||
let k = self.rivk.to_bytes();
|
let k = self.rivk.to_bytes();
|
||||||
let b = [self.ak.0.into(), self.nk.0.to_bytes()];
|
let b = [(&self.ak.0).into(), self.nk.0.to_bytes()];
|
||||||
let r = prf_expand_vec(&k, &[&[0x82], &b[0][..], &b[1][..]]);
|
let r = prf_expand_vec(&k, &[&[0x82], &b[0][..], &b[1][..]]);
|
||||||
(
|
(
|
||||||
DiversifierKey(r.as_bytes()[..32].try_into().unwrap()),
|
DiversifierKey(r.as_bytes()[..32].try_into().unwrap()),
|
||||||
|
@ -205,7 +206,7 @@ pub struct IncomingViewingKey(pallas::Scalar);
|
||||||
|
|
||||||
impl From<&FullViewingKey> for IncomingViewingKey {
|
impl From<&FullViewingKey> for IncomingViewingKey {
|
||||||
fn from(fvk: &FullViewingKey) -> Self {
|
fn from(fvk: &FullViewingKey) -> Self {
|
||||||
let ak = pallas::Point::from_bytes(&fvk.ak.0.into()).unwrap();
|
let ak = pallas::Point::from_bytes(&(&fvk.ak.0).into()).unwrap();
|
||||||
IncomingViewingKey(commit_ivk(&extract_p(&ak), &fvk.nk.0, &fvk.rivk))
|
IncomingViewingKey(commit_ivk(&extract_p(&ak), &fvk.nk.0, &fvk.rivk))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
//! A minimal RedPallas implementation for use in Zcash.
|
//! A minimal RedPallas implementation for use in Zcash.
|
||||||
|
|
||||||
|
use std::convert::{TryFrom, TryInto};
|
||||||
|
|
||||||
/// A RedPallas signature type.
|
/// A RedPallas signature type.
|
||||||
pub trait SigType: reddsa::SigType + private::Sealed {}
|
pub trait SigType: reddsa::SigType + private::Sealed {}
|
||||||
|
|
||||||
|
@ -15,10 +17,56 @@ impl SigType for Binding {}
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SigningKey<T: SigType>(reddsa::SigningKey<T>);
|
pub struct SigningKey<T: SigType>(reddsa::SigningKey<T>);
|
||||||
|
|
||||||
|
impl<T: SigType> From<SigningKey<T>> for [u8; 32] {
|
||||||
|
fn from(sk: SigningKey<T>) -> [u8; 32] {
|
||||||
|
sk.0.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: SigType> From<&SigningKey<T>> for [u8; 32] {
|
||||||
|
fn from(sk: &SigningKey<T>) -> [u8; 32] {
|
||||||
|
sk.0.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: SigType> TryFrom<[u8; 32]> for SigningKey<T> {
|
||||||
|
type Error = reddsa::Error;
|
||||||
|
|
||||||
|
fn try_from(bytes: [u8; 32]) -> Result<Self, Self::Error> {
|
||||||
|
bytes.try_into().map(SigningKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A RedPallas verification key.
|
/// A RedPallas verification key.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct VerificationKey<T: SigType>(reddsa::VerificationKey<T>);
|
pub struct VerificationKey<T: SigType>(reddsa::VerificationKey<T>);
|
||||||
|
|
||||||
|
impl<T: SigType> From<VerificationKey<T>> for [u8; 32] {
|
||||||
|
fn from(vk: VerificationKey<T>) -> [u8; 32] {
|
||||||
|
vk.0.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: SigType> From<&VerificationKey<T>> for [u8; 32] {
|
||||||
|
fn from(vk: &VerificationKey<T>) -> [u8; 32] {
|
||||||
|
vk.0.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: SigType> TryFrom<[u8; 32]> for VerificationKey<T> {
|
||||||
|
type Error = reddsa::Error;
|
||||||
|
|
||||||
|
fn try_from(bytes: [u8; 32]) -> Result<Self, Self::Error> {
|
||||||
|
bytes.try_into().map(VerificationKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, T: SigType> From<&'a SigningKey<T>> for VerificationKey<T> {
|
||||||
|
fn from(sk: &'a SigningKey<T>) -> VerificationKey<T> {
|
||||||
|
VerificationKey((&sk.0).into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A RedPallas signature.
|
/// A RedPallas signature.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Signature<T: SigType>(reddsa::Signature<T>);
|
pub struct Signature<T: SigType>(reddsa::Signature<T>);
|
||||||
|
|
Loading…
Reference in New Issue