本文整理了Java中java.math.BigInteger.modInverse()
方法的一些代码示例,展示了BigInteger.modInverse()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigInteger.modInverse()
方法的具体详情如下:
包路径:java.math.BigInteger
类名称:BigInteger
方法名:modInverse
[英]Returns a BigInteger whose value is 1/this mod m. The modulus m must be positive. The result is guaranteed to be in the interval [0, m) (0 inclusive, m exclusive). If this is not relatively prime to m, then an exception is thrown.
[中]返回一个BigInteger,其值为1/此模m。模m必须为正。结果保证在区间[0,m](包括0,m排除)内。如果这不是相对于m的素数,则抛出异常。
代码示例来源:origin: ethereum/ethereumj
@Override public Fp inverse() { return new Fp(v.modInverse(P)); }
@Override public Fp negate() { return new Fp(v.negate().mod(P)); }
代码示例来源:origin: robovm/robovm
/**
* Returns a {@code BigInteger} whose value is {@code
* pow(this, exponent) mod modulus}. The modulus must be positive. The
* result is guaranteed to be in the interval {@code [0, modulus)}.
* If the exponent is negative, then
* {@code pow(this.modInverse(modulus), -exponent) mod modulus} is computed.
* The inverse of this only exists if {@code this} is relatively prime to the modulus,
* otherwise an exception is thrown.
*
* @throws NullPointerException if {@code modulus == null} or {@code exponent == null}.
* @throws ArithmeticException if {@code modulus < 0} or if {@code exponent < 0} and
* not relatively prime to {@code modulus}.
*/
public BigInteger modPow(BigInteger exponent, BigInteger modulus) {
if (modulus.signum() <= 0) {
throw new ArithmeticException("modulus.signum() <= 0");
}
int exponentSignum = exponent.signum();
if (exponentSignum == 0) { // OpenSSL gets this case wrong; http://b/8574367.
return ONE.mod(modulus);
}
BigInteger base = exponentSignum < 0 ? modInverse(modulus) : this;
return new BigInteger(BigInt.modExp(base.getBigInt(), exponent.getBigInt(), modulus.getBigInt()));
}
代码示例来源:origin: kingthy/TVRemoteIME
rr = r.modPow(BigInteger.valueOf(2), n);
rem = n.remainder(r32);
n0inv = rem.modInverse(r32);
代码示例来源:origin: robovm/robovm
w = s.modInverse(q);
代码示例来源:origin: robovm/robovm
s = k.modInverse(q).multiply(digestBI.add(x.multiply(r)).mod(q))
.mod(q);
代码示例来源:origin: web3j/web3j
BigInteger rInv = sig.r.modInverse(n);
BigInteger srInv = rInv.multiply(sig.s).mod(n);
BigInteger eInvrInv = rInv.multiply(eInv).mod(n);
代码示例来源:origin: ethereum/ethereumj
BigInteger rInv = sig.r.modInverse(n);
BigInteger srInv = rInv.multiply(sig.s).mod(n);
BigInteger eInvrInv = rInv.multiply(eInv).mod(n);
代码示例来源:origin: i2p/i2p.i2p
public FieldElement invert() {
// Euler's theorem
//return modPow(f.getQm2(), f.getQ());
return new BigIntegerFieldElement(f, bi.modInverse(((BigIntegerFieldElement)f.getQ()).bi));
}
代码示例来源:origin: i2p/i2p.i2p
private static ECPoint doublePoint(ECPoint r, EllipticCurve curve) {
if (r.equals(ECPoint.POINT_INFINITY))
return r;
BigInteger slope = (r.getAffineX().pow(2)).multiply(THREE);
slope = slope.add(curve.getA());
BigInteger prime = ((ECFieldFp) curve.getField()).getP();
// use NBI modInverse();
BigInteger tmp = r.getAffineY().multiply(TWO);
tmp = new NativeBigInteger(tmp);
slope = slope.multiply(tmp.modInverse(prime));
BigInteger xOut = slope.pow(2).subtract(r.getAffineX().multiply(TWO)).mod(prime);
BigInteger yOut = (r.getAffineY().negate()).add(slope.multiply(r.getAffineX().subtract(xOut))).mod(prime);
ECPoint out = new ECPoint(xOut, yOut);
return out;
}
代码示例来源:origin: i2p/i2p.i2p
/**
* @throws ArithmeticException if not coprime with m, or m <= 0
* @since 0.9.26 and libjbigi version 3
*/
@Override
public BigInteger modInverse(BigInteger m) {
// Where negative or zero values aren't legal in modInverse() anyway, avoid native,
// as the Java code will throw an exception rather than silently fail or crash the JVM
// Note that 'this' can be negative
// If this and m are not coprime, gmp will do a divide by zero exception and crash the JVM.
// super will throw an ArithmeticException
if (_nativeOk3)
return new NativeBigInteger(nativeModInverse(toByteArray(), m.toByteArray()));
else
return super.modInverse(m);
}
代码示例来源:origin: i2p/i2p.i2p
ng.modPowCT(bi, jp);
else
bi.modInverse(jp);
jval = jg.modPow(bi, jp);
else
jval = bi.modInverse(jp);
long afterJavaModPow = System.nanoTime();
代码示例来源:origin: SeanDragon/protools
/**
* 签名
*
* @param M 签名信息
* @param IDA 签名方唯一标识
* @param keyPair 签名方密钥对
* @return 签名
*/
public Signature sign(String M, String IDA, SM2KeyPair keyPair) {
byte[] ZA = ZA(IDA, keyPair.getPublicKey());
byte[] M_ = join(ZA, M.getBytes());
BigInteger e = new BigInteger(1, sm3hash(M_));
// BigInteger k = new BigInteger(
// "6CB28D99 385C175C 94F94E93 4817663F C176D925 DD72B727 260DBAAE
// 1FB2F96F".replace(" ", ""), 16);
BigInteger k;
BigInteger r;
do {
k = random(n);
ECPoint p1 = G.multiply(k).normalize();
BigInteger x1 = p1.getXCoord().toBigInteger();
r = e.add(x1);
r = r.mod(n);
} while (r.equals(BigInteger.ZERO) || r.add(k).equals(n));
BigInteger s = ((keyPair.getPrivateKey().add(BigInteger.ONE).modInverse(n))
.multiply((k.subtract(r.multiply(keyPair.getPrivateKey()))).mod(n))).mod(n);
return new Signature(r, s);
}
代码示例来源:origin: i2p/i2p.i2p
private static ECPoint addPoint(ECPoint r, ECPoint s, EllipticCurve curve) {
if (r.equals(s))
return doublePoint(r, curve);
else if (r.equals(ECPoint.POINT_INFINITY))
return s;
else if (s.equals(ECPoint.POINT_INFINITY))
return r;
BigInteger prime = ((ECFieldFp) curve.getField()).getP();
// use NBI modInverse();
BigInteger tmp = r.getAffineX().subtract(s.getAffineX());
tmp = new NativeBigInteger(tmp);
BigInteger slope = (r.getAffineY().subtract(s.getAffineY())).multiply(tmp.modInverse(prime)).mod(prime);
slope = new NativeBigInteger(slope);
BigInteger xOut = (slope.modPow(TWO, prime).subtract(r.getAffineX())).subtract(s.getAffineX()).mod(prime);
BigInteger yOut = s.getAffineY().negate().mod(prime);
yOut = yOut.add(slope.multiply(s.getAffineX().subtract(xOut))).mod(prime);
ECPoint out = new ECPoint(xOut, yOut);
return out;
}
代码示例来源:origin: i2p/i2p.i2p
BigInteger kinv = k.modInverse(pm1);
BigInteger h = new NativeBigInteger(1, data);
BigInteger s = (kinv.multiply(h.subtract(x.multiply(r)))).mod(pm1);
代码示例来源:origin: i2p/i2p.i2p
BigInteger kinv = k.modInverse(CryptoConstants.dsaq);
代码示例来源:origin: i2p/i2p.i2p
BigInteger w;
try {
w = s.modInverse(CryptoConstants.dsaq);
} catch (ArithmeticException ae) {
_log.warn("modInverse() error", ae);
代码示例来源:origin: i2p/i2p.i2p
@Test
public void invertReturnsCorrectResult() {
for (int i=0; i<1000; i++) {
// Arrange:
final FieldElement f1 = getRandomFieldElement();
final BigInteger b1 = toBigInteger(f1);
// Act:
final FieldElement f2 = f1.invert();
final BigInteger b2 = toBigInteger(f2).mod(getQ());
// Assert:
Assert.assertThat(b2, IsEqual.equalTo(b1.modInverse(getQ())));
}
}
代码示例来源:origin: i2p/i2p.i2p
final BigInteger g1x = g1X.multiply(g1Z.modInverse(getQ())).mod(getQ());
final BigInteger g1y = g1Y.multiply(g1Z.modInverse(getQ())).mod(getQ());
final BigInteger g2x = g2X.multiply(g2Z.modInverse(getQ())).mod(getQ());
final BigInteger g2y = g2Y.multiply(g2Z.modInverse(getQ())).mod(getQ());
.multiply(BigInteger.ONE.add(dx1x2y1y2).modInverse(getQ())).mod(getQ());
BigInteger y3 = g1x.multiply(g2x).add(g1y.multiply(g2y))
.multiply(BigInteger.ONE.subtract(dx1x2y1y2).modInverse(getQ())).mod(getQ());
BigInteger t3 = x3.multiply(y3).mod(getQ());
代码示例来源:origin: i2p/i2p.i2p
case P3:
case P3PrecomputedDouble:
x = gX.multiply(gZ.modInverse(getQ())).mod(getQ());
y = gY.multiply(gZ.modInverse(getQ())).mod(getQ());
break;
case P1P1:
x = gX.multiply(gZ.modInverse(getQ())).mod(getQ());
y = gY.multiply(gT.modInverse(getQ())).mod(getQ());
break;
case CACHED:
x = gX.subtract(gY).multiply(gZ.multiply(new BigInteger("2")).modInverse(getQ())).mod(getQ());
y = gX.add(gY).multiply(gZ.multiply(new BigInteger("2")).modInverse(getQ())).mod(getQ());
break;
case PRECOMP:
x = gX.subtract(gY).multiply(new BigInteger("2").modInverse(getQ())).mod(getQ());
y = gX.add(gY).multiply(new BigInteger("2").modInverse(getQ())).mod(getQ());
break;
default:
代码示例来源:origin: RUB-NDS/TLS-Attacker
@Override
public FieldElement multInv() {
if (this.getData().equals(BigInteger.ZERO)) {
throw new ArithmeticException();
}
BigInteger tmp = this.getData().modInverse(this.getModulus());
return new FieldElementFp(tmp, this.getModulus());
}
}
内容来源于网络,如有侵权,请联系作者删除!