Skip to content

Commit

Permalink
Normalize the s component of the generated signature.
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarri committed Nov 16, 2023
1 parent edd94af commit f64b4f5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion synedrion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ categories = ["cryptography", "no-std"]
[dependencies]
signature = { version = "2", default-features = false, features = ["alloc"] }
# TODO: we only need `serde` feature in tests
k256 = { version = "0.13", default-features = false, features = ["ecdsa", "arithmetic", "serde"] }
k256 = { version = "0.13.2", default-features = false, features = ["ecdsa", "arithmetic", "serde"] }
rand_core = { version = "0.6.4", default-features = false, features = ["getrandom"] }
sha2 = { version = "0.10", default-features = false }
sha3 = { version = "0.10", default-features = false }
Expand Down
2 changes: 0 additions & 2 deletions synedrion/src/cggmp21/protocols/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ impl<P: SchemeParams> FinalizableToResult for Round1<P> {
let s: Scalar = shares.iter().sum();
let s = s + self.s_part;

// CHECK: should `s` be normalized here?

let sig = RecoverableSignature::from_scalars(
&self.r,
&s,
Expand Down
8 changes: 6 additions & 2 deletions synedrion/src/curve/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ impl RecoverableSignature {
vkey: &Point,
message: &Scalar,
) -> Option<Self> {
// TODO: call `normalize_s()` on the result?
// TODO: pass a message too and derive the recovery byte?
let signature = BackendSignature::from_scalars(r.to_backend(), s.to_backend()).ok()?;

// Normalize the `s` component.
// `BackendSignature`'s constructor does not require `s` to be normalized,
// but consequent usage of it may fail otherwise.
let signature = signature.normalize_s().unwrap_or(signature);

let message_bytes = message.to_be_bytes();
let recovery_id = RecoveryId::trial_recovery_from_prehash(
&VerifyingKey::from_affine(vkey.to_backend().to_affine()).ok()?,
Expand Down

0 comments on commit f64b4f5

Please sign in to comment.