Skip to content

Commit 15c3057

Browse files
committed
fix: keep compatibility with GD60 cards (revert c9892ff) and change ECCurve bitlength computation
1 parent c70f4ed commit 15c3057

File tree

7 files changed

+8
-24
lines changed

7 files changed

+8
-24
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public ECCurve(byte[] p, byte[] a, byte[] b, byte[] G, byte[] r, short k, Resour
3838
for (short i = 0; i < (short) p.length; ++i) {
3939
bits -= 8;
4040
if (p[i] != (byte) 0x00) {
41-
byte tmp = p[i];
42-
while (tmp != (byte) 0x00) {
41+
short tmp = (short) (p[i] & 0xff);
42+
while (tmp != (short) 0x00) {
4343
tmp >>= (short) 1;
4444
++bits;
4545
}

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 SecP256k1(rm);
62+
curve = new ECCurve(SecP256r1.p, SecP256r1.a, SecP256r1.b, SecP256r1.G, SecP256r1.r, SecP256r1.k, 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
@@ -117,7 +117,7 @@ public void initialize() {
117117

118118

119119
// Pre-allocate test objects (no new allocation for every tested operation)
120-
curve = new SecP256r1(rm);
120+
curve = new ECCurve(SecP256r1.p, SecP256r1.a, SecP256r1.b, SecP256r1.G, SecP256r1.r, SecP256r1.k, rm);
121121
memoryInfoOffset = snapshotAvailableMemory((short) 3, memoryInfo, memoryInfoOffset);
122122

123123
memoryInfoOffset = snapshotAvailableMemory((short) 5, memoryInfo, memoryInfoOffset);

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

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

3-
public class SecP256k1 extends ECCurve {
4-
public SecP256k1(ResourceManager rm) {
5-
super(p, a, b, G, r, k, rm);
6-
}
7-
3+
public class SecP256k1 {
84
public final static short k = 1;
95

106
public final static byte[] p = {

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

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

3-
public class SecP256r1 extends ECCurve {
4-
public SecP256r1(ResourceManager rm) {
5-
super(p, a, b, G, r, k, rm);
6-
}
7-
3+
public class SecP256r1 {
84
public final static short k = 1;
95

106
public final static byte[] p = {

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

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

3-
public class SecP512r1 extends ECCurve {
4-
public SecP512r1(ResourceManager rm) {
5-
super(p, a, b, G, r, k, rm);
6-
}
7-
3+
public class SecP512r1 {
84
public final static short k = 1;
95

106
public final static byte[] p = {

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

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

3-
public class Wei25519 extends ECCurve {
4-
public Wei25519(ResourceManager rm) {
5-
super(p, a, b, G, r, k, rm);
6-
}
7-
3+
public class Wei25519 {
84
public final static short k = 8;
95

106
public final static byte[] p = {

0 commit comments

Comments
 (0)