Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

optional dependency on secp256k1 for ethcrypto #8109

Merged
merged 3 commits into from
Mar 19, 2018
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
8 changes: 6 additions & 2 deletions ethcrypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ authors = ["Parity Technologies <[email protected]>"]
[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"]
5 changes: 5 additions & 0 deletions ethcrypto/README.md
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 12 additions & 2 deletions ethcrypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,6 +64,7 @@ impl fmt::Display for ScryptError {

#[derive(PartialEq, Debug)]
pub enum Error {
#[cfg(feature = "secp256k1")]
Secp(SecpError),
Scrypt(ScryptError),
InvalidMessage,
Expand All @@ -73,6 +79,7 @@ impl From<ScryptError> 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(),
Expand All @@ -88,6 +95,7 @@ impl Into<String> for Error {
}
}

#[cfg(feature = "secp256k1")]
impl From<SecpError> for Error {
fn from(e: SecpError) -> Self {
Error::Secp(e)
Expand Down Expand Up @@ -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};
Expand All @@ -198,6 +207,7 @@ pub mod ecdh {
}

/// ECIES function
#[cfg(feature = "secp256k1")]
pub mod ecies {
use rcrypto::digest::Digest;
use rcrypto::sha2::Sha256;
Expand Down
1 change: 0 additions & 1 deletion ethkey/src/extended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down