Forum Stats

  • 3,826,759 Users
  • 2,260,705 Discussions
  • 7,897,072 Comments

Discussions

TDES CMAC on JCOP smart card

smarty_card_pants
smarty_card_pants Member Posts: 14
edited Jan 12, 2017 5:46PM in Java Card

I am looking for a Javacard code snippet that produces a known answer for a

TDES CMAC equal to the known answers in NISP SP 800-38B for the Two Key

TDEA (D.5, p.18) example. What I have done so far is reproduce the CIPH

subkey. I have been able to get the CIPH subkey using either the Cipher or

the Signature class. So, I'm part way there. I need to reproduce the T

values now. Does anybody have something that works?

Here is the current code snippet I wrote:

public byte[] computeCMAC() {

    

    // 4c f1 51 34 a2 85 0d d5 8a 3d 10 ba 80 57 0d 38 4c f1 51 34 a2 85 0d d5

    

    final byte[] KEYS_2 = {

    (byte)0x4c,(byte)0xf1,(byte)0x51,(byte)0x34,

    (byte)0xa2,(byte)0x85,(byte)0x0d,(byte)0xd5,

    (byte)0x8a,(byte)0x3d,(byte)0x10,(byte)0xba,

    (byte)0x80,(byte)0x57,(byte)0x0d,(byte)0x38};

      

   tdesKey2 = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES,(short)128,false);

   tdesKey2.setKey(KEYS_2, (short)0);

  

   tdesC = Cipher.getInstance(Cipher.ALG_DES_CBC_ISO9797_M1, false);

   cmacVP = new byte[32];

   byte[] output = new byte[32];

  

   tdesC.init(tdesKey2, Cipher.MODE_ENCRYPT);

    

   short cmacLen = tdesC.update(null,(short)0,(short)0, output,(short)0);

    

   cmacLen += tdesC.doFinal(output, (short)0, cmacLen, cmacVP, (short)0);

        

   return cmacVP;

}

This produces the following of which the first 8 bytes matches the CIPH

subkey in NIST SP 800-38B:

C7 67 9B 9F 6B 8D 7D 7A 00 00 00 00 00 00 00 00

00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

I am not sure what to do next to get the T value for an empty string.

This discussion has been closed.