Skip to content

Commit

Permalink
feat: add nop measurement
Browse files Browse the repository at this point in the history
  • Loading branch information
dufkan committed Apr 12, 2024
1 parent 4ddd6f3 commit 12bfde1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions applet/src/main/java/jcmint/Consts.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class Consts {
public static final byte INS_SWAP_SINGLE = (byte) 0x05;
public static final byte INS_REDEEM = (byte) 0x06;
public static final byte INS_REDEEM_SINGLE = (byte) 0x07;
public static final byte INS_NOP = (byte) 0x08;

public final static short E_ALREADY_INITIALIZED = (short) 0xee00;
public final static short E_INVALID_PARTY_COUNT = (short) 0xee01;
Expand Down
3 changes: 3 additions & 0 deletions applet/src/main/java/jcmint/JCMint.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public void process(APDU apdu) {
case Consts.INS_REDEEM_SINGLE:
redeemSingle(apdu);
break;
case Consts.INS_NOP:
apdu.setOutgoing();
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
Expand Down
11 changes: 11 additions & 0 deletions applet/src/test/java/tests/PerformanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ public void measureVerifyRedeemPrecomputed() throws Exception {
}
}

@Test
public void measureNop() throws Exception {
String fileName = "nop.csv";
PrintWriter file = new PrintWriter(new FileWriter(fileName, false));
ProtocolManager pm = new ProtocolManager(connect(), (byte) 0);
for (int i = 0; i < REPEAT; ++i) {
pm.nop();
file.printf("%d\n", pm.cm.getLastTransmitTime());
}
}

public void verifySwap(boolean precomputed, int parties) throws Exception {
String fileName = "verify_swap_" + parties + (precomputed ? "_precomputed" : "") + ".csv";
PrintWriter file = new PrintWriter(new FileWriter(fileName, false));
Expand Down
13 changes: 13 additions & 0 deletions applet/src/test/java/tests/ProtocolManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,19 @@ public boolean redeemSingle(byte[] message, ECPoint token, ECPoint precomputed)
return true;
}

public void nop() throws Exception {
CommandAPDU cmd = new CommandAPDU(
Consts.CLA_JCMINT,
Consts.INS_NOP,
(byte) 0,
(byte) 0
);
ResponseAPDU responseAPDU = cm.transmit(cmd);
Assertions.assertNotNull(responseAPDU);
Assertions.assertEquals(ISO7816.SW_NO_ERROR & 0xffff, responseAPDU.getSW());
Assertions.assertArrayEquals(new byte[0], responseAPDU.getData());
}

public static byte[] computeProof(BigInteger secret, ECPoint hashedPoint) throws Exception {
ECPoint verifyingPoint = hashedPoint.multiply(secret);

Expand Down

0 comments on commit 12bfde1

Please sign in to comment.