Skip to content

Commit

Permalink
fix: Fix invalid recovery id with p256 signature
Browse files Browse the repository at this point in the history
  • Loading branch information
conr2d committed Jun 12, 2024
1 parent b717b05 commit 72b5a87
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions primitives/crypto/src/p256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,10 @@ impl Pair {
/// Sign a pre-hashed message
#[cfg(feature = "full_crypto")]
pub fn sign_prehashed(&self, message: &[u8; 32]) -> Signature {
let (mut sig, rid) = self.secret.sign_prehash_recoverable(message).unwrap();
let (mut sig, mut rid) = self.secret.sign_prehash_recoverable(message).unwrap();
if sig.s().is_high().into() {
sig = sig.normalize_s().unwrap();
rid = RecoveryId::from_byte(rid.to_byte() ^ 1).unwrap();
}
Signature::from((sig, rid))
}
Expand Down Expand Up @@ -713,9 +714,10 @@ mod tests {
let msg = [0u8; 32];
let sig1 = pair.sign_prehashed(&msg);
let sig2: Signature = {
let (mut sig, rid) = pair.secret.sign_prehash_recoverable(&msg).unwrap();
let (mut sig, mut rid) = pair.secret.sign_prehash_recoverable(&msg).unwrap();
if sig.s().is_high().into() {
sig = sig.normalize_s().unwrap();
rid = RecoveryId::from_byte(rid.to_byte() ^ 1).unwrap();
}
Signature::from((sig, rid))
};
Expand Down

0 comments on commit 72b5a87

Please sign in to comment.