diff --git a/ethcrypto/Cargo.toml b/ethcrypto/Cargo.toml index 13b098fb3..dfa351023 100644 --- a/ethcrypto/Cargo.toml +++ b/ethcrypto/Cargo.toml @@ -6,7 +6,11 @@ authors = ["Parity Technologies "] [dependencies] rust-crypto = "0.2.36" tiny-keccak = "1.3" -eth-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1" } -ethkey = { path = "../ethkey" } +eth-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1", optional = true } +ethkey = { path = "../ethkey", optional = true } ethereum-types = "0.2" subtle = "0.5" + +[features] +default = ["secp256k1"] +secp256k1 = ["eth-secp256k1", "ethkey"] diff --git a/ethcrypto/README.md b/ethcrypto/README.md new file mode 100644 index 000000000..130d27f3c --- /dev/null +++ b/ethcrypto/README.md @@ -0,0 +1,5 @@ +# Ethcrypto + +General cryptographic utilities for Ethereum. + +By default, this library is compiled with the `secp256k1` feature, which provides ECDH and ECIES capability on that curve. It can be compiled without to avoid a dependency on the `libsecp256k1` library. diff --git a/ethcrypto/src/lib.rs b/ethcrypto/src/lib.rs index 76deb48f7..caa4cf77c 100644 --- a/ethcrypto/src/lib.rs +++ b/ethcrypto/src/lib.rs @@ -18,17 +18,22 @@ extern crate crypto as rcrypto; extern crate ethereum_types; -extern crate ethkey; -extern crate secp256k1; extern crate subtle; extern crate tiny_keccak; +#[cfg(feature = "secp256k1")] +extern crate secp256k1; +#[cfg(feature = "secp256k1")] +extern crate ethkey; + use std::fmt; use tiny_keccak::Keccak; use rcrypto::pbkdf2::pbkdf2; use rcrypto::scrypt::{scrypt, ScryptParams}; use rcrypto::sha2::Sha256; use rcrypto::hmac::Hmac; + +#[cfg(feature = "secp256k1")] use secp256k1::Error as SecpError; pub const KEY_LENGTH: usize = 32; @@ -59,6 +64,7 @@ impl fmt::Display for ScryptError { #[derive(PartialEq, Debug)] pub enum Error { + #[cfg(feature = "secp256k1")] Secp(SecpError), Scrypt(ScryptError), InvalidMessage, @@ -73,6 +79,7 @@ impl From for Error { impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { let s = match *self { + #[cfg(feature = "secp256k1")] Error::Secp(ref err) => err.to_string(), Error::Scrypt(ref err) => err.to_string(), Error::InvalidMessage => "Invalid message".into(), @@ -88,6 +95,7 @@ impl Into for Error { } } +#[cfg(feature = "secp256k1")] impl From for Error { fn from(e: SecpError) -> Self { Error::Secp(e) @@ -174,6 +182,7 @@ pub mod aes { } /// ECDH functions +#[cfg(feature = "secp256k1")] pub mod ecdh { use secp256k1::{ecdh, key, Error as SecpError}; use ethkey::{Secret, Public, SECP256K1}; @@ -198,6 +207,7 @@ pub mod ecdh { } /// ECIES function +#[cfg(feature = "secp256k1")] pub mod ecies { use rcrypto::digest::Digest; use rcrypto::sha2::Sha256; diff --git a/ethkey/src/extended.rs b/ethkey/src/extended.rs index 5a8ede0a4..23aff0bee 100644 --- a/ethkey/src/extended.rs +++ b/ethkey/src/extended.rs @@ -207,7 +207,6 @@ impl ExtendedKeyPair { // Work is based on BIP0032 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki mod derivation { - use rcrypto::hmac::Hmac; use rcrypto::mac::Mac; use rcrypto::sha2::Sha512;