Skip to content

Commit 1ec9c3a

Browse files
committed
Provide fallback for crypto's fixed_time_eq on non-x86/arm targets
1 parent 4d75d4c commit 1ec9c3a

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ description = """
88
A Bitcoin Lightning implementation in Rust.
99
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.
1010
"""
11+
build = "build.rs"
1112

1213
[features]
1314
# 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"
2021
rand = "0.4"
2122
secp256k1 = "0.9"
2223

24+
[build-dependencies]
25+
gcc = "0.3"
26+
2327
[dev-dependencies.bitcoin]
2428
version = "0.13"
2529
features = ["bitcoinconsensus"]

build.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
extern crate gcc;
2+
3+
fn main() {
4+
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64", target_arch = "arm")))]
5+
{
6+
let mut cfg = gcc::Build::new();
7+
cfg.file("src/util/rust_crypto_nonstd_arch.c");
8+
cfg.compile("lib_rust_crypto_nonstd_arch.a");
9+
}
10+
}

fuzz/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name = "lightning-fuzz"
33
version = "0.0.1"
44
authors = ["Automatically generated"]
55
publish = false
6+
# Because the function is unused it gets dropped before we link lightning, so
7+
# we have to duplicate build.rs here. Note that this is only required for
8+
# fuzztarget mode.
9+
build = "../build.rs"
610

711
[package.metadata]
812
cargo-fuzz = true
@@ -19,6 +23,9 @@ rust-crypto = "0.2"
1923
honggfuzz = { version = "0.5", optional = true }
2024
afl = { version = "0.3", optional = true }
2125

26+
[build-dependencies]
27+
gcc = "0.3"
28+
2229
# Prevent this from interfering with workspaces
2330
[workspace]
2431
members = ["."]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../src/util/rust_crypto_nonstd_arch.c

src/util/rust_crypto_nonstd_arch.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <stdint.h>
2+
#include <stdlib.h>
3+
4+
uint32_t rust_crypto_util_fixed_time_eq_asm(uint8_t* lhsp, uint8_t* rhsp, size_t count) {
5+
if (count == 0) {
6+
return 1;
7+
}
8+
uint8_t result = 0;
9+
for (size_t i = 0; i < count; i++) {
10+
result |= (lhsp[i] ^ rhsp[i]);
11+
}
12+
return result;
13+
}

0 commit comments

Comments
 (0)