GenericSqrtRatioCalculator (Bouncy Castle Library 1.85 API Specification)
Date: 2026-07-12

org.bouncycastle.crypto.hash2curve.impl

## 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 and Description
    `GenericSqrtRatioCalculator(ECCurve curve, java.math.BigInteger z)` Constructs a `GenericSqrtRatioCalculator` instance with the specified elliptic curve and a given value z.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    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

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### GenericSqrtRatioCalculator

          public GenericSqrtRatioCalculator(ECCurve curve,
                                            java.math.BigInteger z)

      Constructs a `GenericSqrtRatioCalculator` instance 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 calculations
        `z` - 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:
        `sqrtRatio` in interface `SqrtRatioCalculator`
      Parameters:
        `u` - u parameter, element of F
        `v` - v parameter, element of F, such that v != 0
      Returns:
        SqrtRatio result