diff --git a/Cargo.toml b/Cargo.toml index 7baed61..70381e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/src/batch.rs b/src/batch.rs index cb5719a..93f2634 100644 --- a/src/batch.rs +++ b/src/batch.rs @@ -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, diff --git a/src/lib.rs b/src/lib.rs index fcbaee7..9d4f03c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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}, @@ -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 @@ -174,6 +181,7 @@ pub trait Domain { fn extract_esk(out_plaintext: &[u8; OUT_PLAINTEXT_SIZE]) -> Option; } +#[cfg(feature = "alloc")] pub trait BatchDomain: Domain { /// Computes `Self::kdf` on a batch of items. ///