JavacardOS will not accept order any more, please contact our partner Feitian online Store:
https://ftsafe.en.alibaba.com/index.html
https://ftsafe.en.alibaba.com/index.html
TDES CMAC algorithm for JCOP smart card
-
- Posts: 4
- Joined: Thu Jan 12, 2017 4:14 pm
- Points :68
- Contact:
TDES CMAC algorithm for JCOP smart 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.
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.
- UNKNwYSHSA
- Posts: 630
- Joined: Thu May 21, 2015 4:05 am
- Points :3055
- Contact:
Re: TDES CMAC algorithm for JCOP smart card
Step1: K => K1, K2
Step2: M, K, K1, K2 => CMAC
Next step: Geneate K1 and K2;
Step2: M, K, K1, K2 => CMAC
Next step: Geneate K1 and K2;
sense and simplicity
- UNKNwYSHSA
- Posts: 630
- Joined: Thu May 21, 2015 4:05 am
- Points :3055
- Contact:
Re: TDES CMAC algorithm for JCOP smart card
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
-
- Posts: 4
- Joined: Thu Jan 12, 2017 4:14 pm
- Points :68
- Contact:
Re: TDES CMAC algorithm for JCOP smart card
Thank you! I coded that up and got the known answer.
- UNKNwYSHSA
- Posts: 630
- Joined: Thu May 21, 2015 4:05 am
- Points :3055
- Contact:
Who is online
Users browsing this forum: No registered users and 33 guests