src/main/core/com/gypsyengineer/tlsbunny/utils/MathUtils.java
public static int legendre(BigInteger x, BigInteger p) {
        BigInteger q = p.subtract(BigInteger.ONE).shiftRight(1);
        BigInteger t = x.modPow(q, p);

        if (t.equals(BigInteger.ONE)) {
            return 1;
        }

        if (t.equals(BigInteger.ZERO)) {
            return 0;
        }

        if (t.add(BigInteger.ONE).equals(p)) {
            return -1;
        }

        throw new IllegalArgumentException("p is not prime");
    }
/**
     * (borrowed from wycheproof)
     *
     * Compute the Legendre symbol of x mod p. This implementation is slow. Faster would be the
     * computation for the Jacobi symbol.
     *
     * @param x an integer
     * @param p a prime modulus
     * @returns 1 if x is a quadratic residue, -1 if x is a non-quadratic residue and 0 if x and p are
     *     not coprime.
     */
(borrowed from wycheproof)
Compute the Legendre symbol of x mod p. This implementation is slow. Faster would be the
computation for the Jacobi symbol.

@param x an integer
@param p a prime modulus
@returns 1 if x is a quadratic residue, -1 if x is a non-quadratic residue and 0 if x and p are
not coprime.
( borrowed from wycheproof ) Compute the Legendre symbol of x mod p . This implementation is slow . Faster would be the computation for the Jacobi symbol . @param x an integer @param p a prime modulus @returns 1 if x is a quadratic residue - 1 if x is a non - quadratic residue and 0 if x and p are not coprime .
public static int legendre(BigInteger x, BigInteger p) {
        BigInteger q = p.subtract(BigInteger.ONE).shiftRight(1);
        BigInteger t = x.modPow(q, p);
        if (t.equals(BigInteger.ONE)) {
            return 1;
        }
        if (t.equals(BigInteger.ZERO)) {
            return 0;
        }
        if (t.add(BigInteger.ONE).equals(p)) {
            return -1;
        }
        throw new IllegalArgumentException("p is not prime");
    }
public static int legendre ( BigInteger x , BigInteger p ) { BigInteger q = p . subtract ( BigInteger . ONE ) . shiftRight ( 1 ) ; BigInteger t = x . modPow ( q , p ) ; if ( t . equals ( BigInteger . ONE ) ) { return 1 ; } if ( t . equals ( BigInteger . ZERO ) ) { return 0 ; } if ( t . add ( BigInteger . ONE ) . equals ( p ) ) { return - 1 ; } throw new IllegalArgumentException ( "p is not prime" ) ; }
(borrowed from wycheproof)
 Compute the Legendre symbol of x mod p. This implementation is slow.
( borrowed from wycheproof ) Compute the Legendre symbol of x mod p . This implementation is slow .