From 13f03a60bb3e94c90cc1269295b6fa6a21b79e30 Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Fri, 29 Oct 2010 12:01:57 +0000 Subject: [PATCH] Change rol8() to rol() to work with buffers of any length. --- libfreefare/freefare_internal.h | 2 +- libfreefare/mifare_desfire.c | 4 ++-- libfreefare/mifare_desfire_authenticate.c | 6 +++--- test/test_mifare_desfire_des.c | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libfreefare/freefare_internal.h b/libfreefare/freefare_internal.h index 4559685..08d81cd 100644 --- a/libfreefare/freefare_internal.h +++ b/libfreefare/freefare_internal.h @@ -117,7 +117,7 @@ typedef enum { void *mifare_cryto_preprocess_data (MifareTag tag, void *data, size_t *nbytes, int communication_settings); void *mifare_cryto_postprocess_data (MifareTag tag, void *data, ssize_t *nbytes, int communication_settings); void mifare_cbc_des (MifareDESFireKey key, uint8_t *data, size_t data_size, MifareDirection direction, int mac); -void rol8(uint8_t *data); +void rol (uint8_t *data, const size_t len); void *assert_crypto_buffer_size (MifareTag tag, size_t nbytes); #define MIFARE_ULTRALIGHT_PAGE_COUNT 16 diff --git a/libfreefare/mifare_desfire.c b/libfreefare/mifare_desfire.c index ab8dc22..faf8099 100644 --- a/libfreefare/mifare_desfire.c +++ b/libfreefare/mifare_desfire.c @@ -354,7 +354,7 @@ mifare_desfire_authenticate (MifareTag tag, uint8_t key_no, MifareDESFireKey key uint8_t PCD_r_RndB[8]; memcpy (PCD_r_RndB, PICC_RndB, 8); - rol8 (PCD_r_RndB); + rol (PCD_r_RndB, 8); uint8_t token[16]; memcpy (token, PCD_RndA, 8); @@ -378,7 +378,7 @@ mifare_desfire_authenticate (MifareTag tag, uint8_t key_no, MifareDESFireKey key uint8_t PCD_RndA_s[8]; memcpy (PCD_RndA_s, PCD_RndA, 8); - rol8 (PCD_RndA_s); + rol (PCD_RndA_s, 8); if (0 != memcmp (PCD_RndA_s, PICC_RndA_s, 8)) { diff --git a/libfreefare/mifare_desfire_authenticate.c b/libfreefare/mifare_desfire_authenticate.c index 04380a9..4f47368 100644 --- a/libfreefare/mifare_desfire_authenticate.c +++ b/libfreefare/mifare_desfire_authenticate.c @@ -43,13 +43,13 @@ xor8 (uint8_t *ivect, uint8_t *data) } void -rol8(uint8_t *data) +rol(uint8_t *data, const size_t len) { uint8_t first = data[0]; - for (int i = 0; i < 7; i++) { + for (size_t i = 0; i < len-1; i++) { data[i] = data[i+1]; } - data[7] = first; + data[len-1] = first; } /* diff --git a/test/test_mifare_desfire_des.c b/test/test_mifare_desfire_des.c index ef6c651..dac47a8 100644 --- a/test/test_mifare_desfire_des.c +++ b/test/test_mifare_desfire_des.c @@ -22,11 +22,11 @@ #include "freefare_internal.h" void -test_mifare_rol8 (void) +test_mifare_rol (void) { uint8_t data[8] = "01234567"; - rol8 (data); - cut_assert_equal_memory ("12345670", 8, data, 8, cut_message ("Wrong data")); + rol (data, sizeof (data)); + cut_assert_equal_memory ("12345670", 8, data, sizeof (data), cut_message ("Wrong data")); } void