Rename some internal functions.

A function with DES in its name that can perform AES crypto is somewhat
disturbing.
This commit is contained in:
Romain Tartiere 2010-12-24 14:10:44 +00:00
parent 7837fa967d
commit e587e26aeb
3 changed files with 17 additions and 17 deletions

View file

@ -146,7 +146,7 @@ typedef enum {
void *mifare_cryto_preprocess_data (MifareTag tag, void *data, size_t *nbytes, off_t offset, int communication_settings); void *mifare_cryto_preprocess_data (MifareTag tag, void *data, size_t *nbytes, off_t offset, int communication_settings);
void *mifare_cryto_postprocess_data (MifareTag tag, void *data, ssize_t *nbytes, int communication_settings); void *mifare_cryto_postprocess_data (MifareTag tag, void *data, ssize_t *nbytes, int communication_settings);
void mifare_cbc_des (MifareTag tag, MifareDESFireKey key, uint8_t *ivect, uint8_t *data, size_t data_size, MifareCryptoDirection direction, MifareCryptoOperation operation); void mifare_cypher_blocks_chained (MifareTag tag, MifareDESFireKey key, uint8_t *ivect, uint8_t *data, size_t data_size, MifareCryptoDirection direction, MifareCryptoOperation operation);
void rol (uint8_t *data, const size_t len); void rol (uint8_t *data, const size_t len);
void desfire_crc32 (const uint8_t *data, const size_t len, uint8_t *crc); void desfire_crc32 (const uint8_t *data, const size_t len, uint8_t *crc);
void desfire_crc32_append (uint8_t *data, const size_t len); void desfire_crc32_append (uint8_t *data, const size_t len);

View file

@ -351,7 +351,7 @@ authenticate (MifareTag tag, uint8_t cmd, uint8_t key_no, MifareDESFireKey key)
uint8_t PICC_RndB[16]; uint8_t PICC_RndB[16];
memcpy (PICC_RndB, PICC_E_RndB, key_length); memcpy (PICC_RndB, PICC_E_RndB, key_length);
mifare_cbc_des (tag, key, MIFARE_DESFIRE (tag)->ivect, PICC_RndB, key_length, MCD_RECEIVE, MCO_DECYPHER); mifare_cypher_blocks_chained (tag, key, MIFARE_DESFIRE (tag)->ivect, PICC_RndB, key_length, MCD_RECEIVE, MCO_DECYPHER);
uint8_t PCD_RndA[16]; uint8_t PCD_RndA[16];
RAND_bytes (PCD_RndA, 16); RAND_bytes (PCD_RndA, 16);
@ -364,7 +364,7 @@ authenticate (MifareTag tag, uint8_t cmd, uint8_t key_no, MifareDESFireKey key)
memcpy (token, PCD_RndA, key_length); memcpy (token, PCD_RndA, key_length);
memcpy (token+key_length, PCD_r_RndB, key_length); memcpy (token+key_length, PCD_r_RndB, key_length);
mifare_cbc_des (tag, key, MIFARE_DESFIRE (tag)->ivect, token, 2 * key_length, MCD_SEND, (0x0A == cmd) ? MCO_DECYPHER : MCO_ENCYPHER); mifare_cypher_blocks_chained (tag, key, MIFARE_DESFIRE (tag)->ivect, token, 2 * key_length, MCD_SEND, (0x0A == cmd) ? MCO_DECYPHER : MCO_ENCYPHER);
BUFFER_INIT (cmd2, 33); BUFFER_INIT (cmd2, 33);
@ -378,7 +378,7 @@ authenticate (MifareTag tag, uint8_t cmd, uint8_t key_no, MifareDESFireKey key)
uint8_t PICC_RndA_s[16]; uint8_t PICC_RndA_s[16];
memcpy (PICC_RndA_s, PICC_E_RndA_s, key_length); memcpy (PICC_RndA_s, PICC_E_RndA_s, key_length);
mifare_cbc_des (tag, key, MIFARE_DESFIRE (tag)->ivect, PICC_RndA_s, key_length, MCD_RECEIVE, MCO_DECYPHER); mifare_cypher_blocks_chained (tag, key, MIFARE_DESFIRE (tag)->ivect, PICC_RndA_s, key_length, MCD_RECEIVE, MCO_DECYPHER);
uint8_t PCD_RndA_s[key_length]; uint8_t PCD_RndA_s[key_length];
memcpy (PCD_RndA_s, PCD_RndA, key_length); memcpy (PCD_RndA_s, PCD_RndA, key_length);

View file

@ -71,7 +71,7 @@
#define CMAC_LENGTH 8 #define CMAC_LENGTH 8
static void xor (const uint8_t *ivect, uint8_t *data, const size_t len); static void xor (const uint8_t *ivect, uint8_t *data, const size_t len);
static void mifare_des (MifareDESFireKey key, uint8_t *data, uint8_t *ivect, MifareCryptoDirection direction, MifareCryptoOperation operation, size_t block_size); static void mifare_cypher_single_block (MifareDESFireKey key, uint8_t *data, uint8_t *ivect, MifareCryptoDirection direction, MifareCryptoOperation operation, size_t block_size);
static void desfire_crc32_byte (uint32_t *crc, const uint8_t value); static void desfire_crc32_byte (uint32_t *crc, const uint8_t value);
static size_t key_macing_length (MifareDESFireKey key); static size_t key_macing_length (MifareDESFireKey key);
@ -114,7 +114,7 @@ cmac_generate_subkeys (MifareDESFireKey key)
uint8_t ivect[kbs]; uint8_t ivect[kbs];
memset (ivect, 0, kbs); memset (ivect, 0, kbs);
mifare_cbc_des (NULL, key, ivect, l, kbs, MCD_RECEIVE, MCO_ENCYPHER); mifare_cypher_blocks_chained (NULL, key, ivect, l, kbs, MCD_RECEIVE, MCO_ENCYPHER);
bool xor = false; bool xor = false;
@ -154,7 +154,7 @@ cmac (const MifareDESFireKey key, uint8_t *ivect, const uint8_t *data, size_t le
xor (key->cmac_sk1, buffer + len - kbs, kbs); xor (key->cmac_sk1, buffer + len - kbs, kbs);
} }
mifare_cbc_des (NULL, key, ivect, buffer, len, MCD_SEND, MCO_ENCYPHER); mifare_cypher_blocks_chained (NULL, key, ivect, buffer, len, MCD_SEND, MCO_ENCYPHER);
memcpy (cmac, ivect, kbs); memcpy (cmac, ivect, kbs);
@ -342,11 +342,11 @@ mifare_cryto_preprocess_data (MifareTag tag, void *data, size_t *nbytes, off_t o
// ... and 0 padding // ... and 0 padding
memset ((uint8_t *)res + *nbytes, 0, edl - *nbytes); memset ((uint8_t *)res + *nbytes, 0, edl - *nbytes);
mifare_cbc_des (tag, NULL, NULL, (uint8_t *) res + offset, edl - offset, MCD_SEND, MCO_ENCYPHER); mifare_cypher_blocks_chained (tag, NULL, NULL, (uint8_t *) res + offset, edl - offset, MCD_SEND, MCO_ENCYPHER);
memcpy (mac, (uint8_t *)res + edl - 8, 4); memcpy (mac, (uint8_t *)res + edl - 8, 4);
// Copy again provided data (was overwritten by mifare_cbc_des) // Copy again provided data (was overwritten by mifare_cypher_blocks_chained)
memcpy (res, data, *nbytes); memcpy (res, data, *nbytes);
if (!(communication_settings & MAC_COMMAND)) if (!(communication_settings & MAC_COMMAND))
@ -424,7 +424,7 @@ mifare_cryto_preprocess_data (MifareTag tag, void *data, size_t *nbytes, off_t o
*nbytes = edl; *nbytes = edl;
mifare_cbc_des (tag, NULL, NULL, (uint8_t *) res + offset, *nbytes - offset, MCD_SEND, (AS_NEW == MIFARE_DESFIRE (tag)->authentication_scheme) ? MCO_ENCYPHER : MCO_DECYPHER); mifare_cypher_blocks_chained (tag, NULL, NULL, (uint8_t *) res + offset, *nbytes - offset, MCD_SEND, (AS_NEW == MIFARE_DESFIRE (tag)->authentication_scheme) ? MCO_ENCYPHER : MCO_DECYPHER);
break; break;
case T_AES: case T_AES:
@ -443,7 +443,7 @@ mifare_cryto_preprocess_data (MifareTag tag, void *data, size_t *nbytes, off_t o
pdl = padded_data_length (*nbytes - offset, key_block_size (MIFARE_DESFIRE (tag)->session_key)); pdl = padded_data_length (*nbytes - offset, key_block_size (MIFARE_DESFIRE (tag)->session_key));
memset ((uint8_t *)res + *nbytes, 0, (offset + pdl) - (*nbytes)); memset ((uint8_t *)res + *nbytes, 0, (offset + pdl) - (*nbytes));
} }
mifare_cbc_des (tag, NULL, NULL, (uint8_t *)res + offset, pdl, MCD_SEND, MCO_ENCYPHER); mifare_cypher_blocks_chained (tag, NULL, NULL, (uint8_t *)res + offset, pdl, MCD_SEND, MCO_ENCYPHER);
*nbytes = offset + pdl; *nbytes = offset + pdl;
break; break;
@ -499,7 +499,7 @@ mifare_cryto_postprocess_data (MifareTag tag, void *data, ssize_t *nbytes, int c
memcpy (edata, data, *nbytes - 1); memcpy (edata, data, *nbytes - 1);
memset ((uint8_t *)edata + *nbytes - 1, 0, edl - *nbytes + 1); memset ((uint8_t *)edata + *nbytes - 1, 0, edl - *nbytes + 1);
mifare_cbc_des (tag, NULL, NULL, edata, edl, MCD_SEND, MCO_ENCYPHER); mifare_cypher_blocks_chained (tag, NULL, NULL, edata, edl, MCD_SEND, MCO_ENCYPHER);
if (0 != memcmp ((uint8_t *)data + *nbytes - 1, (uint8_t *)edata + edl - 8, 4)) { if (0 != memcmp ((uint8_t *)data + *nbytes - 1, (uint8_t *)edata + edl - 8, 4)) {
warnx ("MACing not verified"); warnx ("MACing not verified");
@ -554,7 +554,7 @@ mifare_cryto_postprocess_data (MifareTag tag, void *data, ssize_t *nbytes, int c
(*nbytes)--; (*nbytes)--;
switch (MIFARE_DESFIRE (tag)->authentication_scheme) { switch (MIFARE_DESFIRE (tag)->authentication_scheme) {
case AS_LEGACY: case AS_LEGACY:
mifare_cbc_des (tag, NULL, NULL, res, *nbytes, MCD_RECEIVE, MCO_DECYPHER); mifare_cypher_blocks_chained (tag, NULL, NULL, res, *nbytes, MCD_RECEIVE, MCO_DECYPHER);
/* /*
* Look for the CRC and ensure it is followed by NULL padding. We * Look for the CRC and ensure it is followed by NULL padding. We
@ -594,7 +594,7 @@ mifare_cryto_postprocess_data (MifareTag tag, void *data, ssize_t *nbytes, int c
break; break;
case AS_NEW: case AS_NEW:
mifare_cbc_des (tag, NULL, NULL, res, *nbytes, MCD_RECEIVE, MCO_DECYPHER); mifare_cypher_blocks_chained (tag, NULL, NULL, res, *nbytes, MCD_RECEIVE, MCO_DECYPHER);
uint8_t *p = ((uint8_t *)res) + *nbytes - 1; uint8_t *p = ((uint8_t *)res) + *nbytes - 1;
while (!*p) { while (!*p) {
p--; p--;
@ -637,7 +637,7 @@ mifare_cryto_postprocess_data (MifareTag tag, void *data, ssize_t *nbytes, int c
} }
static void static void
mifare_des (MifareDESFireKey key, uint8_t *data, uint8_t *ivect, MifareCryptoDirection direction, MifareCryptoOperation operation, size_t block_size) mifare_cypher_single_block (MifareDESFireKey key, uint8_t *data, uint8_t *ivect, MifareCryptoDirection direction, MifareCryptoOperation operation, size_t block_size)
{ {
AES_KEY k; AES_KEY k;
uint8_t ovect[MAX_CRYPTO_BLOCK_SIZE]; uint8_t ovect[MAX_CRYPTO_BLOCK_SIZE];
@ -724,7 +724,7 @@ mifare_des (MifareDESFireKey key, uint8_t *data, uint8_t *ivect, MifareCryptoDir
* function with tag, key and ivect defined. * function with tag, key and ivect defined.
*/ */
void void
mifare_cbc_des (MifareTag tag, MifareDESFireKey key, uint8_t *ivect, uint8_t *data, size_t data_size, MifareCryptoDirection direction, MifareCryptoOperation operation) mifare_cypher_blocks_chained (MifareTag tag, MifareDESFireKey key, uint8_t *ivect, uint8_t *data, size_t data_size, MifareCryptoDirection direction, MifareCryptoOperation operation)
{ {
size_t block_size; size_t block_size;
@ -759,7 +759,7 @@ mifare_cbc_des (MifareTag tag, MifareDESFireKey key, uint8_t *ivect, uint8_t *da
size_t offset = 0; size_t offset = 0;
while (offset < data_size) { while (offset < data_size) {
mifare_des (key, data + offset, ivect, direction, operation, block_size); mifare_cypher_single_block (key, data + offset, ivect, direction, operation, block_size);
offset += block_size; offset += block_size;
} }
} }