From 7ea39a13b2620253123aa93c63b7f9a58a8df762 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 18 Dec 2018 00:01:31 -0500 Subject: [PATCH] Use bitcoin_hashes' fixed_time_eq, removing the rust-crypto dep --- Cargo.toml | 5 ----- build.rs | 10 ---------- fuzz/Cargo.toml | 1 - src/lib.rs | 1 - src/ln/channelmanager.rs | 7 +++---- src/util/chacha20poly1305rfc.rs | 3 +-- src/util/rust_crypto_nonstd_arch.c | 13 ------------- 7 files changed, 4 insertions(+), 36 deletions(-) delete mode 100644 build.rs delete mode 100644 src/util/rust_crypto_nonstd_arch.c diff --git a/Cargo.toml b/Cargo.toml index a14984a0..e012639d 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 963075e9..00000000 --- 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 c1069d32..c4ed4c70 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 5564a575..ec6718e8 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 e7214427..2278faae 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 ae1b069a..1d3af1ea 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 f5076580..00000000 --- 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; -} -- 2.30.2