59 lines
2.3 KiB
Java
59 lines
2.3 KiB
Java
|
package org.bouncycastle.math.ec.tools;
|
||
|
|
||
|
import java.io.PrintStream;
|
||
|
import java.math.BigInteger;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.Enumeration;
|
||
|
import java.util.TreeSet;
|
||
|
import org.bouncycastle.asn1.x9.ECNamedCurveTable;
|
||
|
import org.bouncycastle.asn1.x9.X9ECParameters;
|
||
|
import org.bouncycastle.crypto.ec.CustomNamedCurves;
|
||
|
import org.bouncycastle.math.ec.ECAlgorithms;
|
||
|
import org.bouncycastle.math.ec.ECFieldElement;
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public class F2mSqrtOptimizer {
|
||
|
public static void printRootZ(X9ECParameters x9ECParameters) {
|
||
|
if (!ECAlgorithms.isF2mCurve(x9ECParameters.getCurve())) {
|
||
|
throw new IllegalArgumentException("Sqrt optimization only defined over characteristic-2 fields");
|
||
|
}
|
||
|
implPrintRootZ(x9ECParameters);
|
||
|
}
|
||
|
|
||
|
public static void main(String[] strArr) {
|
||
|
TreeSet<String> treeSet = new TreeSet(enumToList(ECNamedCurveTable.getNames()));
|
||
|
treeSet.addAll(enumToList(CustomNamedCurves.getNames()));
|
||
|
for (String str : treeSet) {
|
||
|
X9ECParameters byName = CustomNamedCurves.getByName(str);
|
||
|
if (byName == null) {
|
||
|
byName = ECNamedCurveTable.getByName(str);
|
||
|
}
|
||
|
if (byName != null && ECAlgorithms.isF2mCurve(byName.getCurve())) {
|
||
|
PrintStream printStream = System.out;
|
||
|
StringBuilder sb = new StringBuilder();
|
||
|
sb.append(str);
|
||
|
sb.append(":");
|
||
|
printStream.print(sb.toString());
|
||
|
implPrintRootZ(byName);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private static void implPrintRootZ(X9ECParameters x9ECParameters) {
|
||
|
ECFieldElement fromBigInteger = x9ECParameters.getCurve().fromBigInteger(BigInteger.valueOf(2L));
|
||
|
ECFieldElement sqrt = fromBigInteger.sqrt();
|
||
|
System.out.println(sqrt.toBigInteger().toString(16).toUpperCase());
|
||
|
if (!sqrt.square().equals(fromBigInteger)) {
|
||
|
throw new IllegalStateException("Optimized-sqrt sanity check failed");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private static ArrayList enumToList(Enumeration enumeration) {
|
||
|
ArrayList arrayList = new ArrayList();
|
||
|
while (enumeration.hasMoreElements()) {
|
||
|
arrayList.add(enumeration.nextElement());
|
||
|
}
|
||
|
return arrayList;
|
||
|
}
|
||
|
}
|