diff options
Diffstat (limited to 'repackaged/bcprov/src/main/java/com/android/org/bouncycastle/math/ec/custom/sec/SecP384R1Curve.java')
-rw-r--r-- | repackaged/bcprov/src/main/java/com/android/org/bouncycastle/math/ec/custom/sec/SecP384R1Curve.java | 62 |
1 files changed, 49 insertions, 13 deletions
diff --git a/repackaged/bcprov/src/main/java/com/android/org/bouncycastle/math/ec/custom/sec/SecP384R1Curve.java b/repackaged/bcprov/src/main/java/com/android/org/bouncycastle/math/ec/custom/sec/SecP384R1Curve.java index 21254374..1342081b 100644 --- a/repackaged/bcprov/src/main/java/com/android/org/bouncycastle/math/ec/custom/sec/SecP384R1Curve.java +++ b/repackaged/bcprov/src/main/java/com/android/org/bouncycastle/math/ec/custom/sec/SecP384R1Curve.java @@ -2,7 +2,10 @@ package com.android.org.bouncycastle.math.ec.custom.sec; import java.math.BigInteger; +import java.security.SecureRandom; +import com.android.org.bouncycastle.math.ec.AbstractECLookupTable; +import com.android.org.bouncycastle.math.ec.ECConstants; import com.android.org.bouncycastle.math.ec.ECCurve; import com.android.org.bouncycastle.math.ec.ECFieldElement; import com.android.org.bouncycastle.math.ec.ECLookupTable; @@ -15,10 +18,10 @@ import com.android.org.bouncycastle.util.encoders.Hex; */ public class SecP384R1Curve extends ECCurve.AbstractFp { - public static final BigInteger q = new BigInteger(1, - Hex.decode("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF")); + public static final BigInteger q = SecP384R1FieldElement.Q; - private static final int SecP384R1_DEFAULT_COORDS = COORD_JACOBIAN; + private static final int SECP384R1_DEFAULT_COORDS = COORD_JACOBIAN; + private static final ECFieldElement[] SECP384R1_AFFINE_ZS = new ECFieldElement[] { new SecP384R1FieldElement(ECConstants.ONE) }; protected SecP384R1Point infinity; @@ -29,13 +32,13 @@ public class SecP384R1Curve extends ECCurve.AbstractFp this.infinity = new SecP384R1Point(this, null, null); this.a = fromBigInteger(new BigInteger(1, - Hex.decode("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC"))); + Hex.decodeStrict("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC"))); this.b = fromBigInteger(new BigInteger(1, - Hex.decode("B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF"))); - this.order = new BigInteger(1, Hex.decode("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973")); + Hex.decodeStrict("B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF"))); + this.order = new BigInteger(1, Hex.decodeStrict("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973")); this.cofactor = BigInteger.valueOf(1); - this.coord = SecP384R1_DEFAULT_COORDS; + this.coord = SECP384R1_DEFAULT_COORDS; } protected ECCurve cloneCurve() @@ -69,14 +72,14 @@ public class SecP384R1Curve extends ECCurve.AbstractFp return new SecP384R1FieldElement(x); } - protected ECPoint createRawPoint(ECFieldElement x, ECFieldElement y, boolean withCompression) + protected ECPoint createRawPoint(ECFieldElement x, ECFieldElement y) { - return new SecP384R1Point(this, x, y, withCompression); + return new SecP384R1Point(this, x, y); } - protected ECPoint createRawPoint(ECFieldElement x, ECFieldElement y, ECFieldElement[] zs, boolean withCompression) + protected ECPoint createRawPoint(ECFieldElement x, ECFieldElement y, ECFieldElement[] zs) { - return new SecP384R1Point(this, x, y, zs, withCompression); + return new SecP384R1Point(this, x, y, zs); } public ECPoint getInfinity() @@ -99,7 +102,7 @@ public class SecP384R1Curve extends ECCurve.AbstractFp } } - return new ECLookupTable() + return new AbstractECLookupTable() { public int getSize() { @@ -124,8 +127,41 @@ public class SecP384R1Curve extends ECCurve.AbstractFp pos += (FE_INTS * 2); } - return createRawPoint(new SecP384R1FieldElement(x), new SecP384R1FieldElement(y), false); + return createPoint(x, y); + } + + public ECPoint lookupVar(int index) + { + int[] x = Nat.create(FE_INTS), y = Nat.create(FE_INTS); + int pos = index * FE_INTS * 2; + + for (int j = 0; j < FE_INTS; ++j) + { + x[j] = table[pos + j]; + y[j] = table[pos + FE_INTS + j]; + } + + return createPoint(x, y); + } + + private ECPoint createPoint(int[] x, int[] y) + { + return createRawPoint(new SecP384R1FieldElement(x), new SecP384R1FieldElement(y), SECP384R1_AFFINE_ZS); } }; } + + public ECFieldElement randomFieldElement(SecureRandom r) + { + int[] x = Nat.create(12); + SecP384R1Field.random(r, x); + return new SecP384R1FieldElement(x); + } + + public ECFieldElement randomFieldElementMult(SecureRandom r) + { + int[] x = Nat.create(12); + SecP384R1Field.randomMult(r, x); + return new SecP384R1FieldElement(x); + } } |