Skip to content

Commit

Permalink
remove debug instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
dufkan committed Sep 3, 2024
1 parent 27512c5 commit e2956f3
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 104 deletions.
5 changes: 0 additions & 5 deletions applet/src/main/java/jc2pecdsa/Consts.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ public class Consts {
public static final byte INS_SIGN2 = (byte) 0x02;
public static final byte INS_SIGN3 = (byte) 0x03;

public static final byte INS_SIGN3_BEFORE_MODEXP = (byte) 0xd0;
public static final byte INS_SIGN3_MODEXP = (byte) 0xd1;
public static final byte INS_SIGN3_BEFORE_DIVIDE = (byte) 0xd2;
public static final byte INS_SIGN3_DIVIDE = (byte) 0xd3;

public final static short E_ALREADY_INITIALIZED = (short) 0xee00;

public final static short SW_Exception = (short) 0xff01;
Expand Down
45 changes: 0 additions & 45 deletions applet/src/main/java/jc2pecdsa/JC2pECDSA.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,6 @@ public void process(APDU apdu) {
case Consts.INS_SIGN3:
sign3(apdu);
break;
// DEBUG INSTRUCTIONS
case Consts.INS_SIGN3_BEFORE_MODEXP:
sign3beforeModExp(apdu);
break;
case Consts.INS_SIGN3_MODEXP:
sign3modExp(apdu);
break;
case Consts.INS_SIGN3_BEFORE_DIVIDE:
sign3beforeDivide(apdu);
break;
case Consts.INS_SIGN3_DIVIDE:
sign3divide(apdu);
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
Expand Down Expand Up @@ -248,38 +235,6 @@ private void sign3(APDU apdu) {
apdu.setOutgoingAndSend((short) 0, (short) 70);
}

private void sign3beforeModExp(APDU apdu) {
byte[] apduBuffer = loadApdu(apdu);
apdu.setOutgoingAndSend((short) 0, (short) 70);
}

private void sign3modExp(APDU apdu) {
byte[] apduBuffer = loadApdu(apdu);
nsqExp.doFinal(apduBuffer, apdu.getOffsetCdata(), (short) 512, apduBuffer, apdu.getOffsetCdata());
apdu.setOutgoingAndSend((short) 0, (short) 70);
}

private void sign3beforeDivide(APDU apdu) {
byte[] apduBuffer = loadApdu(apdu);

nsqExp.doFinal(apduBuffer, apdu.getOffsetCdata(), (short) 512, apduBuffer, apdu.getOffsetCdata());

bn.fromByteArray(apduBuffer, apdu.getOffsetCdata(), (short) 512);
bn.decrement();
apdu.setOutgoingAndSend((short) 0, (short) 70);
}

private void sign3divide(APDU apdu) {
byte[] apduBuffer = loadApdu(apdu);

nsqExp.doFinal(apduBuffer, apdu.getOffsetCdata(), (short) 512, apduBuffer, apdu.getOffsetCdata());

bn.fromByteArray(apduBuffer, apdu.getOffsetCdata(), (short) 512);
bn.decrement();
bn.divide(p);
apdu.setOutgoingAndSend((short) 0, (short) 70);
}

private byte[] loadApdu(APDU apdu) {
byte[] apduBuffer = apdu.getBuffer();
short recvLen = (short) (apdu.setIncomingAndReceive() + apdu.getOffsetCdata());
Expand Down
2 changes: 1 addition & 1 deletion applet/src/test/java/tests/AppletTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void testSign() throws Exception {

pm.setup(p, p.pow(2), lambdap, mup, t, X);

for(int i = 0; i < 100; ++i) {
for(int i = 0; i < 10; ++i) {
// Host sends m to card
byte[] comm = pm.sign1(new byte[32]);
file.printf("%d,", pm.cm.getLastTransmitTime());
Expand Down
53 changes: 0 additions & 53 deletions applet/src/test/java/tests/ProtocolManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,59 +88,6 @@ public byte[] sign3(BigInteger cs1) throws Exception {
return responseAPDU.getData();
}

public byte[] sign3beforeModExp(BigInteger cs1) throws Exception {
CommandAPDU cmd = new CommandAPDU(
Consts.CLA_JC2PECDSA,
Consts.INS_SIGN3_BEFORE_MODEXP,
0,
0,
ProtocolManager.encodeBigInteger(cs1, 512)
);
ResponseAPDU responseAPDU = cm.transmit(cmd);
Assertions.assertNotNull(responseAPDU);
Assertions.assertEquals(ISO7816.SW_NO_ERROR & 0xffff, responseAPDU.getSW());
return responseAPDU.getData();
}

public void sign3modExp(BigInteger cs1) throws Exception {
CommandAPDU cmd = new CommandAPDU(
Consts.CLA_JC2PECDSA,
Consts.INS_SIGN3_MODEXP,
0,
0,
ProtocolManager.encodeBigInteger(cs1, 512)
);
ResponseAPDU responseAPDU = cm.transmit(cmd);
Assertions.assertNotNull(responseAPDU);
Assertions.assertEquals(ISO7816.SW_NO_ERROR & 0xffff, responseAPDU.getSW());
}

public void sign3beforeDivide(BigInteger cs1) throws Exception {
CommandAPDU cmd = new CommandAPDU(
Consts.CLA_JC2PECDSA,
Consts.INS_SIGN3_BEFORE_DIVIDE,
0,
0,
ProtocolManager.encodeBigInteger(cs1, 512)
);
ResponseAPDU responseAPDU = cm.transmit(cmd);
Assertions.assertNotNull(responseAPDU);
Assertions.assertEquals(ISO7816.SW_NO_ERROR & 0xffff, responseAPDU.getSW());
}

public void sign3divide(BigInteger cs1) throws Exception {
CommandAPDU cmd = new CommandAPDU(
Consts.CLA_JC2PECDSA,
Consts.INS_SIGN3_DIVIDE,
0,
0,
ProtocolManager.encodeBigInteger(cs1, 512)
);
ResponseAPDU responseAPDU = cm.transmit(cmd);
Assertions.assertNotNull(responseAPDU);
Assertions.assertEquals(ISO7816.SW_NO_ERROR & 0xffff, responseAPDU.getSW());
}

public static BigInteger hash(byte[] message) throws NoSuchAlgorithmException {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] h = digest.digest(message);
Expand Down

0 comments on commit e2956f3

Please sign in to comment.