MIFARE Application Directory

CRC calculation:

Byte 0 of block 1 of Sector 0 (MAD1, MAD2) and Sector 0×10 (MAD2) will contain 8 bit cyclic redundancy code (CRC). It is generated at the generation of the MAD.

This code should be checked whenever the MAD is read in order to ensure data integrity. Both for the CRC generation and the CRC check the internal CRC coprocessor of the MIFARE“ reader ASIC may be used. Actually the mif_calc_crc() function from the MIFARE“ LowLevelLibrary allows an easy calculation of the CRC code.

For the CRC-calculation of Sector 0 the Info byte should be processed first, then ID1, ID2 … ID0xE, ID0xF in this order.

For the CRC-calculation of Sector 0×10 the Info byte should be processed first, then ID0x11, ID0x12 … ID0x26, ID0x27 in this order.

Always process the lower byte first within the AID´s followed by the higher byte. That means the following process order:
-Sector 0×0:block 1, byte 1 to byte 0xF; block 2, byte 0 to byte 0xF
-Sector 0×10:block 0, byte 1 to byte 0xF; block 1, byte 0 to byte 0xF, block 2, byte 0 to byte 0xF
-Of course the calculation can also be achieved via appropriate software.
-8 bit CRC uses the polynomial:x8 + x4 + x3 + x2 + 1and is preset with 0xE3

example for CRC calculation with a sample MAD (hex values):

Table 11. CRC calculation                          
byte byte byte byte byte byte byte byte byte byte byte byte byte byte byte byte
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
AID for AID for AID for AID for AID for AID for AID for info CRC
sector 7 sector 6 sector 5 sector 4 sector 3 sector 2 sector 1    
00 04 00 00 00 00 00 00 08 01 08 01 08 01 01 89
AID for AID for AID for AID for AID for AID for AID for AID for
sector $F sector $E sector $D sector $C sector $B sector $A sector 9 sector 8
30 11 00 00 00 00 00 00 10 02 10 02 10 03 10 03

 

Pointer to card publisher sector:

This information is particularly useful if somebody needs to find out the organization responsible for distribution of free card sectors for new applications. These free card sectors may easily be used for additional applications.

The lower 6 bits (4bits for MAD1) of the Info-byte contain a binary pointer to one of the 38 sectors in use (15 sectors for MAD1). The owner of the corresponding sector is considered to be the card publisher, responsible for card issue, card maintenance and also for maintenance of the MAD. 0×00 should be used if the card publishing organization does not use any sector on the MIFARE“ card.

0×10 shall not be used.
0×28 … 0x3F shall not be used.

Key protection of MAD:

Block 3 of sector 0 (MAD1, MAD2) and block 3 of sector 0×10 (MAD2) contain key information as well as access condition information. The MAD should be well write-protected with a secret key B defined by the card issuer. Anybody should be allowed to read the MAD. This is achieved by using a public read key A (for sector 0 and sector 0×10, if applicable):

key A: a0a1a2a3a4a5 hex

Access conditions should allow reading with key A|B and writing with key B. According to the MIFARE card product specification this means the following code:
C1X0 C2X0 C3X0: x x x(don´t care for manuf.code)
C1X1 C2X1 C3X1: 1 0 0
C1X2 C2X2 C3X2: 1 0 0
C1X3 C2X3 C3X3: 0 1 1

example for sector trailer 0 with hex codes
Type of example card:multiapplication with directory

Table 12. example for sector trailer 0 with hex codes                    
byte byte byte byte byte byte byte byte byte byte byte byte byte byte byte byte
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
s e c r e t   C1 88 77 78 a5 a4 a3 a2 a1 a0
key B access condition key A
All currently unused sectors should be well write protected with secret write keys defined          
by the card issuer in order to prevent unintended redefinition of access conditions and            
keys. It is recommended to use different keys for all free sectors. This enables future            
release of some sectors to new service providers without the need of releasing all free            
sectors.