Final crypto changes for BTPv2. #111

Use BLAKE2s to generate tags.
KDF arguments for key rotation.
Frame IV format.
This commit is contained in:
akwizgran
2016-01-01 14:53:54 +00:00
parent 19bfe71f18
commit 6a4aea77fb
7 changed files with 103 additions and 70 deletions

View File

@@ -30,24 +30,39 @@ public class ByteUtilsTest extends BriarTestCase {
@Test
public void testWriteUint16() {
byte[] b = new byte[3];
byte[] b = new byte[4];
ByteUtils.writeUint16(0, b, 1);
assertEquals("000000", StringUtils.toHexString(b));
assertEquals("00000000", StringUtils.toHexString(b));
ByteUtils.writeUint16(1, b, 1);
assertEquals("000001", StringUtils.toHexString(b));
ByteUtils.writeUint16(65535, b, 1);
assertEquals("00FFFF", StringUtils.toHexString(b));
assertEquals("00000100", StringUtils.toHexString(b));
ByteUtils.writeUint16(Short.MAX_VALUE, b, 1);
assertEquals("007FFF00", StringUtils.toHexString(b));
ByteUtils.writeUint16(ByteUtils.MAX_16_BIT_UNSIGNED, b, 1);
assertEquals("00FFFF00", StringUtils.toHexString(b));
}
@Test
public void testWriteUint32() {
byte[] b = new byte[5];
byte[] b = new byte[6];
ByteUtils.writeUint32(0, b, 1);
assertEquals("0000000000", StringUtils.toHexString(b));
assertEquals("000000000000", StringUtils.toHexString(b));
ByteUtils.writeUint32(1, b, 1);
assertEquals("0000000001", StringUtils.toHexString(b));
ByteUtils.writeUint32(4294967295L, b, 1);
assertEquals("00FFFFFFFF", StringUtils.toHexString(b));
assertEquals("000000000100", StringUtils.toHexString(b));
ByteUtils.writeUint32(Integer.MAX_VALUE, b, 1);
assertEquals("007FFFFFFF00", StringUtils.toHexString(b));
ByteUtils.writeUint32(ByteUtils.MAX_32_BIT_UNSIGNED, b, 1);
assertEquals("00FFFFFFFF00", StringUtils.toHexString(b));
}
@Test
public void testWriteUint64() {
byte[] b = new byte[10];
ByteUtils.writeUint64(0, b, 1);
assertEquals("00000000000000000000", StringUtils.toHexString(b));
ByteUtils.writeUint64(1, b, 1);
assertEquals("00000000000000000100", StringUtils.toHexString(b));
ByteUtils.writeUint64(Long.MAX_VALUE, b, 1);
assertEquals("007FFFFFFFFFFFFFFF00", StringUtils.toHexString(b));
}
@Test