Package net.i2p.router.transport.crypto
Class DHSessionKeyBuilder
- java.lang.Object
-
- net.i2p.router.transport.crypto.DHSessionKeyBuilder
-
public class DHSessionKeyBuilder extends Object
Generate a new session key through a diffie hellman exchange. This uses the constants defined in CryptoConstants, which causes the exchange to create a 256 bit session key. This class precalcs a set of values on its own thread. Whenever the pool has less than the minimum, it fills it up again to the max. There is a delay after each precalculation so that the CPU isn't hosed during startup. These three parameters are controlled by java environmental variables and can be adjusted via: -Dcrypto.dh.precalc.min=40 -Dcrypto.dh.precalc.max=100 -Dcrypto.dh.precalc.delay=60000 (delay is milliseconds) To disable precalculation, set min to 0- Since:
- 0.9 moved from net.i2p.crypto
- Author:
- jrandom
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
DHSessionKeyBuilder.Factory
static class
DHSessionKeyBuilder.InvalidPublicParameterException
static class
DHSessionKeyBuilder.PrecalcRunner
Try to keep DH pairs at the ready.
-
Constructor Summary
Constructors Constructor Description DHSessionKeyBuilder()
Create a new public/private value pair for the DH exchange.DHSessionKeyBuilder(I2PAppContext ctx)
Create a new public/private value pair for the DH exchange.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ByteArray
getExtraBytes()
Retrieve the extra bytes beyond the session key resulting from the DH exchange.BigInteger
getMyPublicValue()
Retrieve the public value used by the local participant in the DH exchange,byte[]
getMyPublicValueBytes()
Return a 256 byte representation of our public key, with leading 0s if necessary.BigInteger
getPeerPublicValue()
byte[]
getPeerPublicValueBytes()
Return a 256 byte representation of his public key, with leading 0s if necessary.SessionKey
getSessionKey()
Retrieve the session key, calculating it if necessary (and if possible).void
setPeerPublicValue(byte[] val)
void
setPeerPublicValue(BigInteger peerVal)
Specify the value given by the peer for use in the session key negotiation
-
-
-
Constructor Detail
-
DHSessionKeyBuilder
DHSessionKeyBuilder()
Create a new public/private value pair for the DH exchange. Only for internal use and unit tests. Others should get instances from PrecalcRunner.getBuilder()
-
DHSessionKeyBuilder
DHSessionKeyBuilder(I2PAppContext ctx)
Create a new public/private value pair for the DH exchange. Only for internal use and unit tests. Others should get instances from PrecalcRunner.getBuilder()
-
-
Method Detail
-
getMyPublicValue
public BigInteger getMyPublicValue()
Retrieve the public value used by the local participant in the DH exchange,
-
getMyPublicValueBytes
public byte[] getMyPublicValueBytes()
Return a 256 byte representation of our public key, with leading 0s if necessary.
-
setPeerPublicValue
public void setPeerPublicValue(BigInteger peerVal) throws DHSessionKeyBuilder.InvalidPublicParameterException
Specify the value given by the peer for use in the session key negotiation- Throws:
IllegalStateException
- if already setDHSessionKeyBuilder.InvalidPublicParameterException
-
setPeerPublicValue
public void setPeerPublicValue(byte[] val) throws DHSessionKeyBuilder.InvalidPublicParameterException
- Parameters:
val
- 256 bytes- Throws:
DHSessionKeyBuilder.InvalidPublicParameterException
-
getPeerPublicValue
public BigInteger getPeerPublicValue()
-
getPeerPublicValueBytes
public byte[] getPeerPublicValueBytes()
Return a 256 byte representation of his public key, with leading 0s if necessary.
-
getSessionKey
public SessionKey getSessionKey()
Retrieve the session key, calculating it if necessary (and if possible).- Returns:
- session key exchanged, or null if the exchange is not complete
-
getExtraBytes
public ByteArray getExtraBytes()
Retrieve the extra bytes beyond the session key resulting from the DH exchange. If there aren't enough bytes (with all of them being consumed by the 32 byte key), the SHA256 of the key itself is used - but that won't ever happen. Used only by UDP. getData() will be non-null and have at least 32 bytes after call to getSessionKey()- Returns:
- non-null (but rv.getData() may be null)
-
-