From f2a0f3e272f6893cabf9e260b7251f7e39e78daa Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 7 Mar 2021 23:48:48 +0100 Subject: [PATCH] replace static countones & bitcount by utils in client --- client/src/cmdhficlass.c | 10 +--------- client/src/cmdlffdxb.c | 12 +----------- client/src/cmdlfnedap.c | 12 +----------- 3 files changed, 3 insertions(+), 31 deletions(-) diff --git a/client/src/cmdhficlass.c b/client/src/cmdhficlass.c index 2fda649b8..7225a443b 100644 --- a/client/src/cmdhficlass.c +++ b/client/src/cmdhficlass.c @@ -103,14 +103,6 @@ static inline uint32_t leadingzeros(uint64_t a) { #else return 0; #endif -} -static inline uint32_t countones(uint64_t a) { -#if defined __GNUC__ - return __builtin_popcountll(a); -#else - return 0; -#endif - } const char *card_types[] = { @@ -2034,7 +2026,7 @@ static int CmdHFiClass_ReadBlock(const char *Cmd) { uint64_t a = bytes_to_num(data, 8); bool starts = (leadingzeros(a) < 12); - bool ones = (countones(a) > 16 && countones(a) < 48); + bool ones = (bitcount64(a) > 16 && bitcount64(a) < 48); if (starts && ones) { PrintAndLogEx(INFO, "data looks encrypted, False Positives " _YELLOW_("ARE") " possible"); diff --git a/client/src/cmdlffdxb.c b/client/src/cmdlffdxb.c index fdead8ea9..4287db630 100644 --- a/client/src/cmdlffdxb.c +++ b/client/src/cmdlffdxb.c @@ -118,16 +118,6 @@ static void verify_values(uint64_t *animalid, uint32_t *countryid, uint32_t *ext } } -static inline uint32_t bitcount(uint32_t a) { -#if defined __GNUC__ - return __builtin_popcountl(a); -#else - a = a - ((a >> 1) & 0x55555555); - a = (a & 0x33333333) + ((a >> 2) & 0x33333333); - return (((a + (a >> 4)) & 0x0f0f0f0f) * 0x01010101) >> 24; -#endif -} - // FDX-B ISO11784/85 demod (aka animal tag) BIPHASE, inverted, rf/32, with preamble of 00000000001 (128bits) // 8 databits + 1 parity (1) // CIITT 16 chksum @@ -594,7 +584,7 @@ int demodFDXB(bool verbose) { uint8_t bt_par = (extended & 0x100) >> 8; uint8_t bt_temperature = extended & 0xff; - uint8_t bt_calc_parity = (bitcount(bt_temperature) & 0x1) ? 0 : 1; + uint8_t bt_calc_parity = (bitcount32(bt_temperature) & 0x1) ? 0 : 1; uint8_t is_bt_temperature = (bt_calc_parity == bt_par) && !(extended & 0xe00) ; if (is_bt_temperature) { diff --git a/client/src/cmdlfnedap.c b/client/src/cmdlfnedap.c index 20cb5eec5..829a5b106 100644 --- a/client/src/cmdlfnedap.c +++ b/client/src/cmdlfnedap.c @@ -37,20 +37,10 @@ const uint8_t translateTable[10] = {8, 2, 1, 12, 4, 5, 10, 13, 0, 9}; const uint8_t invTranslateTable[16] = {8, 2, 1, 0xff, 4, 5, 0xff, 0xff, 0, 9, 6, 0xff, 3, 7, 0xff, 0xff}; const uint8_t preamble[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}; // zero inside -static inline uint32_t bitcount(uint32_t a) { -#if defined __GNUC__ - return __builtin_popcountl(a); -#else - a = a - ((a >> 1) & 0x55555555); - a = (a & 0x33333333) + ((a >> 2) & 0x33333333); - return (((a + (a >> 4)) & 0x0f0f0f0f) * 0x01010101) >> 24; -#endif -} - static uint8_t isEven_64_63(const uint8_t *data) { // 8 uint32_t tmp[2]; memcpy(tmp, data, 8); - return (bitcount(tmp[0]) + (bitcount(tmp[1] & 0xfeffffff))) & 1; + return (bitcount32(tmp[0]) + (bitcount32(tmp[1] & 0xfeffffff))) & 1; } //NEDAP demod - ASK/Biphase (or Diphase), RF/64 with preamble of 1111111110 (always a 128 bit data stream)