Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Implement signs having low-s.
Browse files Browse the repository at this point in the history
Closes #159
  • Loading branch information
gavofyork committed Jan 18, 2016
1 parent 17969dc commit f946088
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion util/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ pub mod ec {
let mut signature: crypto::Signature = unsafe { ::std::mem::uninitialized() };
signature.clone_from_slice(&data);
signature[64] = rec_id.to_i32() as u8;

let (_, s, v) = signature.to_rsv();
let secp256k1n = U256::from_str("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141").unwrap();
if !is_low_s(&s) {
signature = super::Signature::from_rsv(&H256::from_slice(&signature[0..32]), &H256::from(secp256k1n - s), v ^ 1);
}
Ok(signature)
}
/// Verify signature.
Expand All @@ -174,7 +180,7 @@ pub mod ec {

/// Check if this is a "low" signature.
pub fn is_low(sig: &Signature) -> bool {
H256::from_slice(&sig[32..64]) <= h256_from_hex("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0")
H256::from_slice(&sig[32..64]) <= h256_from_hex("7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0")
}

/// Check if this is a "low" signature.
Expand Down

0 comments on commit f946088

Please sign in to comment.