package Y3;

import java.lang.reflect.Array;
import java.math.BigInteger;

/* JADX INFO: loaded from: classes3.dex */
public abstract class k {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final long[] f8824a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final long[] f8825b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final long[] f8826c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final g[][] f8827d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final g[] f8828e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final BigInteger f8829f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public static final BigInteger f8830g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public static final BigInteger f8831h;

    static {
        BigInteger bigIntegerSubtract = BigInteger.valueOf(2L).pow(255).subtract(BigInteger.valueOf(19L));
        f8829f = bigIntegerSubtract;
        BigInteger bigIntegerMod = BigInteger.valueOf(-121665L).multiply(BigInteger.valueOf(121666L).modInverse(bigIntegerSubtract)).mod(bigIntegerSubtract);
        f8830g = bigIntegerMod;
        BigInteger bigIntegerMod2 = BigInteger.valueOf(2L).multiply(bigIntegerMod).mod(bigIntegerSubtract);
        f8831h = bigIntegerMod2;
        BigInteger bigIntegerValueOf = BigInteger.valueOf(2L);
        BigInteger bigInteger = BigInteger.ONE;
        BigInteger bigIntegerModPow = bigIntegerValueOf.modPow(bigIntegerSubtract.subtract(bigInteger).divide(BigInteger.valueOf(4L)), bigIntegerSubtract);
        T.p pVar = new T.p(24, false);
        BigInteger bigIntegerMod3 = BigInteger.valueOf(4L).multiply(BigInteger.valueOf(5L).modInverse(bigIntegerSubtract)).mod(bigIntegerSubtract);
        pVar.f6346c = bigIntegerMod3;
        BigInteger bigIntegerMultiply = bigIntegerMod3.pow(2).subtract(bigInteger).multiply(bigIntegerMod.multiply(bigIntegerMod3.pow(2)).add(bigInteger).modInverse(bigIntegerSubtract));
        BigInteger bigIntegerModPow2 = bigIntegerMultiply.modPow(bigIntegerSubtract.add(BigInteger.valueOf(3L)).divide(BigInteger.valueOf(8L)), bigIntegerSubtract);
        if (!bigIntegerModPow2.pow(2).subtract(bigIntegerMultiply).mod(bigIntegerSubtract).equals(BigInteger.ZERO)) {
            bigIntegerModPow2 = bigIntegerModPow2.multiply(bigIntegerModPow).mod(bigIntegerSubtract);
        }
        if (bigIntegerModPow2.testBit(0)) {
            bigIntegerModPow2 = bigIntegerSubtract.subtract(bigIntegerModPow2);
        }
        pVar.f6345b = bigIntegerModPow2;
        f8824a = j.g(c(bigIntegerMod));
        f8825b = j.g(c(bigIntegerMod2));
        f8826c = j.g(c(bigIntegerModPow));
        f8827d = (g[][]) Array.newInstance((Class<?>) g.class, 32, 8);
        T.p pVarA = pVar;
        for (int i6 = 0; i6 < 32; i6++) {
            T.p pVarA2 = pVarA;
            for (int i7 = 0; i7 < 8; i7++) {
                f8827d[i6][i7] = b(pVarA2);
                pVarA2 = a(pVarA2, pVarA);
            }
            for (int i8 = 0; i8 < 8; i8++) {
                pVarA = a(pVarA, pVarA);
            }
        }
        T.p pVarA3 = a(pVar, pVar);
        f8828e = new g[8];
        for (int i9 = 0; i9 < 8; i9++) {
            f8828e[i9] = b(pVar);
            pVar = a(pVar, pVarA3);
        }
    }

    public static T.p a(T.p pVar, T.p pVar2) {
        T.p pVar3 = new T.p(24, false);
        BigInteger bigIntegerMultiply = f8830g.multiply(((BigInteger) pVar.f6345b).multiply((BigInteger) pVar2.f6345b).multiply((BigInteger) pVar.f6346c).multiply((BigInteger) pVar2.f6346c));
        BigInteger bigInteger = f8829f;
        BigInteger bigIntegerMod = bigIntegerMultiply.mod(bigInteger);
        BigInteger bigIntegerAdd = ((BigInteger) pVar.f6345b).multiply((BigInteger) pVar2.f6346c).add(((BigInteger) pVar2.f6345b).multiply((BigInteger) pVar.f6346c));
        BigInteger bigInteger2 = BigInteger.ONE;
        pVar3.f6345b = bigIntegerAdd.multiply(bigInteger2.add(bigIntegerMod).modInverse(bigInteger)).mod(bigInteger);
        pVar3.f6346c = ((BigInteger) pVar.f6346c).multiply((BigInteger) pVar2.f6346c).add(((BigInteger) pVar.f6345b).multiply((BigInteger) pVar2.f6345b)).multiply(bigInteger2.subtract(bigIntegerMod).modInverse(bigInteger)).mod(bigInteger);
        return pVar3;
    }

    public static g b(T.p pVar) {
        BigInteger bigIntegerAdd = ((BigInteger) pVar.f6346c).add((BigInteger) pVar.f6345b);
        BigInteger bigInteger = f8829f;
        return new g(j.g(c(bigIntegerAdd.mod(bigInteger))), j.g(c(((BigInteger) pVar.f6346c).subtract((BigInteger) pVar.f6345b).mod(bigInteger))), j.g(c(f8831h.multiply((BigInteger) pVar.f6345b).multiply((BigInteger) pVar.f6346c).mod(bigInteger))));
    }

    public static byte[] c(BigInteger bigInteger) {
        byte[] bArr = new byte[32];
        byte[] byteArray = bigInteger.toByteArray();
        System.arraycopy(byteArray, 0, bArr, 32 - byteArray.length, byteArray.length);
        for (int i6 = 0; i6 < 16; i6++) {
            byte b5 = bArr[i6];
            int i7 = 31 - i6;
            bArr[i6] = bArr[i7];
            bArr[i7] = b5;
        }
        return bArr;
    }
}
