Use bitcoin_hashes' fixed_time_eq, removing the rust-crypto dep
authorMatt Corallo <git@bluematt.me>
Tue, 18 Dec 2018 05:01:31 +0000 (00:01 -0500)
committerMatt Corallo <git@bluematt.me>
Thu, 20 Dec 2018 01:02:36 +0000 (20:02 -0500)
Cargo.toml
build.rs [deleted file]
fuzz/Cargo.toml
src/lib.rs
src/ln/channelmanager.rs
src/util/chacha20poly1305rfc.rs
src/util/rust_crypto_nonstd_arch.c [deleted file]

index a14984a00b90f64ff4d5b2bfe58fdd6f085627ef..e012639d306817776646036f53d158103a858cd0 100644 (file)
@@ -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 (file)
index 963075e..0000000
--- 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");
-       }
-}
index c1069d32c184b9cee3e26e01a31bff191f7fdb5a..c4ed4c70346d5059a7121e2840f45720ae8f8751 100644 (file)
@@ -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
index 5564a575f8c8aae8ba8c37f600c8b587dfd4412a..ec6718e814876037cfed1d359071ab670f8cc70b 100644 (file)
@@ -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;
index e7214427cd3448a8b28a895342fa4b8c59ec8317..2278faaebd338e5f12677d303dd373459d90c41e 100644 (file)
@@ -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::<Sha256>::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::<Sha256>::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;
index ae1b069ac13b658236b6e778f123182bab58b125..1d3af1ea32072b4622756dcb8ef292921293904b 100644 (file)
@@ -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 (file)
index f507658..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-#include <stdint.h>
-#include <stdlib.h>
-
-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;
-}