Fix fuzztarget ECDH to be symmetric

This commit is contained in:
Matt Corallo 2018-03-29 11:21:13 -04:00
parent 758380991a
commit eee25f6265
1 changed files with 11 additions and 2 deletions

View File

@ -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
}