Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-03-04 08:12:26 +0400
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-03-04 08:12:26 +0400
commit62ba2073804aa5a3657c3ab42d6119d6dac8193b (patch)
tree40e6809730de4577b394d5810c28b59cde273067 /core/src/main/java/org
parent6c2a2a1ed5d97d75eb3f2c1bde63c0d3dc9cacae (diff)
Just use shift methods from Nat class evverywhere
Diffstat (limited to 'core/src/main/java/org')
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/custom/sec/Curve25519Field.java2
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat192.java87
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat224.java87
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat256.java87
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP192K1Field.java8
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP192R1Field.java8
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP224K1Field.java8
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP224R1Field.java8
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP256K1Field.java6
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP256R1Field.java8
10 files changed, 38 insertions, 271 deletions
diff --git a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Curve25519Field.java b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Curve25519Field.java
index 6e38b34e..5caab12d 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Curve25519Field.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Curve25519Field.java
@@ -148,7 +148,7 @@ public class Curve25519Field
public static void twice(int[] x, int[] z)
{
- Nat256.shiftUpBit(x, 0, z);
+ Nat.shiftUpBit(8, x, 0, z);
if (Nat256.gte(z, P))
{
Nat256.addWord(PInv, z, 0);
diff --git a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat192.java b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat192.java
index 65430adc..0841ff03 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat192.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat192.java
@@ -3,6 +3,7 @@ package org.bouncycastle.math.ec.custom.sec;
import java.math.BigInteger;
import org.bouncycastle.crypto.util.Pack;
+import org.bouncycastle.math.ec.Nat;
public abstract class Nat192
{
@@ -712,88 +713,6 @@ public abstract class Nat192
return (int)c;
}
- public static int shiftDownBit(int[] x, int xLen, int c)
- {
- int i = xLen;
- while (--i >= 0)
- {
- int next = x[i];
- x[i] = (next >>> 1) | (c << 31);
- c = next;
- }
- return c << 31;
- }
-
- public static int shiftDownBit(int[] x, int c, int[] z)
- {
- int i = 6;
- while (--i >= 0)
- {
- int next = x[i];
- z[i] = (next >>> 1) | (c << 31);
- c = next;
- }
- return c << 31;
- }
-
- public static int shiftDownBits(int[] x, int xLen, int bits, int c)
- {
-// assert bits > 0 && bits < 32;
- int i = xLen;
- while (--i >= 0)
- {
- int next = x[i];
- x[i] = (next >>> bits) | (c << -bits);
- c = next;
- }
- return c << -bits;
- }
-
- public static int shiftDownWord(int[] x, int xLen, int c)
- {
- int i = xLen;
- while (--i >= 0)
- {
- int next = x[i];
- x[i] = c;
- c = next;
- }
- return c;
- }
-
- public static int shiftUpBit(int[] x, int xLen, int c)
- {
- for (int i = 0; i < xLen; ++i)
- {
- int next = x[i];
- x[i] = (next << 1) | (c >>> 31);
- c = next;
- }
- return c >>> 31;
- }
-
- public static int shiftUpBit(int[] x, int xOff, int xLen, int c)
- {
- for (int i = 0; i < xLen; ++i)
- {
- int next = x[xOff + i];
- x[xOff + i] = (next << 1) | (c >>> 31);
- c = next;
- }
- return c >>> 31;
- }
-
- public static int shiftUpBit(int[] x, int c, int[] z)
- {
- for (int i = 0; i < 6; ++i)
- {
- int next = x[i];
- z[i] = (next << 1) | (c >>> 31);
- c = next;
- }
- return c >>> 31;
- }
-
public static void square(int[] x, int[] zz)
{
long x_0 = x[0] & M;
@@ -886,7 +805,7 @@ public abstract class Nat192
zz[10] = (int)zz_10;
zz[11] += (int)(zz_10 >>> 32);
- shiftUpBit(zz, 12, (int)x_0 << 31);
+ Nat.shiftUpBit(12, zz, (int)x_0 << 31);
}
public static void square(int[] x, int xOff, int[] zz, int zzOff)
@@ -981,7 +900,7 @@ public abstract class Nat192
zz[zzOff + 10] = (int)zz_10;
zz[zzOff + 11] += (int)(zz_10 >>> 32);
- shiftUpBit(zz, zzOff, 12, (int)x_0 << 31);
+ Nat.shiftUpBit(12, zz, zzOff, (int)x_0 << 31);
}
public static int sub(int[] x, int[] y, int[] z)
diff --git a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat224.java b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat224.java
index 7bd29cb7..8053a880 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat224.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat224.java
@@ -3,6 +3,7 @@ package org.bouncycastle.math.ec.custom.sec;
import java.math.BigInteger;
import org.bouncycastle.crypto.util.Pack;
+import org.bouncycastle.math.ec.Nat;
public abstract class Nat224
{
@@ -864,88 +865,6 @@ public abstract class Nat224
return (int)c;
}
- public static int shiftDownBit(int[] x, int xLen, int c)
- {
- int i = xLen;
- while (--i >= 0)
- {
- int next = x[i];
- x[i] = (next >>> 1) | (c << 31);
- c = next;
- }
- return c << 31;
- }
-
- public static int shiftDownBit(int[] x, int c, int[] z)
- {
- int i = 7;
- while (--i >= 0)
- {
- int next = x[i];
- z[i] = (next >>> 1) | (c << 31);
- c = next;
- }
- return c << 31;
- }
-
- public static int shiftDownBits(int[] x, int xLen, int bits, int c)
- {
-// assert bits > 0 && bits < 32;
- int i = xLen;
- while (--i >= 0)
- {
- int next = x[i];
- x[i] = (next >>> bits) | (c << -bits);
- c = next;
- }
- return c << -bits;
- }
-
- public static int shiftDownWord(int[] x, int xLen, int c)
- {
- int i = xLen;
- while (--i >= 0)
- {
- int next = x[i];
- x[i] = c;
- c = next;
- }
- return c;
- }
-
- public static int shiftUpBit(int[] x, int xLen, int c)
- {
- for (int i = 0; i < xLen; ++i)
- {
- int next = x[i];
- x[i] = (next << 1) | (c >>> 31);
- c = next;
- }
- return c >>> 31;
- }
-
- public static int shiftUpBit(int[] x, int xOff, int xLen, int c)
- {
- for (int i = 0; i < xLen; ++i)
- {
- int next = x[xOff + i];
- x[xOff + i] = (next << 1) | (c >>> 31);
- c = next;
- }
- return c >>> 31;
- }
-
- public static int shiftUpBit(int[] x, int c, int[] z)
- {
- for (int i = 0; i < 7; ++i)
- {
- int next = x[i];
- z[i] = (next << 1) | (c >>> 31);
- c = next;
- }
- return c >>> 31;
- }
-
public static void square(int[] x, int[] zz)
{
long x_0 = x[0] & M;
@@ -1057,7 +976,7 @@ public abstract class Nat224
zz[12] = (int)zz_12;
zz[13] += (int)(zz_12 >>> 32);
- shiftUpBit(zz, 14, (int)x_0 << 31);
+ Nat.shiftUpBit(14, zz, (int)x_0 << 31);
}
public static void square(int[] x, int xOff, int[] zz, int zzOff)
@@ -1171,7 +1090,7 @@ public abstract class Nat224
zz[zzOff + 12] = (int)zz_12;
zz[zzOff + 13] += (int)(zz_12 >>> 32);
- shiftUpBit(zz, zzOff, 14, (int)x_0 << 31);
+ Nat.shiftUpBit(14, zz, zzOff, (int)x_0 << 31);
}
public static int sub(int[] x, int[] y, int[] z)
diff --git a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat256.java b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat256.java
index cb8ec7c8..0ec467b5 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat256.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/Nat256.java
@@ -3,6 +3,7 @@ package org.bouncycastle.math.ec.custom.sec;
import java.math.BigInteger;
import org.bouncycastle.crypto.util.Pack;
+import org.bouncycastle.math.ec.Nat;
public abstract class Nat256
{
@@ -931,88 +932,6 @@ public abstract class Nat256
return (int)c;
}
- public static int shiftDownBit(int[] x, int xLen, int c)
- {
- int i = xLen;
- while (--i >= 0)
- {
- int next = x[i];
- x[i] = (next >>> 1) | (c << 31);
- c = next;
- }
- return c << 31;
- }
-
- public static int shiftDownBit(int[] x, int c, int[] z)
- {
- int i = 8;
- while (--i >= 0)
- {
- int next = x[i];
- z[i] = (next >>> 1) | (c << 31);
- c = next;
- }
- return c << 31;
- }
-
- public static int shiftDownBits(int[] x, int xLen, int bits, int c)
- {
-// assert bits > 0 && bits < 32;
- int i = xLen;
- while (--i >= 0)
- {
- int next = x[i];
- x[i] = (next >>> bits) | (c << -bits);
- c = next;
- }
- return c << -bits;
- }
-
- public static int shiftDownWord(int[] x, int xLen, int c)
- {
- int i = xLen;
- while (--i >= 0)
- {
- int next = x[i];
- x[i] = c;
- c = next;
- }
- return c;
- }
-
- public static int shiftUpBit(int[] x, int xLen, int c)
- {
- for (int i = 0; i < xLen; ++i)
- {
- int next = x[i];
- x[i] = (next << 1) | (c >>> 31);
- c = next;
- }
- return c >>> 31;
- }
-
- public static int shiftUpBit(int[] x, int xOff, int xLen, int c)
- {
- for (int i = 0; i < xLen; ++i)
- {
- int next = x[xOff + i];
- x[xOff + i] = (next << 1) | (c >>> 31);
- c = next;
- }
- return c >>> 31;
- }
-
- public static int shiftUpBit(int[] x, int c, int[] z)
- {
- for (int i = 0; i < 8; ++i)
- {
- int next = x[i];
- z[i] = (next << 1) | (c >>> 31);
- c = next;
- }
- return c >>> 31;
- }
-
public static void square(int[] x, int[] zz)
{
long x_0 = x[0] & M;
@@ -1145,7 +1064,7 @@ public abstract class Nat256
zz[14] = (int)zz_14;
zz[15] += (int)(zz_14 >>> 32);
- shiftUpBit(zz, 16, (int)x_0 << 31);
+ Nat.shiftUpBit(16, zz, (int)x_0 << 31);
}
public static void square(int[] x, int xOff, int[] zz, int zzOff)
@@ -1280,7 +1199,7 @@ public abstract class Nat256
zz[zzOff + 14] = (int)zz_14;
zz[zzOff + 15] += (int)(zz_14 >>> 32);
- shiftUpBit(zz, zzOff, 16, (int)x_0 << 31);
+ Nat.shiftUpBit(16, zz, zzOff, (int)x_0 << 31);
}
public static int sub(int[] x, int[] y, int[] z)
diff --git a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP192K1Field.java b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP192K1Field.java
index 63d38ad9..b8683854 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP192K1Field.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP192K1Field.java
@@ -2,6 +2,8 @@ package org.bouncycastle.math.ec.custom.sec;
import java.math.BigInteger;
+import org.bouncycastle.math.ec.Nat;
+
public class SecP192K1Field
{
// 2^192 - 2^32 - 2^12 - 2^8 - 2^7 - 2^6 - 2^3 - 1
@@ -55,12 +57,12 @@ public class SecP192K1Field
{
if ((x[0] & 1) == 0)
{
- Nat192.shiftDownBit(x, 0, z);
+ Nat.shiftDownBit(6, x, 0, z);
}
else
{
int c = Nat192.add(x, P, z);
- Nat192.shiftDownBit(z, c, z);
+ Nat.shiftDownBit(6, z, c);
}
}
@@ -147,7 +149,7 @@ public class SecP192K1Field
public static void twice(int[] x, int[] z)
{
- int c = Nat192.shiftUpBit(x, 0, z);
+ int c = Nat.shiftUpBit(6, x, 0, z);
if (c != 0 || (z[5] == P5 && Nat192.gte(z, P)))
{
Nat192.addDWord(PInv, z, 0);
diff --git a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP192R1Field.java b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP192R1Field.java
index 84cebebe..12695d4a 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP192R1Field.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP192R1Field.java
@@ -2,6 +2,8 @@ package org.bouncycastle.math.ec.custom.sec;
import java.math.BigInteger;
+import org.bouncycastle.math.ec.Nat;
+
public class SecP192R1Field
{
private static final long M = 0xFFFFFFFFL;
@@ -55,12 +57,12 @@ public class SecP192R1Field
{
if ((x[0] & 1) == 0)
{
- Nat192.shiftDownBit(x, 0, z);
+ Nat.shiftDownBit(6, x, 0, z);
}
else
{
int c = Nat192.add(x, P, z);
- Nat192.shiftDownBit(z, c, z);
+ Nat.shiftDownBit(6, z, c);
}
}
@@ -173,7 +175,7 @@ public class SecP192R1Field
public static void twice(int[] x, int[] z)
{
- int c = Nat192.shiftUpBit(x, 0, z);
+ int c = Nat.shiftUpBit(6, x, 0, z);
if (c != 0 || (z[5] == P5 && Nat192.gte(z, P)))
{
Nat192.subFrom(P, z);
diff --git a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP224K1Field.java b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP224K1Field.java
index 4dc9e121..8d7e08ec 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP224K1Field.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP224K1Field.java
@@ -2,6 +2,8 @@ package org.bouncycastle.math.ec.custom.sec;
import java.math.BigInteger;
+import org.bouncycastle.math.ec.Nat;
+
public class SecP224K1Field
{
// 2^224 - 2^32 - 2^12 - 2^11 - 2^9 - 2^7 - 2^4 - 2 - 1
@@ -56,12 +58,12 @@ public class SecP224K1Field
{
if ((x[0] & 1) == 0)
{
- Nat224.shiftDownBit(x, 0, z);
+ Nat.shiftDownBit(7, x, 0, z);
}
else
{
int c = Nat224.add(x, P, z);
- Nat224.shiftDownBit(z, c, z);
+ Nat.shiftDownBit(7, z, c);
}
}
@@ -148,7 +150,7 @@ public class SecP224K1Field
public static void twice(int[] x, int[] z)
{
- int c = Nat224.shiftUpBit(x, 0, z);
+ int c = Nat.shiftUpBit(7, x, 0, z);
if (c != 0 || (z[6] == P6 && Nat224.gte(z, P)))
{
Nat224.addDWord(PInv, z, 0);
diff --git a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP224R1Field.java b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP224R1Field.java
index 4eabd3a4..eb77d3fe 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP224R1Field.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP224R1Field.java
@@ -2,6 +2,8 @@ package org.bouncycastle.math.ec.custom.sec;
import java.math.BigInteger;
+import org.bouncycastle.math.ec.Nat;
+
public class SecP224R1Field
{
private static final long M = 0xFFFFFFFFL;
@@ -55,12 +57,12 @@ public class SecP224R1Field
{
if ((x[0] & 1) == 0)
{
- Nat224.shiftDownBit(x, 0, z);
+ Nat.shiftDownBit(7, x, 0, z);
}
else
{
int c = Nat224.add(x, P, z);
- Nat224.shiftDownBit(z, c, z);
+ Nat.shiftDownBit(7, z, c);
}
}
@@ -177,7 +179,7 @@ public class SecP224R1Field
public static void twice(int[] x, int[] z)
{
- int c = Nat224.shiftUpBit(x, 0, z);
+ int c = Nat.shiftUpBit(7, x, 0, z);
if (c != 0 || (z[6] == P6 && Nat224.gte(z, P)))
{
Nat224.subFrom(P, z);
diff --git a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP256K1Field.java b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP256K1Field.java
index ad92be7f..dd07ea54 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP256K1Field.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP256K1Field.java
@@ -63,12 +63,12 @@ public class SecP256K1Field
{
if ((x[0] & 1) == 0)
{
- Nat256.shiftDownBit(x, 0, z);
+ Nat.shiftDownBit(8, x, 0, z);
}
else
{
int c = Nat256.add(x, P, z);
- Nat256.shiftDownBit(z, c, z);
+ Nat.shiftDownBit(8, z, c);
}
}
@@ -158,7 +158,7 @@ public class SecP256K1Field
public static void twice(int[] x, int[] z)
{
- int c = Nat256.shiftUpBit(x, 0, z);
+ int c = Nat.shiftUpBit(8, x, 0, z);
if (c != 0 || (z[7] == P7 && Nat256.gte(z, P)))
{
Nat256.add33To(PInv33, z);
diff --git a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP256R1Field.java b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP256R1Field.java
index b7889258..6ba928f8 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP256R1Field.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/custom/sec/SecP256R1Field.java
@@ -2,6 +2,8 @@ package org.bouncycastle.math.ec.custom.sec;
import java.math.BigInteger;
+import org.bouncycastle.math.ec.Nat;
+
public class SecP256R1Field
{
private static final long M = 0xFFFFFFFFL;
@@ -58,12 +60,12 @@ public class SecP256R1Field
{
if ((x[0] & 1) == 0)
{
- Nat256.shiftDownBit(x, 0, z);
+ Nat.shiftDownBit(8, x, 0, z);
}
else
{
int c = Nat256.add(x, P, z);
- Nat256.shiftDownBit(z, c, z);
+ Nat.shiftDownBit(8, z, c);
}
}
@@ -227,7 +229,7 @@ public class SecP256R1Field
public static void twice(int[] x, int[] z)
{
- int c = Nat256.shiftUpBit(x, 0, z);
+ int c = Nat.shiftUpBit(8, x, 0, z);
if (c != 0 || (z[7] == P7 && Nat256.gte(z, P)))
{
Nat256.subFrom(P, z);