本文整理汇总了Java中com.squareup.jnagmp.Gmp类的典型用法代码示例。如果您正苦于以下问题:Java Gmp类的具体用法?Java Gmp怎么用?Java Gmp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Gmp类属于com.squareup.jnagmp包,在下文中一共展示了Gmp类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.squareup.jnagmp.Gmp; //导入依赖的package包/类
public static void main(String[] args) {
Gmp.checkLoaded();
testJavaPublic(NativeRSAVectors.VECTOR1, 512, 200000);
testJavaPublic(NativeRSAVectors.VECTOR2, 1024, 100000);
testJavaPublic(NativeRSAVectors.VECTOR3, 2048, 50000);
System.out.println();
testJava(NativeRSAVectors.VECTOR1, 512, 10000);
testJava(NativeRSAVectors.VECTOR2, 1024, 2000);
testJava(NativeRSAVectors.VECTOR3, 2048, 400);
System.out.println();
testNativePublic(NativeRSAVectors.VECTOR1, 512, 300000);
testNativePublic(NativeRSAVectors.VECTOR2, 1024, 150000);
testNativePublic(NativeRSAVectors.VECTOR3, 2048, 75000);
System.out.println();
testNative(NativeRSAVectors.VECTOR1, 512, 30000);
testNative(NativeRSAVectors.VECTOR2, 1024, 6000);
testNative(NativeRSAVectors.VECTOR3, 2048, 1200);
System.out.println();
}
示例2: canLoadGmp
import com.squareup.jnagmp.Gmp; //导入依赖的package包/类
private static boolean canLoadGmp(){
try{
Gmp.checkLoaded();
return true;
}catch(Error e){
logger.log(Level.WARNING, "can't load Gmp library. Falling back to native Java for modPow. Unfortunately, that's a 'lot' slower.", e);
return false;
}
}
示例3: 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
示例4: modInverse
import com.squareup.jnagmp.Gmp; //导入依赖的package包/类
public static BigInteger modInverse(BigInteger value, BigInteger modulus) {
if (gmpLoaded) {
return Gmp.modInverse(value, modulus);
} else {
return value.modInverse(modulus);
}
}
示例5: jacobiSymbol
import com.squareup.jnagmp.Gmp; //导入依赖的package包/类
public static int jacobiSymbol(BigInteger value, BigInteger n) {
if (gmpLoaded) {
return Gmp.kronecker(value, n);
} else {
return jacobiSymbol.computeJacobiSymbol(value, n);
}
}
示例6: modPow
import com.squareup.jnagmp.Gmp; //导入依赖的package包/类
public static BigInteger modPow(BigInteger base, BigInteger pow, BigInteger mod) {
MPBridge i = i();
// FIXME remove this test
if(i.debug) new Exception().printStackTrace();
if(i.recording) {
total++;
addModPow(base, pow, mod);
return i.dummy;
}
else if(i.replaying) {
return getModPow();
}
else if(i.replayingDebug) {
ModPowResult result = getModPowDebug();
boolean ok = base.equals(result.base()) && pow.equals(result.pow()) && mod.equals(result.mod());
if(!ok) throw new RuntimeException();
return result.result();
}
else {
total++;
if(useGmp) {
return Gmp.modPowInsecure(base, pow, mod);
}
else {
return base.modPow(pow, mod);
}
}
}
示例7: 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;
}
示例8: 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);
}
}
示例9: modPow
import com.squareup.jnagmp.Gmp; //导入依赖的package包/类
/**
* computes a modular exponentiation. It will call the GMP library, if available on this system.
* This leads to a significant speed-up.
* @param base of the modular exponentiation
* @param exponent of the exponentiation
* @param modulus
* @return (base ^ exponent) mod modulus
*/
public static BigInteger modPow(BigInteger base, BigInteger exponent, BigInteger modulus) {
if (USE_GMP) {
return exponent.signum() < 0 //Gmp library can't handle negative exponents
? modInverse(Gmp.modPowInsecure(base, exponent.negate(), modulus), modulus)
: Gmp.modPowInsecure(base, exponent, modulus);
} else {
return base.modPow(exponent, modulus);
}
}
示例10: 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);
}
示例11: checkLoaded
import com.squareup.jnagmp.Gmp; //导入依赖的package包/类
@BeforeClass public static void checkLoaded() {
Gmp.checkLoaded();
}
示例12: modInverse
import com.squareup.jnagmp.Gmp; //导入依赖的package包/类
/**
* Computes the multiplicitive inverse of `a` in the integers, modulo `b`.
*
* @param a the number to invert
* @param b the modulus
* @throws ArithmeticException if the inverse doesn't exist
* @return x, where a * x == 1 mod b
*/
public static BigInteger modInverse(BigInteger a, BigInteger b) throws ArithmeticException {
if(USE_GMP){
return Gmp.modInverse(a, b);
} else {
return a.modInverse(b);
}
}