Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
jmwample committed Jul 28, 2024
1 parent 125343b commit a3c2ba0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
10 changes: 5 additions & 5 deletions curve25519-dalek/src/backend/serial/fiat_u32/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,13 @@ impl FieldElement2625 {

// start from least significant go to most significant
for i in 0..10 {
_ul = self.0[i];
_vl = other.0[i];
_ul = self.0[i];
_vl = other.0[i];

gt_i = _ul > _vl;
eq_i = _ul == _vl;
gt_i = _ul > _vl;
eq_i = _ul == _vl;

c_gt = gt_i || (eq_i & c_gt);
c_gt = gt_i || (eq_i & c_gt);
}

Choice::from(c_gt as u8)
Expand Down
11 changes: 5 additions & 6 deletions curve25519-dalek/src/backend/serial/fiat_u64/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ impl FieldElement51 {
output
}


/// Returns 1 if self is greater than the other and 0 otherwise
// strategy: check if b-a overflows. if it does not overflow, then a was larger
pub(crate) fn gt_direct(&self, other: &Self) -> Choice {
Expand All @@ -274,13 +273,13 @@ impl FieldElement51 {

// start from least significant go to most significant
for i in 0..5 {
_ul = self.0[i];
_vl = other.0[i];
_ul = self.0[i];
_vl = other.0[i];

gt_i = _ul > _vl;
eq_i = _ul == _vl;
gt_i = _ul > _vl;
eq_i = _ul == _vl;

c_gt = gt_i || (eq_i & c_gt);
c_gt = gt_i || (eq_i & c_gt);
}

Choice::from(c_gt as u8)
Expand Down
10 changes: 5 additions & 5 deletions curve25519-dalek/src/backend/serial/u32/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,13 +615,13 @@ impl FieldElement2625 {

// start from least significant go to most significant
for i in 0..10 {
_ul = self.0[i];
_vl = other.0[i];
_ul = self.0[i];
_vl = other.0[i];

gt_i = _ul > _vl;
eq_i = _ul == _vl;
gt_i = _ul > _vl;
eq_i = _ul == _vl;

c_gt = gt_i || (eq_i & c_gt);
c_gt = gt_i || (eq_i & c_gt);
}

Choice::from(c_gt as u8)
Expand Down
10 changes: 5 additions & 5 deletions curve25519-dalek/src/backend/serial/u64/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,13 +586,13 @@ impl FieldElement51 {

// start from least significant go to most significant
for i in 0..5 {
_ul = self.0[i];
_vl = other.0[i];
_ul = self.0[i];
_vl = other.0[i];

gt_i = _ul > _vl;
eq_i = _ul == _vl;
gt_i = _ul > _vl;
eq_i = _ul == _vl;

c_gt = gt_i || (eq_i & c_gt);
c_gt = gt_i || (eq_i & c_gt);
}

Choice::from(c_gt as u8)
Expand Down
11 changes: 6 additions & 5 deletions curve25519-dalek/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,9 @@ impl ConstantTimeGreater for FieldElement {
/// If self > other return Choice(1), otherwise return Choice(0)
///
fn ct_gt(&self, other: &FieldElement) -> Choice {

// One possible failure for is if self.or other falls in 0..18
// One possible failure for is if self or other falls in 0..18
// as s+p in 2^255-19..2^255-1. We can check this by
// converting to bytes and then back to FieldElement,
// converting to bytes and then back to FieldElement,
// since our encoding routine is canonical the returned value
// will always be compared properly.
let a = FieldElement::from_bytes(&self.as_bytes());
Expand Down Expand Up @@ -520,11 +519,13 @@ mod test {
// 2^255 - 1 = 18
let low_high_val = <[u8; 32]>::from_hex(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
).expect("should never fail");
)
.expect("should never fail");
// 32
let higher_low_val = <[u8; 32]>::from_hex(
"0000000000000000000000000000000000000000000000000000000000000020",
).expect("should never fail");
)
.expect("should never fail");

let cases = [
(FieldElement::ONE, FieldElement::ZERO, true),
Expand Down

0 comments on commit a3c2ba0

Please sign in to comment.