mirror of
https://github.com/saymrwulf/risc0-curve25519-dalek-source.git
synced 2026-09-09 20:50:40 +00:00
fixup! Properly handle exceptional points.
This commit is contained in:
parent
db53b58e89
commit
5d3d114628
1 changed files with 11 additions and 5 deletions
16
src/curve.rs
16
src/curve.rs
|
|
@ -462,7 +462,7 @@ impl ProjectivePoint {
|
||||||
let u = &Z_plus_Y * &Z_minus_Y.invert();
|
let u = &Z_plus_Y * &Z_minus_Y.invert();
|
||||||
|
|
||||||
if Z_minus_Y.is_zero() == 0u8 {
|
if Z_minus_Y.is_zero() == 0u8 {
|
||||||
CompressedMontgomeryU(u.to_bytes())
|
Some(CompressedMontgomeryU(u.to_bytes()))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
@ -512,8 +512,14 @@ impl ExtendedPoint {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compress this point to `CompressedMontgomeryU` format
|
/// Convert this point to a `CompressedMontgomeryU`.
|
||||||
pub fn compress_montgomery(&self) -> CompressedMontgomeryU {
|
/// Note that this discards the sign.
|
||||||
|
///
|
||||||
|
/// # Return
|
||||||
|
/// - `None` if `self` is the identity point;
|
||||||
|
/// - `Some(CompressedMontgomeryU)` otherwise.
|
||||||
|
///
|
||||||
|
pub fn compress_montgomery(&self) -> Option<CompressedMontgomeryU> {
|
||||||
self.to_projective().compress_montgomery()
|
self.to_projective().compress_montgomery()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1076,7 +1082,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_basepoint_to_montgomery() {
|
fn test_basepoint_to_montgomery() {
|
||||||
let bp = BASE_CMPRSSD.decompress().unwrap();
|
let bp = BASE_CMPRSSD.decompress().unwrap();
|
||||||
let bp_monty = bp.compress_montgomery();
|
let bp_monty = bp.compress_montgomery().unwrap();
|
||||||
assert_eq!(bp_monty, BASE_CMPRSSD_MONTY);
|
assert_eq!(bp_monty, BASE_CMPRSSD_MONTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1106,7 +1112,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_identity_to_monty() {
|
fn test_identity_to_monty() {
|
||||||
let id = ExtendedPoint::identity();
|
let id = ExtendedPoint::identity();
|
||||||
assert!(id.compressed_montgomery().is_none());
|
assert!(id.compress_montgomery().is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Test round-trip decompression for the basepoint.
|
/// Test round-trip decompression for the basepoint.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue