From 8975c60de784e93a1cdcfe0f8698a0c6166ca593 Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Sat, 20 Nov 2010 22:24:36 +0000 Subject: [PATCH] Add some shortcuts. --- libfreefare/mifare_desfire_authenticate.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libfreefare/mifare_desfire_authenticate.c b/libfreefare/mifare_desfire_authenticate.c index 4a89d4e..4cf2160 100644 --- a/libfreefare/mifare_desfire_authenticate.c +++ b/libfreefare/mifare_desfire_authenticate.c @@ -133,7 +133,7 @@ assert_crypto_buffer_size (MifareTag tag, size_t nbytes) void * mifare_cryto_preprocess_data (MifareTag tag, void *data, size_t *nbytes, off_t offset, int communication_settings) { - void *res; + void *res = data; uint8_t mac[4]; size_t edl, mdl; MifareDESFireKey key = MIFARE_DESFIRE (tag)->session_key; @@ -141,9 +141,12 @@ mifare_cryto_preprocess_data (MifareTag tag, void *data, size_t *nbytes, off_t o if (!key) return data; + // Return directly if we just have a command code. + if (1 == *nbytes) + return data; + switch (communication_settings) { case MDCM_PLAIN: - res = data; break; case MDCM_MACED: edl = padded_data_length (*nbytes - offset, key_block_size (MIFARE_DESFIRE (tag)->session_key)) + offset; @@ -201,6 +204,10 @@ mifare_cryto_postprocess_data (MifareTag tag, void *data, ssize_t *nbytes, int c size_t edl; void *edata; + // Return directly if we just have a status code. + if (1 == *nbytes) + return res; + switch (communication_settings) { case MDCM_PLAIN: break;