First pass of the UDP transport. No where near ready for use, but it does

the basics (negotiate a session and send I2NP messages back and forth).  Lots,
lots more left.
This commit is contained in:
jrandom
2005-04-12 16:48:43 +00:00
committed by zzz
parent 5b56d22da9
commit 7beb92b1cc
34 changed files with 5744 additions and 47 deletions

View File

@ -247,6 +247,23 @@ public class DHSessionKeyBuilder {
if (_myPublicValue == null) _myPublicValue = generateMyValue();
return _myPublicValue;
}
/**
* Return a 256 byte representation of our public key, with leading 0s
* if necessary.
*
*/
public byte[] getMyPublicValueBytes() {
BigInteger bi = getMyPublicValue();
byte data[] = bi.toByteArray();
byte rv[] = new byte[256];
if (data.length == 257) // high byte has the sign bit
System.arraycopy(data, 1, rv, 0, rv.length);
else if (data.length == 256)
System.arraycopy(data, 0, rv, 0, rv.length);
else
System.arraycopy(data, 0, rv, rv.length-data.length, data.length);
return rv;
}
/**
* Specify the value given by the peer for use in the session key negotiation
@ -255,6 +272,20 @@ public class DHSessionKeyBuilder {
public void setPeerPublicValue(BigInteger peerVal) {
_peerValue = peerVal;
}
public void setPeerPublicValue(byte val[]) {
if (val.length != 256)
throw new IllegalArgumentException("Peer public value must be exactly 256 bytes");
if (1 == (val[0] & 0x80)) {
// high bit set, need to inject an additional byte to keep 2s complement
if (_log.shouldLog(Log.DEBUG))
_log.debug("High bit set");
byte val2[] = new byte[257];
System.arraycopy(val, 0, val2, 1, 256);
val = val2;
}
_peerValue = new NativeBigInteger(val);
}
public BigInteger getPeerPublicValue() {
return _peerValue;