diff options
-rw-r--r-- | crypto/test/src/crypto/test/SipHashTest.cs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/crypto/test/src/crypto/test/SipHashTest.cs b/crypto/test/src/crypto/test/SipHashTest.cs index 886ffc4d6..82dfce82c 100644 --- a/crypto/test/src/crypto/test/SipHashTest.cs +++ b/crypto/test/src/crypto/test/SipHashTest.cs @@ -7,6 +7,7 @@ using NUnit.Framework; using Org.BouncyCastle.Crypto.Macs; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Crypto.Utilities; +using Org.BouncyCastle.Security; using Org.BouncyCastle.Utilities.Encoders; using Org.BouncyCastle.Utilities.Test; @@ -37,6 +38,12 @@ namespace Org.BouncyCastle.Crypto.Tests RunMac(key, input, UPDATE_BYTES); RunMac(key, input, UPDATE_FULL); RunMac(key, input, UPDATE_MIX); + + SecureRandom random = new SecureRandom(); + for (int i = 0; i < 100; ++i) + { + RandomTest(random); + } } private void RunMac(byte[] key, byte[] input, int updateType) @@ -71,6 +78,33 @@ namespace Org.BouncyCastle.Crypto.Tests } } + private void RandomTest(SecureRandom random) + { + byte[] key = new byte[16]; + random.NextBytes(key); + + int length = 1 + random.Next(1024); + byte[] input = new byte[length]; + random.NextBytes(input); + + SipHash mac = new SipHash(); + mac.Init(new KeyParameter(key)); + + UpdateMac(mac, input, UPDATE_BYTES); + long result1 = mac.DoFinal(); + + UpdateMac(mac, input, UPDATE_FULL); + long result2 = mac.DoFinal(); + + UpdateMac(mac, input, UPDATE_MIX); + long result3 = mac.DoFinal(); + + if (result1 != result2 || result1 != result3) + { + Fail("Inconsistent results in random test"); + } + } + private void UpdateMac(SipHash mac, byte[] input, int updateType) { switch (updateType) |