Our Online Store have the new products: RFID antenna board. Currently it can work with JC10M24R and JCOP4 card chips.
Compared with normal cards, the antenna board module has a smaller size and fixed holes, which is easy to integrate in the IOT(Internet Of Things) project.

TDES CMAC algorithm for JCOP smart card

JavaCard Applet Development Related Questions and Answers.
smartycardpants
Posts: 4
Joined: Thu Jan 12, 2017 4:14 pm
Points :68
Contact:

TDES CMAC algorithm for JCOP smart card

Post by smartycardpants » Thu Jan 12, 2017 5:32 pm

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.

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: TDES CMAC algorithm for JCOP smart card

Post by UNKNwYSHSA » Thu Jan 12, 2017 11:12 pm

Step1: K => K1, K2
Step2: M, K, K1, K2 => CMAC

Next step: Geneate K1 and K2;
sense and simplicity

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: TDES CMAC algorithm for JCOP smart card

Post by UNKNwYSHSA » Thu Jan 12, 2017 11:41 pm

Details:

Code: Select all

Step1 (k => ciph(0000000000000000)):
    Key: 4CF15134A2850DD5 8A3D10BA80570D38
    m: 0000000000000000
    s: C7679B9F6B8D7D7A

Step2: ciph(0000000000000000) => k1, k2:
    (MSB(s) == 1) => true
    L << 1
        (C7679B9F6B8D7D7A << 1) => 018ECF373ED71AFAF4 => 8ECF373ED71AFAF4
    K1 = (L << 1) | Rb
        8ECF373ED71AFAF4 XOR 000000000000001B => 8ECF373ED71AFAEF
    K1 << 1
        (8ECF373ED71AFAEF << 1) => 011D9E6E7DAE35F5DE => 1D9E6E7DAE35F5DE
    K2 = (K1 << 1) | Rb
        (1D9E6E7DAE35F5DE) XOR 000000000000001B => 1D9E6E7DAE35F5C5
 
 Step3: K, m, K1, K2 => T
     K: 4CF15134A2850DD5 8A3D10BA80570D38
     m: (empty string)
     K1: 8ECF373ED71AFAEF
     K2: 1D9E6E7DAE35F5C5
     
     M1 = K2 XOR (M1* || 10j)
         M1 = K2 XOR 8000000000000000 => 9D9E6E7DAE35F5C5
         C0 XOR M1 => 0000000000000000 XOR 9D9E6E7DAE35F5C5 => 9D9E6E7DAE35F5C5
         C1 = CIPH_k_(C0 XOR M1) => BD2EBF9A3BA00361
         T = BD2EBF9A3BA00361
sense and simplicity

smartycardpants
Posts: 4
Joined: Thu Jan 12, 2017 4:14 pm
Points :68
Contact:

Re: TDES CMAC algorithm for JCOP smart card

Post by smartycardpants » Fri Jan 13, 2017 7:07 pm

Thank you! I coded that up and got the known answer.

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: TDES CMAC algorithm for JCOP smart card

Post by UNKNwYSHSA » Sat Jan 14, 2017 1:45 am

OK.
sense and simplicity

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 51 guests

JavaCard OS : Disclaimer