Single retrieval of RSA_PKCS1 cipher instance

This commit is contained in:
Arnaud Fontaine 2017-08-26 18:34:59 +02:00
parent f1d0c6f276
commit 04404d6a4e

View File

@ -39,9 +39,12 @@ public final class PGPKey {
private KeyPair keys; private KeyPair keys;
private final Cipher cipher_rsa_pkcs1;
protected PGPKey() { protected PGPKey() {
cipher_rsa_pkcs1 = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, false);
fingerprint = new Fingerprint(); fingerprint = new Fingerprint();
generation_date = new byte[Constants.GENERATION_DATE_SIZE]; generation_date = new byte[Constants.GENERATION_DATE_SIZE];
@ -470,11 +473,10 @@ public final class PGPKey {
return 0; return 0;
} }
final Cipher cipher = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, false); cipher_rsa_pkcs1.init(priv, Cipher.MODE_ENCRYPT);
cipher.init(priv, Cipher.MODE_ENCRYPT);
off = cipher.doFinal(buf, (short)0, lc, off = cipher_rsa_pkcs1.doFinal(buf, (short)0, lc,
buf, (short)lc); buf, (short)lc);
return Util.arrayCopyNonAtomic(buf, (short)lc, return Util.arrayCopyNonAtomic(buf, (short)lc,
buf, (short)0, buf, (short)0,
@ -511,11 +513,10 @@ public final class PGPKey {
return 0; return 0;
} }
final Cipher cipher = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, false); cipher_rsa_pkcs1.init(priv, Cipher.MODE_DECRYPT);
cipher.init(priv, Cipher.MODE_DECRYPT);
final short len = cipher.doFinal(buf, (short)1, (short)(lc - 1), final short len = cipher_rsa_pkcs1.doFinal(buf, (short)1, (short)(lc - 1),
buf, (short)lc); buf, (short)lc);
off = Util.arrayCopyNonAtomic(buf, lc, off = Util.arrayCopyNonAtomic(buf, lc,
buf, (short)0, buf, (short)0,