From eee25f6265b2572aebe2f6a40ba1e3d497e836d5 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 29 Mar 2018 11:21:13 -0400 Subject: [PATCH] Fix fuzztarget ECDH to be symmetric --- src/ffi.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ffi.rs b/src/ffi.rs index 1493e25..60126c0 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -642,8 +642,17 @@ mod fuzz_dummy { assert!(!cx.is_null() && (*cx).0 as u32 & !(SECP256K1_START_NONE | SECP256K1_START_VERIFY | SECP256K1_START_SIGN) == 0); assert!((*cx).0 as u32 & SECP256K1_START_SIGN == SECP256K1_START_SIGN); if secp256k1_ec_seckey_verify(cx, scalar) != 1 { return 0; } - (*out).0[0..16].copy_from_slice(&(*point).0[0..16]); - ptr::copy(scalar, (*out).0[16..32].as_mut_ptr(), 16); + + let mut scalar_prefix = [0; 16]; + ptr::copy(scalar, scalar_prefix[..].as_mut_ptr(), 16); + + if (*point).0[0..16] > scalar_prefix[0..16] { + (*out).0[0..16].copy_from_slice(&(*point).0[0..16]); + ptr::copy(scalar, (*out).0[16..32].as_mut_ptr(), 16); + } else { + ptr::copy(scalar, (*out).0[0..16].as_mut_ptr(), 16); + (*out).0[16..32].copy_from_slice(&(*point).0[0..16]); + } (*out).0[16] = 0x00; // result should always be a valid secret key 1 }