Search in sources :

Example 1 with GmpInteger

use of com.squareup.jnagmp.GmpInteger in project universa by UniversaBlockchain.

the class NativeRSACoreEngine method init.

/**
 * initialise the RSA engine.
 *
 * @param forEncryption true if we are encrypting, false otherwise.
 * @param param         the necessary RSA key parameters.
 */
public void init(boolean forEncryption, CipherParameters param) {
    if (param instanceof ParametersWithRandom) {
        ParametersWithRandom rParam = (ParametersWithRandom) param;
        key = (RSAKeyParameters) rParam.getParameters();
    } else {
        key = (RSAKeyParameters) param;
    }
    this.forEncryption = forEncryption;
    if (key instanceof RSAPrivateCrtKeyParameters) {
        isPrivate = true;
        // 
        // we have the extra factors, use the Chinese Remainder Theorem - the author
        // wishes to express his thanks to Dirk Bonekaemper at rtsffm.com for
        // advice regarding the expression of this.
        // 
        RSAPrivateCrtKeyParameters crtKey = (RSAPrivateCrtKeyParameters) key;
        p = new GmpInteger(crtKey.getP());
        q = new GmpInteger(crtKey.getQ());
        dP = new GmpInteger(crtKey.getDP());
        dQ = new GmpInteger(crtKey.getDQ());
        qInv = crtKey.getQInv();
        exponent = modulus = null;
    } else {
        isPrivate = false;
        exponent = new GmpInteger(key.getExponent());
        modulus = new GmpInteger(key.getModulus());
        isSmallExponent = exponent.bitLength() < 64;
        p = q = dP = dQ = null;
        qInv = null;
    }
}
Also used : GmpInteger(com.squareup.jnagmp.GmpInteger) ParametersWithRandom(org.spongycastle.crypto.params.ParametersWithRandom) RSAPrivateCrtKeyParameters(org.spongycastle.crypto.params.RSAPrivateCrtKeyParameters)

Aggregations

GmpInteger (com.squareup.jnagmp.GmpInteger)1 ParametersWithRandom (org.spongycastle.crypto.params.ParametersWithRandom)1 RSAPrivateCrtKeyParameters (org.spongycastle.crypto.params.RSAPrivateCrtKeyParameters)1