7 #define MAX_CRYPTO_BLOCK_SIZE 16
8 /* Mifare DESFire EV1 Application crypto operations */
9 #define APPLICATION_CRYPTO_DES 0x00
10 #define APPLICATION_CRYPTO_3K3DES 0x40
11 #define APPLICATION_CRYPTO_AES 0x80
19 } MifareCryptoDirection
;
24 } MifareCryptoOperation
;
26 #define MDCM_MASK 0x000F
30 // Data send to the PICC is used to update the CMAC
31 #define CMAC_COMMAND 0x010
32 // Data received from the PICC is used to update the CMAC
33 #define CMAC_VERIFY 0x020
35 // MAC the command (when MDCM_MACED)
36 #define MAC_COMMAND 0x100
37 // The command returns a MAC to verify (when MDCM_MACED)
38 #define MAC_VERIFY 0x200
40 #define ENC_COMMAND 0x1000
43 #define MAC_MASK 0x0F0
44 #define CMAC_MACK 0xF00
46 /* Communication mode */
47 #define MDCM_PLAIN 0x00
48 #define MDCM_MACED 0x01
49 #define MDCM_ENCIPHERED 0x03
51 /* Error code managed by the library */
52 #define CRYPTO_ERROR 0x01
55 enum DESFIRE_AUTH_SCHEME
{
60 enum DESFIRE_CRYPTOALGO
{
69 #define DESFIRE_KEY(key) ((struct desfire_key *) key)
71 enum DESFIRE_CRYPTOALGO type
;
77 typedef struct desfire_key
*desfirekey_t
;
79 #define DESFIRE(tag) ((struct desfire_tag *) tag)
81 iso14a_card_select_t info
;
83 uint8_t last_picc_error
;
84 uint8_t last_internal_error
;
85 uint8_t last_pcd_error
;
86 desfirekey_t session_key
;
87 enum DESFIRE_AUTH_SCHEME authentication_scheme
;
88 uint8_t authenticated_key_no
;
90 uint8_t ivect
[MAX_CRYPTO_BLOCK_SIZE
];
92 uint8_t *crypto_buffer
;
93 size_t crypto_buffer_size
;
94 uint32_t selected_application
;
96 typedef struct desfire_tag
*desfiretag_t
;
100 enum DESFIRE_FILE_TYPES
{
101 MDFT_STANDARD_DATA_FILE
= 0x00,
102 MDFT_BACKUP_DATA_FILE
= 0x01,
103 MDFT_VALUE_FILE_WITH_BACKUP
= 0x02,
104 MDFT_LINEAR_RECORD_FILE_WITH_BACKUP
= 0x03,
105 MDFT_CYCLIC_RECORD_FILE_WITH_BACKUP
= 0x04
108 enum DESFIRE_STATUS
{
111 OUT_OF_EEPROM_ERROR
= 0x0e,
112 ILLEGAL_COMMAND_CODE
= 0x1c,
113 INTEGRITY_ERROR
= 0x1e,
116 PERMISSION_DENIED
= 0x9d,
117 PARAMETER_ERROR
= 0x9e,
118 APPLICATION_NOT_FOUND
= 0xa0,
119 APPL_INTEGRITY_ERROR
= 0xa1,
120 AUTHENTICATION_ERROR
= 0xae,
121 ADDITIONAL_FRAME
= 0xaf,
122 BOUNDARY_ERROR
= 0xbe,
123 PICC_INTEGRITY_ERROR
= 0xc1,
124 COMMAND_ABORTED
= 0xca,
125 PICC_DISABLED_ERROR
= 0xcd,
127 DUPLICATE_ERROR
= 0xde,
129 FILE_NOT_FOUND
= 0xf0,
130 FILE_INTEGRITY_ERROR
= 0xf1
134 CREATE_APPLICATION
= 0xca,
135 DELETE_APPLICATION
= 0xda,
136 GET_APPLICATION_IDS
= 0x6a,
137 SELECT_APPLICATION
= 0x5a,
145 LIMITED_CREDIT
= 0x1c,
148 CLEAR_RECORD_FILE
= 0xeb,
149 COMMIT_TRANSACTION
= 0xc7,
150 ABORT_TRANSACTION
= 0xa7,
151 GET_FREE_MEMORY
= 0x6e,
153 GET_FILE_SETTINGS
= 0xf5,
155 CHANGE_FILE_SETTINGS
= 0x5f,
156 CREATE_STD_DATA_FILE
= 0xcd,
157 CREATE_BACKUP_DATA_FILE
= 0xcb,
158 CREATE_VALUE_FILE
= 0xcc,
159 CREATE_LINEAR_RECORD_FILE
= 0xc1,
160 CREATE_CYCLIC_RECORD_FILE
= 0xc0,
162 AUTHENTICATE
= 0x0a, // AUTHENTICATE_NATIVE
163 AUTHENTICATE_ISO
= 0x1a, // AUTHENTICATE_STANDARD
164 AUTHENTICATE_AES
= 0xaa,
165 CHANGE_KEY_SETTINGS
= 0x54,
166 GET_KEY_SETTINGS
= 0x45,
168 GET_KEY_VERSION
= 0x64,
169 AUTHENTICATION_FRAME
= 0xAF