public void HChaCha20BlockTestVector() { // https://tools.ietf.org/html/draft-irtf-cfrg-xchacha-03#section-2.2.1 // Arrange var key = CryptoBytes.FromHexString("00:01:02:03:04:05:06:07:08:09:0a:0b:0c:0d:0e:0f:10:11:12:13:14:15:16:17:18:19:1a:1b:1c:1d:1e:1f".Replace(":", string.Empty)); var nonce = CryptoBytes.FromHexString("00:00:00:09:00:00:00:4a:00:00:00:00:31:41:59:27".Replace(":", string.Empty)); var cipher = new XChaCha20(key, 0); // Act var subKey = new byte[32]; cipher.HChaCha20(subKey, nonce); var state = subKey.ToUInt16Array(); //var stateHex = CryptoBytes.ToHexStringLower(subKey.ToArray()); // Assert // HChaCha20 returns only the first and last rows var expectedState = new uint[] { 0x423b4182, 0xfe7bb227, 0x50420ed3, 0x737d878a, //0x0aa76448, 0x7954cdf3, 0x846acd37, 0x7b3c58ad, //0x77e35583, 0x83e77c12, 0xe0076a2d, 0xbc6cd0e5, 0xd5e4f9a0, 0x53a8748a, 0x13c42ec1, 0xdcecd326 }; // Same as above but in HEX //var expectedStateHex = "82413b4" + "227b27bfe" + "d30e4250" + "8a877d73" // + "a0f9e4d" + "58a74a853" + "c12ec413" + "26d3ecdc"; state.Should().BeEquivalentTo(expectedState); //stateHex.Should().Be(expectedStateHex); }
public void HChaCha20_computes_key() { // From https://trac.tools.ietf.org/html/draft-irtf-cfrg-xchacha-01#section-2.2.1 var key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f".DecodeHex(); var nonce = "000000090000004a0000000031415927".DecodeHex(); var expected = "82413b4227b27bfed30e42508a877d73a0f9e4d58a74a853c12ec41326d3ecdc".DecodeHex(); var result = new byte[32]; XChaCha20.HChaCha20(key, nonce, result); Assert.Equal(expected, result); }
public void HChaCha20TestVectors() { // Arrange foreach (var test in HChaCha20TestVector.HChaCha20TestVectors) { var cipher = new XChaCha20(test.Key, 0); // Act var output = new byte[Snuffle.KEY_SIZE_IN_BYTES]; cipher.HChaCha20(output, test.Input); // Assert output.Should().Equal(test.Output); } }
public void HChaCha20TestVectors() { // Arrange foreach (var test in HChaCha20TestVector.HChaCha20TestVectors) { var cipher = new XChaCha20(test.Key, 0); // Act var output = cipher.HChaCha20(test.Input); // Assert //Assert.That(output, Is.EqualTo(test.Output)); Assert.IsTrue(CryptoBytes.ConstantTimeEquals(test.Output, output)); } }