Skip to content
Merged
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
16 changes: 10 additions & 6 deletions ecdsa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ where

// Not constant time, but we're operating on public values
if s_option.is_some().into() {
let mut s = s_option.unwrap();
let (s_low, was_high) = s_option.unwrap().normalize_low();

if s.normalize_low() {
s_bytes.copy_from_slice(&s.into());
if was_high {
s_bytes.copy_from_slice(&s_low.into());
Ok(true)
} else {
Ok(false)
Expand Down Expand Up @@ -248,8 +248,12 @@ where
/// in [BIP 0062: Dealing with Malleability][1].
///
/// [1]: https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki
pub trait NormalizeLow {
pub trait NormalizeLow: Sized {
/// Normalize scalar to the lower half of the field (i.e. negate it if it's
/// larger than half the curve's order)
fn normalize_low(&mut self) -> bool;
/// larger than half the curve's order).
/// Returns a tuple with the new scalar and a boolean indicating whether the given scalar
/// was in the higher half.
///
/// May be implemented to work in variable time.
fn normalize_low(&self) -> (Self, bool);
}