-
Notifications
You must be signed in to change notification settings - Fork 11
Implement Point Compression/Decompression for Twisted Edwards Coordinates. #69
Conversation
This two trait impl rely on the `ConstantTimeEq` impl which compares both point sets con CTTime.
Given a `y-coordinate´, this function solves the equation of the curve returning a FieldElement with `x^2` represented on it.
This function compresses an EdwardsPoint into a `CompressedEdwardsY`. It encodes the sign of the x-coordinate and sets it on the highest bit of the last byte of the compressed point. 1 => positive. 0 => negative.
The `compress()` function had an error since it was encoding the x-coordinate and not the `y` one as bytes. Refactored this, tests were done and all of them passed.
Implemented tests for both results of point compression. All sign encodings are valid and correct. This finnishes the half part of #30
This function returns `None` if the y-coordinate of the point does not rely on the curve. Otherways, returns Some(ExtendedPoint) with the result shown as a `EdwardsPoint` struct.
It's easier to execute the comparaisons by unwraping the Choice and comparing it to `1u8` than getting a bool from the Choice.
Codecov Report
@@ Coverage Diff @@
## master #69 +/- ##
=========================================
+ Coverage 96.77% 97.4% +0.62%
=========================================
Files 4 4
Lines 2358 2544 +186
=========================================
+ Hits 2282 2478 +196
+ Misses 76 66 -10
Continue to review full report at Codecov.
|
@Bounce23, once you review this, (if everything it's okay), merge it! |
@@ -822,7 +871,7 @@ impl ConstantTimeEq for AffinePoint { | |||
|
|||
impl PartialEq for AffinePoint { | |||
fn eq(&self, other: &Self) -> bool { | |||
bool::from(self.ct_eq(&other)) | |||
self.ct_eq(&other).unwrap_u8() == 1u8 | |||
} | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The projective here is perfect, is there a means of hyperlinking or somehow directing users from this code to worked examples in other parts of the library?
@@ -448,7 +448,7 @@ impl<'a> ModSqrt for &'a FieldElement { | |||
let b; | |||
while i < m { | |||
i = i + one; | |||
if bool::from(t.pow(&e).ct_eq(&one)) {break;} | |||
if t.pow(&e).ct_eq(&one).unwrap_u8() == 1u8 {break;} | |||
e = e * two; | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is approved, however, I want to open an issue for using a different modular method (perhaps on associated with the inverse function), to determine positive and negative outputs from the prime_mod_sqrt function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approved as it all 'suffices' for moving on to ristretto works. However, if you read the single comments you will see that I am looking to improve the first commit.
This PR closes #30
On this PR are included the functions that allow encoding an
EdwardsPoint
as aCompressedEdwardsY
, which is the most optimal way of representing a point over the Twisted Edwards Extended Coordinates.The
CompressedEdwardsY
consists on the y-coordinate of theEdwardsPoint
encoded as bytesand the highest bit of the last byte of it set to:
decompress()
returns anOption<EdwardsPoint>
since we cannot assume that they
is a valid coordinate over the curve.