From bf7785dbd7b840e0ad403756d3e62ccad19dfa2f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 16 Aug 2022 03:39:42 +0000 Subject: [PATCH 1/2] Update crypto_box requirement from 0.7.1 to 0.8.1 Updates the requirements on [crypto_box](https://github.com/RustCrypto/nacl-compat) to permit the latest version. - [Release notes](https://github.com/RustCrypto/nacl-compat/releases) - [Commits](https://github.com/RustCrypto/nacl-compat/compare/crypto_box-v0.7.1...crypto_box-v0.8.1) --- updated-dependencies: - dependency-name: crypto_box dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- primitives/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index 6cb09308e..66e3bd784 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -34,7 +34,7 @@ zeroize = { version = "1.3", default-features = false } itertools = { version = "0.10.1", default-features = false, features = [ "use_alloc" ] } serde = { version = "1.0", default-features = false, features = ["derive"] } generic-array = { version = "^0.14", default-features = false } -crypto_box = { version = "0.7.1", default-features = false, features = [ "u64_backend", "alloc" ] } +crypto_box = { version = "0.8.1", default-features = false, features = [ "u64_backend", "alloc" ] } displaydoc = { version = "0.2.3", default-features = false } derivative = { version = "2", features = ["use_core"] } rand_chacha = { version = "0.3.1", default-features = false } From 98cb292543461993f973e61195d7d40dedd56748 Mon Sep 17 00:00:00 2001 From: Alex Xiong Date: Thu, 18 Aug 2022 19:17:02 +0800 Subject: [PATCH 2/2] update with crypto_box new API --- primitives/Cargo.toml | 2 +- primitives/src/aead.rs | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index 66e3bd784..0b6068f34 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -34,7 +34,7 @@ zeroize = { version = "1.3", default-features = false } itertools = { version = "0.10.1", default-features = false, features = [ "use_alloc" ] } serde = { version = "1.0", default-features = false, features = ["derive"] } generic-array = { version = "^0.14", default-features = false } -crypto_box = { version = "0.8.1", default-features = false, features = [ "u64_backend", "alloc" ] } +crypto_box = "0.8.1" displaydoc = { version = "0.2.3", default-features = false } derivative = { version = "2", features = ["use_core"] } rand_chacha = { version = "0.3.1", default-features = false } diff --git a/primitives/src/aead.rs b/primitives/src/aead.rs index 6e6d17b7b..2e9dfe7e2 100644 --- a/primitives/src/aead.rs +++ b/primitives/src/aead.rs @@ -15,7 +15,7 @@ use ark_std::{ vec::Vec, }; use crypto_box::{ - aead::{Aead, Nonce, Payload}, + aead::{Aead, AeadCore, Nonce, Payload}, ChaChaBox, }; use generic_array::{typenum::U24, GenericArray}; @@ -82,19 +82,16 @@ impl EncKey { /// during encryption will cause decryption to fail, which is useful if you /// would like to "bind" the ciphertext to some identifier, like a /// digital signature key. - pub fn encrypt( + pub fn encrypt( &self, - rng: &mut R, + mut rng: impl RngCore + CryptoRng, message: &[u8], aad: &[u8], - ) -> Result - where - R: RngCore + CryptoRng, - { - let nonce = crypto_box::generate_nonce(rng); + ) -> Result { + let nonce = ChaChaBox::generate_nonce(&mut rng); // generate an ephemeral key pair as the virtual sender to derive the crypto box - let ephemeral_sk = crypto_box::SecretKey::generate(rng); + let ephemeral_sk = crypto_box::SecretKey::generate(&mut rng); let ephemeral_pk = EncKey(crypto_box::PublicKey::from(&ephemeral_sk)); let my_box = ChaChaBox::new(&self.0, &ephemeral_sk);