]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Provide fallback for crypto's fixed_time_eq on non-x86/arm targets
authorMatt Corallo <git@bluematt.me>
Mon, 16 Apr 2018 20:55:03 +0000 (16:55 -0400)
committerMatt Corallo <git@bluematt.me>
Tue, 17 Apr 2018 00:35:21 +0000 (20:35 -0400)
Cargo.toml
build.rs [new file with mode: 0644]
fuzz/Cargo.toml
fuzz/src/util/rust_crypto_nonstd_arch.c [new symlink]
src/util/rust_crypto_nonstd_arch.c [new file with mode: 0644]

index bb00a9239269f502582430c8b13ecc50e8502963..f097d7fbc65d46ab62643254d720b42a97a08bf2 100644 (file)
@@ -8,6 +8,7 @@ description = """
 A Bitcoin Lightning implementation in Rust.
 Still super-early code-dump quality and is missing large chunks. See README in git repo 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 finish building 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.
@@ -20,6 +21,9 @@ rust-crypto = "0.2"
 rand = "0.4"
 secp256k1 = "0.9"
 
+[build-dependencies]
+gcc = "0.3"
+
 [dev-dependencies.bitcoin]
 version = "0.13"
 features = ["bitcoinconsensus"]
diff --git a/build.rs b/build.rs
new file mode 100644 (file)
index 0000000..7dd3403
--- /dev/null
+++ b/build.rs
@@ -0,0 +1,10 @@
+extern crate gcc;
+
+fn main() {
+       #[cfg(not(any(target_arch = "x86", target_arch = "x86_64", target_arch = "arm")))]
+       {
+               let mut cfg = gcc::Build::new();
+               cfg.file("src/util/rust_crypto_nonstd_arch.c");
+               cfg.compile("lib_rust_crypto_nonstd_arch.a");
+       }
+}
index 1d2e24420f5d28f1e5a87f480355b8eba40a4b38..9b718badf3d6a2e422dd14c564c0b573c825ea01 100644 (file)
@@ -3,6 +3,10 @@ name = "lightning-fuzz"
 version = "0.0.1"
 authors = ["Automatically generated"]
 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
@@ -19,6 +23,9 @@ rust-crypto = "0.2"
 honggfuzz = { version = "0.5", optional = true }
 afl = { version = "0.3", optional = true }
 
+[build-dependencies]
+gcc = "0.3"
+
 # Prevent this from interfering with workspaces
 [workspace]
 members = ["."]
diff --git a/fuzz/src/util/rust_crypto_nonstd_arch.c b/fuzz/src/util/rust_crypto_nonstd_arch.c
new file mode 120000 (symlink)
index 0000000..321d648
--- /dev/null
@@ -0,0 +1 @@
+../../../src/util/rust_crypto_nonstd_arch.c
\ No newline at end of file
diff --git a/src/util/rust_crypto_nonstd_arch.c b/src/util/rust_crypto_nonstd_arch.c
new file mode 100644 (file)
index 0000000..f507658
--- /dev/null
@@ -0,0 +1,13 @@
+#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;
+}