Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
350 changes: 155 additions & 195 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pairing/src/bls12_381/ec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ pub mod g1 {
let negyrepr = negy.into_repr();

let p = G1Affine {
x: x,
x,
y: if yrepr < negyrepr { y } else { negy },
infinity: false,
};
Expand Down Expand Up @@ -1637,7 +1637,7 @@ pub mod g2 {
negy.negate();

let p = G2Affine {
x: x,
x,
y: if y < negy { y } else { negy },
infinity: false,
};
Expand Down
4 changes: 2 additions & 2 deletions pairing/src/bls12_381/fq12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ fn test_fq12_mul_by_014() {
a.mul_by_014(&c0, &c1, &c5);
b.mul_assign(&Fq12 {
c0: Fq6 {
c0: c0,
c1: c1,
c0,
c1,
c2: Fq2::zero(),
},
c1: Fq6 {
Expand Down
6 changes: 3 additions & 3 deletions pairing/src/bls12_381/fq6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ fn test_fq6_mul_by_1() {
a.mul_by_1(&c1);
b.mul_assign(&Fq6 {
c0: Fq2::zero(),
c1: c1,
c1,
c2: Fq2::zero(),
});

Expand All @@ -366,8 +366,8 @@ fn test_fq6_mul_by_01() {

a.mul_by_01(&c0, &c1);
b.mul_assign(&Fq6 {
c0: c0,
c1: c1,
c0,
c1,
c2: Fq2::zero(),
});

Expand Down
14 changes: 7 additions & 7 deletions pairing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// common mistakes or strange code patterns. If the `cargo-clippy` feature
// is provided, all compiler warnings are prohibited.
#![cfg_attr(feature = "cargo-clippy", deny(warnings))]
#![cfg_attr(feature = "cargo-clippy", allow(inline_always))]
#![cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))]
#![cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))]
#![cfg_attr(feature = "cargo-clippy", allow(many_single_char_names))]
#![cfg_attr(feature = "cargo-clippy", allow(new_without_default_derive))]
#![cfg_attr(feature = "cargo-clippy", allow(write_literal))]
#![cfg_attr(feature = "cargo-clippy", allow(clippy::inline_always))]
#![cfg_attr(feature = "cargo-clippy", allow(clippy::too_many_arguments))]
#![cfg_attr(feature = "cargo-clippy", allow(clippy::unreadable_literal))]
#![cfg_attr(feature = "cargo-clippy", allow(clippy::many_single_char_names))]
#![cfg_attr(feature = "cargo-clippy", allow(clippy::new_without_default))]
#![cfg_attr(feature = "cargo-clippy", allow(clippy::write_literal))]
// Force public structures to implement Debug
#![deny(missing_debug_implementations)]

Expand Down Expand Up @@ -100,7 +100,7 @@ pub trait Engine: ScalarEngine {
G2: Into<Self::G2Affine>,
{
Self::final_exponentiation(&Self::miller_loop(
[(&(p.into().prepare()), &(q.into().prepare()))].into_iter(),
[(&(p.into().prepare()), &(q.into().prepare()))].iter(),
)).unwrap()
}
}
Expand Down
2 changes: 1 addition & 1 deletion sapling-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ blake2b_simd = "0.5"
blake2s_simd = "0.5"
ff = { path = "../ff" }
rand_core = "0.5"
digest = "0.7"
digest = "0.8"
byteorder = "1"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion zcash_client_backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = [
edition = "2018"

[dependencies]
bech32 = "0.6"
bech32 = "0.7"
pairing = { path = "../pairing" }
sapling-crypto = { path = "../sapling-crypto" }
zcash_primitives = { path = "../zcash_primitives" }
Expand Down
15 changes: 5 additions & 10 deletions zcash_client_backend/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! Human-Readable Prefixes (HRPs) for Bech32 encodings are located in the [`constants`]
//! module.

use bech32::{convert_bits, Bech32, Error};
use bech32::{self, Error, FromBase32, ToBase32};
use pairing::bls12_381::Bls12;
use sapling_crypto::{
jubjub::edwards,
Expand All @@ -21,21 +21,16 @@ where
{
let mut data: Vec<u8> = vec![];
write(&mut data).expect("Should be able to write to a Vec");

let converted =
convert_bits(&data, 8, 5, true).expect("Should be able to convert Vec<u8> to Vec<u5>");
let encoded = Bech32::new_check_data(hrp.into(), converted).expect("hrp is not empty");

encoded.to_string()
bech32::encode(hrp, data.to_base32()).expect("hrp is invalid")
}

fn bech32_decode<T, F>(hrp: &str, s: &str, read: F) -> Result<Option<T>, Error>
where
F: Fn(Vec<u8>) -> Option<T>,
{
let decoded = s.parse::<Bech32>()?;
if decoded.hrp() == hrp {
convert_bits(decoded.data(), 5, 8, false).map(|data| read(data))
let (decoded_hrp, data) = bech32::decode(s)?;
if decoded_hrp == hrp {
Vec::<u8>::from_base32(&data).map(|data| read(data))
} else {
Ok(None)
}
Expand Down
6 changes: 3 additions & 3 deletions zcash_primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ authors = [
]

[dependencies]
aes = "0.2"
aes = "0.3"
blake2b_simd = "0.5"
byteorder = "1"
crypto_api_chachapoly = "0.1"
crypto_api_chachapoly = "0.2.1"
ff = { path = "../ff" }
fpe = "0.1"
fpe = "0.2"
hex = "0.3"
lazy_static = "1"
pairing = { path = "../pairing" }
Expand Down
21 changes: 5 additions & 16 deletions zcash_primitives/src/note_encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,23 +444,12 @@ pub fn try_sapling_compact_note_decryption(
let shared_secret = sapling_ka_agree(ivk, epk);
let key = kdf_sapling(shared_secret, &epk);

// Prefix plaintext with 64 zero-bytes to skip over Poly1305 keying output
const CHACHA20_BLOCK_SIZE: usize = 64;
let mut plaintext = [0; CHACHA20_BLOCK_SIZE + COMPACT_NOTE_SIZE];
plaintext[CHACHA20_BLOCK_SIZE..].copy_from_slice(&enc_ciphertext[0..COMPACT_NOTE_SIZE]);
assert_eq!(
ChaCha20Ietf::cipher()
.decrypt(
&mut plaintext,
CHACHA20_BLOCK_SIZE + COMPACT_NOTE_SIZE,
key.as_bytes(),
&[0u8; 12],
)
.ok()?,
CHACHA20_BLOCK_SIZE + COMPACT_NOTE_SIZE
);
// Start from block 1 to skip over Poly1305 keying output
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything else LGTM but I'm curious what prompted this change?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also there is no longer an assert, that's fine yes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #69 (comment) for the context.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And yes, there's no longer an assert because ChaCha20Ietf::xor mutates in-place and doesn't return anything.

let mut plaintext = [0; COMPACT_NOTE_SIZE];
plaintext.copy_from_slice(&enc_ciphertext);
ChaCha20Ietf::xor(key.as_bytes(), &[0u8; 12], 1, &mut plaintext);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming the 3rd argument is the signifier of which block to start from instead of prefixing with a 'block' of zero bytes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. See RFC 7539 section 2.8 for details.


parse_note_plaintext_without_memo(ivk, cmu, &plaintext[CHACHA20_BLOCK_SIZE..])
parse_note_plaintext_without_memo(ivk, cmu, &plaintext)
}

/// Recovery of the full note plaintext by the sender.
Expand Down