Further refactoring of get_point_from_x()
This commit is contained in:
parent
683f21a4d5
commit
dbac57c27b
@ -85,11 +85,12 @@ macro_rules! curve_impl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl $affine {
|
impl $affine {
|
||||||
/// Constructs an affine point with the lexicographically smallest
|
/// Attempts to construct an affine point given an x-coordinate. The
|
||||||
/// y-coordinate, given an x-coordinate, so long as the x-coordinate
|
/// point is not guaranteed to be in the prime order subgroup.
|
||||||
/// exists on the curve. The point is not guaranteed to be in the
|
///
|
||||||
/// prime order subgroup.
|
/// If and only if `greatest` is set will the lexicographically
|
||||||
fn get_point_from_x(x: $basefield) -> Option<$affine> {
|
/// largest y-coordinate be selected.
|
||||||
|
fn get_point_from_x(x: $basefield, greatest: bool) -> Option<$affine> {
|
||||||
// Compute x^3 + b
|
// Compute x^3 + b
|
||||||
let mut x3b = x;
|
let mut x3b = x;
|
||||||
x3b.square();
|
x3b.square();
|
||||||
@ -102,7 +103,7 @@ macro_rules! curve_impl {
|
|||||||
|
|
||||||
$affine {
|
$affine {
|
||||||
x: x,
|
x: x,
|
||||||
y: if y < negy {
|
y: if (y < negy) ^ greatest {
|
||||||
y
|
y
|
||||||
} else {
|
} else {
|
||||||
negy
|
negy
|
||||||
@ -808,19 +809,7 @@ pub mod g1 {
|
|||||||
// Interpret as Fq element.
|
// Interpret as Fq element.
|
||||||
let x = Fq::from_repr(x).map_err(|e| GroupDecodingError::CoordinateDecodingError("x coordinate", e))?;
|
let x = Fq::from_repr(x).map_err(|e| GroupDecodingError::CoordinateDecodingError("x coordinate", e))?;
|
||||||
|
|
||||||
match G1Affine::get_point_from_x(x) {
|
G1Affine::get_point_from_x(x, greatest).ok_or(GroupDecodingError::NotOnCurve)
|
||||||
Some(mut p) => {
|
|
||||||
if greatest {
|
|
||||||
p.negate();
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(p)
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
// Point must not be on the curve.
|
|
||||||
Err(GroupDecodingError::NotOnCurve)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn from_affine(affine: G1Affine) -> Self {
|
fn from_affine(affine: G1Affine) -> Self {
|
||||||
@ -1321,19 +1310,7 @@ pub mod g2 {
|
|||||||
c1: Fq::from_repr(x_c1).map_err(|e| GroupDecodingError::CoordinateDecodingError("x coordinate (c1)", e))?
|
c1: Fq::from_repr(x_c1).map_err(|e| GroupDecodingError::CoordinateDecodingError("x coordinate (c1)", e))?
|
||||||
};
|
};
|
||||||
|
|
||||||
match G2Affine::get_point_from_x(x) {
|
G2Affine::get_point_from_x(x, greatest).ok_or(GroupDecodingError::NotOnCurve)
|
||||||
Some(mut p) => {
|
|
||||||
if greatest {
|
|
||||||
p.negate();
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(p)
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
// Point must not be on the curve.
|
|
||||||
Err(GroupDecodingError::NotOnCurve)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn from_affine(affine: G2Affine) -> Self {
|
fn from_affine(affine: G2Affine) -> Self {
|
||||||
|
Loading…
Reference in New Issue
Block a user