AES-CMAC calculation
Posted: Mon Oct 19, 2020 11:10 pm
Hi, I want to calculate Cryptographic Checksum for SCP-80 / AES in cbc-mode.
but, when I use Signature.ALG_AES_MAC_128_NOPAD, I got different result as I expected. Expected data is calculated by another tool. it is same by calculated by software implementation.
Is Signature.ALG_AES_MAC_128_NOPAD not for that ?
if so, how to calculate CC for SCP-80 by AES cbc-mode ?
1) software implementation I tried is described this topic
https://javacardos.com/javacardforum/vi ... php?t=1114
2) the code for Signature.ALG_AES_MAC_128_NOPAD.
// CREATE SIGNATURE OBJECT
m_sessionAesCMAC = Signature.getInstance(Signature.ALG_AES_MAC_128_NOPAD , false);
// CREATE KEY USED IN MAC
m_sessionAesKey = (AESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_AES, KeyBuilder.LENGTH_AES_128, false);
// INITIALIZE SIGNATURE AES KEY
m_sessionAesKey.setKey(aesKey, (short) 0);
// SET KEY INTO SIGNATURE OBJECT
m_sessionAesCMAC.init(m_sessionAesKey, Signature.MODE_SIGN);
// GENERATE SIGNATURE OF buff ARRAY, STORE INTO cMAC ARRAY
m_sessionAesCMAC.sign(buffer, (short) 0, len, cMAC, (short) 0);
My test condition is as below.
Java Card 2.2.2
Key : 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10
Input data : 00 26 15 12 21 52 52 00 00 00 75 1F AD C5 79 07 AA 07 22 05 80 CA FF 21 00 00 00 00 00 00 00 00
Result
1) : 46 20 F0 A0 4C 30 74 0F 50 A9 BF 04 8C 7F A3 F5
2) : EC B5 1F 1C 6E CE 63 35 40 48 C3 7D 1D 81 4E 6E
by calculate another tool, the result is same as 1).
JCOS VM.
Best Regards
Yasuhiro Mitsui
but, when I use Signature.ALG_AES_MAC_128_NOPAD, I got different result as I expected. Expected data is calculated by another tool. it is same by calculated by software implementation.
Is Signature.ALG_AES_MAC_128_NOPAD not for that ?
if so, how to calculate CC for SCP-80 by AES cbc-mode ?
1) software implementation I tried is described this topic
https://javacardos.com/javacardforum/vi ... php?t=1114
2) the code for Signature.ALG_AES_MAC_128_NOPAD.
// CREATE SIGNATURE OBJECT
m_sessionAesCMAC = Signature.getInstance(Signature.ALG_AES_MAC_128_NOPAD , false);
// CREATE KEY USED IN MAC
m_sessionAesKey = (AESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_AES, KeyBuilder.LENGTH_AES_128, false);
// INITIALIZE SIGNATURE AES KEY
m_sessionAesKey.setKey(aesKey, (short) 0);
// SET KEY INTO SIGNATURE OBJECT
m_sessionAesCMAC.init(m_sessionAesKey, Signature.MODE_SIGN);
// GENERATE SIGNATURE OF buff ARRAY, STORE INTO cMAC ARRAY
m_sessionAesCMAC.sign(buffer, (short) 0, len, cMAC, (short) 0);
My test condition is as below.
Java Card 2.2.2
Key : 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10
Input data : 00 26 15 12 21 52 52 00 00 00 75 1F AD C5 79 07 AA 07 22 05 80 CA FF 21 00 00 00 00 00 00 00 00
Result
1) : 46 20 F0 A0 4C 30 74 0F 50 A9 BF 04 8C 7F A3 F5
2) : EC B5 1F 1C 6E CE 63 35 40 48 C3 7D 1D 81 4E 6E
by calculate another tool, the result is same as 1).
JCOS VM.
Best Regards
Yasuhiro Mitsui