forked from I2P_Developers/i2p.i2p
update generateKeyPair() return type to make it easier
This commit is contained in:
@ -20,6 +20,7 @@ import net.i2p.data.SessionKey;
|
|||||||
import net.i2p.data.Signature;
|
import net.i2p.data.Signature;
|
||||||
import net.i2p.data.SigningPrivateKey;
|
import net.i2p.data.SigningPrivateKey;
|
||||||
import net.i2p.data.SigningPublicKey;
|
import net.i2p.data.SigningPublicKey;
|
||||||
|
import net.i2p.data.SimpleDataStructure;
|
||||||
import net.i2p.util.Clock;
|
import net.i2p.util.Clock;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
import net.i2p.util.NativeBigInteger;
|
import net.i2p.util.NativeBigInteger;
|
||||||
@ -29,18 +30,17 @@ import net.i2p.util.RandomSource;
|
|||||||
* @author jrandom
|
* @author jrandom
|
||||||
*/
|
*/
|
||||||
public class KeyGenerator {
|
public class KeyGenerator {
|
||||||
private Log _log;
|
private final Log _log;
|
||||||
private I2PAppContext _context;
|
private final I2PAppContext _context;
|
||||||
|
|
||||||
public KeyGenerator(I2PAppContext context) {
|
public KeyGenerator(I2PAppContext context) {
|
||||||
_log = context.logManager().getLog(KeyGenerator.class);
|
_log = context.logManager().getLog(KeyGenerator.class);
|
||||||
_context = context;
|
_context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static KeyGenerator getInstance() {
|
public static KeyGenerator getInstance() {
|
||||||
return I2PAppContext.getGlobalContext().keyGenerator();
|
return I2PAppContext.getGlobalContext().keyGenerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Generate a private 256 bit session key
|
/** Generate a private 256 bit session key
|
||||||
* @return session key
|
* @return session key
|
||||||
@ -84,11 +84,11 @@ public class KeyGenerator {
|
|||||||
* index 1 is a PrivateKey
|
* index 1 is a PrivateKey
|
||||||
* @return pair of keys
|
* @return pair of keys
|
||||||
*/
|
*/
|
||||||
public Object[] generatePKIKeypair() {
|
public SimpleDataStructure[] generatePKIKeypair() {
|
||||||
BigInteger a = new NativeBigInteger(PUBKEY_EXPONENT_SIZE, _context.random());
|
BigInteger a = new NativeBigInteger(PUBKEY_EXPONENT_SIZE, _context.random());
|
||||||
BigInteger aalpha = CryptoConstants.elgg.modPow(a, CryptoConstants.elgp);
|
BigInteger aalpha = CryptoConstants.elgg.modPow(a, CryptoConstants.elgp);
|
||||||
|
|
||||||
Object[] keys = new Object[2];
|
SimpleDataStructure[] keys = new SimpleDataStructure[2];
|
||||||
keys[0] = new PublicKey();
|
keys[0] = new PublicKey();
|
||||||
keys[1] = new PrivateKey();
|
keys[1] = new PrivateKey();
|
||||||
byte[] k0 = aalpha.toByteArray();
|
byte[] k0 = aalpha.toByteArray();
|
||||||
@ -97,8 +97,8 @@ public class KeyGenerator {
|
|||||||
// bigInteger.toByteArray returns SIGNED integers, but since they'return positive,
|
// bigInteger.toByteArray returns SIGNED integers, but since they'return positive,
|
||||||
// signed two's complement is the same as unsigned
|
// signed two's complement is the same as unsigned
|
||||||
|
|
||||||
((PublicKey) keys[0]).setData(padBuffer(k0, PublicKey.KEYSIZE_BYTES));
|
keys[0].setData(padBuffer(k0, PublicKey.KEYSIZE_BYTES));
|
||||||
((PrivateKey) keys[1]).setData(padBuffer(k1, PrivateKey.KEYSIZE_BYTES));
|
keys[1].setData(padBuffer(k1, PrivateKey.KEYSIZE_BYTES));
|
||||||
|
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
@ -120,8 +120,8 @@ public class KeyGenerator {
|
|||||||
* index 1 is a SigningPrivateKey
|
* index 1 is a SigningPrivateKey
|
||||||
* @return pair of keys
|
* @return pair of keys
|
||||||
*/
|
*/
|
||||||
public Object[] generateSigningKeypair() {
|
public SimpleDataStructure[] generateSigningKeypair() {
|
||||||
Object[] keys = new Object[2];
|
SimpleDataStructure[] keys = new SimpleDataStructure[2];
|
||||||
BigInteger x = null;
|
BigInteger x = null;
|
||||||
|
|
||||||
// make sure the random key is less than the DSA q
|
// make sure the random key is less than the DSA q
|
||||||
@ -135,8 +135,8 @@ public class KeyGenerator {
|
|||||||
byte k0[] = padBuffer(y.toByteArray(), SigningPublicKey.KEYSIZE_BYTES);
|
byte k0[] = padBuffer(y.toByteArray(), SigningPublicKey.KEYSIZE_BYTES);
|
||||||
byte k1[] = padBuffer(x.toByteArray(), SigningPrivateKey.KEYSIZE_BYTES);
|
byte k1[] = padBuffer(x.toByteArray(), SigningPrivateKey.KEYSIZE_BYTES);
|
||||||
|
|
||||||
((SigningPublicKey) keys[0]).setData(k0);
|
keys[0].setData(k0);
|
||||||
((SigningPrivateKey) keys[1]).setData(k1);
|
keys[1].setData(k1);
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user