From 89cf67c959f4080d67746946101a2375e761e039 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Wed, 31 Jul 2019 17:49:43 +0700 Subject: Rework some of the ImplSquare methods in custom binary curves --- crypto/src/math/ec/custom/sec/SecT131Field.cs | 1 - crypto/src/math/ec/custom/sec/SecT163Field.cs | 5 +---- crypto/src/math/ec/custom/sec/SecT233Field.cs | 5 +---- crypto/src/math/ec/custom/sec/SecT239Field.cs | 5 +---- crypto/src/math/ec/custom/sec/SecT283Field.cs | 8 ++++---- crypto/src/math/ec/custom/sec/SecT409Field.cs | 10 ++++++---- crypto/src/math/ec/custom/sec/SecT571Field.cs | 13 +++++++++---- 7 files changed, 22 insertions(+), 25 deletions(-) (limited to 'crypto/src/math/ec') diff --git a/crypto/src/math/ec/custom/sec/SecT131Field.cs b/crypto/src/math/ec/custom/sec/SecT131Field.cs index b59b0181b..248b1969e 100644 --- a/crypto/src/math/ec/custom/sec/SecT131Field.cs +++ b/crypto/src/math/ec/custom/sec/SecT131Field.cs @@ -321,7 +321,6 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec { Interleave.Expand64To128(x[0], zz, 0); Interleave.Expand64To128(x[1], zz, 2); - zz[4] = Interleave.Expand8to16((uint)x[2]); } } diff --git a/crypto/src/math/ec/custom/sec/SecT163Field.cs b/crypto/src/math/ec/custom/sec/SecT163Field.cs index e76e57b43..bc35ae6e8 100644 --- a/crypto/src/math/ec/custom/sec/SecT163Field.cs +++ b/crypto/src/math/ec/custom/sec/SecT163Field.cs @@ -329,10 +329,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec { Interleave.Expand64To128(x[0], zz, 0); Interleave.Expand64To128(x[1], zz, 2); - - ulong x2 = x[2]; - zz[4] = Interleave.Expand32to64((uint)x2); - zz[5] = Interleave.Expand8to16((uint)(x2 >> 32)); + Interleave.Expand64To128(x[2], zz, 4); } } } diff --git a/crypto/src/math/ec/custom/sec/SecT233Field.cs b/crypto/src/math/ec/custom/sec/SecT233Field.cs index bd493c586..013e6b8f9 100644 --- a/crypto/src/math/ec/custom/sec/SecT233Field.cs +++ b/crypto/src/math/ec/custom/sec/SecT233Field.cs @@ -306,10 +306,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec Interleave.Expand64To128(x[0], zz, 0); Interleave.Expand64To128(x[1], zz, 2); Interleave.Expand64To128(x[2], zz, 4); - - ulong x3 = x[3]; - zz[6] = Interleave.Expand32to64((uint)x3); - zz[7] = Interleave.Expand16to32((uint)(x3 >> 32)); + Interleave.Expand64To128(x[3], zz, 6); } } } diff --git a/crypto/src/math/ec/custom/sec/SecT239Field.cs b/crypto/src/math/ec/custom/sec/SecT239Field.cs index 61b2ed6b7..b0c033fe2 100644 --- a/crypto/src/math/ec/custom/sec/SecT239Field.cs +++ b/crypto/src/math/ec/custom/sec/SecT239Field.cs @@ -317,10 +317,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec Interleave.Expand64To128(x[0], zz, 0); Interleave.Expand64To128(x[1], zz, 2); Interleave.Expand64To128(x[2], zz, 4); - - ulong x3 = x[3]; - zz[6] = Interleave.Expand32to64((uint)x3); - zz[7] = Interleave.Expand16to32((uint)(x3 >> 32)); + Interleave.Expand64To128(x[3], zz, 6); } } } diff --git a/crypto/src/math/ec/custom/sec/SecT283Field.cs b/crypto/src/math/ec/custom/sec/SecT283Field.cs index 64fbc966d..ec2ba2cc1 100644 --- a/crypto/src/math/ec/custom/sec/SecT283Field.cs +++ b/crypto/src/math/ec/custom/sec/SecT283Field.cs @@ -390,10 +390,10 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec protected static void ImplSquare(ulong[] x, ulong[] zz) { - for (int i = 0; i < 4; ++i) - { - Interleave.Expand64To128(x[i], zz, i << 1); - } + Interleave.Expand64To128(x[0], zz, 0); + Interleave.Expand64To128(x[1], zz, 2); + Interleave.Expand64To128(x[2], zz, 4); + Interleave.Expand64To128(x[3], zz, 6); zz[8] = Interleave.Expand32to64((uint)x[4]); } } diff --git a/crypto/src/math/ec/custom/sec/SecT409Field.cs b/crypto/src/math/ec/custom/sec/SecT409Field.cs index f9962de5b..7cb9d4529 100644 --- a/crypto/src/math/ec/custom/sec/SecT409Field.cs +++ b/crypto/src/math/ec/custom/sec/SecT409Field.cs @@ -319,10 +319,12 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec protected static void ImplSquare(ulong[] x, ulong[] zz) { - for (int i = 0; i < 6; ++i) - { - Interleave.Expand64To128(x[i], zz, i << 1); - } + Interleave.Expand64To128(x[0], zz, 0); + Interleave.Expand64To128(x[1], zz, 2); + Interleave.Expand64To128(x[2], zz, 4); + Interleave.Expand64To128(x[3], zz, 6); + Interleave.Expand64To128(x[4], zz, 8); + Interleave.Expand64To128(x[5], zz, 10); zz[12] = Interleave.Expand32to64((uint)x[6]); } } diff --git a/crypto/src/math/ec/custom/sec/SecT571Field.cs b/crypto/src/math/ec/custom/sec/SecT571Field.cs index 9596aa5af..5a91985bc 100644 --- a/crypto/src/math/ec/custom/sec/SecT571Field.cs +++ b/crypto/src/math/ec/custom/sec/SecT571Field.cs @@ -322,10 +322,15 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec protected static void ImplSquare(ulong[] x, ulong[] zz) { - for (int i = 0; i < 9; ++i) - { - Interleave.Expand64To128(x[i], zz, i << 1); - } + Interleave.Expand64To128(x[0], zz, 0); + Interleave.Expand64To128(x[1], zz, 2); + Interleave.Expand64To128(x[2], zz, 4); + Interleave.Expand64To128(x[3], zz, 6); + Interleave.Expand64To128(x[4], zz, 8); + Interleave.Expand64To128(x[5], zz, 10); + Interleave.Expand64To128(x[6], zz, 12); + Interleave.Expand64To128(x[7], zz, 14); + Interleave.Expand64To128(x[8], zz, 16); } } } -- cgit 1.5.1