From: Matt Corallo Date: Tue, 18 Dec 2018 05:01:31 +0000 (-0500) Subject: Use bitcoin_hashes' fixed_time_eq, removing the rust-crypto dep X-Git-Tag: v0.0.12~253^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=7ea39a13b2620253123aa93c63b7f9a58a8df762;p=rust-lightning Use bitcoin_hashes' fixed_time_eq, removing the rust-crypto dep --- diff --git a/Cargo.toml b/Cargo.toml index a14984a00..e012639d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,6 @@ A Bitcoin Lightning library in Rust. Does most of the hard work, without implying a specific runtime, requiring clients implement basic network logic, chain interactions and disk storage. Still missing tons of error-handling. See GitHub issues for suggested projects if you want to contribute. Don't have to bother telling you not to use this for anything serious, because you'd have to build a client around it to even try. """ -build = "build.rs" [features] # Supports tracking channels with a non-bitcoin chain hashes. Currently enables all kinds of fun DoS attacks. @@ -25,13 +24,9 @@ max_level_debug = [] [dependencies] bitcoin = "0.15" bitcoin_hashes = { git = "https://github.com/TheBlueMatt/bitcoin_hashes", branch = "rust-lightning-dep" } -rust-crypto = "0.2" rand = "0.4" secp256k1 = "0.11" -[build-dependencies] -cc = "1.0" - [dev-dependencies.bitcoin] version = "0.15" features = ["bitcoinconsensus"] diff --git a/build.rs b/build.rs deleted file mode 100644 index 963075e92..000000000 --- a/build.rs +++ /dev/null @@ -1,10 +0,0 @@ -extern crate cc; - -fn main() { - #[cfg(not(any(target_arch = "x86", target_arch = "x86_64", target_arch = "arm")))] - { - let mut cfg = cc::Build::new(); - cfg.file("src/util/rust_crypto_nonstd_arch.c"); - cfg.compile("lib_rust_crypto_nonstd_arch.a"); - } -} diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index c1069d32c..c4ed4c703 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -6,7 +6,6 @@ publish = false # Because the function is unused it gets dropped before we link lightning, so # we have to duplicate build.rs here. Note that this is only required for # fuzztarget mode. -build = "../build.rs" [package.metadata] cargo-fuzz = true diff --git a/src/lib.rs b/src/lib.rs index 5564a575f..ec6718e81 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,6 @@ extern crate bitcoin; extern crate bitcoin_hashes; -extern crate crypto; extern crate rand; extern crate secp256k1; #[cfg(test)] extern crate hex; diff --git a/src/ln/channelmanager.rs b/src/ln/channelmanager.rs index e7214427c..2278faaeb 100644 --- a/src/ln/channelmanager.rs +++ b/src/ln/channelmanager.rs @@ -17,6 +17,7 @@ use bitcoin::util::hash::{BitcoinHash, Sha256dHash}; use bitcoin_hashes::{Hash, HashEngine}; use bitcoin_hashes::hmac::{Hmac, HmacEngine}; use bitcoin_hashes::sha256::Hash as Sha256; +use bitcoin_hashes::cmp::fixed_time_eq; use secp256k1::key::{SecretKey,PublicKey}; use secp256k1::{Secp256k1,Message}; @@ -39,8 +40,6 @@ use util::logger::Logger; use util::errors::APIError; use util::errors; -use crypto; - use std::{cmp, ptr, mem}; use std::collections::{HashMap, hash_map, HashSet}; use std::io::Cursor; @@ -991,7 +990,7 @@ impl ChannelManager { let mut hmac = HmacEngine::::new(&mu); hmac.input(&msg.onion_routing_packet.hop_data); hmac.input(&msg.payment_hash.0[..]); - if !crypto::util::fixed_time_eq(&Hmac::from_engine(hmac).into_inner(), &msg.onion_routing_packet.hmac) { + if !fixed_time_eq(&Hmac::from_engine(hmac).into_inner(), &msg.onion_routing_packet.hmac) { return_malformed_err!("HMAC Check failed", 0x8000 | 0x4000 | 5); } @@ -2141,7 +2140,7 @@ impl ChannelManager { let mut hmac = HmacEngine::::new(&um); hmac.input(&err_packet.encode()[32..]); - if crypto::util::fixed_time_eq(&Hmac::from_engine(hmac).into_inner(), &err_packet.hmac) { + if fixed_time_eq(&Hmac::from_engine(hmac).into_inner(), &err_packet.hmac) { if let Some(error_code_slice) = err_packet.failuremsg.get(0..2) { const PERM: u16 = 0x4000; const NODE: u16 = 0x2000; diff --git a/src/util/chacha20poly1305rfc.rs b/src/util/chacha20poly1305rfc.rs index ae1b069ac..1d3af1ea3 100644 --- a/src/util/chacha20poly1305rfc.rs +++ b/src/util/chacha20poly1305rfc.rs @@ -14,8 +14,7 @@ mod real_chachapoly { use util::chacha20::ChaCha20; use util::poly1305::Poly1305; - - use crypto::util::fixed_time_eq; + use bitcoin_hashes::cmp::fixed_time_eq; use util::byte_utils; diff --git a/src/util/rust_crypto_nonstd_arch.c b/src/util/rust_crypto_nonstd_arch.c deleted file mode 100644 index f50765800..000000000 --- a/src/util/rust_crypto_nonstd_arch.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -uint32_t rust_crypto_util_fixed_time_eq_asm(uint8_t* lhsp, uint8_t* rhsp, size_t count) { - if (count == 0) { - return 1; - } - uint8_t result = 0; - for (size_t i = 0; i < count; i++) { - result |= (lhsp[i] ^ rhsp[i]); - } - return result; -}