public class GenericSqrtRatioCalculator extends java.lang.Object implements SqrtRatioCalculator
This computes a square root of u/v in the prime field Fp associated with an elliptic curve, when such a square root exists, and otherwise returns a valid square root of z·u/v for a fixed quadratic non-residue z. This function is a required component of all map-to-curve constructions in RFC 9380, including the Simplified SWU and Elligator 2 maps.
RFC 9380 defines optimized sqrt_ratio formulas for certain curves where the field prime p satisfies special congruences (e.g. p ≡ 3 mod 4 or p ≡ 5 mod 8). However, those optimizations are curve-specific and do not apply to all hash-to-curve suites. This implementation instead follows the fully generic algorithm from Section 5.6.3 of RFC 9380, which is valid for any elliptic curve defined over a prime field Fp.
This generic version supports all curves used in the RFC 9830 test vectors, including the NIST P-256 / P-384 / P-521 curves, Curve25519, Edwards25519 (Ristretto255), Curve448, and Edwards448 (Decaf448). It provides a single uniform implementation suitable for all supported hash-to-curve suites.
| Constructor and Description |
|---|
GenericSqrtRatioCalculator(ECCurve curve,
java.math.BigInteger z)
Constructs a
GenericSqrtRatioCalculator instance with the specified elliptic curve and a
given value z. |
| Modifier and Type | Method and Description |
|---|---|
SqrtRatio |
sqrtRatio(java.math.BigInteger u,
java.math.BigInteger v)
he sqrtRatio subroutine of hash2Curve in the field F
|
public GenericSqrtRatioCalculator(ECCurve curve, java.math.BigInteger z)
GenericSqrtRatioCalculator instance with the specified elliptic curve and a
given value z.curve - the elliptic curve over a finite field to be used for square root and ratio
calculationsz - a non-square element of Fpublic SqrtRatio sqrtRatio(java.math.BigInteger u, java.math.BigInteger v)
sqrtRatio in interface SqrtRatioCalculatoru - u parameter, element of Fv - v parameter, element of F, such that v != 0