From e7e89cce762e32917c1eef745b05da636ed03bbb Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Wed, 31 Jul 2019 17:42:12 +0700 Subject: Accept only properly-sized BigInteger (no auto-reduction) --- crypto/src/math/ec/custom/sec/SecT113Field.cs | 4 +--- crypto/src/math/ec/custom/sec/SecT131Field.cs | 4 +--- crypto/src/math/ec/custom/sec/SecT163Field.cs | 4 +--- crypto/src/math/ec/custom/sec/SecT193Field.cs | 4 +--- crypto/src/math/ec/custom/sec/SecT233Field.cs | 4 +--- crypto/src/math/ec/custom/sec/SecT239Field.cs | 4 +--- crypto/src/math/ec/custom/sec/SecT283Field.cs | 4 +--- crypto/src/math/ec/custom/sec/SecT409Field.cs | 4 +--- crypto/src/math/ec/custom/sec/SecT571Field.cs | 4 +--- 9 files changed, 9 insertions(+), 27 deletions(-) (limited to 'crypto/src/math/ec/custom/sec') diff --git a/crypto/src/math/ec/custom/sec/SecT113Field.cs b/crypto/src/math/ec/custom/sec/SecT113Field.cs index 49773b66d..1c4576062 100644 --- a/crypto/src/math/ec/custom/sec/SecT113Field.cs +++ b/crypto/src/math/ec/custom/sec/SecT113Field.cs @@ -32,9 +32,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec public static ulong[] FromBigInteger(BigInteger x) { - ulong[] z = Nat128.FromBigInteger64(x); - Reduce15(z, 0); - return z; + return Nat.FromBigInteger64(113, x); } public static void Invert(ulong[] x, ulong[] z) diff --git a/crypto/src/math/ec/custom/sec/SecT131Field.cs b/crypto/src/math/ec/custom/sec/SecT131Field.cs index 1b6697afe..b59b0181b 100644 --- a/crypto/src/math/ec/custom/sec/SecT131Field.cs +++ b/crypto/src/math/ec/custom/sec/SecT131Field.cs @@ -37,9 +37,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec public static ulong[] FromBigInteger(BigInteger x) { - ulong[] z = Nat192.FromBigInteger64(x); - Reduce61(z, 0); - return z; + return Nat.FromBigInteger64(131, x); } public static void Invert(ulong[] x, ulong[] z) diff --git a/crypto/src/math/ec/custom/sec/SecT163Field.cs b/crypto/src/math/ec/custom/sec/SecT163Field.cs index b1e9aa725..e76e57b43 100644 --- a/crypto/src/math/ec/custom/sec/SecT163Field.cs +++ b/crypto/src/math/ec/custom/sec/SecT163Field.cs @@ -38,9 +38,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec public static ulong[] FromBigInteger(BigInteger x) { - ulong[] z = Nat192.FromBigInteger64(x); - Reduce29(z, 0); - return z; + return Nat.FromBigInteger64(163, x); } public static void Invert(ulong[] x, ulong[] z) diff --git a/crypto/src/math/ec/custom/sec/SecT193Field.cs b/crypto/src/math/ec/custom/sec/SecT193Field.cs index 41acb4f94..a186da7b6 100644 --- a/crypto/src/math/ec/custom/sec/SecT193Field.cs +++ b/crypto/src/math/ec/custom/sec/SecT193Field.cs @@ -39,9 +39,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec public static ulong[] FromBigInteger(BigInteger x) { - ulong[] z = Nat256.FromBigInteger64(x); - Reduce63(z, 0); - return z; + return Nat.FromBigInteger64(193, x); } public static void Invert(ulong[] x, ulong[] z) diff --git a/crypto/src/math/ec/custom/sec/SecT233Field.cs b/crypto/src/math/ec/custom/sec/SecT233Field.cs index 870dade50..bd493c586 100644 --- a/crypto/src/math/ec/custom/sec/SecT233Field.cs +++ b/crypto/src/math/ec/custom/sec/SecT233Field.cs @@ -40,9 +40,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec public static ulong[] FromBigInteger(BigInteger x) { - ulong[] z = Nat256.FromBigInteger64(x); - Reduce23(z, 0); - return z; + return Nat.FromBigInteger64(233, x); } public static void Invert(ulong[] x, ulong[] z) diff --git a/crypto/src/math/ec/custom/sec/SecT239Field.cs b/crypto/src/math/ec/custom/sec/SecT239Field.cs index 2e6ed2ad6..61b2ed6b7 100644 --- a/crypto/src/math/ec/custom/sec/SecT239Field.cs +++ b/crypto/src/math/ec/custom/sec/SecT239Field.cs @@ -40,9 +40,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec public static ulong[] FromBigInteger(BigInteger x) { - ulong[] z = Nat256.FromBigInteger64(x); - Reduce17(z, 0); - return z; + return Nat.FromBigInteger64(239, x); } public static void Invert(ulong[] x, ulong[] z) diff --git a/crypto/src/math/ec/custom/sec/SecT283Field.cs b/crypto/src/math/ec/custom/sec/SecT283Field.cs index 22b7eaaab..64fbc966d 100644 --- a/crypto/src/math/ec/custom/sec/SecT283Field.cs +++ b/crypto/src/math/ec/custom/sec/SecT283Field.cs @@ -45,9 +45,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec public static ulong[] FromBigInteger(BigInteger x) { - ulong[] z = Nat320.FromBigInteger64(x); - Reduce37(z, 0); - return z; + return Nat.FromBigInteger64(283, x); } public static void Invert(ulong[] x, ulong[] z) diff --git a/crypto/src/math/ec/custom/sec/SecT409Field.cs b/crypto/src/math/ec/custom/sec/SecT409Field.cs index 861b77aa1..f9962de5b 100644 --- a/crypto/src/math/ec/custom/sec/SecT409Field.cs +++ b/crypto/src/math/ec/custom/sec/SecT409Field.cs @@ -42,9 +42,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec public static ulong[] FromBigInteger(BigInteger x) { - ulong[] z = Nat448.FromBigInteger64(x); - Reduce39(z, 0); - return z; + return Nat.FromBigInteger64(409, x); } public static void Invert(ulong[] x, ulong[] z) diff --git a/crypto/src/math/ec/custom/sec/SecT571Field.cs b/crypto/src/math/ec/custom/sec/SecT571Field.cs index 98f4f7fc2..9596aa5af 100644 --- a/crypto/src/math/ec/custom/sec/SecT571Field.cs +++ b/crypto/src/math/ec/custom/sec/SecT571Field.cs @@ -57,9 +57,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec public static ulong[] FromBigInteger(BigInteger x) { - ulong[] z = Nat576.FromBigInteger64(x); - Reduce5(z, 0); - return z; + return Nat.FromBigInteger64(571, x); } public static void Invert(ulong[] x, ulong[] z) -- cgit 1.4.1