summary refs log tree commit diff
path: root/crypto/src/math/raw
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2018-04-15 21:12:11 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2018-04-15 21:12:11 +0700
commitd79a501212d4012139c714e361577669c75171aa (patch)
treef78e8c7d34c9448698e17bc341fd8d293814dd3e /crypto/src/math/raw
parentUpdate Readme.html for SHA-3 perf. opts. (diff)
downloadBouncyCastle.NET-ed25519-d79a501212d4012139c714e361577669c75171aa.tar.xz
Cache-safety for EC lookup tables
- creation of cache-safe lookup tables delegated to ECCurve
- FixedPointCombMultiplier uses cache-safe lookup table
- FixedPointCombMultiplier avoids BigInteger.TestBit
Diffstat (limited to 'crypto/src/math/raw')
-rw-r--r--crypto/src/math/raw/Nat.cs5
-rw-r--r--crypto/src/math/raw/Nat128.cs14
-rw-r--r--crypto/src/math/raw/Nat160.cs9
-rw-r--r--crypto/src/math/raw/Nat192.cs17
-rw-r--r--crypto/src/math/raw/Nat224.cs11
-rw-r--r--crypto/src/math/raw/Nat256.cs20
-rw-r--r--crypto/src/math/raw/Nat320.cs9
-rw-r--r--crypto/src/math/raw/Nat448.cs11
-rw-r--r--crypto/src/math/raw/Nat576.cs13
9 files changed, 109 insertions, 0 deletions
diff --git a/crypto/src/math/raw/Nat.cs b/crypto/src/math/raw/Nat.cs

