From 8d492abf5d47e993ea9cca05523a5fb4a71bd4c8 Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Fri, 24 Dec 2010 12:38:52 +0000 Subject: [PATCH] Change the enciphered_data_length() internal function prototype. --- libfreefare/freefare_internal.h | 2 +- libfreefare/mifare_desfire_crypto.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libfreefare/freefare_internal.h b/libfreefare/freefare_internal.h index a806ce0..3a0ca56 100644 --- a/libfreefare/freefare_internal.h +++ b/libfreefare/freefare_internal.h @@ -153,7 +153,7 @@ void desfire_crc32_append (uint8_t *data, const size_t len); size_t key_block_size (const MifareDESFireKey key); size_t padded_data_length (const size_t nbytes, const size_t block_size); size_t maced_data_length (const MifareDESFireKey key, const size_t nbytes); -size_t enciphered_data_length (const MifareDESFireKey key, const size_t nbytes, int communication_settings); +size_t enciphered_data_length (const MifareTag tag, const size_t nbytes, int communication_settings); void cmac_generate_subkeys (MifareDESFireKey key); void cmac (const MifareDESFireKey key, uint8_t *ivect, const uint8_t *data, size_t len, uint8_t *cmac); diff --git a/libfreefare/mifare_desfire_crypto.c b/libfreefare/mifare_desfire_crypto.c index 557a870..b5f86a1 100644 --- a/libfreefare/mifare_desfire_crypto.c +++ b/libfreefare/mifare_desfire_crypto.c @@ -260,11 +260,11 @@ maced_data_length (const MifareDESFireKey key, const size_t nbytes) * Buffer size required to encipher nbytes of data and a two bytes CRC. */ size_t -enciphered_data_length (const MifareDESFireKey key, const size_t nbytes, int communication_settings) +enciphered_data_length (const MifareTag tag, const size_t nbytes, int communication_settings) { size_t crc_length = 0; if (!(communication_settings & NO_CRC)) { - switch (key->type) { + switch (MIFARE_DESFIRE (tag)->session_key->type) { case T_DES: case T_3DES: crc_length = 2; @@ -276,7 +276,7 @@ enciphered_data_length (const MifareDESFireKey key, const size_t nbytes, int com } } - size_t block_size = key_block_size (key); + size_t block_size = key_block_size (MIFARE_DESFIRE (tag)->session_key); return padded_data_length (nbytes + crc_length, block_size); } @@ -404,7 +404,7 @@ mifare_cryto_preprocess_data (MifareTag tag, void *data, size_t *nbytes, off_t o case T_3K3DES: if (!(communication_settings & ENC_COMMAND)) break; - edl = enciphered_data_length (MIFARE_DESFIRE (tag)->session_key, *nbytes - offset, communication_settings) + offset; + edl = enciphered_data_length (tag, *nbytes - offset, communication_settings) + offset; if (!(res = assert_crypto_buffer_size (tag, edl))) abort(); @@ -437,7 +437,7 @@ mifare_cryto_preprocess_data (MifareTag tag, void *data, size_t *nbytes, off_t o break; case T_AES: - edl = enciphered_data_length (MIFARE_DESFIRE (tag)->session_key, *nbytes - offset, communication_settings) + offset; + edl = enciphered_data_length (tag, *nbytes - offset, communication_settings) + offset; if (!(res = assert_crypto_buffer_size (tag, edl))) abort(); @@ -503,7 +503,7 @@ mifare_cryto_postprocess_data (MifareTag tag, void *data, ssize_t *nbytes, int c if (communication_settings & MAC_VERIFY) { *nbytes -= key_macing_length (key); - edl = enciphered_data_length (MIFARE_DESFIRE (tag)->session_key, *nbytes - 1, communication_settings); + edl = enciphered_data_length (tag, *nbytes - 1, communication_settings); edata = malloc (edl); memcpy (edata, data, *nbytes - 1);