Skip to content

Commit

Permalink
add names to check error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
dufkan committed Jun 14, 2024
1 parent f8ab471 commit 2d367cd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions applet/src/main/java/jcpreecdsa/Consts.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class Consts {
public final static short E_ALREADY_INITIALIZED = (short) 0xee00;
public final static short E_PRESIGNATURE_REUSE = (short) 0xee01;
public final static short E_PRESIGNATURE_INVALID = (short) 0xee02;
public final static short E_MAC_INVALID = (short) 0xee03;
public final static short E_COMMITMENT_INVALID = (short) 0xee04;

public final static short SW_Exception = (short) 0xff01;
public final static short SW_ArrayIndexOutOfBoundsException = (short) 0xff02;
Expand Down
10 changes: 5 additions & 5 deletions applet/src/main/java/jcpreecdsa/JCPreECDSA.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,19 +294,19 @@ private void sign2(APDU apdu) {
bn1.fromByteArray(apduBuffer, ISO7816.OFFSET_CDATA, (short) 32);
bn1.add(a2hat);
if (!bn1.equals(curve.rBN)) {
ISOException.throwIt((short) 0x1230);
ISOException.throwIt(Consts.E_MAC_INVALID);
}

bn1.fromByteArray(apduBuffer, (short) (ISO7816.OFFSET_CDATA + 32), (short) 32);
bn1.add(b2hat);
if (!bn1.equals(curve.rBN)) {
ISOException.throwIt((short) 0x1235);
ISOException.throwIt(Consts.E_MAC_INVALID);
}

bn1.fromByteArray(apduBuffer, (short) (ISO7816.OFFSET_CDATA + 64), (short) 32);
bn1.add(c2hat);
if (!bn1.equals(curve.rBN)) {
ISOException.throwIt((short) 0x1236);
ISOException.throwIt(Consts.E_MAC_INVALID);
}

a2hat.copyToByteArray(apduBuffer, (short) 0);
Expand All @@ -322,13 +322,13 @@ private void sign3(APDU apdu) {
md.reset();
md.doFinal(apduBuffer, ISO7816.OFFSET_CDATA, (short) 65, ramArray, (short) 0);
if (Util.arrayCompare(comm, (short) 0, ramArray, (short) 0, (short) 32) != 0) {
ISOException.throwIt((short) 0x1112);
ISOException.throwIt(Consts.E_COMMITMENT_INVALID);
}

point.setW(apduBuffer, ISO7816.OFFSET_CDATA, (short) 65);
point.negate();
if (!point.isEqual(R2hat)) {
ISOException.throwIt((short) 0x1235);
ISOException.throwIt(Consts.E_MAC_INVALID);
}

// H(m) * t2.a
Expand Down

0 comments on commit 2d367cd

Please sign in to comment.