Ban unreduced points in Monero

This commit is contained in:
Luke Parker 2022-07-31 22:46:46 -04:00
parent 6340607827
commit 1c4707136c
No known key found for this signature in database
GPG key ID: F9F1386DB1E119B6

View file

@ -85,9 +85,11 @@ pub fn read_scalar<R: io::Read>(r: &mut R) -> io::Result<Scalar> {
}
pub fn read_point<R: io::Read>(r: &mut R) -> io::Result<EdwardsPoint> {
CompressedEdwardsY(read_32(r)?)
let bytes = read_32(r)?;
CompressedEdwardsY(bytes)
.decompress()
.filter(|point| point.is_torsion_free())
// Ban torsioned points, and points which are either unreduced or -0
.filter(|point| point.is_torsion_free() && (point.compress().to_bytes() == bytes))
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "invalid point"))
}