Skip to content

Commit

Permalink
Add #![no_std] support for zcash_note_encryption (#450)
Browse files Browse the repository at this point in the history
Co-authored-by: str4d <thestr4d@gmail.com>
  • Loading branch information
krnak and str4d committed Nov 24, 2021
1 parent c48bb4d commit 0ec7f97
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
21 changes: 13 additions & 8 deletions components/zcash_note_encryption/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,23 @@ license = "MIT OR Apache-2.0"
edition = "2018"

[dependencies]
blake2b_simd = "0.5"
byteorder = "1"
chacha20 = "0.8"
chacha20poly1305 = "0.9"
ff = "0.11"
group = "0.11"
rand_core = "0.6"
subtle = "2.2.3"
blake2b_simd = { version = "0.5", default-features = false }
byteorder = { version = "1", default-features = false }
chacha20 = { version = "0.8", default-features = false }
chacha20poly1305 = { version = "0.9", default-features = false }
ff = { version = "0.11", default-features = false }
group = { version = "0.11", default-features = false }
rand_core = { version = "0.6", default-features = false }
subtle = { version = "2.2.3", default-features = false }

[dev-dependencies]
zcash_primitives = { version = "0.5", path = "../../zcash_primitives" }
jubjub = "0.8"

[features]
default = ["std"]
alloc = []
std = ["alloc", "blake2b_simd/std"]

[lib]
bench = false
3 changes: 2 additions & 1 deletion components/zcash_note_encryption/src/batch.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! APIs for batch trial decryption.

use std::iter;
use alloc::vec::Vec; // module is alloc only
use core::iter;

use crate::{
try_compact_note_decryption_inner, try_note_decryption_inner, BatchDomain, EphemeralKeyBytes,
Expand Down
10 changes: 9 additions & 1 deletion components/zcash_note_encryption/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
//! functionality that is shared between the Sapling and Orchard
//! protocols.

#![no_std]
// Catch documentation errors caused by code changes.
#![deny(broken_intra_doc_links)]
#![deny(unsafe_code)]
// TODO: #![deny(missing_docs)]

use std::convert::TryInto;
#[cfg(feature = "alloc")]
extern crate alloc;
#[cfg(feature = "alloc")]
use alloc::vec::Vec;

use core::convert::TryInto;

use chacha20::{
cipher::{NewCipher, StreamCipher, StreamCipherSeek},
Expand All @@ -22,6 +28,7 @@ use chacha20poly1305::{
use rand_core::RngCore;
use subtle::{Choice, ConstantTimeEq};

#[cfg(feature = "alloc")]
pub mod batch;

pub const COMPACT_NOTE_SIZE: usize = 1 + // version
Expand Down Expand Up @@ -174,6 +181,7 @@ pub trait Domain {
fn extract_esk(out_plaintext: &[u8; OUT_PLAINTEXT_SIZE]) -> Option<Self::EphemeralSecretKey>;
}

#[cfg(feature = "alloc")]
pub trait BatchDomain: Domain {
/// Computes `Self::kdf` on a batch of items.
///
Expand Down

0 comments on commit 0ec7f97

Please sign in to comment.