Skip to content

Commit efb9206

Browse files
committed
Provide fallback for crypto's fixed_time_eq on non-x86/arm targets
1 parent 60aa327 commit efb9206

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-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
git = "https://github.com/TheBlueMatt/rust-bitcoin"
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+
}

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)