Skip to content
This repository was archived by the owner on Feb 25, 2021. It is now read-only.

Commit 02d8a51

Browse files
authored
Merge pull request BlockstreamResearch#23 from TheBlueMatt/master
Fix fuzztarget ECDH to be symmetric
2 parents b45c380 + 730da80 commit 02d8a51

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/ffi.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ mod fuzz_dummy {
327327
assert!(!cx.is_null() && (*cx).0 as u32 & !(SECP256K1_START_NONE | SECP256K1_START_VERIFY | SECP256K1_START_SIGN) == 0);
328328
match in_len {
329329
33 => {
330-
if *input != 2 && *input != 3 {
330+
if (*input.offset(1) > 0x7f && *input != 2) || (*input.offset(1) <= 0x7f && *input != 3) {
331331
0
332332
} else {
333333
ptr::copy(input.offset(1), (*pk).0[0..32].as_mut_ptr(), 32);
@@ -642,8 +642,17 @@ mod fuzz_dummy {
642642
assert!(!cx.is_null() && (*cx).0 as u32 & !(SECP256K1_START_NONE | SECP256K1_START_VERIFY | SECP256K1_START_SIGN) == 0);
643643
assert!((*cx).0 as u32 & SECP256K1_START_SIGN == SECP256K1_START_SIGN);
644644
if secp256k1_ec_seckey_verify(cx, scalar) != 1 { return 0; }
645-
(*out).0[0..16].copy_from_slice(&(*point).0[0..16]);
646-
ptr::copy(scalar, (*out).0[16..32].as_mut_ptr(), 16);
645+
646+
let mut scalar_prefix = [0; 16];
647+
ptr::copy(scalar, scalar_prefix[..].as_mut_ptr(), 16);
648+
649+
if (*point).0[0..16] > scalar_prefix[0..16] {
650+
(*out).0[0..16].copy_from_slice(&(*point).0[0..16]);
651+
ptr::copy(scalar, (*out).0[16..32].as_mut_ptr(), 16);
652+
} else {
653+
ptr::copy(scalar, (*out).0[0..16].as_mut_ptr(), 16);
654+
(*out).0[16..32].copy_from_slice(&(*point).0[0..16]);
655+
}
647656
(*out).0[16] = 0x00; // result should always be a valid secret key
648657
1
649658
}

0 commit comments

Comments
 (0)