From 2d367cd34ea613555bca5490e18d1e485488c9f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=C3=ADn=20Dufka?= Date: Fri, 14 Jun 2024 14:21:25 +0200 Subject: [PATCH] add names to check error codes --- applet/src/main/java/jcpreecdsa/Consts.java | 2 ++ applet/src/main/java/jcpreecdsa/JCPreECDSA.java | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/applet/src/main/java/jcpreecdsa/Consts.java b/applet/src/main/java/jcpreecdsa/Consts.java index 9b84d0d..66c3613 100644 --- a/applet/src/main/java/jcpreecdsa/Consts.java +++ b/applet/src/main/java/jcpreecdsa/Consts.java @@ -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; diff --git a/applet/src/main/java/jcpreecdsa/JCPreECDSA.java b/applet/src/main/java/jcpreecdsa/JCPreECDSA.java index ddac983..73a7cb6 100755 --- a/applet/src/main/java/jcpreecdsa/JCPreECDSA.java +++ b/applet/src/main/java/jcpreecdsa/JCPreECDSA.java @@ -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); @@ -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