// 
// Decompiled by Procyon v0.6.0
// 

package org.bouncycastle.crypto.agreement.ecjpake;

import java.math.BigInteger;
import org.bouncycastle.math.ec.ECPoint;
import org.bouncycastle.math.ec.ECCurve;

public class ECJPAKECurve
{
    private final ECCurve.AbstractFp curve;
    private final ECPoint g;
    
    public ECJPAKECurve(final BigInteger bigInteger, final BigInteger bigInteger2, final BigInteger bigInteger3, final BigInteger bigInteger4, final BigInteger bigInteger5, final BigInteger bigInteger6, final BigInteger bigInteger7) {
        ECJPAKEUtil.validateNotNull(bigInteger2, "a");
        ECJPAKEUtil.validateNotNull(bigInteger3, "b");
        ECJPAKEUtil.validateNotNull(bigInteger, "q");
        ECJPAKEUtil.validateNotNull(bigInteger4, "n");
        ECJPAKEUtil.validateNotNull(bigInteger5, "h");
        ECJPAKEUtil.validateNotNull(bigInteger6, "g_x");
        ECJPAKEUtil.validateNotNull(bigInteger7, "g_y");
        if (!bigInteger.isProbablePrime(20)) {
            throw new IllegalArgumentException("Field size q must be prime");
        }
        if (bigInteger2.compareTo(BigInteger.ZERO) < 0 || bigInteger2.compareTo(bigInteger) >= 0) {
            throw new IllegalArgumentException("The parameter 'a' is not in the field [0, q-1]");
        }
        if (bigInteger3.compareTo(BigInteger.ZERO) < 0 || bigInteger3.compareTo(bigInteger) >= 0) {
            throw new IllegalArgumentException("The parameter 'b' is not in the field [0, q-1]");
        }
        if (calculateDeterminant(bigInteger, bigInteger2, bigInteger3).equals(BigInteger.ZERO)) {
            throw new IllegalArgumentException("The curve is singular, i.e the discriminant is equal to 0 mod q.");
        }
        if (!bigInteger4.isProbablePrime(20)) {
            throw new IllegalArgumentException("The order n must be prime");
        }
        this.curve = new ECCurve.Fp(bigInteger, bigInteger2, bigInteger3, bigInteger4, bigInteger5);
        this.g = this.curve.validatePoint(bigInteger6, bigInteger7);
    }
    
    ECJPAKECurve(final ECCurve.AbstractFp curve, final ECPoint g) {
        ECJPAKEUtil.validateNotNull(curve, "curve");
        ECJPAKEUtil.validateNotNull(g, "g");
        ECJPAKEUtil.validateNotNull(curve.getOrder(), "n");
        ECJPAKEUtil.validateNotNull(curve.getCofactor(), "h");
        this.curve = curve;
        this.g = g;
    }
    
    public ECCurve.AbstractFp getCurve() {
        return this.curve;
    }
    
    public ECPoint getG() {
        return this.g;
    }
    
    public BigInteger getA() {
        return this.curve.getA().toBigInteger();
    }
    
    public BigInteger getB() {
        return this.curve.getB().toBigInteger();
    }
    
    public BigInteger getN() {
        return this.curve.getOrder();
    }
    
    public BigInteger getH() {
        return this.curve.getCofactor();
    }
    
    public BigInteger getQ() {
        return this.curve.getQ();
    }
    
    private static BigInteger calculateDeterminant(final BigInteger bigInteger, final BigInteger bigInteger2, final BigInteger val) {
        return bigInteger2.multiply(bigInteger2).mod(bigInteger).multiply(bigInteger2).mod(bigInteger).shiftLeft(2).add(val.multiply(val).mod(bigInteger).multiply(BigInteger.valueOf(27L))).mod(bigInteger);
    }
}
