schnorrsig: change tweak_add_check to return a bool, take a fixed-length array

This commit is contained in:
Andrew Poelstra 2020-12-09 16:49:48 +00:00
parent 0ec8fab82c
commit ea027ce258
1 changed files with 4 additions and 12 deletions

View File

@ -322,12 +322,8 @@ impl PublicKey {
secp: &Secp256k1<V>, secp: &Secp256k1<V>,
tweaked_key: &Self, tweaked_key: &Self,
tweaked_parity: bool, tweaked_parity: bool,
tweak: &[u8], tweak: [u8; 32],
) -> Result<(), Error> { ) -> bool {
if tweak.len() != 32 {
return Err(Error::InvalidTweak);
}
let tweaked_ser = tweaked_key.serialize(); let tweaked_ser = tweaked_key.serialize();
unsafe { unsafe {
let err = ffi::secp256k1_xonly_pubkey_tweak_add_check( let err = ffi::secp256k1_xonly_pubkey_tweak_add_check(
@ -338,11 +334,7 @@ impl PublicKey {
tweak.as_c_ptr(), tweak.as_c_ptr(),
); );
if err == 1 { err == 1
Ok(())
} else {
Err(Error::TweakCheckFailed)
}
} }
} }
} }
@ -766,7 +758,7 @@ mod tests {
kp.tweak_add_assign(&s, &tweak).expect("Tweak error"); kp.tweak_add_assign(&s, &tweak).expect("Tweak error");
let parity = pk.tweak_add_assign(&s, &tweak).expect("Tweak error"); let parity = pk.tweak_add_assign(&s, &tweak).expect("Tweak error");
assert_eq!(PublicKey::from_keypair(&s, &kp), pk); assert_eq!(PublicKey::from_keypair(&s, &kp), pk);
orig_pk.tweak_add_check(&s, &pk, parity, &tweak).expect("tweak check"); assert!(orig_pk.tweak_add_check(&s, &pk, parity, tweak));
} }
} }