Class GenericSqrtRatioCalculator
- java.lang.Object
-
- org.bouncycastle.crypto.hash2curve.impl.GenericSqrtRatioCalculator
-
- All Implemented Interfaces:
SqrtRatioCalculator
public class GenericSqrtRatioCalculator extends java.lang.Object implements SqrtRatioCalculator
Generic implementation of the sqrt_ratio(u, v) operation defined in RFC 9380.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 Summary
Constructors Constructor Description GenericSqrtRatioCalculator(ECCurve curve, java.math.BigInteger z)Constructs aGenericSqrtRatioCalculatorinstance with the specified elliptic curve and a given value z.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SqrtRatiosqrtRatio(java.math.BigInteger u, java.math.BigInteger v)he sqrtRatio subroutine of hash2Curve in the field F
-
-
-
Constructor Detail
-
GenericSqrtRatioCalculator
public GenericSqrtRatioCalculator(ECCurve curve, java.math.BigInteger z)
Constructs aGenericSqrtRatioCalculatorinstance with the specified elliptic curve and a given value z.- Parameters:
curve- the elliptic curve over a finite field to be used for square root and ratio calculationsz- a non-square element of F
-
-
Method Detail
-
sqrtRatio
public SqrtRatio sqrtRatio(java.math.BigInteger u, java.math.BigInteger v)
he sqrtRatio subroutine of hash2Curve in the field F- Specified by:
sqrtRatioin interfaceSqrtRatioCalculator- Parameters:
u- u parameter, element of Fv- v parameter, element of F, such that v != 0- Returns:
- SqrtRatio result
-
-