Skip to content

Commit c9892ff

Browse files
committed
feat: make curve definitions extend ECCurve
1 parent 0e53ada commit c9892ff

File tree

6 files changed

+19
-8
lines changed

6 files changed

+19
-8
lines changed

applet/src/main/java/opencrypto/jcmathlib/ECCurve.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package opencrypto.jcmathlib;
22

33
import javacard.framework.JCSystem;
4-
import javacard.framework.Util;
54
import javacard.security.ECPrivateKey;
65
import javacard.security.ECPublicKey;
76
import javacard.security.KeyBuilder;
@@ -56,8 +55,8 @@ public ECCurve(byte[] p, byte[] a, byte[] b, byte[] G, byte[] r, ResourceManager
5655
disposablePair = newKeyPair(null);
5756
disposablePriv = (ECPrivateKey) disposablePair.getPrivate();
5857
disposablePub = (ECPublicKey) disposablePair.getPublic();
59-
}
60-
58+
}
59+
6160
/**
6261
* Refresh critical information stored in RAM for performance reasons after a card reset (RAM was cleared).
6362
*/

applet/src/main/java/opencrypto/jcmathlib/Example.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void initialize() {
5959
// Allocate resources for a required elliptic curve size (in bits)
6060
rm = new ResourceManager((short) 256);
6161
// Allocate SecP256r1 curve and two EC points on this curve
62-
curve = new ECCurve(SecP256r1.p, SecP256r1.a, SecP256r1.b, SecP256r1.G, SecP256r1.r, rm);
62+
curve = new SecP256k1(rm);
6363
point1 = new ECPoint(curve);
6464
point2 = new ECPoint(curve);
6565
// Allocate two BigNats large enough to hold scalars of the elliptic curve

applet/src/main/java/opencrypto/jcmathlib/UnitTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void initialize() {
120120

121121

122122
// Pre-allocate test objects (no new allocation for every tested operation)
123-
curve = new ECCurve(SecP256r1.p, SecP256r1.a, SecP256r1.b, SecP256r1.G, SecP256r1.r, rm);
123+
curve = new SecP256r1(rm);
124124
memoryInfoOffset = snapshotAvailableMemory((short) 3, memoryInfo, memoryInfoOffset);
125125
customG = new byte[(short) SecP256r1.G.length];
126126
Util.arrayCopyNonAtomic(SecP256r1.G, (short) 0, customG, (short) 0, (short) SecP256r1.G.length);

applet/src/main/java/opencrypto/jcmathlib/curves/SecP256k1.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package opencrypto.jcmathlib;
22

3-
public class SecP256k1 {
3+
public class SecP256k1 extends ECCurve {
4+
public SecP256k1(ResourceManager rm) {
5+
super(p, a, b, G, r, rm);
6+
}
7+
48
public final static byte[] p = {
59
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
610
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,

applet/src/main/java/opencrypto/jcmathlib/curves/SecP256r1.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package opencrypto.jcmathlib;
22

3-
public class SecP256r1 {
3+
public class SecP256r1 extends ECCurve {
4+
public SecP256r1(ResourceManager rm) {
5+
super(p, a, b, G, r, rm);
6+
}
7+
48
public final static byte[] p = {
59
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
610
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,

applet/src/main/java/opencrypto/jcmathlib/curves/SecP512r1.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package opencrypto.jcmathlib;
22

3-
public class SecP512r1 {
3+
public class SecP512r1 extends ECCurve {
4+
public SecP512r1(ResourceManager rm) {
5+
super(p, a, b, G, r, rm);
6+
}
7+
48
public final static byte[] p = {
59
(byte) 0xaa, (byte) 0xdd, (byte) 0x9d, (byte) 0xb8,
610
(byte) 0xdb, (byte) 0xe9, (byte) 0xc4, (byte) 0x8b,

0 commit comments

Comments
 (0)