Refine type for MAC (#577)
This commit is contained in:
parent
7f1bc8d922
commit
c216f5ca25
|
@ -34,9 +34,7 @@ pub struct JoinSplit<P: ZkSnarkProof> {
|
||||||
/// JoinSplit description.
|
/// JoinSplit description.
|
||||||
pub random_seed: [u8; 32],
|
pub random_seed: [u8; 32],
|
||||||
/// A message authentication tag.
|
/// A message authentication tag.
|
||||||
///
|
pub vmacs: [crate::types::MAC; 2],
|
||||||
/// XXX refine type to [T; 2] -- there are two macs
|
|
||||||
pub vmacs: [[u8; 32]; 2],
|
|
||||||
/// A ZK JoinSplit proof, either a
|
/// A ZK JoinSplit proof, either a
|
||||||
/// [`Groth16Proof`](crate::proofs::Groth16Proof) or a
|
/// [`Groth16Proof`](crate::proofs::Groth16Proof) or a
|
||||||
/// [`Bctv14Proof`](crate::proofs::Bctv14Proof).
|
/// [`Bctv14Proof`](crate::proofs::Bctv14Proof).
|
||||||
|
|
|
@ -242,8 +242,8 @@ impl<P: ZkSnarkProof> ZcashSerialize for JoinSplit<P> {
|
||||||
writer.write_all(&self.commitments[1][..])?;
|
writer.write_all(&self.commitments[1][..])?;
|
||||||
writer.write_all(&self.ephemeral_key.as_bytes()[..])?;
|
writer.write_all(&self.ephemeral_key.as_bytes()[..])?;
|
||||||
writer.write_all(&self.random_seed[..])?;
|
writer.write_all(&self.random_seed[..])?;
|
||||||
writer.write_all(&self.vmacs[0][..])?;
|
self.vmacs[0].zcash_serialize(&mut writer)?;
|
||||||
writer.write_all(&self.vmacs[1][..])?;
|
self.vmacs[1].zcash_serialize(&mut writer)?;
|
||||||
self.zkproof.zcash_serialize(&mut writer)?;
|
self.zkproof.zcash_serialize(&mut writer)?;
|
||||||
self.enc_ciphertexts[0].zcash_serialize(&mut writer)?;
|
self.enc_ciphertexts[0].zcash_serialize(&mut writer)?;
|
||||||
self.enc_ciphertexts[1].zcash_serialize(&mut writer)?;
|
self.enc_ciphertexts[1].zcash_serialize(&mut writer)?;
|
||||||
|
@ -261,7 +261,10 @@ impl<P: ZkSnarkProof> ZcashDeserialize for JoinSplit<P> {
|
||||||
commitments: [reader.read_32_bytes()?, reader.read_32_bytes()?],
|
commitments: [reader.read_32_bytes()?, reader.read_32_bytes()?],
|
||||||
ephemeral_key: x25519_dalek::PublicKey::from(reader.read_32_bytes()?),
|
ephemeral_key: x25519_dalek::PublicKey::from(reader.read_32_bytes()?),
|
||||||
random_seed: reader.read_32_bytes()?,
|
random_seed: reader.read_32_bytes()?,
|
||||||
vmacs: [reader.read_32_bytes()?, reader.read_32_bytes()?],
|
vmacs: [
|
||||||
|
crate::types::MAC::zcash_deserialize(&mut reader)?,
|
||||||
|
crate::types::MAC::zcash_deserialize(&mut reader)?,
|
||||||
|
],
|
||||||
zkproof: P::zcash_deserialize(&mut reader)?,
|
zkproof: P::zcash_deserialize(&mut reader)?,
|
||||||
enc_ciphertexts: [
|
enc_ciphertexts: [
|
||||||
notes::sprout::EncryptedCiphertext::zcash_deserialize(&mut reader)?,
|
notes::sprout::EncryptedCiphertext::zcash_deserialize(&mut reader)?,
|
||||||
|
|
|
@ -26,7 +26,7 @@ impl<P: ZkSnarkProof + Arbitrary + 'static> Arbitrary for JoinSplit<P> {
|
||||||
array::uniform2(array::uniform32(any::<u8>())),
|
array::uniform2(array::uniform32(any::<u8>())),
|
||||||
array::uniform32(any::<u8>()),
|
array::uniform32(any::<u8>()),
|
||||||
array::uniform32(any::<u8>()),
|
array::uniform32(any::<u8>()),
|
||||||
array::uniform2(array::uniform32(any::<u8>())),
|
array::uniform2(any::<crate::types::MAC>()),
|
||||||
any::<P>(),
|
any::<P>(),
|
||||||
array::uniform2(any::<sprout::EncryptedCiphertext>()),
|
array::uniform2(any::<sprout::EncryptedCiphertext>()),
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,20 +1,15 @@
|
||||||
//! Newtype wrappers for primitive data types with semantic meaning.
|
//! Newtype wrappers for primitive data types with semantic meaning.
|
||||||
|
#![allow(clippy::unit_arg)]
|
||||||
|
use crate::serialization::{
|
||||||
|
ReadZcashExt, SerializationError, WriteZcashExt, ZcashDeserialize, ZcashSerialize,
|
||||||
|
};
|
||||||
|
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||||
|
use chrono::{DateTime, TimeZone, Utc};
|
||||||
use std::{
|
use std::{
|
||||||
fmt,
|
fmt,
|
||||||
io::{self, Read},
|
io::{self, Read},
|
||||||
};
|
};
|
||||||
|
|
||||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
|
||||||
use chrono::{DateTime, TimeZone, Utc};
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
use proptest_derive::Arbitrary;
|
|
||||||
|
|
||||||
use crate::serialization::{
|
|
||||||
ReadZcashExt, SerializationError, WriteZcashExt, ZcashDeserialize, ZcashSerialize,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub mod amount;
|
pub mod amount;
|
||||||
|
|
||||||
/// A u32 which represents a block height value.
|
/// A u32 which represents a block height value.
|
||||||
|
@ -93,9 +88,30 @@ impl Arbitrary for LockTime {
|
||||||
type Strategy = BoxedStrategy<Self>;
|
type Strategy = BoxedStrategy<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A sequence of message authentication tags ...
|
||||||
|
///
|
||||||
|
/// binding h_sig to each a_sk of the JoinSplit description, computed as
|
||||||
|
/// described in § 4.10 ‘Non-malleability (Sprout)’ on p. 37
|
||||||
|
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
|
||||||
|
#[cfg_attr(test, derive(proptest_derive::Arbitrary))]
|
||||||
|
pub struct MAC([u8; 32]);
|
||||||
|
|
||||||
|
impl ZcashDeserialize for MAC {
|
||||||
|
fn zcash_deserialize<R: Read>(mut reader: R) -> Result<Self, SerializationError> {
|
||||||
|
let bytes = reader.read_32_bytes()?;
|
||||||
|
|
||||||
|
Ok(Self(bytes))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ZcashSerialize for MAC {
|
||||||
|
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
|
||||||
|
writer.write_all(&self.0[..])
|
||||||
|
}
|
||||||
|
}
|
||||||
/// An encoding of a Bitcoin script.
|
/// An encoding of a Bitcoin script.
|
||||||
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize)]
|
||||||
#[cfg_attr(test, derive(Arbitrary))]
|
#[cfg_attr(test, derive(proptest_derive::Arbitrary))]
|
||||||
pub struct Script(pub Vec<u8>);
|
pub struct Script(pub Vec<u8>);
|
||||||
|
|
||||||
impl fmt::Debug for Script {
|
impl fmt::Debug for Script {
|
||||||
|
|
Loading…
Reference in New Issue