const ge_frombytes_negx: FieldElement = fe()
const ge_frombytes_x_sqrtm1: FieldElement = fe()
/**
- * Constant-time point conversion from byte representation.
+ * Constant-time decoding from bytes to a point.
*
* @returns {i32} 0 if `s` decodes to a valid point, else -1
*/
return i32(has_m_root | has_p_root) - 1
}
-const ge_frombytes_negate_vartime_u: FieldElement = fe()
-const ge_frombytes_negate_vartime_v: FieldElement = fe()
-const ge_frombytes_negate_vartime_vx2: FieldElement = fe()
-const ge_frombytes_negate_vartime_check: FieldElement = fe()
/**
- * Variable-time point negation converted from byte representation.
- *
- * Compiler optimization of vartime function is OK.
+ * Decode the byte representation of a point and negate it.
*
* @returns {i32} 0 if `s` decodes to a valid point, else -1
*/
export function ge_frombytes_negate_vartime (h: p3, s: StaticArray<u8>,
t_u8x32: StaticArray<u8>, t_fe_0: FieldElement, t_fe_1: FieldElement, t_fe_2: FieldElement
): i32 {
- const u = ge_frombytes_negate_vartime_u
- const v = ge_frombytes_negate_vartime_v
- const vx2 = ge_frombytes_negate_vartime_vx2
- const check = ge_frombytes_negate_vartime_check
-
- // Decode bytes to y-coordinate
- fe_frombytes(h.Y, s)
- fe_1(h.Z)
-
- // u = y²
- fe_sq(u, h.Y)
- // v = dy²
- fe_mul_d(v, u)
- // u = y²-1
- u[0] -= 1
- // v = dy²+1
- v[0] += 1
-
- // x = uv
- fe_mul(h.X, u, v)
- // x = (uv)⁽𐞥⁻⁵⁾⸍⁸
- fe_pow22523(h.X, h.X, t_fe_0, t_fe_1, t_fe_2)
- // x = u(uv)⁽𐞥⁻⁵⁾⸍⁸
- fe_mul(h.X, u, h.X)
-
- // vx2 = x²
- fe_sq(vx2, h.X)
- // vx2 = vx²
- fe_mul(vx2, vx2, v)
-
- // m = vx²-u
- fe_sub(check, vx2, u)
- if (fe_iszero(check, t_fe_0, t_u8x32) == 0) {
- // p = vx²+u
- fe_add(check, vx2, u)
- if (fe_iszero(check, t_fe_0, t_u8x32) == 0) {
- // Reject invalid point
- return -1
- }
- // x = x√-1
- fe_mul_sqrtm1(h.X, h.X)
- }
-
- // x = |x|
- if (fe_isnegative(h.X, t_fe_0) == (s[31] >> 7)) {
- fe_neg(h.X, h.X)
- }
- // Create point projection
- fe_mul(h.T, h.X, h.Y)
-
- return 0
+ const check = ge_frombytes(h, s, t_fe_0, t_fe_1, t_fe_2, t_u8x32)
+ fe_neg(h.X, h.X)
+ fe_neg(h.T, h.T)
+ return check
}
/**