diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-03-10 13:51:28 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-03-10 13:51:28 +0700 |
commit | 44da462ba03951c22b1fa552f4d74b1a69882197 (patch) | |
tree | 15c0c88305e64b0e192d0f61053b1c8c50d26374 /crypto/src | |
parent | Inline Reduce32 calls and registerize some values to avoid extra writes (diff) | |
download | BouncyCastle.NET-ed25519-44da462ba03951c22b1fa552f4d74b1a69882197.tar.xz |
Refactor temporary variables in reductions
Diffstat (limited to 'crypto/src')
-rw-r--r-- | crypto/src/math/ec/custom/sec/SecP224R1Field.cs | 11 | ||||
-rw-r--r-- | crypto/src/math/ec/custom/sec/SecP256R1Field.cs | 16 | ||||
-rw-r--r-- | crypto/src/math/ec/custom/sec/SecP384R1Field.cs | 31 |
3 files changed, 30 insertions, 28 deletions
diff --git a/crypto/src/math/ec/custom/sec/SecP224R1Field.cs b/crypto/src/math/ec/custom/sec/SecP224R1Field.cs index 17c9b92a5..51d9020b6 100644 --- a/crypto/src/math/ec/custom/sec/SecP224R1Field.cs +++ b/crypto/src/math/ec/custom/sec/SecP224R1Field.cs @@ -88,16 +88,13 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec public static void Reduce(uint[] xx, uint[] z) { - long xx07 = xx[7], xx08 = xx[8], xx09 = xx[9], xx10 = xx[10]; - long xx11 = xx[11], xx12 = xx[12], xx13 = xx[13]; - - long t0 = xx07 + xx11; - long t1 = xx08 + xx12; - long t2 = xx09 + xx13; + long xx10 = xx[10], xx11 = xx[11], xx12 = xx[12], xx13 = xx[13]; const long n = 1; - t0 -= n; + long t0 = (long)xx[7] + xx11 - n; + long t1 = (long)xx[8] + xx12; + long t2 = (long)xx[9] + xx13; long cc = 0; cc += (long)xx[0] - t0; diff --git a/crypto/src/math/ec/custom/sec/SecP256R1Field.cs b/crypto/src/math/ec/custom/sec/SecP256R1Field.cs index aeb6f52fc..1ae07f341 100644 --- a/crypto/src/math/ec/custom/sec/SecP256R1Field.cs +++ b/crypto/src/math/ec/custom/sec/SecP256R1Field.cs @@ -88,18 +88,18 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec long xx08 = xx[8], xx09 = xx[9], xx10 = xx[10], xx11 = xx[11]; long xx12 = xx[12], xx13 = xx[13], xx14 = xx[14], xx15 = xx[15]; + const long n = 6; + + xx08 -= n; + long t0 = xx08 + xx09; long t1 = xx09 + xx10; - long t2 = xx10 + xx11; + long t2 = xx10 + xx11 - xx15; long t3 = xx11 + xx12; long t4 = xx12 + xx13; long t5 = xx13 + xx14; long t6 = xx14 + xx15; - const long n = 6; - - t0 -= n; - long cc = 0; cc += (long)xx[0] + t0 - t3 - t5; z[0] = (uint)cc; @@ -107,7 +107,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec cc += (long)xx[1] + t1 - t4 - t6; z[1] = (uint)cc; cc >>= 32; - cc += (long)xx[2] + t2 - t5 - xx15; + cc += (long)xx[2] + t2 - t5; z[2] = (uint)cc; cc >>= 32; cc += (long)xx[3] + (t3 << 1) + xx13 - xx15 - t0; @@ -116,13 +116,13 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec cc += (long)xx[4] + (t4 << 1) + xx14 - t1; z[4] = (uint)cc; cc >>= 32; - cc += (long)xx[5] + (t5 << 1) + xx15 - t2; + cc += (long)xx[5] + (t5 << 1) - t2; z[5] = (uint)cc; cc >>= 32; cc += (long)xx[6] + (t6 << 1) + t5 - t0; z[6] = (uint)cc; cc >>= 32; - cc += (long)xx[7] + (xx15 << 1) + xx15 + xx08 - t2 - t4 - n; + cc += (long)xx[7] + (xx15 << 1) + xx08 - t2 - t4; z[7] = (uint)cc; cc >>= 32; cc += n; diff --git a/crypto/src/math/ec/custom/sec/SecP384R1Field.cs b/crypto/src/math/ec/custom/sec/SecP384R1Field.cs index a12529d2c..508b01e3c 100644 --- a/crypto/src/math/ec/custom/sec/SecP384R1Field.cs +++ b/crypto/src/math/ec/custom/sec/SecP384R1Field.cs @@ -91,49 +91,54 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec public static void Reduce(uint[] xx, uint[] z) { - long xx12 = xx[12], xx13 = xx[13], xx14 = xx[14], xx15 = xx[15]; long xx16 = xx[16], xx17 = xx[17], xx18 = xx[18], xx19 = xx[19]; long xx20 = xx[20], xx21 = xx[21], xx22 = xx[22], xx23 = xx[23]; const long n = 1; - xx12 -= n; + long t0 = (long)xx[12] + xx20 - n; + long t1 = (long)xx[13] + xx22; + long t2 = (long)xx[14] + xx22 + xx23; + long t3 = (long)xx[15] + xx23; + long t4 = xx17 + xx21; + long t5 = xx21 - xx23; + long t6 = xx22 - xx23; long cc = 0; - cc += (long)xx[0] + xx12 + xx20 + xx21 - xx23; + cc += (long)xx[0] + t0 + t5; z[0] = (uint)cc; cc >>= 32; - cc += (long)xx[1] + xx13 + xx22 + xx23 - xx12 - xx20; + cc += (long)xx[1] + xx23 - t0 + t1; z[1] = (uint)cc; cc >>= 32; - cc += (long)xx[2] + xx14 + xx23 - xx13 - xx21; + cc += (long)xx[2] - xx21 - t1 + t2; z[2] = (uint)cc; cc >>= 32; - cc += (long)xx[3] + xx12 + xx15 + xx20 + xx21 - xx14 - xx22 - xx23; + cc += (long)xx[3] + t0 - t2 + t3 + t5; z[3] = (uint)cc; cc >>= 32; - cc += (long)xx[4] + xx12 + xx13 + xx16 + xx20 + ((xx21 - xx23) << 1) + xx22 - xx15; + cc += (long)xx[4] + xx16 + xx21 + t0 + t1 - t3 + t5; z[4] = (uint)cc; cc >>= 32; - cc += (long)xx[5] + xx13 + xx14 + xx17 + xx21 + (xx22 << 1) + xx23 - xx16; + cc += (long)xx[5] - xx16 + t1 + t2 + t4; z[5] = (uint)cc; cc >>= 32; - cc += (long)xx[6] + xx14 + xx15 + xx18 + xx22 + (xx23 << 1) - xx17; + cc += (long)xx[6] + xx18 - xx17 + t2 + t3; z[6] = (uint)cc; cc >>= 32; - cc += (long)xx[7] + xx15 + xx16 + xx19 + xx23 - xx18; + cc += (long)xx[7] + xx16 + xx19 - xx18 + t3; z[7] = (uint)cc; cc >>= 32; cc += (long)xx[8] + xx16 + xx17 + xx20 - xx19; z[8] = (uint)cc; cc >>= 32; - cc += (long)xx[9] + xx17 + xx18 + xx21 - xx20; + cc += (long)xx[9] + xx18 - xx20 + t4; z[9] = (uint)cc; cc >>= 32; - cc += (long)xx[10] + xx18 + xx19 + xx22 - xx21; + cc += (long)xx[10] + xx18 + xx19 - t5 + t6; z[10] = (uint)cc; cc >>= 32; - cc += (long)xx[11] + xx19 + xx20 + xx23 - xx22; + cc += (long)xx[11] + xx19 + xx20 - t6; z[11] = (uint)cc; cc >>= 32; cc += n; |