diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2019-07-29 22:59:50 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2019-07-29 22:59:50 +0700 |
commit | 3d4e40e51c2eefe48cc927c6efa8c10317abaa8b (patch) | |
tree | 747da65df7ad3abdbd2c5e7724fe822f54fc3da6 /crypto/test/src | |
parent | Fix a corner-case for DER set-value sorting (diff) | |
download | BouncyCastle.NET-ed25519-3d4e40e51c2eefe48cc927c6efa8c10317abaa8b.tar.xz |
Adapt test to access restrictions
Diffstat (limited to 'crypto/test/src')
-rw-r--r-- | crypto/test/src/math/ec/custom/sec/test/SecP128R1FieldTest.cs | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/crypto/test/src/math/ec/custom/sec/test/SecP128R1FieldTest.cs b/crypto/test/src/math/ec/custom/sec/test/SecP128R1FieldTest.cs index 40e1a61c1..26b4060b0 100644 --- a/crypto/test/src/math/ec/custom/sec/test/SecP128R1FieldTest.cs +++ b/crypto/test/src/math/ec/custom/sec/test/SecP128R1FieldTest.cs @@ -2,41 +2,60 @@ using NUnit.Framework; -using Org.BouncyCastle.Math.Raw; -using Org.BouncyCastle.Utilities; +using Org.BouncyCastle.Asn1.Sec; +using Org.BouncyCastle.Asn1.X9; +using Org.BouncyCastle.Crypto.EC; namespace Org.BouncyCastle.Math.EC.Custom.Sec.Tests { [TestFixture] public class SecP128R1FieldTest { + private static readonly X9ECParameters DP = CustomNamedCurves + .GetByOid(SecObjectIdentifiers.SecP128r1); + [Test] public void Test_GitHub566() { uint[] x = new uint[]{ 0x4B1E2F5E, 0x09E29D21, 0xA58407ED, 0x6FC3C7CF }; uint[] y = new uint[]{ 0x2FFE8892, 0x55CA61CA, 0x0AF780B5, 0x4BD7B797 }; - uint[] z = Nat128.Create(); - SecP128R1Field.Multiply(x, y, z); + ECFieldElement Z = FE(x).Multiply(FE(y)); - uint[] expected = new uint[]{ 0x01FFFF01, 0, 0, 0 }; - Assert.IsTrue(Arrays.AreEqual(expected, z)); + uint[] expected = new uint[] { 0x01FFFF01, 0, 0, 0 }; + Assert.AreEqual(FE(expected), Z); } - [Test] - public void TestReduce32() + private ECFieldElement FE(BigInteger x) + { + return DP.Curve.FromBigInteger(x); + } + + private ECFieldElement FE(uint[] x) { - uint[] z = Nat128.Create(); - //Arrays.Fill(z, 0xFFFFFFFF); - for (int i = 0; i < z.Length; ++i) + return FE(Nat128_ToBigInteger(x)); + } + + private static BigInteger Nat128_ToBigInteger(uint[] x) + { + byte[] bs = new byte[16]; + for (int i = 0; i < 4; ++i) { - z[i] = 0xFFFFFFFF; + uint x_i = x[i]; + if (x_i != 0) + { + Pack_UInt32_To_BE(x_i, bs, (3 - i) << 2); + } } + return new BigInteger(1, bs); + } - SecP128R1Field.Reduce32(0xFFFFFFFF, z); - - uint[] expected = new uint[]{ 1, 1, 0, 4 }; - Assert.IsTrue(Arrays.AreEqual(expected, z)); + 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); } } } |