An 10922
An 10922
Document information
Information Content
Keywords MIFARE Plus, MIFARE DESFire, MIFARE SAM AV3, Key diversification,
CMAC, TDEA, AES.
Abstract This Application note describes CMAC based symmetric key diversification
algorithms supported by NXP’s MIFARE SAM AV3.
NXP Semiconductors
AN10922
Symmetric key diversifications
Revision history
Rev Date Description
2.2 20190702 Fixed the AES256 key diversification example
2.1 20190417 Update for MIFARE SAM AV3
2.0 20170208 General update
1.3 20100317 Re-organization, addition of examples
1.2 20100129 Addition of AES-192, 2TDEA, 3TDEA key diversification algorithms
1.1 20090813 Editorial changes, no content change
1.0 20081112 Preliminary version
AN10922 All information provided in this document is subject to legal disclaimers. © NXP B.V. 2019. All rights reserved.
1 Introduction
Key diversification is a process of deriving the keys from a master (base) key using some
unique input. Each card is getting a different value for each key, so that if one key is
broken somehow (maybe from the terminal). The vulnerability is limited to that key on
that card rather than the whole system being affected.
The diversified keys are generated and given (stored) to the PICC at its personalization
phase, so all cards get unique keys. In the validation process, the POS terminal gets the
information to generate the unique key for that unique card which is presented. MIFARE
SAM AV3 can be an optimum secure solution for this key diversification process. The
master (base) key can be stored securely in the MIFARE SAM AV3 and can be used to
generate or use only the diversified keys.
MIFARE SAM AV3 supports two types of key diversification:
• old method, based on classical encryption, and
• new method, based on CMAC calculation
In this document, only the key diversification based on CMAC calculation is discussed, as
it is the recommended algorithm. AES (128 and 192-bit key length) and TDEA (2-key and
3-key TDES) keys can be diversified using this CMAC-based key diversification method.
In this document, the algorithms are explained in a way that they can be implemented
easily in SW without SAM today, but tomorrow using SAM.
All keys in a card can be derived from one master key however it is also possible to use a
different master key for one set of keys versus another set of keys.
1.1 Abbreviations
Table 1. Abbreviations
Abbreviations Meaning
AES Advanced Encryption Standard
AID Application ID
CBC Cipher Block Chaining
CMAC Cipher based MAC
DES Data Encryption Standard
DF DESFire
IV Init Vector
LSB Lowest Significant Bit
MAC Message Authentication Code
MSB Most Significant Bit
PCD Proximity Coupling Device (reader/ writer unit)
PICC Proximity Integrated Circuit Card
POS Point Of Sales
SW Software
TDEA Triple Data Encryption Algorithm
UID Unique Identification number
AN10922 All information provided in this document is subject to legal disclaimers. © NXP B.V. 2019. All rights reserved.
AN10922 All information provided in this document is subject to legal disclaimers. © NXP B.V. 2019. All rights reserved.
2 Key Diversification
2.1 Construction
For diversification, the recommended way by NXP is to use the CMAC construction of an
amount of data using a master key. See [CMAC].
The pre-requisite is that there is enough input “diversification data” in order to make it a
MAC. A MAC is used rather than encryption to make it a one-way function.
Figure 1. CMAC construction (2 cases: left without padding, right with padding)
Fig 1 illustrates the standard CMAC constructions (see [CMAC]) in two possible padding
cases.
According to [CMAC], to avoid certain classes of attack (in the CMAC), the last block
is modified before ciphering by being XORed with one of two possible “sub key” values
(denoted K1 or K2), derived from an encryption of the zero vector under the key in use;
the choice of which sub key to use is determined by whether the last message block
contains padding or not.
These computations can be abstracted by the function CMAC (K, D, padded). In the
context of the key derivations described further in this document another primitive is used
because the padding is performed in a non-CMAC standard way. The corresponding
computations can be abstracted by the function CMAC (K, D, Padded), where K is the
key to be diversified, D the diversification input data and Padded is a Boolean flag that
signals to the CMAC(.,.,.) function whether M had to be padded or not.
If the keys are to be diversified per card, it is recommended to use for the diversification
input at least the UID of the card concatenated with e.g.
• For MIFARE Plus family: the block number where the key is stored. Note however that
if multi-sector authentication is desired, all keys that need to be the same need to be
generated using same block number.
• For MIFARE DESFire family: key number concatenated with application number.
Note: In this implementation, always two blocks (two times 16-byte for AES and
two times 8-byte for TDEA) of message have been used.
AN10922 All information provided in this document is subject to legal disclaimers. © NXP B.V. 2019. All rights reserved.
AN10922 All information provided in this document is subject to legal disclaimers. © NXP B.V. 2019. All rights reserved.
If the length of M is more than 15 bytes, standard CMAC algorithm can be used, without
taking care of padding, XOR and encryption. The message for standard CMAC is then
the data of step 9.
AN10922 All information provided in this document is subject to legal disclaimers. © NXP B.V. 2019. All rights reserved.
AN10922 All information provided in this document is subject to legal disclaimers. © NXP B.V. 2019. All rights reserved.
AN10922 All information provided in this document is subject to legal disclaimers. © NXP B.V. 2019. All rights reserved.
If the length of M is more than 15 bytes, standard CMAC algorithm can be used, without
taking care of padding, XOR and encryption. The message for standard CMAC is then
the data of step 9 and data of step 16.
AN10922 All information provided in this document is subject to legal disclaimers. © NXP B.V. 2019. All rights reserved.
AN10922 All information provided in this document is subject to legal disclaimers. © NXP B.V. 2019. All rights reserved.
If the length of M is more than 15 bytes, standard CMAC algorithm can be used, without
taking care of padding, XOR and encryption. The message for standard CMAC is then
the data of step 9 and data of step 16.
AN10922 All information provided in this document is subject to legal disclaimers. © NXP B.V. 2019. All rights reserved.
MIFARE DESFire products store key version information in the lowest significant bits of
the first 8 bytes 2TDEA key. If this versioning information is to be preserved, it is to be
copied from the master key into the diversified key.
AN10922 All information provided in this document is subject to legal disclaimers. © NXP B.V. 2019. All rights reserved.
AN10922 All information provided in this document is subject to legal disclaimers. © NXP B.V. 2019. All rights reserved.
If the length of M is more than 7 bytes, standard CMAC algorithm can be used, without
taking care of padding, XOR and encryption. The message for standard CMAC is then
the data of step 9 and data of step 15.
AN10922 All information provided in this document is subject to legal disclaimers. © NXP B.V. 2019. All rights reserved.
MIFARE DESFire products store key version information in the lowest significant bits of
the first 8 bytes 3TDEA key. If this versioning information is to be preserved, it is to be
copied from the master key into the diversified key.
AN10922 All information provided in this document is subject to legal disclaimers. © NXP B.V. 2019. All rights reserved.
If the length of M is more than 7 bytes, standard CMAC algorithm can be used, without
taking care of padding, XOR and encryption. The message for standard CMAC is then
the data of step 9, step 15 and step 21.
AN10922 All information provided in this document is subject to legal disclaimers. © NXP B.V. 2019. All rights reserved.
3 Conclusion
The master keys must be stored securely if the algorithms are implemented in
software. MIFARE SAM AV3 offers secure storage of the master keys and dynamic
diversifications. For the optimum security, using MIFARE SAM AV3 can be the best
solution. The user shall take care for defining his master keys, shall avoid the weak
keys whenever necessary. Neither the SAM nor the algorithms analyze the keys. NXP
recommends using AES instead of TDEA.
AN10922 All information provided in this document is subject to legal disclaimers. © NXP B.V. 2019. All rights reserved.
4 References
1. CMAC specification: https://nvlpubs.nist.gov/nistpubs/SpecialPublications/
NIST.SP.800-38b.pdf
AN10922 All information provided in this document is subject to legal disclaimers. © NXP B.V. 2019. All rights reserved.
5 Legal information
Semiconductors product is suitable and fit for the customer’s applications
and products planned, as well as for the planned application and use of
5.1 Definitions customer’s third party customer(s). Customers should provide appropriate
design and operating safeguards to minimize the risks associated with
Draft — The document is a draft version only. The content is still under their applications and products. NXP Semiconductors does not accept any
internal review and subject to formal approval, which may result in liability related to any default, damage, costs or problem which is based
modifications or additions. NXP Semiconductors does not give any on any weakness or default in the customer’s applications or products, or
representations or warranties as to the accuracy or completeness of the application or use by customer’s third party customer(s). Customer is
information included herein and shall have no liability for the consequences responsible for doing all necessary testing for the customer’s applications
of use of such information. and products using NXP Semiconductors products in order to avoid a
default of the applications and the products or of the application or use by
customer’s third party customer(s). NXP does not accept any liability in this
respect.
5.2 Disclaimers Export control — This document as well as the item(s) described herein
may be subject to export control regulations. Export might require a prior
Limited warranty and liability — Information in this document is believed authorization from competent authorities.
to be accurate and reliable. However, NXP Semiconductors does not
give any representations or warranties, expressed or implied, as to the
Evaluation products — This product is provided on an “as is” and “with all
accuracy or completeness of such information and shall have no liability
faults” basis for evaluation purposes only. NXP Semiconductors, its affiliates
for the consequences of use of such information. NXP Semiconductors
and their suppliers expressly disclaim all warranties, whether express,
takes no responsibility for the content in this document if provided by an
implied or statutory, including but not limited to the implied warranties of
information source outside of NXP Semiconductors. In no event shall NXP
non-infringement, merchantability and fitness for a particular purpose. The
Semiconductors be liable for any indirect, incidental, punitive, special or
entire risk as to the quality, or arising out of the use or performance, of this
consequential damages (including - without limitation - lost profits, lost
product remains with customer. In no event shall NXP Semiconductors, its
savings, business interruption, costs related to the removal or replacement
affiliates or their suppliers be liable to customer for any special, indirect,
of any products or rework charges) whether or not such damages are based
consequential, punitive or incidental damages (including without limitation
on tort (including negligence), warranty, breach of contract or any other
damages for loss of business, business interruption, loss of use, loss of
legal theory. Notwithstanding any damages that customer might incur for
data or information, and the like) arising out the use of or inability to use
any reason whatsoever, NXP Semiconductors’ aggregate and cumulative
the product, whether or not based on tort (including negligence), strict
liability towards customer for the products described herein shall be limited
liability, breach of contract, breach of warranty or any other theory, even if
in accordance with the Terms and conditions of commercial sale of NXP
advised of the possibility of such damages. Notwithstanding any damages
Semiconductors.
that customer might incur for any reason whatsoever (including without
limitation, all damages referenced above and all direct or general damages),
Right to make changes — NXP Semiconductors reserves the right to the entire liability of NXP Semiconductors, its affiliates and their suppliers
make changes to information published in this document, including without and customer’s exclusive remedy for all of the foregoing shall be limited to
limitation specifications and product descriptions, at any time and without actual damages incurred by customer based on reasonable reliance up to
notice. This document supersedes and replaces all information supplied prior the greater of the amount actually paid by customer for the product or five
to the publication hereof. dollars (US$5.00). The foregoing limitations, exclusions and disclaimers
shall apply to the maximum extent permitted by applicable law, even if any
Suitability for use — NXP Semiconductors products are not designed, remedy fails of its essential purpose.
authorized or warranted to be suitable for use in life support, life-critical or
safety-critical systems or equipment, nor in applications where failure or Translations — A non-English (translated) version of a document is for
malfunction of an NXP Semiconductors product can reasonably be expected reference only. The English version shall prevail in case of any discrepancy
to result in personal injury, death or severe property or environmental between the translated and English versions.
damage. NXP Semiconductors and its suppliers accept no liability for
inclusion and/or use of NXP Semiconductors products in such equipment or
applications and therefore such inclusion and/or use is at the customer’s own
risk.
5.3 Trademarks
Applications — Applications that are described herein for any of these
products are for illustrative purposes only. NXP Semiconductors makes Notice: All referenced brands, product names, service names and
no representation or warranty that such applications will be suitable trademarks are the property of their respective owners.
for the specified use without further testing or modification. Customers
are responsible for the design and operation of their applications and MIFARE — is a trademark of NXP B.V.
products using NXP Semiconductors products, and NXP Semiconductors DESFire — is a trademark of NXP B.V.
accepts no liability for any assistance with applications or customer product
design. It is customer’s sole responsibility to determine whether the NXP MIFARE Plus — is a trademark of NXP B.V.
AN10922 All information provided in this document is subject to legal disclaimers. © NXP B.V. 2019. All rights reserved.
Tables
Tab. 1. Abbreviations .....................................................3 Tab. 4. Example – AES 256 key diversification ........... 12
Tab. 2. Example – AES 128 key diversification .............7 Tab. 5. Example – 2TDEA key diversification ............. 15
Tab. 3. Example – AES 192 key diversification .............9 Tab. 6. Example – 3TDEA key diversification ............. 18
AN10922 All information provided in this document is subject to legal disclaimers. © NXP B.V. 2019. All rights reserved.
Figures
Fig. 1. CMAC construction (2 cases: left without Fig. 4. Diversification of 256-bit AES key ................... 12
padding, right with padding) .............................. 5 Fig. 5. Diversification of 2TDEA key ...........................15
Fig. 2. Diversification of 128-bit AES key ..................... 6 Fig. 6. Diversification of 3TDEA key ...........................18
Fig. 3. Diversification of 192-bit AES key ..................... 9
AN10922 All information provided in this document is subject to legal disclaimers. © NXP B.V. 2019. All rights reserved.
Contents
1 Introduction ......................................................... 3
1.1 Abbreviations ..................................................... 3
1.2 Examples presented in this document ...............4
2 Key Diversification ..............................................5
2.1 Construction .......................................................5
2.2 AES-128 key ......................................................5
2.2.1 AES-128 key diversification example ................ 7
2.3 AES-192 key ......................................................8
2.3.1 AES-192 key diversification example ................ 9
2.4 AES-256 key ....................................................11
2.4.1 AES-256 key diversification example ...............12
2.5 2TDEA key ...................................................... 14
2.5.1 2TDEA key diversification example ................. 15
2.6 3TDEA key ...................................................... 17
2.6.1 3TDEA key diversification example ................. 18
3 Conclusion .........................................................21
4 References ......................................................... 22
5 Legal information .............................................. 23
Please be aware that important notices concerning this document and the product(s)
described herein, have been included in section 'Legal information'.