本文整理汇总了Java中com.squareup.jnagmp.Gmp.modPowSecure方法的典型用法代码示例。如果您正苦于以下问题:Java Gmp.modPowSecure方法的具体用法?Java Gmp.modPowSecure怎么用?Java Gmp.modPowSecure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.jnagmp.Gmp
的用法示例。
在下文中一共展示了Gmp.modPowSecure方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: modExp
import com.squareup.jnagmp.Gmp; //导入方法依赖的package包/类
public static BigInteger modExp(BigInteger base, BigInteger exponent, BigInteger modulus) {
if (gmpLoaded) {
if (exponent.signum() < 0) {
return Gmp.modPowSecure(modInverse(base, modulus), exponent.negate(), modulus);
} else {
return Gmp.modPowSecure(base, exponent, modulus);
}
} else {
return base.modPow(exponent, modulus);
}
}
开发者ID:republique-et-canton-de-geneve,项目名称:chvote-protocol-poc,代码行数:12,代码来源:BigIntegerArithmetic.java
示例2: modPow
import com.squareup.jnagmp.Gmp; //导入方法依赖的package包/类
/**
* Performs modPow: ({@code base}^{@code exponent}) mod {@code modulus}
*
* This method uses the values of {@code paillier.useGMPForModPow} and {@code paillier.GMPConstantTimeMode} as they were when the class was loaded to decide
* which implementation of modPow to invoke.
*
* These values can be reloaded by invoking static method {@code ModPowAbstraction.reloadConfiguration()}
*
* @return The result of modPow
*/
public static BigInteger modPow(BigInteger base, BigInteger exponent, BigInteger modulus)
{
BigInteger result;
if (useGMPForModPow)
{
if (useGMPConstantTimeMethods)
{
// Use GMP and use the "timing attack resistant" method
// The timing attack resistance slows down performance and is not necessarily proven to block timing attacks.
// Before getting concerned, please carefully consider your threat model
// and if you really believe that you may need it
result = Gmp.modPowSecure(base, exponent, modulus);
}
else
{
// The word "insecure" here does not imply any actual, direct insecurity.
// It denotes that this function runs as fast as possible without trying to
// counteract timing attacks. This is probably what you want unless you have a
// compelling reason why you believe that this environment is safe enough to house
// your keys but doesn't protect you from another entity on the machine watching
// how long the program runs.
result = Gmp.modPowInsecure(base, exponent, modulus);
}
}
else
{
// If GMP isn't used, BigInteger's built-in modPow is used.
// This is significantly slower but has the virtue of working everywhere.
result = base.modPow(exponent, modulus);
}
return result;
}
示例3: modPowSecure
import com.squareup.jnagmp.Gmp; //导入方法依赖的package包/类
/**
* computes a modular exponentiation. It will call the GMP library, if available on this system.
* If GMP is available, it will use 'mpz_powm_sec' which is side channel attack resistant.
* Use this function if you want to protect the exponent from side channel attacks.
* @param base of the modular exponentiation
* @param exponent of the exponentiation
* @param modulus
* @return (base ^ exponent) mod modulus
*/
public static BigInteger modPowSecure(BigInteger base, BigInteger exponent, BigInteger modulus) {
if (USE_GMP) {
return exponent.signum() < 0 // Gmp library can't handle negative exponents
? modInverse(Gmp.modPowSecure(base, exponent.negate(), modulus), modulus)
: Gmp.modPowSecure(base, exponent, modulus);
} else {
logger.log(Level.WARNING,
"Gmp library is not available. Falling back to native Java for modPow. This does not "
+ "provide protection against timing attacks!");
return base.modPow(exponent, modulus);
}
}
示例4: processBlock
import com.squareup.jnagmp.Gmp; //导入方法依赖的package包/类
/**
* Process a single block using the basic RSA algorithm.
*
* @param in the input array.
* @param inOff the offset into the input buffer where the data starts.
* @param inLen the length of the data to be processed.
* @return the result of the RSA process.
* @exception DataLengthException the input block is too large.
*/
@Override
public byte[] processBlock(final byte[] in, final int inOff, final int inLen) {
if (key == null) {
throw new IllegalStateException("RSA engine not initialised");
}
BigInteger input = core.convertInput(in, inOff, inLen);
BigInteger result;
if (key instanceof RSAPrivateCrtKeyParameters) {
RSAPrivateCrtKeyParameters k = (RSAPrivateCrtKeyParameters)key;
BigInteger e = k.getPublicExponent();
// can't do blinding without a public exponent
if (e != null) {
BigInteger m = k.getModulus();
BigInteger r = BigIntegers.createRandomInRange(ONE, m.subtract(ONE), random);
// This is a modification to use the GMP native library method
BigInteger blindedModPow = Gmp.modPowSecure(r, e, m);
BigInteger blindedInput = blindedModPow.multiply(input).mod(m);
BigInteger blindedResult = core.processBlock(blindedInput);
// This is a modification to use the GMP native library method
BigInteger rInv = Gmp.modInverse(r, m);
result = blindedResult.multiply(rInv).mod(m);
// defence against Arjen Lenstra’s CRT attack
// This is a modification to use the GMP native library method
if (!input.equals(Gmp.modPowInsecure(result, e, m))) {
throw new IllegalStateException("RSA engine faulty decryption/signing detected");
}
} else {
result = core.processBlock(input);
}
} else {
result = core.processBlock(input);
}
return core.convertOutput(result);
}