diff --git a/crypto/test/src/crypto/test/GOST3411_2012_256DigestTest.cs b/crypto/test/src/crypto/test/GOST3411_2012_256DigestTest.cs
index dd9ed11c0..d08447df5 100644
--- a/crypto/test/src/crypto/test/GOST3411_2012_256DigestTest.cs
+++ b/crypto/test/src/crypto/test/GOST3411_2012_256DigestTest.cs
@@ -1,6 +1,8 @@
using System;
-using System.Collections.Generic;
+using System.Collections;
+
using NUnit.Framework;
+
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Digests;
using Org.BouncyCastle.Crypto.Macs;
@@ -12,9 +14,9 @@ using Org.BouncyCastle.Utilities.Encoders;
namespace UnitTests.src.crypto.test
{
[TestFixture]
- public class GOST3411_2012_256DigestTest : DigestTest
+ public class GOST3411_2012_256DigestTest
+ : DigestTest
{
-
private static readonly String[] messages;
private static char[] M1 =
@@ -50,38 +52,28 @@ namespace UnitTests.src.crypto.test
static GOST3411_2012_256DigestTest()
{
-
- List<String> strList = new List<String>();
-
- strList.Add(new String(M1));
- strList.Add(new String(M2));
-
- messages = new String[strList.Count];
- for (int i = 0; i < strList.Count; i++)
- {
- messages[i] = (String)strList[i];
- }
+ messages = new string[] { new string(M1), new string(M2) };
}
private static readonly String[] digests = {
- "9d151eefd8590b89daa6ba6cb74af9275dd051026bb149a452fd84e5e57b5500",
- "9dd2fe4e90409e5da87f53976d7405b0c0cac628fc669a741d50063c557e8f50"
- };
-
-
+ "9d151eefd8590b89daa6ba6cb74af9275dd051026bb149a452fd84e5e57b5500",
+ "9dd2fe4e90409e5da87f53976d7405b0c0cac628fc669a741d50063c557e8f50"
+ };
- public GOST3411_2012_256DigestTest() : base(new GOST3411_2012_256Digest(), messages, digests)
+ public GOST3411_2012_256DigestTest()
+ : base(new GOST3411_2012_256Digest(), messages, digests)
{
}
- public override void PerformTest() {
+ public override void PerformTest()
+ {
base.PerformTest();
- HMac gMac = new HMac(new GOST3411_2012_256Digest());
+ HMac gMac = new HMac(new GOST3411_2012_256Digest());
- gMac.Init(new KeyParameter(Hex.Decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f")));
+ gMac.Init(new KeyParameter(Hex.Decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f")));
- byte[] data = Hex.Decode("0126bdb87800af214341456563780100");
+ byte[] data = Hex.Decode("0126bdb87800af214341456563780100");
gMac.BlockUpdate(data, 0, data.Length);
byte[] mac = new byte[gMac.GetMacSize()];
diff --git a/crypto/test/src/crypto/test/GOST3411_2012_512DigestTest.cs b/crypto/test/src/crypto/test/GOST3411_2012_512DigestTest.cs
index 1f7e0ab50..05b33e7f9 100644
--- a/crypto/test/src/crypto/test/GOST3411_2012_512DigestTest.cs
+++ b/crypto/test/src/crypto/test/GOST3411_2012_512DigestTest.cs
@@ -1,19 +1,20 @@
using System;
-using System.Collections.Generic;
+using System.Collections;
+
using NUnit.Framework;
+
using Org.BouncyCastle.Crypto.Digests;
using Org.BouncyCastle.Crypto.Macs;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Utilities;
using Org.BouncyCastle.Utilities.Encoders;
-
namespace Org.BouncyCastle.Crypto.Tests
{
[TestFixture]
- public class GOST3411_2012_512DigestTest : DigestTest
+ public class GOST3411_2012_512DigestTest
+ : DigestTest
{
-
private static readonly String[] messages;
private static char[] M1 =
@@ -48,21 +49,13 @@ namespace Org.BouncyCastle.Crypto.Tests
static GOST3411_2012_512DigestTest()
{
- List<String> strList = new List<String>();
-
- strList.Add(new String(M1));
- strList.Add(new String(M2));
- messages = new String[strList.Count];
- for (int i = 0; i < strList.Count; i++)
- {
- messages[i] = (String)strList[i];
- }
+ messages = new string[]{ new string(M1), new string(M2) };
}
private static readonly String[] digests = {
- "1b54d01a4af5b9d5cc3d86d68d285462b19abc2475222f35c085122be4ba1ffa00ad30f8767b3a82384c6574f024c311e2a481332b08ef7f41797891c1646f48",
- "1e88e62226bfca6f9994f1f2d51569e0daf8475a3b0fe61a5300eee46d961376035fe83549ada2b8620fcd7c496ce5b33f0cb9dddc2b6460143b03dabac9fb28",
- };
+ "1b54d01a4af5b9d5cc3d86d68d285462b19abc2475222f35c085122be4ba1ffa00ad30f8767b3a82384c6574f024c311e2a481332b08ef7f41797891c1646f48",
+ "1e88e62226bfca6f9994f1f2d51569e0daf8475a3b0fe61a5300eee46d961376035fe83549ada2b8620fcd7c496ce5b33f0cb9dddc2b6460143b03dabac9fb28",
+ };
public override void PerformTest()
{
@@ -85,7 +78,8 @@ namespace Org.BouncyCastle.Crypto.Tests
}
}
- public GOST3411_2012_512DigestTest() : base(new GOST3411_2012_512Digest(), messages, digests)
+ public GOST3411_2012_512DigestTest()
+ : base(new GOST3411_2012_512Digest(), messages, digests)
{
}
diff --git a/crypto/test/src/math/ec/custom/sec/test/SecP256R1FieldTest.cs b/crypto/test/src/math/ec/custom/sec/test/SecP256R1FieldTest.cs
index 374b1ecd1..c6b7b311d 100644
--- a/crypto/test/src/math/ec/custom/sec/test/SecP256R1FieldTest.cs
+++ b/crypto/test/src/math/ec/custom/sec/test/SecP256R1FieldTest.cs
@@ -5,7 +5,6 @@ using NUnit.Framework;
using Org.BouncyCastle.Asn1.Sec;
using Org.BouncyCastle.Asn1.X9;
using Org.BouncyCastle.Crypto.EC;
-using Org.BouncyCastle.Math.Raw;
using Org.BouncyCastle.Security;
namespace Org.BouncyCastle.Math.EC.Custom.Sec.Tests
@@ -150,32 +149,59 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec.Tests
private ECFieldElement GenerateMultiplyInputA_OpenSSLBug()
{
- uint[] x = Nat256.Create();
+ uint[] x = Nat256_Create();
x[0] = (uint)Random.NextInt() >> 1;
x[4] = 3;
x[7] = 0xFFFFFFFF;
- return FE(Nat256.ToBigInteger(x));
+ return FE(Nat256_ToBigInteger(x));
}
private ECFieldElement GenerateMultiplyInputB_OpenSSLBug()
{
- uint[] x = Nat256.Create();
+ uint[] x = Nat256_Create();
x[0] = (uint)Random.NextInt() >> 1;
x[3] = 1;
x[7] = 0xFFFFFFFF;
- return FE(Nat256.ToBigInteger(x));
+ return FE(Nat256_ToBigInteger(x));
}
private ECFieldElement GenerateSquareInput_OpenSSLBug()
{
- uint[] x = Nat256.Create();
+ uint[] x = Nat256_Create();
x[0] = (uint)Random.NextInt() >> 1;
x[4] = 2;
x[7] = 0xFFFFFFFF;
- return FE(Nat256.ToBigInteger(x));
+ return FE(Nat256_ToBigInteger(x));
+ }
+
+ private static uint[] Nat256_Create()
+ {
+ return new uint[8];
+ }
+
+ private static BigInteger Nat256_ToBigInteger(uint[] x)
+ {
+ byte[] bs = new byte[32];
+ for (int i = 0; i < 8; ++i)
+ {
+ uint x_i = x[i];
+ if (x_i != 0)
+ {
+ Pack_UInt32_To_BE(x_i, bs, (7 - i) << 2);
+ }
+ }
+ return new BigInteger(1, bs);
+ }
+
+ private static void Pack_UInt32_To_BE(uint n, byte[] bs, int off)
+ {
+ bs[off] = (byte)(n >> 24);
+ bs[off + 1] = (byte)(n >> 16);
+ bs[off + 2] = (byte)(n >> 8);
+ bs[off + 3] = (byte)(n);
}
}
}
diff --git a/crypto/test/src/math/ec/custom/sec/test/SecP384R1FieldTest.cs b/crypto/test/src/math/ec/custom/sec/test/SecP384R1FieldTest.cs
index 86ec4894f..6045c1bdf 100644
--- a/crypto/test/src/math/ec/custom/sec/test/SecP384R1FieldTest.cs
+++ b/crypto/test/src/math/ec/custom/sec/test/SecP384R1FieldTest.cs
@@ -5,7 +5,6 @@ using NUnit.Framework;
using Org.BouncyCastle.Asn1.Sec;
using Org.BouncyCastle.Asn1.X9;
using Org.BouncyCastle.Crypto.EC;
-using Org.BouncyCastle.Math.Raw;
using Org.BouncyCastle.Security;
namespace Org.BouncyCastle.Math.EC.Custom.Sec.Tests
@@ -134,13 +133,40 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec.Tests
private ECFieldElement GenerateSquareInput_CarryBug()
{
- uint[] x = Nat.Create(12);
+ uint[] x = Nat_Create(12);
x[0] = (uint)Random.NextInt() >> 1;
x[6] = 2;
x[10] = 0xFFFF0000;
x[11] = 0xFFFFFFFF;
- return FE(Nat.ToBigInteger(12, x));
+ return FE(Nat_ToBigInteger(12, x));
+ }
+
+ private static uint[] Nat_Create(int len)
+ {
+ return new uint[len];
+ }
+
+ private static BigInteger Nat_ToBigInteger(int len, uint[] x)
+ {
+ byte[] bs = new byte[len << 2];
+ for (int i = 0; i < len; ++i)
+ {
+ uint x_i = x[i];
+ if (x_i != 0)
+ {
+ Pack_UInt32_To_BE(x_i, bs, (len - 1 - i) << 2);
+ }
+ }
+ return new BigInteger(1, bs);
+ }
+
+ private static void Pack_UInt32_To_BE(uint n, byte[] bs, int off)
+ {
+ bs[off] = (byte)(n >> 24);
+ bs[off + 1] = (byte)(n >> 16);
+ bs[off + 2] = (byte)(n >> 8);
+ bs[off + 3] = (byte)(n);
}
}
}
diff --git a/crypto/test/src/test/DHTest.cs b/crypto/test/src/test/DHTest.cs
index fca487008..1acc0d603 100644
--- a/crypto/test/src/test/DHTest.cs
+++ b/crypto/test/src/test/DHTest.cs
@@ -708,7 +708,7 @@ namespace Org.BouncyCastle.Tests
}
catch (ArgumentException ex)
{
- IsTrue("wrong message (constructor)", Platform.StartsWith(ex.Message, "invalid DH public key"));
+ IsTrue("wrong message (constructor)", ex.Message.StartsWith("invalid DH public key"));
}
ka.Init(priv);
|