Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

k256: update Signature::normalize_s usages #1017

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ members = [
[profile.dev]
opt-level = 2

[patch.crates-io.crypto-bigint]
git = "https://github.com/RustCrypto/crypto-bigint.git"
[patch.crates-io]
crypto-bigint = { git = "https://github.com/RustCrypto/crypto-bigint.git" }
ecdsa = { git = "https://github.com/RustCrypto/signatures.git" }
9 changes: 4 additions & 5 deletions k256/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,8 @@ impl SignPrimitive<Secp256k1> for Scalar {
{
let (sig, recid) = hazmat::sign_prehashed::<Secp256k1, K>(self, k, z)?;
let is_y_odd = recid.is_y_odd() ^ bool::from(sig.s().is_high());
let sig_low = sig.normalize_s().unwrap_or(sig);
let recid = RecoveryId::new(is_y_odd, recid.is_x_reduced());
Ok((sig_low, Some(recid)))
Ok((sig.normalize_s(), Some(recid)))
}
}

Expand Down Expand Up @@ -239,7 +238,7 @@ mod tests {
0xfb, 0x42, 0xef, 0x20, 0xe3, 0xc6, 0xad, 0xb2,
].as_slice()).unwrap();

let sig_normalized = sig_hi.normalize_s().unwrap();
let sig_normalized = sig_hi.normalize_s();
assert_eq!(sig_lo, sig_normalized);
}

Expand All @@ -253,7 +252,7 @@ mod tests {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
].as_slice()).unwrap();

assert_eq!(sig.normalize_s(), None);
assert_eq!(sig.normalize_s(), sig);
}
}

Expand Down Expand Up @@ -386,7 +385,7 @@ mod tests {
ecdsa_core::VerifyingKey::from_encoded_point(&q_encoded).unwrap();

let sig = match Signature::<Secp256k1>::from_der(sig) {
Ok(s) => s.normalize_s().unwrap_or(s),
Ok(s) => s.normalize_s(),
Err(_) if !pass => return None,
Err(_) => return Some("failed to parse signature ASN.1"),
};
Expand Down
Loading