From: Matt Corallo Date: Mon, 16 Apr 2018 20:55:03 +0000 (-0400) Subject: Provide fallback for crypto's fixed_time_eq on non-x86/arm targets X-Git-Tag: v0.0.12~412^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=rust-lightning;a=commitdiff_plain;h=1ec9c3aa4bf99022df969de20acc84ff49314910 Provide fallback for crypto's fixed_time_eq on non-x86/arm targets --- diff --git a/Cargo.toml b/Cargo.toml index bb00a923..f097d7fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 index 00000000..7dd34039 --- /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"); + } +} diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 1d2e2442..9b718bad 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -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 index 00000000..321d648a --- /dev/null +++ b/fuzz/src/util/rust_crypto_nonstd_arch.c @@ -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 index 00000000..f5076580 --- /dev/null +++ b/src/util/rust_crypto_nonstd_arch.c @@ -0,0 +1,13 @@ +#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; +}