forked from I2P_Developers/i2p.i2p
Router: Don't re-derive public key from private for every HandshakeState
This commit is contained in:
@ -107,6 +107,10 @@ class Curve25519DHState implements DHState, Cloneable {
|
||||
System.arraycopy(privateKey, 0, key, offset, 32);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use setKeys()
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public void setPrivateKey(byte[] key, int offset) {
|
||||
System.arraycopy(key, offset, privateKey, 0, 32);
|
||||
@ -114,6 +118,25 @@ class Curve25519DHState implements DHState, Cloneable {
|
||||
mode = 0x03;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the private and public keys for this object.
|
||||
* I2P for efficiency, since setPrivateKey() calculates the public key
|
||||
* and overwrites it.
|
||||
* Does NOT check that the two keys match.
|
||||
*
|
||||
* @param privkey The buffer containing the private key.
|
||||
* @param privoffset The first offset in the buffer that contains the key.
|
||||
* @param pubkey The buffer containing the public key.
|
||||
* @param puboffset The first offset in the buffer that contains the key.
|
||||
* @since 0.9.48
|
||||
*/
|
||||
@Override
|
||||
public void setKeys(byte[] privkey, int privoffset, byte[] pubkey, int puboffset) {
|
||||
System.arraycopy(privkey, privoffset, privateKey, 0, 32);
|
||||
System.arraycopy(pubkey, puboffset, publicKey, 0, 32);
|
||||
mode = 0x03;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setToNullPublicKey() {
|
||||
Arrays.fill(publicKey, (byte)0);
|
||||
|
@ -95,9 +95,26 @@ public interface DHState extends Destroyable, Cloneable {
|
||||
*
|
||||
* If this object previously held only a public key, then
|
||||
* this function will change it into a key pair.
|
||||
*
|
||||
* @deprecated use setKeys()
|
||||
*/
|
||||
@Deprecated
|
||||
void setPrivateKey(byte[] key, int offset);
|
||||
|
||||
/**
|
||||
* Sets the private and public keys for this object.
|
||||
* I2P for efficiency, since setPrivateKey() calculates the public key
|
||||
* and overwrites it.
|
||||
* Does NOT check that the two keys match.
|
||||
*
|
||||
* @param privkey The buffer containing the private key.
|
||||
* @param privoffset The first offset in the buffer that contains the key.
|
||||
* @param pubkey The buffer containing the private key.
|
||||
* @param puboffset The first offset in the buffer that contains the key.
|
||||
* @since 0.9.48
|
||||
*/
|
||||
void setKeys(byte[] privkey, int privoffset, byte[] pubkey, int puboffset);
|
||||
|
||||
/**
|
||||
* Sets this object to the null public key and clears the private key.
|
||||
*/
|
||||
|
@ -380,8 +380,8 @@ public class BuildRequestRecord {
|
||||
try {
|
||||
KeyFactory kf = TEST ? TESTKF : ctx.commSystem().getXDHFactory();
|
||||
state = new HandshakeState(HandshakeState.PATTERN_ID_N, HandshakeState.RESPONDER, kf);
|
||||
state.getLocalKeyPair().setPublicKey(ourKey.toPublic().getData(), 0);
|
||||
state.getLocalKeyPair().setPrivateKey(ourKey.getData(), 0);
|
||||
state.getLocalKeyPair().setKeys(ourKey.getData(), 0,
|
||||
ourKey.toPublic().getData(), 0);
|
||||
state.start();
|
||||
decrypted = new byte[LENGTH_EC];
|
||||
state.readMessage(encryptedRecord.getData(), PEER_SIZE, EncryptedBuildRecord.LENGTH - PEER_SIZE,
|
||||
|
@ -356,8 +356,8 @@ public final class ECIESAEADEngine {
|
||||
} catch (GeneralSecurityException gse) {
|
||||
throw new IllegalStateException("bad proto", gse);
|
||||
}
|
||||
state.getLocalKeyPair().setPublicKey(targetPrivateKey.toPublic().getData(), 0);
|
||||
state.getLocalKeyPair().setPrivateKey(targetPrivateKey.getData(), 0);
|
||||
state.getLocalKeyPair().setKeys(targetPrivateKey.getData(), 0,
|
||||
targetPrivateKey.toPublic().getData(), 0);
|
||||
state.start();
|
||||
if (_log.shouldDebug())
|
||||
_log.debug("State before decrypt new session: " + state);
|
||||
@ -786,8 +786,8 @@ public final class ECIESAEADEngine {
|
||||
throw new IllegalStateException("bad proto", gse);
|
||||
}
|
||||
state.getRemotePublicKey().setPublicKey(target.getData(), 0);
|
||||
state.getLocalKeyPair().setPublicKey(priv.toPublic().getData(), 0);
|
||||
state.getLocalKeyPair().setPrivateKey(priv.getData(), 0);
|
||||
state.getLocalKeyPair().setKeys(priv.getData(), 0,
|
||||
priv.toPublic().getData(), 0);
|
||||
state.start();
|
||||
if (_log.shouldDebug())
|
||||
_log.debug("State before encrypt new session: " + state);
|
||||
|
@ -685,8 +685,8 @@ class InboundEstablishState extends EstablishBase implements NTCP2Payload.Payloa
|
||||
} catch (GeneralSecurityException gse) {
|
||||
throw new IllegalStateException("bad proto", gse);
|
||||
}
|
||||
_handshakeState.getLocalKeyPair().setPublicKey(_transport.getNTCP2StaticPubkey(), 0);
|
||||
_handshakeState.getLocalKeyPair().setPrivateKey(_transport.getNTCP2StaticPrivkey(), 0);
|
||||
_handshakeState.getLocalKeyPair().setKeys(_transport.getNTCP2StaticPrivkey(), 0,
|
||||
_transport.getNTCP2StaticPubkey(), 0);
|
||||
Hash h = _context.routerHash();
|
||||
SessionKey bobHash = new SessionKey(h.getData());
|
||||
// save encrypted data for CBC for msg 2
|
||||
|
@ -217,8 +217,8 @@ class OutboundNTCP2State implements EstablishState {
|
||||
return;
|
||||
}
|
||||
_handshakeState.getRemotePublicKey().setPublicKey(bk, 0);
|
||||
_handshakeState.getLocalKeyPair().setPublicKey(_transport.getNTCP2StaticPubkey(), 0);
|
||||
_handshakeState.getLocalKeyPair().setPrivateKey(_transport.getNTCP2StaticPrivkey(), 0);
|
||||
_handshakeState.getLocalKeyPair().setKeys(_transport.getNTCP2StaticPrivkey(), 0,
|
||||
_transport.getNTCP2StaticPubkey(), 0);
|
||||
// output to _tmp
|
||||
try {
|
||||
_handshakeState.start();
|
||||
|
Reference in New Issue
Block a user