Skip to content

Commit

Permalink
feat: measure nop with various input/output sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
dufkan committed Apr 24, 2024
1 parent 12bfde1 commit 9aea2ee
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
8 changes: 7 additions & 1 deletion applet/src/main/java/jcmint/JCMint.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void process(APDU apdu) {
redeemSingle(apdu);
break;
case Consts.INS_NOP:
apdu.setOutgoing();
nop(apdu);
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
Expand Down Expand Up @@ -370,6 +370,12 @@ private void redeemSingle(APDU apdu) {
apdu.setOutgoing();
}

private void nop(APDU apdu) {
byte[] apduBuffer = loadApdu(apdu);
short p1 = (short) (apduBuffer[ISO7816.OFFSET_P1] & 0xff);
apdu.setOutgoingAndSend((short) 0, p1);
}

private byte[] loadApdu(APDU apdu) {
byte[] apduBuffer = apdu.getBuffer();
short recvLen = (short) (apdu.setIncomingAndReceive() + apdu.getOffsetCdata());
Expand Down
21 changes: 19 additions & 2 deletions applet/src/test/java/tests/PerformanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,30 @@ public void measureVerifyRedeemPrecomputed() throws Exception {

@Test
public void measureNop() throws Exception {
String fileName = "nop.csv";
String fileName = "nop_0b.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();
pm.nop(new byte[0]);
file.printf("%d\n", pm.cm.getLastTransmitTime());
}
file.close();
fileName = "nop_768b.csv";
file = new PrintWriter(new FileWriter(fileName, false));
pm = new ProtocolManager(connect(), (byte) 0);
for (int i = 0; i < REPEAT; ++i) {
pm.nop(new byte[768]);
file.printf("%d\n", pm.cm.getLastTransmitTime());
}
file.close();
fileName = "nop_768b_250b.csv";
file = new PrintWriter(new FileWriter(fileName, false));
pm = new ProtocolManager(connect(), (byte) 0);
for (int i = 0; i < REPEAT; ++i) {
pm.nop(new byte[768], 250);
file.printf("%d\n", pm.cm.getLastTransmitTime());
}
file.close();
}

public void verifySwap(boolean precomputed, int parties) throws Exception {
Expand Down
10 changes: 7 additions & 3 deletions applet/src/test/java/tests/ProtocolManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,21 @@ public boolean redeemSingle(byte[] message, ECPoint token, ECPoint precomputed)
return true;
}

public void nop() throws Exception {
public void nop(byte[] data) throws Exception {
nop(data, 0);
}

public void nop(byte[] data, int outputSize) throws Exception {
CommandAPDU cmd = new CommandAPDU(
Consts.CLA_JCMINT,
Consts.INS_NOP,
(byte) (outputSize & 0xff),
(byte) 0,
(byte) 0
data
);
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 {
Expand Down

0 comments on commit 9aea2ee

Please sign in to comment.