NFC Mifare Desfire EV3 - CMAC calculation issue

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

NFC Mifare Desfire EV3 - CMAC calculation issue

1,753 Views
tanmay_chauk
Contributor II

Hello,

I am using NFC Mifare Desfire EV3 cards and I am able to get the authentication sequence correct, and after that when we send the read command, I getting the response in which data part is correct but the CMAC is not matching with we calculated. 

Reader is PN532 NFC HAT + Raspberry pi 
prog language used - Python

Please find the detailed steps below :
1. Application is created with id 0xA1A2A3. (one time process)
2. File creation - file id = 0, type = plaintext
3. Authentication sequence is followed and received expected responses. Session key is generated.
4. Read command sent to read from file 0, location 0, no of bytes - 6


Session key - 0B C6 7C 01 B1 3F 82 2D C0 B7 59 1F 77 17 26 AF

read Request - 
APDU CMD: BD 00 00 00 00 06 00 00
APDU RESP: 00 31 32 33 34 35 36 85 64 57 2D B0 B0 5C C7

CMAC calculations - 
Subkey1: f3b468b1db783e3b5c0e0f24503a54cc
Subkey2: e768d163b6f07c76b81c1e48a074a91f
Status: 00
Data: 313233343536
CMAC from card: 8564572db0b05cc7


CMAC input data: 31323334353600
CMAC encryption key: 0bc67c01b13f822dc0b7591f771726af
Padded data: 31323334353600800000000000000000


Padding was added, XOR last block with subkey2
XOR output (last block after XOR): d65ae25783c67cf6b81c1e48a074a91f
CMAC encrypted: c8e5e3dda222026be99ab3ce4a5ff1b6
CMAC: c8e5e3dda222026b

Doubts-
1. After authentication, we are sending this first command, hence the iv being used should be 00000000000000000000000000000000, right ?
2. Can we get more details about the CMAC calculation.

note - the card was written from one of the third party Android app. Data written on card "123456"

0 Kudos
Reply
1 Reply

1,731 Views
stephanie_m
NXP TechSupport
NXP TechSupport

Hello, 

 

As you might know, there are some of the documents and libraries which are under NDA (Non-Disclosure Agreement) the information it's not public

For the specific questions you have we have some documents available; still in order to access them you will have to request higher access. 

Please refer to the following guide   Secure Access Rights | NXP Semiconductors

 

Regards, 

 

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2178240%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ENFC%20Mifare%20Desfire%20EV3%20-%20CMAC%20calculation%20issue%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2178240%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%2C%3CBR%20%2F%3E%3CBR%20%2F%3EI%20am%20using%20NFC%20Mifare%20Desfire%20EV3%20cards%20and%20I%20am%20able%20to%20get%20the%20authentication%20sequence%20correct%2C%20and%20after%20that%20when%20we%20send%20the%20read%20command%2C%20I%20getting%20the%20response%20in%20which%20data%20part%20is%20correct%20but%20the%20CMAC%20is%20not%20matching%20with%20we%20calculated.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3EReader%20is%20PN532%20NFC%20HAT%20%2B%20Raspberry%20pi%26nbsp%3B%3CBR%20%2F%3Eprog%20language%20used%20-%20Python%3CBR%20%2F%3E%3CBR%20%2F%3EPlease%20find%20the%20detailed%20steps%20below%20%3A%3CBR%20%2F%3E1.%20Application%20is%20created%20with%20id%200xA1A2A3.%20(one%20time%20process)%3CBR%20%2F%3E2.%20File%20creation%20-%20file%20id%20%3D%200%2C%20type%20%3D%20plaintext%3CBR%20%2F%3E3.%20Authentication%20sequence%20is%20followed%20and%20received%20expected%20responses.%20Session%20key%20is%20generated.%3CBR%20%2F%3E4.%20Read%20command%20sent%20to%20read%20from%20file%200%2C%20location%200%2C%20no%20of%20bytes%20-%206%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3ESession%20key%20-%26nbsp%3B0B%20C6%207C%2001%20B1%203F%2082%202D%20C0%20B7%2059%201F%2077%2017%2026%20AF%3CBR%20%2F%3E%3CBR%20%2F%3Eread%20Request%20-%26nbsp%3B%3CBR%20%2F%3EAPDU%20CMD%3A%20BD%2000%2000%2000%2000%2006%2000%2000%3CBR%20%2F%3EAPDU%20RESP%3A%2000%2031%2032%2033%2034%2035%2036%2085%2064%2057%202D%20B0%20B0%205C%20C7%3CBR%20%2F%3E%3CBR%20%2F%3ECMAC%20calculations%20-%26nbsp%3B%3CBR%20%2F%3ESubkey1%3A%20f3b468b1db783e3b5c0e0f24503a54cc%3CBR%20%2F%3ESubkey2%3A%20e768d163b6f07c76b81c1e48a074a91f%3CBR%20%2F%3EStatus%3A%2000%3CBR%20%2F%3EData%3A%20313233343536%3CBR%20%2F%3ECMAC%20from%20card%3A%208564572db0b05cc7%3C%2FP%3E%3CP%3E%3CBR%20%2F%3ECMAC%20input%20data%3A%2031323334353600%3CBR%20%2F%3ECMAC%20encryption%20key%3A%200bc67c01b13f822dc0b7591f771726af%3CBR%20%2F%3EPadded%20data%3A%2031323334353600800000000000000000%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EPadding%20was%20added%2C%20XOR%20last%20block%20with%20subkey2%3CBR%20%2F%3EXOR%20output%20(last%20block%20after%20XOR)%3A%20d65ae25783c67cf6b81c1e48a074a91f%3CBR%20%2F%3ECMAC%20encrypted%3A%20c8e5e3dda222026be99ab3ce4a5ff1b6%3CBR%20%2F%3ECMAC%3A%20c8e5e3dda222026b%3CBR%20%2F%3E%3CBR%20%2F%3EDoubts-%3CBR%20%2F%3E1.%20After%20authentication%2C%20we%20are%20sending%20this%20first%20command%2C%20hence%20the%20iv%20being%20used%20should%20be%2000000000000000000000000000000000%2C%20right%20%3F%3CBR%20%2F%3E2.%20Can%20we%20get%20more%20details%20about%20the%20CMAC%20calculation.%3CBR%20%2F%3E%3CBR%20%2F%3Enote%20-%20the%20card%20was%20written%20from%20one%20of%20the%20third%20party%20Android%20app.%20Data%20written%20on%20card%20%22123456%22%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2178280%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20NFC%20Mifare%20Desfire%20EV3%20-%20CMAC%20calculation%20issue%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2178280%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%2C%26nbsp%3B%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EAs%20you%20might%20know%2C%20there%20are%20some%20of%20the%20documents%20and%20libraries%20which%20are%20under%20NDA%20(Non-Disclosure%20Agreement)%20the%20information%20it's%20not%20public%3C%2FP%3E%0A%3CP%3EFor%20the%20specific%20questions%20you%20have%20we%20have%20some%20documents%20available%3B%20still%20in%20order%20to%20access%20them%20you%20will%20have%20to%20request%20higher%20access.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPlease%20refer%20to%20the%20following%20guide%26nbsp%3B%20%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fwww.nxp.com%2Fsupport%2Fsupport%2Fsecure-access-rights%3ASEC-ACCESS%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3ESecure%20Access%20Rights%20%7C%20NXP%20Semiconductors%3C%2FA%3E%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3ERegards%2C%26nbsp%3B%3C%2FP%3E%0A%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E