index 1f9ab00ec..cf6516c61 100644 --- a/crypto/src/math/raw/Nat.cs +++ b/crypto/src/math/raw/Nat.cs
@@ -207,6 +207,11 @@ namespace Org.BouncyCastle.Math.Raw return z; } + public static void Copy(int len, uint[] x, int xOff, uint[] z, int zOff) + { + Array.Copy(x, xOff, z, zOff, len); + } + public static uint[] Create(int len) { return new uint[len]; diff --git a/crypto/src/math/raw/Nat128.cs b/crypto/src/math/raw/Nat128.cs
index 1d3b64d32..27ed5abe4 100644 --- a/crypto/src/math/raw/Nat128.cs +++ b/crypto/src/math/raw/Nat128.cs
@@ -111,12 +111,26 @@ namespace Org.BouncyCastle.Math.Raw z[3] = x[3]; } + public static void Copy(uint[] x, int xOff, uint[] z, int zOff) + { + z[zOff + 0] = x[xOff + 0]; + z[zOff + 1] = x[xOff + 1]; + z[zOff + 2] = x[xOff + 2]; + z[zOff + 3] = x[xOff + 3]; + } + public static void Copy64(ulong[] x, ulong[] z) { z[0] = x[0]; z[1] = x[1]; } + public static void Copy64(ulong[] x, int xOff, ulong[] z, int zOff) + { + z[zOff + 0] = x[xOff + 0]; + z[zOff + 1] = x[xOff + 1]; + } + public static uint[] Create() { return new uint[4]; diff --git a/crypto/src/math/raw/Nat160.cs b/crypto/src/math/raw/Nat160.cs
index 1fd00e576..57212cae0 100644 --- a/crypto/src/math/raw/Nat160.cs +++ b/crypto/src/math/raw/Nat160.cs
@@ -129,6 +129,15 @@ namespace Org.BouncyCastle.Math.Raw z[4] = x[4]; } + public static void Copy(uint[] x, int xOff, uint[] z, int zOff) + { + z[zOff + 0] = x[xOff + 0]; + z[zOff + 1] = x[xOff + 1]; + z[zOff + 2] = x[xOff + 2]; + z[zOff + 3] = x[xOff + 3]; + z[zOff + 4] = x[xOff + 4]; + } + public static uint[] Create() { return new uint[5]; diff --git a/crypto/src/math/raw/Nat192.cs b/crypto/src/math/raw/Nat192.cs
index 3099bafab..06c75aa54 100644 --- a/crypto/src/math/raw/Nat192.cs +++ b/crypto/src/math/raw/Nat192.cs
@@ -145,6 +145,16 @@ namespace Org.BouncyCastle.Math.Raw z[5] = x[5]; } + public static void Copy(uint[] x, int xOff, uint[] z, int zOff) + { + z[zOff + 0] = x[xOff + 0]; + z[zOff + 1] = x[xOff + 1]; + z[zOff + 2] = x[xOff + 2]; + z[zOff + 3] = x[xOff + 3]; + z[zOff + 4] = x[xOff + 4]; + z[zOff + 5] = x[xOff + 5]; + } + public static void Copy64(ulong[] x, ulong[] z) { z[0] = x[0]; @@ -152,6 +162,13 @@ namespace Org.BouncyCastle.Math.Raw z[2] = x[2]; } + public static void Copy64(ulong[] x, int xOff, ulong[] z, int zOff) + { + z[zOff + 0] = x[xOff + 0]; + z[zOff + 1] = x[xOff + 1]; + z[zOff + 2] = x[xOff + 2]; + } + public static uint[] Create() { return new uint[6]; diff --git a/crypto/src/math/raw/Nat224.cs b/crypto/src/math/raw/Nat224.cs
index 978caf265..ff1eb6306 100644 --- a/crypto/src/math/raw/Nat224.cs +++ b/crypto/src/math/raw/Nat224.cs
@@ -216,6 +216,17 @@ namespace Org.BouncyCastle.Math.Raw z[6] = x[6]; } + public static void Copy(uint[] x, int xOff, uint[] z, int zOff) + { + z[zOff + 0] = x[xOff + 0]; + z[zOff + 1] = x[xOff + 1]; + z[zOff + 2] = x[xOff + 2]; + z[zOff + 3] = x[xOff + 3]; + z[zOff + 4] = x[xOff + 4]; + z[zOff + 5] = x[xOff + 5]; + z[zOff + 6] = x[xOff + 6]; + } + public static uint[] Create() { return new uint[7]; diff --git a/crypto/src/math/raw/Nat256.cs b/crypto/src/math/raw/Nat256.cs
index 09c751a5a..2be03d642 100644 --- a/crypto/src/math/raw/Nat256.cs +++ b/crypto/src/math/raw/Nat256.cs
@@ -239,6 +239,18 @@ namespace Org.BouncyCastle.Math.Raw z[7] = x[7]; } + public static void Copy(uint[] x, int xOff, uint[] z, int zOff) + { + z[zOff + 0] = x[xOff + 0]; + z[zOff + 1] = x[xOff + 1]; + z[zOff + 2] = x[xOff + 2]; + z[zOff + 3] = x[xOff + 3]; + z[zOff + 4] = x[xOff + 4]; + z[zOff + 5] = x[xOff + 5]; + z[zOff + 6] = x[xOff + 6]; + z[zOff + 7] = x[xOff + 7]; + } + public static void Copy64(ulong[] x, ulong[] z) { z[0] = x[0]; @@ -247,6 +259,14 @@ namespace Org.BouncyCastle.Math.Raw z[3] = x[3]; } + public static void Copy64(ulong[] x, int xOff, ulong[] z, int zOff) + { + z[zOff + 0] = x[xOff + 0]; + z[zOff + 1] = x[xOff + 1]; + z[zOff + 2] = x[xOff + 2]; + z[zOff + 3] = x[xOff + 3]; + } + public static uint[] Create() { return new uint[8]; diff --git a/crypto/src/math/raw/Nat320.cs b/crypto/src/math/raw/Nat320.cs
index c7daa71e2..0ad677db4 100644 --- a/crypto/src/math/raw/Nat320.cs +++ b/crypto/src/math/raw/Nat320.cs
@@ -16,6 +16,15 @@ namespace Org.BouncyCastle.Math.Raw z[4] = x[4]; } + public static void Copy64(ulong[] x, int xOff, ulong[] z, int zOff) + { + z[zOff + 0] = x[xOff + 0]; + z[zOff + 1] = x[xOff + 1]; + z[zOff + 2] = x[xOff + 2]; + z[zOff + 3] = x[xOff + 3]; + z[zOff + 4] = x[xOff + 4]; + } + public static ulong[] Create64() { return new ulong[5]; diff --git a/crypto/src/math/raw/Nat448.cs b/crypto/src/math/raw/Nat448.cs
index 52a253f1b..b0774b37a 100644 --- a/crypto/src/math/raw/Nat448.cs +++ b/crypto/src/math/raw/Nat448.cs
@@ -18,6 +18,17 @@ namespace Org.BouncyCastle.Math.Raw z[6] = x[6]; } + public static void Copy64(ulong[] x, int xOff, ulong[] z, int zOff) + { + z[zOff + 0] = x[xOff + 0]; + z[zOff + 1] = x[xOff + 1]; + z[zOff + 2] = x[xOff + 2]; + z[zOff + 3] = x[xOff + 3]; + z[zOff + 4] = x[xOff + 4]; + z[zOff + 5] = x[xOff + 5]; + z[zOff + 6] = x[xOff + 6]; + } + public static ulong[] Create64() { return new ulong[7]; diff --git a/crypto/src/math/raw/Nat576.cs b/crypto/src/math/raw/Nat576.cs
index 813fb86be..14279b61a 100644 --- a/crypto/src/math/raw/Nat576.cs +++ b/crypto/src/math/raw/Nat576.cs
@@ -20,6 +20,19 @@ namespace Org.BouncyCastle.Math.Raw z[8] = x[8]; } + public static void Copy64(ulong[] x, int xOff, ulong[] z, int zOff) + { + z[zOff + 0] = x[xOff + 0]; + z[zOff + 1] = x[xOff + 1]; + z[zOff + 2] = x[xOff + 2]; + z[zOff + 3] = x[xOff + 3]; + z[zOff + 4] = x[xOff + 4]; + z[zOff + 5] = x[xOff + 5]; + z[zOff + 6] = x[xOff + 6]; + z[zOff + 7] = x[xOff + 7]; + z[zOff + 8] = x[xOff + 8]; + } + public static ulong[] Create64() { return new ulong[9];