Skip to content

Commit 4abc7af

Browse files
committed
Let EC J-PAKE work with custom curves
1 parent 0ea89a4 commit 4abc7af

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

core/src/main/java/org/bouncycastle/crypto/agreement/ecjpake/ECJPAKECurve.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
public class ECJPAKECurve
2020
{
21-
private final ECCurve.Fp curve;
21+
private final ECCurve.AbstractFp curve;
2222
private final ECPoint g;
2323

2424
/**
@@ -116,7 +116,7 @@ public ECJPAKECurve(BigInteger q, BigInteger a, BigInteger b, BigInteger n, BigI
116116
* groups in {@link ECJPAKECurves}.
117117
* These pre-approved curves can avoid the expensive checks.
118118
*/
119-
ECJPAKECurve(ECCurve.Fp curve, ECPoint g)
119+
ECJPAKECurve(ECCurve.AbstractFp curve, ECPoint g)
120120
{
121121
ECJPAKEUtil.validateNotNull(curve, "curve");
122122
ECJPAKEUtil.validateNotNull(g, "g");
@@ -127,7 +127,7 @@ public ECJPAKECurve(BigInteger q, BigInteger a, BigInteger b, BigInteger n, BigI
127127
this.g = g;
128128
}
129129

130-
public ECCurve.Fp getCurve()
130+
public ECCurve.AbstractFp getCurve()
131131
{
132132
return curve;
133133
}
@@ -159,7 +159,7 @@ public BigInteger getH()
159159

160160
public BigInteger getQ()
161161
{
162-
return curve.getQ();
162+
return curve.getField().getCharacteristic();
163163
}
164164

165165
private static BigInteger calculateDeterminant(BigInteger q, BigInteger a, BigInteger b)

core/src/main/java/org/bouncycastle/crypto/agreement/ecjpake/ECJPAKECurves.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.bouncycastle.crypto.agreement.ecjpake;
22

3-
import org.bouncycastle.asn1.nist.NISTNamedCurves;
43
import org.bouncycastle.asn1.x9.X9ECParameters;
4+
import org.bouncycastle.crypto.ec.CustomNamedCurves;
55
import org.bouncycastle.math.ec.ECCurve;
66

77
/**
@@ -37,13 +37,14 @@ public class ECJPAKECurves
3737

3838
static
3939
{
40-
NIST_P256 = fromX9ECParameters(NISTNamedCurves.getByName("P-256"));
41-
NIST_P384 = fromX9ECParameters(NISTNamedCurves.getByName("P-384"));
42-
NIST_P521 = fromX9ECParameters(NISTNamedCurves.getByName("P-521"));
40+
NIST_P256 = getCurve("P-256");
41+
NIST_P384 = getCurve("P-384");
42+
NIST_P521 = getCurve("P-521");
4343
}
4444

45-
private static ECJPAKECurve fromX9ECParameters(X9ECParameters x9)
45+
private static ECJPAKECurve getCurve(String curveName)
4646
{
47-
return new ECJPAKECurve((ECCurve.Fp)x9.getCurve(), x9.getG());
47+
X9ECParameters x9 = CustomNamedCurves.getByName(curveName);
48+
return new ECJPAKECurve((ECCurve.AbstractFp)x9.getCurve(), x9.getG());
4849
}
4950
}

core/src/main/java/org/bouncycastle/crypto/agreement/ecjpake/ECJPAKEParticipant.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ public class ECJPAKEParticipant
107107
*/
108108
private String partnerParticipantId;
109109

110-
private ECCurve.Fp ecCurve;
111-
private BigInteger ecca;
112-
private BigInteger eccb;
110+
private ECCurve.AbstractFp ecCurve;
113111
private BigInteger q;
114112
private BigInteger h;
115113
private BigInteger n;
@@ -255,8 +253,6 @@ public ECJPAKEParticipant(
255253
this.password = Arrays.copyOf(password, password.length);
256254

257255
this.ecCurve = curve.getCurve();
258-
this.ecca = curve.getA();
259-
this.eccb = curve.getB();
260256
this.g = curve.getG();
261257
this.h = curve.getH();
262258
this.n = curve.getN();

core/src/test/java/org/bouncycastle/crypto/agreement/test/ECJPAKEUtilTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
public class ECJPAKEUtilTest
1919
extends TestCase
2020
{
21-
private static final BigInteger TEN = BigInteger.valueOf(10);
2221
private static final BigInteger ONE = BigInteger.valueOf(1);
2322

2423
public void testValidateParticipantIdsDiffer()
@@ -217,7 +216,7 @@ public void testValidateZeroKnowledgeProof()
217216
}
218217

219218
// (x,y) elements for Gx are not in Fq ie: not in [0,q-1]
220-
ECCurve.Fp curve = (ECCurve.Fp)curve1.getCurve();
219+
ECCurve.AbstractFp curve = curve1.getCurve();
221220
try
222221
{
223222
ECPoint invalidGx_1 = curve.createPoint(ONE.negate(), ONE);

0 commit comments

Comments
 (0)