mirror of
https://github.com/wismna/ModernKeePassLib.git
synced 2025-10-03 15:40:20 -04:00
Removed useless Bouncy Castle package and test
Migrated to Nunit Refactor
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
using ModernKeePassLib.Serialization;
|
||||
using ModernKeePassLib.Cryptography;
|
||||
using ModernKeePassLib.Cryptography.Cipher;
|
||||
using ModernKeePassLib.Utility;
|
||||
using Org.BouncyCastle.Crypto.Engines;
|
||||
using Org.BouncyCastle.Crypto.Parameters;
|
||||
using Xunit;
|
||||
using System.Security.Cryptography;
|
||||
using ModernKeePassLib.Cryptography;
|
||||
|
||||
namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
{
|
||||
[TestFixture]
|
||||
public class AesTests
|
||||
{
|
||||
// Test vector (official ECB test vector #356)
|
||||
@@ -27,7 +26,7 @@ namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestEncryptStream()
|
||||
{
|
||||
var a = CryptoUtil.CreateAes();
|
||||
@@ -45,35 +44,20 @@ namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
|
||||
iCrypt.TransformBlock(_pbTestData, 0, 16, _pbTestData, 0);
|
||||
|
||||
Assert.True(MemUtil.ArraysEqual(_pbTestData, _pbReferenceCt));
|
||||
Assert.That(MemUtil.ArraysEqual(_pbTestData, _pbReferenceCt), Is.True);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestDecryptStream()
|
||||
{
|
||||
// Possible Mono Bug? This only works with size >= 48
|
||||
using (var inStream = new MemoryStream(new byte[32]))
|
||||
{
|
||||
inStream.Write(_pbReferenceCt, 0, _pbReferenceCt.Length);
|
||||
inStream.Position = 0;
|
||||
var aes = new StandardAesEngine();
|
||||
using (var outStream = aes.DecryptStream(inStream, _pbTestKey, _pbIv))
|
||||
{
|
||||
var outBytes = new BinaryReaderEx(outStream, Encoding.UTF8, string.Empty).ReadBytes(16);
|
||||
Assert.True(MemUtil.ArraysEqual(outBytes, _pbTestData));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestBouncyCastleAes()
|
||||
{
|
||||
var aesEngine = new AesEngine();
|
||||
//var parametersWithIv = new ParametersWithIV(new KeyParameter(pbTestKey), pbIV);
|
||||
aesEngine.Init(true, new KeyParameter(_pbTestKey));
|
||||
Assert.Equal(_pbTestData.Length, aesEngine.GetBlockSize());
|
||||
aesEngine.ProcessBlock(_pbTestData, 0, _pbTestData, 0);
|
||||
Assert.True(MemUtil.ArraysEqual(_pbReferenceCt,_pbTestData));
|
||||
using var inStream = new MemoryStream(new byte[32]);
|
||||
inStream.Write(_pbReferenceCt, 0, _pbReferenceCt.Length);
|
||||
inStream.Position = 0;
|
||||
var aes = new StandardAesEngine();
|
||||
using var outStream = aes.DecryptStream(inStream, _pbTestKey, _pbIv);
|
||||
var outBytes = new BinaryReaderEx(outStream, Encoding.UTF8, string.Empty).ReadBytes(16);
|
||||
Assert.That(MemUtil.ArraysEqual(outBytes, _pbTestData), Is.True);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,13 +4,14 @@ using System.IO;
|
||||
using ModernKeePassLib.Cryptography;
|
||||
using ModernKeePassLib.Cryptography.Cipher;
|
||||
using ModernKeePassLib.Utility;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
{
|
||||
[TestFixture]
|
||||
public class Chacha20Tests
|
||||
{
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestChacha20Cipher()
|
||||
{
|
||||
// ======================================================
|
||||
@@ -23,7 +24,7 @@ namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
pbIV[3] = 0x09;
|
||||
pbIV[7] = 0x4A;
|
||||
|
||||
var pbExpc = new byte[64] {
|
||||
var pbExpc = new byte[] {
|
||||
0x10, 0xF1, 0xE7, 0xE4, 0xD1, 0x3B, 0x59, 0x15,
|
||||
0x50, 0x0F, 0xDD, 0x1F, 0xA3, 0x20, 0x71, 0xC4,
|
||||
0xC7, 0xD1, 0xF4, 0xC7, 0x33, 0xC0, 0x68, 0x03,
|
||||
@@ -36,12 +37,12 @@ namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
|
||||
var pb = new byte[64];
|
||||
|
||||
using (var c = new ChaCha20Cipher(pbKey, pbIV))
|
||||
using (var chaCha20Cipher1 = new ChaCha20Cipher(pbKey, pbIV))
|
||||
{
|
||||
c.Seek(64, SeekOrigin.Begin); // Skip first block
|
||||
c.Encrypt(pb, 0, pb.Length);
|
||||
chaCha20Cipher1.Seek(64, SeekOrigin.Begin); // Skip first block
|
||||
chaCha20Cipher1.Encrypt(pb, 0, pb.Length);
|
||||
|
||||
Assert.True(MemUtil.ArraysEqual(pb, pbExpc));
|
||||
Assert.That(MemUtil.ArraysEqual(pb, pbExpc), Is.True);
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
@@ -74,12 +75,12 @@ namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
|
||||
var pb64 = new byte[64];
|
||||
|
||||
using (var c = new ChaCha20Cipher(pbKey, pbIV))
|
||||
using (var chaCha20Cipher2 = new ChaCha20Cipher(pbKey, pbIV))
|
||||
{
|
||||
c.Encrypt(pb64, 0, pb64.Length); // Skip first block
|
||||
c.Encrypt(pb, 0, pb.Length);
|
||||
chaCha20Cipher2.Encrypt(pb64, 0, pb64.Length); // Skip first block
|
||||
chaCha20Cipher2.Encrypt(pb, 0, pb.Length);
|
||||
|
||||
Assert.True(MemUtil.ArraysEqual(pb, pbExpc));
|
||||
Assert.That(MemUtil.ArraysEqual(pb, pbExpc), Is.True);
|
||||
}
|
||||
|
||||
// ======================================================
|
||||
@@ -116,17 +117,17 @@ namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
|
||||
using (var msEnc = new MemoryStream())
|
||||
{
|
||||
using (var c = new ChaCha20Stream(msEnc, true, pbKey, pbIV))
|
||||
using (var chaCha20Stream = new ChaCha20Stream(msEnc, true, pbKey, pbIV))
|
||||
{
|
||||
var r = CryptoRandom.NewWeakRandom();
|
||||
r.NextBytes(pb64);
|
||||
c.Write(pb64, 0, pb64.Length); // Skip first block
|
||||
chaCha20Stream.Write(pb64, 0, pb64.Length); // Skip first block
|
||||
|
||||
var p = 0;
|
||||
while (p < pb.Length)
|
||||
{
|
||||
var cb = r.Next(1, pb.Length - p + 1);
|
||||
c.Write(pb, p, cb);
|
||||
chaCha20Stream.Write(pb, p, cb);
|
||||
p += cb;
|
||||
}
|
||||
Debug.Assert(p == pb.Length);
|
||||
@@ -134,27 +135,22 @@ namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
|
||||
var pbEnc0 = msEnc.ToArray();
|
||||
var pbEnc = MemUtil.Mid(pbEnc0, 64, pbEnc0.Length - 64);
|
||||
Assert.True(MemUtil.ArraysEqual(pbEnc, pbExpc));
|
||||
Assert.That(MemUtil.ArraysEqual(pbEnc, pbExpc), Is.True);
|
||||
|
||||
using (var msCT = new MemoryStream(pbEnc0, false))
|
||||
{
|
||||
using (var cDec = new ChaCha20Stream(msCT, false,
|
||||
pbKey, pbIV))
|
||||
{
|
||||
var pbPT = MemUtil.Read(cDec, pbEnc0.Length);
|
||||
using var msCT = new MemoryStream(pbEnc0, false);
|
||||
using var cDec = new ChaCha20Stream(msCT, false, pbKey, pbIV);
|
||||
var pbPT = MemUtil.Read(cDec, pbEnc0.Length);
|
||||
|
||||
Assert.True(cDec.ReadByte() < 0);
|
||||
Assert.True(MemUtil.ArraysEqual(MemUtil.Mid(pbPT, 0, 64), pb64));
|
||||
Assert.True(MemUtil.ArraysEqual(MemUtil.Mid(pbPT, 64, pbEnc.Length), pb));
|
||||
}
|
||||
}
|
||||
Assert.That(cDec.ReadByte(), Is.LessThan(0));
|
||||
Assert.That(MemUtil.ArraysEqual(MemUtil.Mid(pbPT, 0, 64), pb64), Is.True);
|
||||
Assert.That(MemUtil.ArraysEqual(MemUtil.Mid(pbPT, 64, pbEnc.Length), pb), Is.True);
|
||||
}
|
||||
|
||||
// ======================================================
|
||||
// Test vector TC8 from RFC draft by J. Strombergson:
|
||||
// https://tools.ietf.org/html/draft-strombergson-chacha-test-vectors-01
|
||||
|
||||
pbKey = new byte[32] {
|
||||
pbKey = new byte[] {
|
||||
0xC4, 0x6E, 0xC1, 0xB1, 0x8C, 0xE8, 0xA8, 0x78,
|
||||
0x72, 0x5A, 0x37, 0xE7, 0x80, 0xDF, 0xB7, 0x35,
|
||||
0x1F, 0x68, 0xED, 0x2E, 0x19, 0x4C, 0x79, 0xFB,
|
||||
@@ -165,13 +161,13 @@ namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
// is used; this makes the RFC 7539 version of ChaCha20
|
||||
// compatible with the original specification by
|
||||
// D. J. Bernstein.
|
||||
pbIV = new byte[12] { 0x00, 0x00, 0x00, 0x00,
|
||||
pbIV = new byte[] { 0x00, 0x00, 0x00, 0x00,
|
||||
0x1A, 0xDA, 0x31, 0xD5, 0xCF, 0x68, 0x82, 0x21
|
||||
};
|
||||
|
||||
pb = new byte[128];
|
||||
|
||||
pbExpc = new byte[128] {
|
||||
pbExpc = new byte[] {
|
||||
0xF6, 0x3A, 0x89, 0xB7, 0x5C, 0x22, 0x71, 0xF9,
|
||||
0x36, 0x88, 0x16, 0x54, 0x2B, 0xA5, 0x2F, 0x06,
|
||||
0xED, 0x49, 0x24, 0x17, 0x92, 0x30, 0x2B, 0x00,
|
||||
@@ -191,12 +187,10 @@ namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
0x05, 0x3C, 0x84, 0xE4, 0x9A, 0x4A, 0x33, 0x32
|
||||
};
|
||||
|
||||
using (var c = new ChaCha20Cipher(pbKey, pbIV, true))
|
||||
{
|
||||
c.Decrypt(pb, 0, pb.Length);
|
||||
using var c = new ChaCha20Cipher(pbKey, pbIV, true);
|
||||
c.Decrypt(pb, 0, pb.Length);
|
||||
|
||||
Assert.True(MemUtil.ArraysEqual(pb, pbExpc));
|
||||
}
|
||||
Assert.That(MemUtil.ArraysEqual(pb, pbExpc), Is.True);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@@ -3,13 +3,14 @@ using System.Collections.Generic;
|
||||
using ModernKeePassLib.Cryptography;
|
||||
using ModernKeePassLib.Cryptography.Cipher;
|
||||
using ModernKeePassLib.Utility;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
{
|
||||
[TestFixture]
|
||||
public class Salsa20Tests
|
||||
{
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestSalsa20Cipher()
|
||||
{
|
||||
var r = CryptoRandom.NewWeakRandom();
|
||||
@@ -31,7 +32,7 @@ namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
var pb = new byte[16];
|
||||
var c = new Salsa20Cipher(pbKey, pbIv);
|
||||
c.Encrypt(pb, 0, pb.Length);
|
||||
Assert.True(MemUtil.ArraysEqual(pb, pbExpected));
|
||||
Assert.That(MemUtil.ArraysEqual(pb, pbExpected), Is.True);
|
||||
|
||||
// Extended test
|
||||
var pbExpected2 = new byte[] {
|
||||
@@ -46,12 +47,12 @@ namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
var nPos = Salsa20ToPos(c, r, pb.Length, 65536);
|
||||
Array.Clear(pb, 0, pb.Length);
|
||||
c.Encrypt(pb, 0, pb.Length);
|
||||
Assert.True(MemUtil.ArraysEqual(pb, pbExpected2));
|
||||
Assert.That(MemUtil.ArraysEqual(pb, pbExpected2), Is.True);
|
||||
|
||||
Salsa20ToPos(c, r, nPos + pb.Length, 131008);
|
||||
Array.Clear(pb, 0, pb.Length);
|
||||
c.Encrypt(pb, 0, pb.Length);
|
||||
Assert.True(MemUtil.ArraysEqual(pb, pbExpected3));
|
||||
Assert.That(MemUtil.ArraysEqual(pb, pbExpected3), Is.True);
|
||||
|
||||
var d = new Dictionary<string, bool>();
|
||||
const int nRounds = 100;
|
||||
@@ -62,7 +63,7 @@ namespace ModernKeePassLib.Test.Cryptography.Cipher
|
||||
c.Encrypt(z, 0, z.Length);
|
||||
d[MemUtil.ByteArrayToHexString(z)] = true;
|
||||
}
|
||||
Assert.Equal(nRounds, d.Count);
|
||||
Assert.That(d.Count, Is.EqualTo(nRounds));
|
||||
}
|
||||
|
||||
private static int Salsa20ToPos(Salsa20Cipher c, Random r, int nPos,
|
||||
|
@@ -1,28 +1,29 @@
|
||||
using ModernKeePassLib.Cryptography;
|
||||
using ModernKeePassLib.Utility;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace ModernKeePassLib.Test.Cryptography
|
||||
{
|
||||
[TestFixture]
|
||||
public class CryptoRandomStreamTests
|
||||
{
|
||||
private void TestGetRandomBytes(CryptoRandomStream stream)
|
||||
{
|
||||
const uint length = 16;
|
||||
var bytes1 = stream.GetRandomBytes(length);
|
||||
Assert.Equal(bytes1.Length, (int)length);
|
||||
Assert.That((int)length, Is.EqualTo(bytes1.Length));
|
||||
var bytes2 = stream.GetRandomBytes(length);
|
||||
Assert.False(MemUtil.ArraysEqual(bytes2, bytes1));
|
||||
Assert.That(MemUtil.ArraysEqual(bytes2, bytes1), Is.False);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestGetRandomBytesCrsAlgorithmSalsa20()
|
||||
{
|
||||
var stream = new CryptoRandomStream(CrsAlgorithm.Salsa20, new byte[16]);
|
||||
TestGetRandomBytes(stream);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestGetRandomBytesCrsAlgorithmArcFourVariant()
|
||||
{
|
||||
var stream = new CryptoRandomStream(CrsAlgorithm.ArcFourVariant, new byte[16]);
|
||||
@@ -33,17 +34,17 @@ namespace ModernKeePassLib.Test.Cryptography
|
||||
{
|
||||
var value1 = stream.GetRandomUInt64();
|
||||
var value2 = stream.GetRandomUInt64();
|
||||
Assert.NotEqual(value2, value1);
|
||||
Assert.That(value2, Is.Not.EqualTo(value1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestGetRandomInt64AlgorithmSalsa20()
|
||||
{
|
||||
var stream = new CryptoRandomStream(CrsAlgorithm.Salsa20, new byte[16]);
|
||||
TestGetRandomInt64(stream);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestGetRandomInt64AlgorithmArcFourVariant()
|
||||
{
|
||||
var stream = new CryptoRandomStream(CrsAlgorithm.ArcFourVariant, new byte[16]);
|
||||
|
@@ -1,28 +1,30 @@
|
||||
using ModernKeePassLib.Cryptography;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace ModernKeePassLib.Test.Cryptography
|
||||
{
|
||||
[TestFixture]
|
||||
public class CryptoRandomTests
|
||||
{
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestAddEntropy()
|
||||
{
|
||||
// just making sure it does not throw an exception
|
||||
CryptoRandom.Instance.AddEntropy(new byte[1]);
|
||||
Assert.DoesNotThrow(() => CryptoRandom.Instance.AddEntropy(new byte[1]));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestGetRandomBytes()
|
||||
{
|
||||
const int length = 32;
|
||||
var bytes1 = CryptoRandom.Instance.GetRandomBytes(length);
|
||||
Assert.Equal(bytes1.Length, length);
|
||||
var bytes2 = CryptoRandom.Instance.GetRandomBytes(length);
|
||||
Assert.NotEqual(bytes2, bytes1);
|
||||
|
||||
Assert.That(length, Is.EqualTo(bytes1.Length));
|
||||
Assert.That(bytes1, Is.Not.EqualTo(bytes2));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestGeneratedBytesCount()
|
||||
{
|
||||
const int length = 1;
|
||||
@@ -30,7 +32,8 @@ namespace ModernKeePassLib.Test.Cryptography
|
||||
var count1 = CryptoRandom.Instance.GeneratedBytesCount;
|
||||
CryptoRandom.Instance.GetRandomBytes(length);
|
||||
var count2 = CryptoRandom.Instance.GeneratedBytesCount;
|
||||
Assert.True(count2 > count1);
|
||||
|
||||
Assert.That(count2, Is.GreaterThan(count1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,24 +1,36 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Text;
|
||||
using ModernKeePassLib.Cryptography;
|
||||
using ModernKeePassLib.Cryptography.Hash;
|
||||
using ModernKeePassLib.Utility;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace ModernKeePassLib.Test.Cryptography.Hash
|
||||
{
|
||||
[TestFixture]
|
||||
public class Blake2bTests
|
||||
{
|
||||
[Fact]
|
||||
private Blake2b _blake2bHash;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_blake2bHash = new Blake2b();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
_blake2bHash.Clear();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBlake2bUtf8()
|
||||
{
|
||||
Blake2b h = new Blake2b();
|
||||
|
||||
// ======================================================
|
||||
// From https://tools.ietf.org/html/rfc7693
|
||||
|
||||
byte[] pbData = StrUtil.Utf8.GetBytes("abc");
|
||||
byte[] pbExpc = new byte[64]
|
||||
var pbData = StrUtil.Utf8.GetBytes("abc");
|
||||
var pbExpc = new byte[]
|
||||
{
|
||||
0xBA, 0x80, 0xA5, 0x3F, 0x98, 0x1C, 0x4D, 0x0D,
|
||||
0x6A, 0x27, 0x97, 0xB6, 0x9F, 0x12, 0xF6, 0xE9,
|
||||
@@ -30,18 +42,17 @@ namespace ModernKeePassLib.Test.Cryptography.Hash
|
||||
0xB9, 0x23, 0x86, 0xED, 0xD4, 0x00, 0x99, 0x23
|
||||
};
|
||||
|
||||
byte[] pbC = h.ComputeHash(pbData);
|
||||
Assert.True(MemUtil.ArraysEqual(pbC, pbExpc));
|
||||
var pbC = _blake2bHash.ComputeHash(pbData);
|
||||
Assert.That(MemUtil.ArraysEqual(pbC, pbExpc), Is.True);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestBlake2bEmpty()
|
||||
{
|
||||
// ======================================================
|
||||
// Computed using the official b2sum tool
|
||||
Blake2b h = new Blake2b();
|
||||
|
||||
var pbExpc = new byte[64]
|
||||
var pbExpc = new byte[]
|
||||
{
|
||||
0x78, 0x6A, 0x02, 0xF7, 0x42, 0x01, 0x59, 0x03,
|
||||
0xC6, 0xC6, 0xFD, 0x85, 0x25, 0x52, 0xD2, 0x72,
|
||||
@@ -53,23 +64,22 @@ namespace ModernKeePassLib.Test.Cryptography.Hash
|
||||
0xD5, 0x6F, 0x70, 0x1A, 0xFE, 0x9B, 0xE2, 0xCE
|
||||
};
|
||||
|
||||
var pbC = h.ComputeHash(new byte[0]);
|
||||
Assert.True(MemUtil.ArraysEqual(pbC, pbExpc));
|
||||
var pbC = _blake2bHash.ComputeHash(new byte[0]);
|
||||
Assert.That(MemUtil.ArraysEqual(pbC, pbExpc), Is.True);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestBlake2bString()
|
||||
{
|
||||
// ======================================================
|
||||
// Computed using the official b2sum tool
|
||||
Blake2b h = new Blake2b();
|
||||
|
||||
string strS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.:,;_-\r\n";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < 1000; ++i) sb.Append(strS);
|
||||
var strS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.:,;_-\r\n";
|
||||
var sb = new StringBuilder();
|
||||
for (var i = 0; i < 1000; ++i) sb.Append(strS);
|
||||
var pbData = StrUtil.Utf8.GetBytes(sb.ToString());
|
||||
|
||||
var pbExpc = new byte[64] {
|
||||
var pbExpc = new byte[] {
|
||||
0x59, 0x69, 0x8D, 0x3B, 0x83, 0xF4, 0x02, 0x4E,
|
||||
0xD8, 0x99, 0x26, 0x0E, 0xF4, 0xE5, 0x9F, 0x20,
|
||||
0xDC, 0x31, 0xEE, 0x5B, 0x45, 0xEA, 0xBB, 0xFC,
|
||||
@@ -80,21 +90,19 @@ namespace ModernKeePassLib.Test.Cryptography.Hash
|
||||
0x3F, 0x08, 0x8A, 0x93, 0xF8, 0x75, 0x91, 0xB0
|
||||
};
|
||||
|
||||
Random r = CryptoRandom.NewWeakRandom();
|
||||
int p = 0;
|
||||
var r = CryptoRandom.NewWeakRandom();
|
||||
var p = 0;
|
||||
while (p < pbData.Length)
|
||||
{
|
||||
int cb = r.Next(1, pbData.Length - p + 1);
|
||||
h.TransformBlock(pbData, p, cb, pbData, p);
|
||||
var cb = r.Next(1, pbData.Length - p + 1);
|
||||
_blake2bHash.TransformBlock(pbData, p, cb, pbData, p);
|
||||
p += cb;
|
||||
}
|
||||
Assert.Equal(p, pbData.Length);
|
||||
Assert.That(p, Is.EqualTo(pbData.Length));
|
||||
|
||||
h.TransformFinalBlock(new byte[0], 0, 0);
|
||||
_blake2bHash.TransformFinalBlock(new byte[0], 0, 0);
|
||||
|
||||
Assert.True(MemUtil.ArraysEqual(h.Hash, pbExpc));
|
||||
|
||||
h.Clear();
|
||||
Assert.That(MemUtil.ArraysEqual(_blake2bHash.Hash, pbExpc), Is.True);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,13 +1,15 @@
|
||||
using ModernKeePassLib.Cryptography;
|
||||
using System.Linq;
|
||||
using ModernKeePassLib.Cryptography;
|
||||
using ModernKeePassLib.Utility;
|
||||
using System.Security.Cryptography;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace ModernKeePassLib.Test.Cryptography.Hash
|
||||
{
|
||||
[TestFixture]
|
||||
public class HmacTests
|
||||
{
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestHmac1()
|
||||
{
|
||||
// Test vectors from RFC 4231
|
||||
@@ -25,7 +27,7 @@ namespace ModernKeePassLib.Test.Cryptography.Hash
|
||||
HmacEval(pbKey, pbMsg, pbExpc);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestHmac2()
|
||||
{
|
||||
var pbKey = new byte[131];
|
||||
@@ -43,74 +45,65 @@ namespace ModernKeePassLib.Test.Cryptography.Hash
|
||||
HmacEval(pbKey, pbMsg, pbExpc);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestHmacSha1ComputeHash()
|
||||
{
|
||||
var expectedHash = "AC2C2E614882CE7158F69B7E3B12114465945D01";
|
||||
var message = StrUtil.Utf8.GetBytes("testing123");
|
||||
var key = StrUtil.Utf8.GetBytes("hello");
|
||||
using (var result = new HMACSHA1(key))
|
||||
{
|
||||
Assert.Equal(ByteToString(result.ComputeHash(message)), expectedHash);
|
||||
}
|
||||
using var result = new HMACSHA1(key);
|
||||
Assert.That(expectedHash, Is.EqualTo(ByteToString(result.ComputeHash(message))));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestHmacSha256ComputeHash()
|
||||
{
|
||||
var expectedHash = "09C1BD2DE4E5659C0EFAF9E6AE4723E9CF96B69609B4E562F6AFF1745D7BF4E0";
|
||||
var message = StrUtil.Utf8.GetBytes("testing123");
|
||||
var key = StrUtil.Utf8.GetBytes("hello");
|
||||
using (var result = new HMACSHA256(key))
|
||||
{
|
||||
Assert.Equal(ByteToString(result.ComputeHash(message)), expectedHash);
|
||||
}
|
||||
using var result = new HMACSHA256(key);
|
||||
Assert.That(expectedHash, Is.EqualTo(ByteToString(result.ComputeHash(message))));
|
||||
}
|
||||
|
||||
private static string ByteToString(byte[] buff)
|
||||
{
|
||||
string sbinary = "";
|
||||
|
||||
for (int i = 0; i < buff.Length; i++)
|
||||
{
|
||||
sbinary += buff[i].ToString("X2"); // hex format
|
||||
}
|
||||
return (sbinary);
|
||||
return buff.Aggregate("", (current, t) => current + t.ToString("X2"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestHmacOtp()
|
||||
[Test]
|
||||
[TestCase(0, ExpectedResult = "755224")]
|
||||
[TestCase(1, ExpectedResult = "287082")]
|
||||
[TestCase(2, ExpectedResult = "359152")]
|
||||
[TestCase(3, ExpectedResult = "969429")]
|
||||
[TestCase(4, ExpectedResult = "338314")]
|
||||
[TestCase(5, ExpectedResult = "254676")]
|
||||
[TestCase(6, ExpectedResult = "287922")]
|
||||
[TestCase(7, ExpectedResult = "162583")]
|
||||
[TestCase(8, ExpectedResult = "399871")]
|
||||
[TestCase(9, ExpectedResult = "520489")]
|
||||
public string TestHmacOtp(int factor)
|
||||
{
|
||||
var pbSecret = StrUtil.Utf8.GetBytes("12345678901234567890");
|
||||
var vExp = new []{ "755224", "287082", "359152",
|
||||
"969429", "338314", "254676", "287922", "162583", "399871",
|
||||
"520489" };
|
||||
|
||||
for (var i = 0; i < vExp.Length; ++i)
|
||||
{
|
||||
Assert.Equal(HmacOtp.Generate(pbSecret, (ulong)i, 6, false, -1), vExp[i]);
|
||||
}
|
||||
return HmacOtp.Generate(pbSecret, (ulong)factor, 6, false, -1);
|
||||
}
|
||||
|
||||
private static void HmacEval(byte[] pbKey, byte[] pbMsg,
|
||||
byte[] pbExpc)
|
||||
{
|
||||
using (var h = new HMACSHA256(pbKey))
|
||||
{
|
||||
h.TransformBlock(pbMsg, 0, pbMsg.Length, pbMsg, 0);
|
||||
h.TransformFinalBlock(new byte[0], 0, 0);
|
||||
using var h = new HMACSHA256(pbKey);
|
||||
h.TransformBlock(pbMsg, 0, pbMsg.Length, pbMsg, 0);
|
||||
h.TransformFinalBlock(new byte[0], 0, 0);
|
||||
|
||||
byte[] pbHash = h.Hash;
|
||||
Assert.True(MemUtil.ArraysEqual(pbHash, pbExpc));
|
||||
var pbHash = h.Hash;
|
||||
Assert.That(MemUtil.ArraysEqual(pbHash, pbExpc), Is.True);
|
||||
|
||||
// Reuse the object
|
||||
h.Initialize();
|
||||
h.TransformBlock(pbMsg, 0, pbMsg.Length, pbMsg, 0);
|
||||
h.TransformFinalBlock(new byte[0], 0, 0);
|
||||
// Reuse the object
|
||||
h.Initialize();
|
||||
h.TransformBlock(pbMsg, 0, pbMsg.Length, pbMsg, 0);
|
||||
h.TransformFinalBlock(new byte[0], 0, 0);
|
||||
|
||||
pbHash = h.Hash;
|
||||
Assert.True(MemUtil.ArraysEqual(pbHash, pbExpc));
|
||||
}
|
||||
pbHash = h.Hash;
|
||||
Assert.That(MemUtil.ArraysEqual(pbHash, pbExpc), Is.True);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,13 +1,15 @@
|
||||
using ModernKeePassLib.Utility;
|
||||
using System.Linq;
|
||||
using ModernKeePassLib.Utility;
|
||||
using System.Security.Cryptography;
|
||||
using ModernKeePassLib.Cryptography;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace ModernKeePassLib.Test.Cryptography.Hash
|
||||
{
|
||||
[TestFixture]
|
||||
public class ShaManagedTests
|
||||
{
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestSha256()
|
||||
{
|
||||
var r = CryptoRandom.NewWeakRandom();
|
||||
@@ -34,39 +36,31 @@ namespace ModernKeePassLib.Test.Cryptography.Hash
|
||||
pbH2 = h2.ComputeHash(pbData);
|
||||
}
|
||||
|
||||
Assert.True(MemUtil.ArraysEqual(pbH1, pbH2));
|
||||
Assert.That(MemUtil.ArraysEqual(pbH1, pbH2), Is.True);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestSha256ComputeHash()
|
||||
{
|
||||
var expectedHash = "B822F1CD2DCFC685B47E83E3980289FD5D8E3FF3A82DEF24D7D1D68BB272EB32";
|
||||
var message = StrUtil.Utf8.GetBytes("testing123");
|
||||
using (var result = new SHA256Managed())
|
||||
{
|
||||
Assert.Equal(ByteToString(result.ComputeHash(message)), expectedHash);
|
||||
}
|
||||
using var result = new SHA256Managed();
|
||||
Assert.That(expectedHash, Is.EqualTo(ByteToString(result.ComputeHash(message))));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestSha512ComputeHash()
|
||||
{
|
||||
var expectedHash = "4120117B3190BA5E24044732B0B09AA9ED50EB1567705ABCBFA78431A4E0A96B1152ED7F4925966B1C82325E186A8100E692E6D2FCB6702572765820D25C7E9E";
|
||||
var message = StrUtil.Utf8.GetBytes("testing123");
|
||||
using (var result = new SHA512Managed())
|
||||
{
|
||||
Assert.Equal(ByteToString(result.ComputeHash(message)), expectedHash);
|
||||
}
|
||||
using var result = new SHA512Managed();
|
||||
Assert.That(expectedHash, Is.EqualTo(ByteToString(result.ComputeHash(message))));
|
||||
}
|
||||
|
||||
private static string ByteToString(byte[] buff)
|
||||
{
|
||||
var sbinary = "";
|
||||
var sbinary = buff.Aggregate("", (current, t) => current + t.ToString("X2"));
|
||||
|
||||
for (var i = 0; i < buff.Length; i++)
|
||||
{
|
||||
sbinary += buff[i].ToString("X2"); // hex format
|
||||
}
|
||||
return (sbinary);
|
||||
}
|
||||
}
|
||||
|
@@ -1,16 +1,17 @@
|
||||
using System.IO;
|
||||
using ModernKeePassLib.Cryptography;
|
||||
using ModernKeePassLib.Utility;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace ModernKeePassLib.Test.Cryptography
|
||||
{
|
||||
[TestFixture]
|
||||
public class HashingStreamExTests
|
||||
{
|
||||
const string data = "test";
|
||||
private const string Data = "test";
|
||||
|
||||
// The expected hash includes the \n added by WriteLine
|
||||
static readonly byte[] sha256HashOfData =
|
||||
private static readonly byte[] Sha256HashOfData =
|
||||
{
|
||||
0xf2, 0xca, 0x1b, 0xb6, 0xc7, 0xe9, 0x07, 0xd0,
|
||||
0x6d, 0xaf, 0xe4, 0x68, 0x7e, 0x57, 0x9f, 0xce,
|
||||
@@ -18,63 +19,52 @@ namespace ModernKeePassLib.Test.Cryptography
|
||||
0x22, 0xda, 0x52, 0xe6, 0xcc, 0xc2, 0x6f, 0xd2
|
||||
};
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestRead()
|
||||
{
|
||||
// if we use larger size, StreamReader will read past newline and cause bad hash
|
||||
var bytes = new byte[data.Length + 1];
|
||||
using (var ms = new MemoryStream(bytes))
|
||||
var bytes = new byte[Data.Length + 1];
|
||||
using (var memoryStream1 = new MemoryStream(bytes))
|
||||
{
|
||||
using (var sw = new StreamWriter(ms))
|
||||
{
|
||||
// set NewLine to ensure we don't run into cross-platform issues on Windows
|
||||
sw.NewLine = "\n";
|
||||
sw.WriteLine(data);
|
||||
}
|
||||
using var sw = new StreamWriter(memoryStream1);
|
||||
// set NewLine to ensure we don't run into cross-platform issues on Windows
|
||||
sw.NewLine = "\n";
|
||||
sw.WriteLine(Data);
|
||||
}
|
||||
using (var ms = new MemoryStream(bytes))
|
||||
|
||||
using var memoryStream2 = new MemoryStream(bytes);
|
||||
using var hs = new HashingStreamEx(memoryStream2, false, null);
|
||||
using (var sr = new StreamReader(hs))
|
||||
{
|
||||
using (var hs = new HashingStreamEx(ms, false, null))
|
||||
{
|
||||
using (var sr = new StreamReader(hs))
|
||||
{
|
||||
var read = sr.ReadLine();
|
||||
Assert.Equal(read, data);
|
||||
}
|
||||
// When the StreamReader is disposed, it calls Dispose on the
|
||||
//HasingStreamEx, which computes the hash.
|
||||
Assert.True(MemUtil.ArraysEqual(hs.Hash, sha256HashOfData));
|
||||
}
|
||||
var read = sr.ReadLine();
|
||||
Assert.That(read, Is.EqualTo(Data));
|
||||
}
|
||||
// When the StreamReader is disposed, it calls Dispose on the HasingStreamEx, which computes the hash.
|
||||
Assert.That(MemUtil.ArraysEqual(hs.Hash, Sha256HashOfData), Is.True);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestWrite()
|
||||
{
|
||||
var bytes = new byte[16];
|
||||
using (var ms = new MemoryStream(bytes))
|
||||
using (var memoryStream1 = new MemoryStream(bytes))
|
||||
{
|
||||
using (var hs = new HashingStreamEx(ms, true, null))
|
||||
using var hs = new HashingStreamEx(memoryStream1, true, null);
|
||||
using (var sw = new StreamWriter(hs))
|
||||
{
|
||||
using (var sw = new StreamWriter(hs))
|
||||
{
|
||||
// set NewLine to ensure we don't run into cross-platform issues on Windows
|
||||
sw.NewLine = "\n";
|
||||
sw.WriteLine(data);
|
||||
}
|
||||
// When the StreamWriter is disposed, it calls Dispose on the
|
||||
//HasingStreamEx, which computes the hash.
|
||||
Assert.True(MemUtil.ArraysEqual(hs.Hash, sha256HashOfData));
|
||||
}
|
||||
}
|
||||
using (var ms = new MemoryStream(bytes))
|
||||
{
|
||||
using (var sr = new StreamReader(ms))
|
||||
{
|
||||
var read = sr.ReadLine();
|
||||
Assert.Equal(read, data);
|
||||
// set NewLine to ensure we don't run into cross-platform issues on Windows
|
||||
sw.NewLine = "\n";
|
||||
sw.WriteLine(Data);
|
||||
}
|
||||
// When the StreamWriter is disposed, it calls Dispose on the HasingStreamEx, which computes the hash.
|
||||
Assert.True(MemUtil.ArraysEqual(hs.Hash, Sha256HashOfData));
|
||||
}
|
||||
|
||||
using var memoryStream2 = new MemoryStream(bytes);
|
||||
using var sr = new StreamReader(memoryStream2);
|
||||
var read = sr.ReadLine();
|
||||
|
||||
Assert.That(read, Is.EqualTo(Data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,30 +1,30 @@
|
||||
using System.Text;
|
||||
using ModernKeePassLib.Cryptography;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace ModernKeePassLib.Test.Cryptography
|
||||
{
|
||||
[TestFixture]
|
||||
public class HmacOtpTests
|
||||
{
|
||||
// Using the test case from Appendix D of RFC 4226
|
||||
|
||||
const string secret = "12345678901234567890";
|
||||
private const string Secret = "12345678901234567890";
|
||||
|
||||
static readonly string[] expectedHOTP = new string[]
|
||||
{
|
||||
private static readonly string[] ExpectedHotp = {
|
||||
"755224", "287082", "359152", "969429", "338314",
|
||||
"254676", "287922", "162583", "399871", "520489"
|
||||
};
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestGenerate()
|
||||
{
|
||||
var secretBytes = Encoding.UTF8.GetBytes(secret);
|
||||
var secretBytes = Encoding.UTF8.GetBytes(Secret);
|
||||
|
||||
for (ulong i = 0; i < 10; i++)
|
||||
{
|
||||
var hotp = HmacOtp.Generate(secretBytes, i, 6, false, -1);
|
||||
Assert.Equal(hotp, expectedHOTP[i]);
|
||||
Assert.That(ExpectedHotp[i], Is.EqualTo(hotp));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -2,13 +2,14 @@
|
||||
using ModernKeePassLib.Cryptography;
|
||||
using ModernKeePassLib.Cryptography.KeyDerivation;
|
||||
using ModernKeePassLib.Utility;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
{
|
||||
[TestFixture]
|
||||
public class AesKdfTests
|
||||
{
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestAesKdf()
|
||||
{
|
||||
// Up to KeePass 2.34, the OtpKeyProv plugin used the public
|
||||
@@ -26,7 +27,7 @@ namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
|
||||
var pbMan = new byte[pbKey.Length];
|
||||
Array.Copy(pbKey, pbMan, pbKey.Length);
|
||||
Assert.True(AesKdf.TransformKeyManaged(pbMan, pbSeed, uRounds));
|
||||
Assert.That(AesKdf.TransformKeyManaged(pbMan, pbSeed, uRounds), Is.True);
|
||||
pbMan = CryptoUtil.HashSha256(pbMan);
|
||||
|
||||
var kdf = new AesKdf();
|
||||
@@ -35,7 +36,7 @@ namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
p.SetByteArray(AesKdf.ParamSeed, pbSeed);
|
||||
var pbKdf = kdf.Transform(pbKey, p);
|
||||
|
||||
Assert.True(MemUtil.ArraysEqual(pbMan, pbKdf));
|
||||
Assert.That(MemUtil.ArraysEqual(pbMan, pbKdf), Is.True);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,15 +1,16 @@
|
||||
using ModernKeePassLib.Cryptography.KeyDerivation;
|
||||
using ModernKeePassLib.Utility;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
{
|
||||
[TestFixture]
|
||||
public class Argon2Tests
|
||||
{
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TestArgon2()
|
||||
{
|
||||
Argon2Kdf kdf = new Argon2Kdf();
|
||||
var kdf = new Argon2Kdf();
|
||||
|
||||
// ======================================================
|
||||
// From the official Argon2 1.3 reference code package
|
||||
@@ -19,37 +20,37 @@ namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
var p = kdf.GetDefaultParameters();
|
||||
kdf.Randomize(p);
|
||||
|
||||
Assert.Equal(0x13U, p.GetUInt32(Argon2Kdf.ParamVersion, 0));
|
||||
Assert.That(p.GetUInt32(Argon2Kdf.ParamVersion, 0), Is.EqualTo(0x13U));
|
||||
|
||||
byte[] pbMsg = new byte[32];
|
||||
for (int i = 0; i < pbMsg.Length; ++i) pbMsg[i] = 1;
|
||||
var pbMsg = new byte[32];
|
||||
for (var i = 0; i < pbMsg.Length; ++i) pbMsg[i] = 1;
|
||||
|
||||
p.SetUInt64(Argon2Kdf.ParamMemory, 32 * 1024);
|
||||
p.SetUInt64(Argon2Kdf.ParamIterations, 3);
|
||||
p.SetUInt32(Argon2Kdf.ParamParallelism, 4);
|
||||
|
||||
byte[] pbSalt = new byte[16];
|
||||
for (int i = 0; i < pbSalt.Length; ++i) pbSalt[i] = 2;
|
||||
var pbSalt = new byte[16];
|
||||
for (var i = 0; i < pbSalt.Length; ++i) pbSalt[i] = 2;
|
||||
p.SetByteArray(Argon2Kdf.ParamSalt, pbSalt);
|
||||
|
||||
byte[] pbKey = new byte[8];
|
||||
for (int i = 0; i < pbKey.Length; ++i) pbKey[i] = 3;
|
||||
var pbKey = new byte[8];
|
||||
for (var i = 0; i < pbKey.Length; ++i) pbKey[i] = 3;
|
||||
p.SetByteArray(Argon2Kdf.ParamSecretKey, pbKey);
|
||||
|
||||
byte[] pbAssoc = new byte[12];
|
||||
for (int i = 0; i < pbAssoc.Length; ++i) pbAssoc[i] = 4;
|
||||
var pbAssoc = new byte[12];
|
||||
for (var i = 0; i < pbAssoc.Length; ++i) pbAssoc[i] = 4;
|
||||
p.SetByteArray(Argon2Kdf.ParamAssocData, pbAssoc);
|
||||
|
||||
byte[] pbExpc = new byte[32] {
|
||||
var pbExpc = new byte[] {
|
||||
0x51, 0x2B, 0x39, 0x1B, 0x6F, 0x11, 0x62, 0x97,
|
||||
0x53, 0x71, 0xD3, 0x09, 0x19, 0x73, 0x42, 0x94,
|
||||
0xF8, 0x68, 0xE3, 0xBE, 0x39, 0x84, 0xF3, 0xC1,
|
||||
0xA1, 0x3A, 0x4D, 0xB9, 0xFA, 0xBE, 0x4A, 0xCB
|
||||
};
|
||||
|
||||
byte[] pb = kdf.Transform(pbMsg, p);
|
||||
var pb = kdf.Transform(pbMsg, p);
|
||||
|
||||
Assert.True(MemUtil.ArraysEqual(pb, pbExpc));
|
||||
Assert.That(MemUtil.ArraysEqual(pb, pbExpc), Is.True);
|
||||
|
||||
// ======================================================
|
||||
// From the official Argon2 1.3 reference code package
|
||||
@@ -57,7 +58,7 @@ namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
|
||||
p.SetUInt32(Argon2Kdf.ParamVersion, 0x10);
|
||||
|
||||
pbExpc = new byte[32] {
|
||||
pbExpc = new byte[] {
|
||||
0x96, 0xA9, 0xD4, 0xE5, 0xA1, 0x73, 0x40, 0x92,
|
||||
0xC8, 0x5E, 0x29, 0xF4, 0x10, 0xA4, 0x59, 0x14,
|
||||
0xA5, 0xDD, 0x1F, 0x5C, 0xBF, 0x08, 0xB2, 0x67,
|
||||
@@ -66,7 +67,7 @@ namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
|
||||
pb = kdf.Transform(pbMsg, p);
|
||||
|
||||
Assert.True(MemUtil.ArraysEqual(pb, pbExpc));
|
||||
Assert.That(MemUtil.ArraysEqual(pb, pbExpc), Is.True);
|
||||
|
||||
// ======================================================
|
||||
// From the official 'phc-winner-argon2-20151206.zip'
|
||||
@@ -74,7 +75,7 @@ namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
|
||||
p.SetUInt64(Argon2Kdf.ParamMemory, 16 * 1024);
|
||||
|
||||
pbExpc = new byte[32] {
|
||||
pbExpc = new byte[] {
|
||||
0x57, 0xB0, 0x61, 0x3B, 0xFD, 0xD4, 0x13, 0x1A,
|
||||
0x0C, 0x34, 0x88, 0x34, 0xC6, 0x72, 0x9C, 0x2C,
|
||||
0x72, 0x29, 0x92, 0x1E, 0x6B, 0xBA, 0x37, 0x66,
|
||||
@@ -83,7 +84,7 @@ namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
|
||||
pb = kdf.Transform(pbMsg, p);
|
||||
|
||||
Assert.True(MemUtil.ArraysEqual(pb, pbExpc));
|
||||
Assert.That(MemUtil.ArraysEqual(pb, pbExpc), Is.True);
|
||||
|
||||
// ======================================================
|
||||
// Computed using the official 'argon2' application
|
||||
@@ -100,7 +101,7 @@ namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
pbSalt = StrUtil.Utf8.GetBytes("somesalt");
|
||||
p.SetByteArray(Argon2Kdf.ParamSalt, pbSalt);
|
||||
|
||||
pbExpc = new byte[32] {
|
||||
pbExpc = new byte[] {
|
||||
0x29, 0xCB, 0xD3, 0xA1, 0x93, 0x76, 0xF7, 0xA2,
|
||||
0xFC, 0xDF, 0xB0, 0x68, 0xAC, 0x0B, 0x99, 0xBA,
|
||||
0x40, 0xAC, 0x09, 0x01, 0x73, 0x42, 0xCE, 0xF1,
|
||||
@@ -109,12 +110,12 @@ namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
|
||||
pb = kdf.Transform(pbMsg, p);
|
||||
|
||||
Assert.True(MemUtil.ArraysEqual(pb, pbExpc));
|
||||
Assert.That(MemUtil.ArraysEqual(pb, pbExpc), Is.True);
|
||||
|
||||
p.SetUInt64(Argon2Kdf.ParamMemory, (1 << 10) * 1024); // 1 MB
|
||||
p.SetUInt64(Argon2Kdf.ParamIterations, 3);
|
||||
|
||||
pbExpc = new byte[32] {
|
||||
pbExpc = new byte[] {
|
||||
0x7A, 0xBE, 0x1C, 0x1C, 0x8D, 0x7F, 0xD6, 0xDC,
|
||||
0x7C, 0x94, 0x06, 0x3E, 0xD8, 0xBC, 0xD8, 0x1C,
|
||||
0x2F, 0x87, 0x84, 0x99, 0x12, 0x83, 0xFE, 0x76,
|
||||
@@ -123,14 +124,14 @@ namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
|
||||
pb = kdf.Transform(pbMsg, p);
|
||||
|
||||
Assert.True(MemUtil.ArraysEqual(pb, pbExpc));
|
||||
Assert.That(MemUtil.ArraysEqual(pb, pbExpc), Is.True);
|
||||
|
||||
// TODO: Out of memory exception
|
||||
/*p.SetUInt64(Argon2Kdf.ParamMemory, (1 << 20) * 1024); // 1 GB
|
||||
p.SetUInt64(Argon2Kdf.ParamMemory, (1 << 20) * 1024); // 1 GB
|
||||
p.SetUInt64(Argon2Kdf.ParamIterations, 2);
|
||||
p.SetUInt32(Argon2Kdf.ParamParallelism, 3);
|
||||
|
||||
pbExpc = new byte[32] {
|
||||
pbExpc = new byte[] {
|
||||
0xE6, 0xE7, 0xCB, 0xF5, 0x5A, 0x06, 0x93, 0x05,
|
||||
0x32, 0xBA, 0x86, 0xC6, 0x1F, 0x45, 0x17, 0x99,
|
||||
0x65, 0x41, 0x77, 0xF9, 0x30, 0x55, 0x9A, 0xE8,
|
||||
@@ -139,7 +140,7 @@ namespace ModernKeePassLib.Test.Cryptography.KeyDerivation
|
||||
|
||||
pb = kdf.Transform(pbMsg, p);
|
||||
|
||||
Assert.IsTrue(MemUtil.ArraysEqual(pb, pbExpc));*/
|
||||
Assert.That(MemUtil.ArraysEqual(pb, pbExpc), Is.True);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user