Further simplified I2P repliable datagram format: they now contain

senderPubDest + S(H(payload)) + payload
(human)
This commit is contained in:
human
2004-04-19 21:43:06 +00:00
committed by zzz
parent 5e78a41b75
commit 3658cca3e5
2 changed files with 13 additions and 20 deletions

View File

@ -59,20 +59,20 @@ public final class I2PDatagramDissector {
*/
public void loadI2PDatagram(byte[] dgram) throws DataFormatException {
ByteArrayInputStream dgStream = new ByteArrayInputStream(dgram);
byte[] hashedData;
byte[] rxTrimmedPayload;
try {
rxDest.readBytes(dgStream);
rxSign.readBytes(dgStream);
rxDest.readBytes(dgStream);
rxPayloadLen = dgStream.read(rxPayload);
// FIXME: hashGen.calculateHash(source, offset, len) would rock...
rxTrimmedPayload = new byte[rxPayloadLen];
System.arraycopy(rxPayload, 0, rxTrimmedPayload, 0, rxPayloadLen);
hashedData = new byte[dgram.length - Signature.SIGNATURE_BYTES];
System.arraycopy(dgram, Signature.SIGNATURE_BYTES,
hashedData, 0,
hashedData.length);
rxHashBytes = hashGen.calculateHash(hashedData).toByteArray();
rxHashBytes =hashGen.calculateHash(rxTrimmedPayload).toByteArray();
} catch (IOException e) {
_log.error("Caught IOException - INCONSISTENT STATE!", e);
}

View File

@ -36,7 +36,6 @@ public final class I2PDatagramMaker {
private SigningPrivateKey sxPrivKey = null;
private byte[] sxDestBytes = null;
private ByteArrayOutputStream sxBuf = new ByteArrayOutputStream(DGRAM_BUFSIZE);
private ByteArrayOutputStream sxDGram = new ByteArrayOutputStream(DGRAM_BUFSIZE);
/**
@ -56,22 +55,16 @@ public final class I2PDatagramMaker {
* @param payload Bytes to be contained in the I2P datagram.
*/
public byte[] makeI2PDatagram(byte[] payload) {
byte[] hashedData;
sxBuf.reset();
sxDGram.reset();
try {
sxBuf.write(sxDestBytes);
sxBuf.write(payload);
hashedData = sxBuf.toByteArray();
dsaEng.sign(hashGen.calculateHash(hashedData).toByteArray(),
sxDGram.write(sxDestBytes);
dsaEng.sign(hashGen.calculateHash(payload).toByteArray(),
sxPrivKey).writeBytes(sxDGram);
sxDGram.write(hashedData);
sxDGram.write(payload);
return sxDGram.toByteArray();
} catch (IOException e) {
_log.error("Caught IOException", e);