Using OfflineChangeKey to Update KeyEntry for SAM AV3

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

Using OfflineChangeKey to Update KeyEntry for SAM AV3

Using OfflineChangeKey to Update KeyEntry for SAM AV3

 

Background


OfflineChangeKey is a secure key management mechanism in SAM AV3 that allows a KeyEntry to be updated without exposing the new key value to the host MCU. It is typically used for personalization, key rotation, remote field updates, and other high-security applications where keys must remain protected inside the SAM. OfflineChange Key can only be of type AES-128, AES-192 or AES-256. Some usage scenarios of OfflineChange Key are as follows:
Using in “SAM_ChangeKeyEntry” command and “SAM_ChangeKUCEntry” command to:
➢Update the key entries offline. The update of a key entry in offline is only possible if
the KeyNoCEK of that key entry is OfflineChange key.
➢Update key usage counter offline. The update of a key usage counter is offline only
possible if the KeyNoCKUC of that RefNoKUC is OfflineChange key.
The offline update of a key entry is only possible if the KeyNoCEK of that key entry is an OfflineChange key.
Build Debugging Environment
•Software reference design: NfcrdlibEx7_MIFAREPlus and SAM AV3 X-mode Project
•NFC reader ICs: RC663 / PN7642
•NFC Reader Library versions: NxpNfcRdLib_v7.16
•NXP Reader Library versions: NxpRdLib_v17.1.0.2535
Issue Description – A Key entry will be changed using an OfflineChangeKey key entry
NXP's MIFARE SAM AV3 comes with a default key and configuration. Before applying it to actual projects, users typically need to complete two configuration phases: pre-personalization and personalization.

Pre-personalization
Define and Register two KeyEntries, one is KeyEntry 0x11 with keyclass PICC and the other is KeyEntry 0x10 with OfflineChangeKey. And the KeyNoCEK of KeyEntry 0x11 is KeyEntry 0x10.
Define KeyEntry 0x10 =

KaiLi_0-1794878913497.png

Define KeyEntry 0x11=

KaiLi_1-1794878967844.png

If you are developing on an MCU platform, the NXP Reader Library provides the necessary APIs to perform the SAM AV3 personalization process, including creating and updating KeyEntry 0x10 and KeyEntry 0x11.

KaiLi_2-1794878981981.png

Alternatively, the same operation can be performed using Pegoda 3 together with RFIDDiscover, which provides a convenient way to explore and validate the personalization flow without writing application code. As an example, the following screenshots demonstrate how to provision KeyEntry 0x10 using RFIDDiscover:

KaiLi_3-1794878996098.pngKaiLi_4-1794879004375.png

Personalization
Use the OfflineChangeKey procedure to perform a secure key update. Specifically, KeyEntry 0x10 is configured as the OfflineChangeKey (KeyNoCEK), and KeyEntry 0x11 is defined to reference this key. As a result, KeyEntry 0x11 can only be updated using a cryptogram generated with the OfflineChangeKey stored in KeyEntry 0x10.
➢ Set the New KeyEntry values to be written into KeyEntry 0x11=

KaiLi_5-1794879096611.png

➢ Concatenation the new value of Key Entry 0x11, which is called PlainKeyEntry[80] =
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
000000000000FF20000000000100FEFE
80000000000000000000000000000000 (padding 16bytes)
➢ Generate Kce and Kcm, both encrypted using Ks in AES-CBC mode. Here should be noted that,
Inputs parameters:
Ks is saved in key entry 0x10 in my example. And the value = 00000000000000000000000000000000
SV1: ChangeCtr || 14 bytes of 0x71
SV2: ChangeCtr || 14 bytes of 0x72
ChangeCtr: 0x0001
Outputs are:
SV1: 00017171717171717171717171717171
SV2: 00017272727272727272727272727272
Kce: 91E868E9890A05B692E49ECBAE916289 (Ek (Ks, SV1))

Kcm: 4CCB0BC24405CC5CFA2E05F81812A181 (Ek (Ks, SV2))
Kce is to encrypt keyentry, and Kcm is to calculate the CMAC.

KaiLi_6-1794879161829.png

 

 

KaiLi_7-1794879171295.png


➢ Encrypt PlainKeyEntry [80] with Kce under AES-CBC mode and output EncKeyEntry[80] =
E78E4571BD8FBDBFD9A16E74F92E0921
2A4286925E6AF74CD650C12F0751A486
ECFAFABFA88FDD17C124250BCED89AE3
A479B21E7FD66D683696D2461D452EE2
F0D4FE0568F29226FC6C9CDA93AD44BD
➢ Calculate CMAC
Input data:
80C111FF5A0001 (CLA, INS, P1, P2, Lc+10, change ctr)
E78E4571BD8FBDBFD9A16E74F92E0921 (Encrypted KeyEntry)
2A4286925E6AF74CD650C12F0751A486
ECFAFABFA88FDD17C124250BCED89AE3

A479B21E7FD66D683696D2461D452EE2
F0D4FE0568F29226FC6C9CDA93AD44BD
and calculated CMAC with Kcm, output is:
81C7931698390354968FED95B8A2FC14
And make MFP Truncate, finally output is CMAC_Truc[8] = C71639548F95A214
➢ Activate offlinechankekey
Enable the Offline Change mechanism and specify the corresponding OfflineChangeKey. This step is required so that the SAM can identify which key shall be used to authorize and process future offline key update operations.
If you are developing on an MCU platform, the same configuration can be performed programmatically using the APIs provided by the NXP Reader Library.

KaiLi_8-1794879259359.png

Alternatively, you can use Pegoda 3 and RFIDDiscover to perform the same configuration without developing MCU application code, as shown below:

KaiLi_9-1794879281677.pngKaiLi_10-1794879289603.png

➢ Update KeyEntry 0x11 using OfflineChangeKey
If you are developing on an MCU platform, which can be implemented using the APIs provided by the NXP Reader Library. And need to note that the key parameter:
uint8_t * pOfflineCrypto = EncKeyEntry[80] + OfflineMAC[8]
EncKeyEntry[80] = EncKeyEntry [80]
OfflineMAC[8] = CMAC_Truc [8]

KaiLi_11-1794879314227.png

At the same time, instead of implementing the configuration through MCU software, you can use Pegoda 3 and RFIDDiscover to perform and verify the same configuration interactively, as the below:

KaiLi_12-1794879327493.pngKaiLi_13-1794879335556.png

References
1. Data sheet – Data sheet of MIFARE SAM AV3, doc nr. 3235xx.
2. Application note – AN5212 – MIFARE SAM AV3 – Key Management and Personalization, document nr. 5212xx.

Attachments
No ratings
Version history
Last update:
yesterday
Updated by: