KeyGenerator: Use new PrivateKey constructor to cache pubkey

Clear cached public key on private key destroy()
This commit is contained in:
zzz
2019-11-11 14:24:11 +00:00
parent 9d46a5d838
commit 9ddb655a88
2 changed files with 7 additions and 5 deletions

View File

@ -159,15 +159,16 @@ public final class KeyGenerator {
BigInteger aalpha = CryptoConstants.elgg.modPow(a, CryptoConstants.elgp);
SimpleDataStructure[] keys = new SimpleDataStructure[2];
keys[0] = new PublicKey();
keys[1] = new PrivateKey();
// bigInteger.toByteArray returns SIGNED integers, but since they'return positive,
// signed two's complement is the same as unsigned
try {
keys[0].setData(SigUtil.rectify(aalpha, PublicKey.KEYSIZE_BYTES));
keys[1].setData(SigUtil.rectify(a, PrivateKey.KEYSIZE_BYTES));
PublicKey pub = new PublicKey(SigUtil.rectify(aalpha, PublicKey.KEYSIZE_BYTES));
keys[0] = pub;
keys[1] = new PrivateKey(EncType.ELGAMAL_2048,
SigUtil.rectify(a, PrivateKey.KEYSIZE_BYTES),
pub);
} catch (InvalidKeyException ike) {
throw new IllegalArgumentException(ike);
}
@ -199,7 +200,7 @@ public final class KeyGenerator {
byte[] bpub = new byte[32];
Curve25519.eval(bpub, 0, bpriv, null);
pub = new PublicKey(type, bpub);
priv = new PrivateKey(type, bpriv);
priv = new PrivateKey(type, bpriv, pub);
break;
default:

View File

@ -123,6 +123,7 @@ public class PrivateKey extends SimpleDataStructure implements Destroyable {
Arrays.fill(data, (byte) 0);
SimpleByteCache.release(data);
}
_pubKey = null;
}
/**