forked from I2P_Developers/i2p.i2p
* SSU:
- Ignore padding beyond last multiple of 16 (prep for obfuscation) - Comment out xor with 0 (version) - Don't need to zero IV buf before overwriting * AES: - Decrypt speedup by XOR in place - Log if decrypt not mod 16
This commit is contained in:
@@ -121,8 +121,11 @@ class PacketBuilder {
|
||||
static final int TYPE_SREQ = 52;
|
||||
static final int TYPE_CREAT = 53;
|
||||
|
||||
/** we only talk to people of the right version */
|
||||
/** we only talk to people of the right version
|
||||
* Commented out to prevent findbugs noop complaint
|
||||
* If we ever change this, uncomment below and in UDPPacket
|
||||
static final int PROTOCOL_VERSION = 0;
|
||||
*/
|
||||
|
||||
/** if no extended options or rekey data, which we don't support = 37 */
|
||||
public static final int HEADER_SIZE = UDPPacket.MAC_SIZE + UDPPacket.IV_SIZE + 1 + 4;
|
||||
@@ -1317,7 +1320,7 @@ class PacketBuilder {
|
||||
off += encryptSize;
|
||||
System.arraycopy(iv, 0, data, off, UDPPacket.IV_SIZE);
|
||||
off += UDPPacket.IV_SIZE;
|
||||
DataHelper.toLong(data, off, 2, encryptSize ^ PROTOCOL_VERSION);
|
||||
DataHelper.toLong(data, off, 2, encryptSize /* ^ PROTOCOL_VERSION */ );
|
||||
|
||||
int hmacOff = packet.getPacket().getOffset();
|
||||
int hmacLen = encryptSize + UDPPacket.IV_SIZE + 2;
|
||||
|
@@ -202,7 +202,7 @@ class UDPPacket implements CDQEntry {
|
||||
off += payloadLength;
|
||||
System.arraycopy(_data, _packet.getOffset() + MAC_SIZE, _validateBuf, off, IV_SIZE);
|
||||
off += IV_SIZE;
|
||||
DataHelper.toLong(_validateBuf, off, 2, payloadLength ^ PacketBuilder.PROTOCOL_VERSION);
|
||||
DataHelper.toLong(_validateBuf, off, 2, payloadLength /* ^ PacketBuilder.PROTOCOL_VERSION */ );
|
||||
off += 2;
|
||||
|
||||
eq = _context.hmac().verify(macKey, _validateBuf, 0, off, _data, _packet.getOffset(), MAC_SIZE);
|
||||
@@ -241,10 +241,18 @@ class UDPPacket implements CDQEntry {
|
||||
*/
|
||||
public void decrypt(SessionKey cipherKey) {
|
||||
verifyNotReleased();
|
||||
Arrays.fill(_ivBuf, (byte)0);
|
||||
System.arraycopy(_data, MAC_SIZE, _ivBuf, 0, IV_SIZE);
|
||||
int len = _packet.getLength();
|
||||
_context.aes().decrypt(_data, _packet.getOffset() + MAC_SIZE + IV_SIZE, _data, _packet.getOffset() + MAC_SIZE + IV_SIZE, cipherKey, _ivBuf, len - MAC_SIZE - IV_SIZE);
|
||||
// As of 0.9.7, ignore padding beyond the last mod 16,
|
||||
// it could otherwise blow up in decryption.
|
||||
// This allows for better obfuscation.
|
||||
// Probably works without this since _data is bigger than necessary, but let's not
|
||||
// bother decrypting and risk overrun.
|
||||
int rem = len & 0x0f;
|
||||
if (rem != 0)
|
||||
len -= rem;
|
||||
int off = _packet.getOffset() + MAC_SIZE + IV_SIZE;
|
||||
_context.aes().decrypt(_data, off, _data, off, cipherKey, _ivBuf, len - MAC_SIZE - IV_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user