mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
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).
20 lines
492 B
Java
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);
|
|
}
|
|
}
|