Files
briar/components/net/sf/briar/transport/IvEncoder.java
akwizgran 51d58fadad Include the frame number in the header.
This ensures the frame number is covered by the MAC, cleanly
separating encryption from authentication (previously we depended on
the encryption layer to garble frames if they were reordered).
2011-12-02 13:37:44 +00:00

20 lines
492 B
Java

package net.sf.briar.transport;
import net.sf.briar.util.ByteUtils;
class IvEncoder {
static byte[] encodeIv(long frame, int blockSize) {
if(frame < 0 || frame > ByteUtils.MAX_32_BIT_UNSIGNED)
throw new IllegalArgumentException();
byte[] iv = new byte[blockSize];
updateIv(iv, frame);
return iv;
}
static void updateIv(byte[] iv, long frame) {
// Encode the frame number as a uint32, leaving 2 bytes for the counter
ByteUtils.writeUint32(frame, iv, iv.length - 6);
}
}