本文整理汇总了Java中org.bouncycastle.math.ec.ECFieldElement.sqrt方法的典型用法代码示例。如果您正苦于以下问题:Java ECFieldElement.sqrt方法的具体用法?Java ECFieldElement.sqrt怎么用?Java ECFieldElement.sqrt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.math.ec.ECFieldElement
的用法示例。
在下文中一共展示了ECFieldElement.sqrt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encodeToECPoint
import org.bouncycastle.math.ec.ECFieldElement; //导入方法依赖的package包/类
private static ECPoint encodeToECPoint(ECParameterSpec ps, byte[] message, SecureRandom sr) {
// Method based on Section 2.4 of https://eprint.iacr.org/2013/373.pdf
// System.out.println("Encoding: " + BBS98BouncyCastle.bytesToHex(message));
int lBits = ps.getN().bitLength() / 2;
// System.out.println("N = " + ps.getN());
// System.out.println("lbits: " + lBits);
if (message.length * 8 > lBits) {
throw new IllegalArgumentException("Message too large to be encoded");
}
BigInteger mask = BigInteger.ZERO.flipBit(lBits).subtract(BigInteger.ONE);
BigInteger m = new BigInteger(1, message);
ECFieldElement a = ps.getCurve().getA();
ECFieldElement b = ps.getCurve().getB();
BigInteger r;
ECFieldElement x = null, y = null;
do {
r = BBS98BouncyCastle.getRandom(sr, ps.getN());
r = r.andNot(mask).or(m);
if (!ps.getCurve().isValidFieldElement(r)) {
continue;
}
x = ps.getCurve().fromBigInteger(r);
// y^2 = x^3 + ax + b = (x^2+a)x +b
ECFieldElement y2 = x.square().add(a).multiply(x).add(b);
y = y2.sqrt();
} while (y == null);
return ps.getCurve().createPoint(x.toBigInteger(), y.toBigInteger());
}
示例2: implPrintRootZ
import org.bouncycastle.math.ec.ECFieldElement; //导入方法依赖的package包/类
private static void implPrintRootZ(X9ECParameters x9)
{
ECFieldElement z = x9.getCurve().fromBigInteger(BigInteger.valueOf(2));
ECFieldElement rootZ = z.sqrt();
System.out.println(rootZ.toBigInteger().toString(16).toUpperCase());
if (!rootZ.square().equals(z))
{
throw new IllegalStateException("Optimized-sqrt sanity check failed");
}
}