mirror of https://github.com/zcash/orchard.git
Migrate to latest `zcash_note_encryption` API
This commit is contained in:
parent
4592c2f275
commit
4b0b32275f
|
@ -47,6 +47,7 @@ plotters = { version = "0.3.0", optional = true }
|
||||||
criterion = "0.3"
|
criterion = "0.3"
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
proptest = "1.0.0"
|
proptest = "1.0.0"
|
||||||
|
zcash_note_encryption = { version = "0.0", features = ["pre-zip-212"] }
|
||||||
|
|
||||||
[target.'cfg(unix)'.dev-dependencies]
|
[target.'cfg(unix)'.dev-dependencies]
|
||||||
pprof = { version = "0.5", features = ["criterion", "flamegraph"] }
|
pprof = { version = "0.5", features = ["criterion", "flamegraph"] }
|
||||||
|
@ -81,5 +82,5 @@ debug = true
|
||||||
debug = true
|
debug = true
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
zcash_note_encryption = { git = "https://github.com/zcash/librustzcash.git", rev = "35e75420657599fdc701cb45704878eb3fa2e59a" }
|
zcash_note_encryption = { git = "https://github.com/zcash/librustzcash.git", rev = "76f364593a6d5b190dd23d26f8202adcd031b2d3" }
|
||||||
incrementalmerkletree = { git = "https://github.com/zcash/incrementalmerkletree.git", rev = "b7bd6246122a6e9ace8edb51553fbf5228906cbb" }
|
incrementalmerkletree = { git = "https://github.com/zcash/incrementalmerkletree.git", rev = "b7bd6246122a6e9ace8edb51553fbf5228906cbb" }
|
||||||
|
|
|
@ -5,8 +5,9 @@ use std::{convert::TryInto, fmt};
|
||||||
use blake2b_simd::{Hash, Params};
|
use blake2b_simd::{Hash, Params};
|
||||||
use halo2::arithmetic::FieldExt;
|
use halo2::arithmetic::FieldExt;
|
||||||
use zcash_note_encryption::{
|
use zcash_note_encryption::{
|
||||||
BatchDomain, Domain, EphemeralKeyBytes, NotePlaintextBytes, NoteValidity, OutPlaintextBytes,
|
BatchDomain, Domain, EphemeralKeyBytes, NotePlaintextBytes, OutPlaintextBytes,
|
||||||
OutgoingCipherKey, ShieldedOutput, COMPACT_NOTE_SIZE, NOTE_PLAINTEXT_SIZE, OUT_PLAINTEXT_SIZE,
|
OutgoingCipherKey, ShieldedOutput, COMPACT_NOTE_SIZE, ENC_CIPHERTEXT_SIZE, NOTE_PLAINTEXT_SIZE,
|
||||||
|
OUT_PLAINTEXT_SIZE,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -182,13 +183,6 @@ impl Domain for OrchardDomain {
|
||||||
EphemeralPublicKey::from_bytes(&ephemeral_key.0).into()
|
EphemeralPublicKey::from_bytes(&ephemeral_key.0).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_epk_bytes<F: Fn(&Self::EphemeralSecretKey) -> NoteValidity>(
|
|
||||||
note: &Self::Note,
|
|
||||||
check: F,
|
|
||||||
) -> NoteValidity {
|
|
||||||
check(¬e.esk())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn cmstar(note: &Self::Note) -> Self::ExtractedCommitment {
|
fn cmstar(note: &Self::Note) -> Self::ExtractedCommitment {
|
||||||
note.commitment().into()
|
note.commitment().into()
|
||||||
}
|
}
|
||||||
|
@ -208,9 +202,9 @@ impl Domain for OrchardDomain {
|
||||||
pk_d: &Self::DiversifiedTransmissionKey,
|
pk_d: &Self::DiversifiedTransmissionKey,
|
||||||
esk: &Self::EphemeralSecretKey,
|
esk: &Self::EphemeralSecretKey,
|
||||||
ephemeral_key: &EphemeralKeyBytes,
|
ephemeral_key: &EphemeralKeyBytes,
|
||||||
plaintext: &[u8],
|
plaintext: &NotePlaintextBytes,
|
||||||
) -> Option<(Self::Note, Self::Recipient)> {
|
) -> Option<(Self::Note, Self::Recipient)> {
|
||||||
orchard_parse_note_plaintext_without_memo(self, plaintext, |diversifier| {
|
orchard_parse_note_plaintext_without_memo(self, &plaintext.0, |diversifier| {
|
||||||
if esk
|
if esk
|
||||||
.derive_public(diversify_hash(diversifier.as_array()))
|
.derive_public(diversify_hash(diversifier.as_array()))
|
||||||
.to_bytes()
|
.to_bytes()
|
||||||
|
@ -224,20 +218,18 @@ impl Domain for OrchardDomain {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_memo(&self, plaintext: &[u8]) -> Self::Memo {
|
fn extract_memo(&self, plaintext: &NotePlaintextBytes) -> Self::Memo {
|
||||||
plaintext[COMPACT_NOTE_SIZE..NOTE_PLAINTEXT_SIZE]
|
plaintext.0[COMPACT_NOTE_SIZE..NOTE_PLAINTEXT_SIZE]
|
||||||
.try_into()
|
.try_into()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_pk_d(
|
fn extract_pk_d(out_plaintext: &OutPlaintextBytes) -> Option<Self::DiversifiedTransmissionKey> {
|
||||||
out_plaintext: &[u8; OUT_PLAINTEXT_SIZE],
|
DiversifiedTransmissionKey::from_bytes(out_plaintext.0[0..32].try_into().unwrap()).into()
|
||||||
) -> Option<Self::DiversifiedTransmissionKey> {
|
|
||||||
DiversifiedTransmissionKey::from_bytes(out_plaintext[0..32].try_into().unwrap()).into()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_esk(out_plaintext: &[u8; OUT_PLAINTEXT_SIZE]) -> Option<Self::EphemeralSecretKey> {
|
fn extract_esk(out_plaintext: &OutPlaintextBytes) -> Option<Self::EphemeralSecretKey> {
|
||||||
EphemeralSecretKey::from_bytes(out_plaintext[32..OUT_PLAINTEXT_SIZE].try_into().unwrap())
|
EphemeralSecretKey::from_bytes(out_plaintext.0[32..OUT_PLAINTEXT_SIZE].try_into().unwrap())
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -260,7 +252,7 @@ impl BatchDomain for OrchardDomain {
|
||||||
/// Implementation of in-band secret distribution for Orchard bundles.
|
/// Implementation of in-band secret distribution for Orchard bundles.
|
||||||
pub type OrchardNoteEncryption = zcash_note_encryption::NoteEncryption<OrchardDomain>;
|
pub type OrchardNoteEncryption = zcash_note_encryption::NoteEncryption<OrchardDomain>;
|
||||||
|
|
||||||
impl<T> ShieldedOutput<OrchardDomain> for Action<T> {
|
impl<T> ShieldedOutput<OrchardDomain, ENC_CIPHERTEXT_SIZE> for Action<T> {
|
||||||
fn ephemeral_key(&self) -> EphemeralKeyBytes {
|
fn ephemeral_key(&self) -> EphemeralKeyBytes {
|
||||||
EphemeralKeyBytes(self.encrypted_note().epk_bytes)
|
EphemeralKeyBytes(self.encrypted_note().epk_bytes)
|
||||||
}
|
}
|
||||||
|
@ -269,7 +261,7 @@ impl<T> ShieldedOutput<OrchardDomain> for Action<T> {
|
||||||
self.cmx().to_bytes()
|
self.cmx().to_bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enc_ciphertext(&self) -> &[u8] {
|
fn enc_ciphertext(&self) -> &[u8; ENC_CIPHERTEXT_SIZE] {
|
||||||
&self.encrypted_note().enc_ciphertext
|
&self.encrypted_note().enc_ciphertext
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -299,7 +291,7 @@ impl<T> From<&Action<T>> for CompactAction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ShieldedOutput<OrchardDomain> for CompactAction {
|
impl ShieldedOutput<OrchardDomain, COMPACT_NOTE_SIZE> for CompactAction {
|
||||||
fn ephemeral_key(&self) -> EphemeralKeyBytes {
|
fn ephemeral_key(&self) -> EphemeralKeyBytes {
|
||||||
EphemeralKeyBytes(self.ephemeral_key.0)
|
EphemeralKeyBytes(self.ephemeral_key.0)
|
||||||
}
|
}
|
||||||
|
@ -308,7 +300,7 @@ impl ShieldedOutput<OrchardDomain> for CompactAction {
|
||||||
self.cmx.to_bytes()
|
self.cmx.to_bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enc_ciphertext(&self) -> &[u8] {
|
fn enc_ciphertext(&self) -> &[u8; COMPACT_NOTE_SIZE] {
|
||||||
&self.enc_ciphertext
|
&self.enc_ciphertext
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue