optional dependency on secp256k1 for ethcrypto (#8109)
* optional dependency on secp256k1 for ethcrypto * README
This commit is contained in:
parent
373036bb7a
commit
249f81cbc5
@ -6,7 +6,11 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
[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
ethcrypto/README.md
Normal file
5
ethcrypto/README.md
Normal file
@ -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.
|
@ -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<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(),
|
||||
@ -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)
|
||||
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user