Merge pull request #641 from nuttycom/upgrade_chacha20

Upgrade chacha20poly1305 dependency to version 0.10
This commit is contained in:
Kris Nuttycombe 2022-09-16 14:39:32 -06:00 committed by GitHub
commit bc626156c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 53 deletions

View File

@ -19,15 +19,15 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"] rustdoc-args = ["--cfg", "docsrs"]
[dependencies] [dependencies]
chacha20 = { version = "0.8", default-features = false } cipher = { version = "0.4", default-features = false }
chacha20poly1305 = { version = "0.9", default-features = false } chacha20 = { version = "0.9", default-features = false }
chacha20poly1305 = { version = "0.10", default-features = false }
group = "0.12" group = "0.12"
rand_core = { version = "0.6", default-features = false } rand_core = { version = "0.6", default-features = false }
subtle = { version = "2.2.3", default-features = false } subtle = { version = "2.3", default-features = false }
[dev-dependencies] [dev-dependencies]
ff = { version = "0.12", default-features = false } ff = { version = "0.12", default-features = false }
zcash_primitives = { version = "0.7", path = "../../zcash_primitives" }
jubjub = "0.9" jubjub = "0.9"
[features] [features]

View File

@ -25,13 +25,11 @@ extern crate alloc;
use alloc::vec::Vec; use alloc::vec::Vec;
use chacha20::{ use chacha20::{
cipher::{NewCipher, StreamCipher, StreamCipherSeek}, cipher::{StreamCipher, StreamCipherSeek},
ChaCha20, ChaCha20,
}; };
use chacha20poly1305::{ use chacha20poly1305::{aead::AeadInPlace, ChaCha20Poly1305, KeyInit};
aead::{AeadInPlace, NewAead}, use cipher::KeyIvInit;
ChaCha20Poly1305,
};
use rand_core::RngCore; use rand_core::RngCore;
use subtle::{Choice, ConstantTimeEq}; use subtle::{Choice, ConstantTimeEq};
@ -347,50 +345,6 @@ pub trait ShieldedOutput<D: Domain, const CIPHERTEXT_SIZE: usize> {
/// ///
/// Implements section 4.19 of the /// Implements section 4.19 of the
/// [Zcash Protocol Specification](https://zips.z.cash/protocol/nu5.pdf#saplingandorchardinband) /// [Zcash Protocol Specification](https://zips.z.cash/protocol/nu5.pdf#saplingandorchardinband)
/// NB: the example code is only covering the post-Canopy case.
///
/// # Examples
///
/// ```
/// extern crate ff;
/// extern crate rand_core;
/// extern crate zcash_primitives;
///
/// use ff::Field;
/// use rand_core::OsRng;
/// use zcash_primitives::{
/// keys::{OutgoingViewingKey, prf_expand},
/// consensus::{TEST_NETWORK, TestNetwork, NetworkUpgrade, Parameters},
/// memo::MemoBytes,
/// sapling::{
/// note_encryption::sapling_note_encryption,
/// util::generate_random_rseed,
/// Diversifier, PaymentAddress, Rseed, ValueCommitment
/// },
/// };
///
/// let mut rng = OsRng;
///
/// let diversifier = Diversifier([0; 11]);
/// let pk_d = diversifier.g_d().unwrap();
/// let to = PaymentAddress::from_parts(diversifier, pk_d).unwrap();
/// let ovk = Some(OutgoingViewingKey([0; 32]));
///
/// let value = 1000;
/// let rcv = jubjub::Fr::random(&mut rng);
/// let cv = ValueCommitment {
/// value,
/// randomness: rcv.clone(),
/// };
/// let height = TEST_NETWORK.activation_height(NetworkUpgrade::Canopy).unwrap();
/// let rseed = generate_random_rseed(&TEST_NETWORK, height, &mut rng);
/// let note = to.create_note(value, rseed).unwrap();
/// let cmu = note.cmu();
///
/// let mut enc = sapling_note_encryption::<_, TestNetwork>(ovk, note, to, MemoBytes::empty(), &mut rng);
/// let encCiphertext = enc.encrypt_note_plaintext();
/// let outCiphertext = enc.encrypt_outgoing_plaintext(&cv.commitment().into(), &cmu, &mut rng);
/// ```
pub struct NoteEncryption<D: Domain> { pub struct NoteEncryption<D: Domain> {
epk: D::EphemeralPublicKey, epk: D::EphemeralPublicKey,
esk: D::EphemeralSecretKey, esk: D::EphemeralSecretKey,

View File

@ -1,4 +1,7 @@
//! Implementation of in-band secret distribution for Zcash transactions. //! Implementation of in-band secret distribution for Zcash transactions.
//!
//! NB: the example code is only covering the post-Canopy case.
use blake2b_simd::{Hash as Blake2bHash, Params as Blake2bParams}; use blake2b_simd::{Hash as Blake2bHash, Params as Blake2bParams};
use byteorder::{LittleEndian, WriteBytesExt}; use byteorder::{LittleEndian, WriteBytesExt};
use ff::PrimeField; use ff::PrimeField;
@ -381,6 +384,47 @@ impl<P: consensus::Parameters> BatchDomain for SaplingDomain<P> {
/// ///
/// Setting `ovk` to `None` represents the `ovk = ⊥` case, where the note cannot be /// Setting `ovk` to `None` represents the `ovk = ⊥` case, where the note cannot be
/// recovered by the sender. /// recovered by the sender.
///
/// NB: the example code here only covers the post-Canopy case.
///
/// # Examples
///
/// ```
/// use ff::Field;
/// use rand_core::OsRng;
/// use zcash_primitives::{
/// keys::{OutgoingViewingKey, prf_expand},
/// consensus::{TEST_NETWORK, TestNetwork, NetworkUpgrade, Parameters},
/// memo::MemoBytes,
/// sapling::{
/// note_encryption::sapling_note_encryption,
/// util::generate_random_rseed,
/// Diversifier, PaymentAddress, Rseed, ValueCommitment
/// },
/// };
///
/// let mut rng = OsRng;
///
/// let diversifier = Diversifier([0; 11]);
/// let pk_d = diversifier.g_d().unwrap();
/// let to = PaymentAddress::from_parts(diversifier, pk_d).unwrap();
/// let ovk = Some(OutgoingViewingKey([0; 32]));
///
/// let value = 1000;
/// let rcv = jubjub::Fr::random(&mut rng);
/// let cv = ValueCommitment {
/// value,
/// randomness: rcv.clone(),
/// };
/// let height = TEST_NETWORK.activation_height(NetworkUpgrade::Canopy).unwrap();
/// let rseed = generate_random_rseed(&TEST_NETWORK, height, &mut rng);
/// let note = to.create_note(value, rseed).unwrap();
/// let cmu = note.cmu();
///
/// let mut enc = sapling_note_encryption::<_, TestNetwork>(ovk, note, to, MemoBytes::empty(), &mut rng);
/// let encCiphertext = enc.encrypt_note_plaintext();
/// let outCiphertext = enc.encrypt_outgoing_plaintext(&cv.commitment().into(), &cmu, &mut rng);
/// ```
pub fn sapling_note_encryption<R: RngCore, P: consensus::Parameters>( pub fn sapling_note_encryption<R: RngCore, P: consensus::Parameters>(
ovk: Option<OutgoingViewingKey>, ovk: Option<OutgoingViewingKey>,
note: Note, note: Note,