forked from I2P_Developers/i2p.i2p
KeyGenerator: Use new PrivateKey constructor to cache pubkey
Clear cached public key on private key destroy()
This commit is contained in:
@ -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:
|
||||
|
@ -123,6 +123,7 @@ public class PrivateKey extends SimpleDataStructure implements Destroyable {
|
||||
Arrays.fill(data, (byte) 0);
|
||||
SimpleByteCache.release(data);
|
||||
}
|
||||
_pubKey = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user