From 8e4690c426dbe48c9ecfa8b100c39e009ead2a55 Mon Sep 17 00:00:00 2001 From: Victor Costan Date: Tue, 17 Nov 2009 14:36:25 -0500 Subject: [PATCH] Instruction for computing the size of some data after encryption. --- .jcop | 2 +- src/edu/mit/csail/tc/TEMApplet.java | 2 +- src/edu/mit/csail/tc/TEMExecution.java | 19 +++++++++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.jcop b/.jcop index ee4d2bd..e62eb60 100644 --- a/.jcop +++ b/.jcop @@ -1 +1 @@ -1.01.01.01.01983122910face1983122910BABE1.14 \ No newline at end of file +1.01.01.01.01983122910face1983122910BABE1.15 \ No newline at end of file diff --git a/src/edu/mit/csail/tc/TEMApplet.java b/src/edu/mit/csail/tc/TEMApplet.java index 1b6ca34..95f79e6 100644 --- a/src/edu/mit/csail/tc/TEMApplet.java +++ b/src/edu/mit/csail/tc/TEMApplet.java @@ -24,7 +24,7 @@ */ public class TEMApplet extends Applet { /** The firmware version. */ - public static final short FIRMWARE_VER = 0x010E; + public static final short FIRMWARE_VER = 0x010F; public static void install(byte[] bArray, short bOffset, byte bLength) { // GP-compliant JavaCard applet registration diff --git a/src/edu/mit/csail/tc/TEMExecution.java b/src/edu/mit/csail/tc/TEMExecution.java index 3f8c243..d262aa8 100644 --- a/src/edu/mit/csail/tc/TEMExecution.java +++ b/src/edu/mit/csail/tc/TEMExecution.java @@ -456,7 +456,7 @@ else if ((opcode & 2) != 0) { operand3, ((opcode & 2) == 0)); } Util.setShort(pBuffer, sp, result); sp += 2; - break; + break; case 0x5A: // rdk (read key) sp -= 2; operand1 = Util.getShort(pBuffer, sp); result = TEMCrypto.loadKey(pBuffer, operand1); @@ -464,17 +464,24 @@ else if ((opcode & 2) != 0) { authorizedKeys[result] = true; Util.setShort(pBuffer, sp, result); sp += 2; break; + case 0x58: // ldkel (load key encryption length) case 0x5B: // stk (store key) sp -= 2; operand2 = Util.getShort(pBuffer, sp); sp -= 2; operand1 = Util.getShort(pBuffer, sp); if(authorizedKeys[operand1] == false) ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED); - if(operand2 == (short)-1) { - result = TEMCrypto.saveKey((byte)operand1, outBuffer, outOffset); - outOffset += result; + + if (opcode == 0x58) { // ldkel + result = TEMCrypto.getEncryptedDataSize((byte)operand1, operand2); + } + else { + if(operand2 == (short)-1) { // stk + result = TEMCrypto.saveKey((byte)operand1, outBuffer, outOffset); + outOffset += result; + } + else + result = TEMCrypto.saveKey((byte)operand1, pBuffer, operand2); } - else - result = TEMCrypto.saveKey((byte)operand1, pBuffer, operand2); Util.setShort(pBuffer, sp, result); sp += 2; break; case 0x5C: // relk (release key)