mirror of
https://github.com/RfidResearchGroup/ChameleonUltra.git
synced 2026-10-23 12:53:05 +00:00
* Implement MF1_ENC_NESTED_ACQUIRE in firmware * Implement MF1_ENC_NESTED_ACQUIRE in software + fix code formatter * Remove xz and pthreads from sources, use CMake FetchContent * Update changelog * lzma.h * Update CMakeLists.txt * Update CMakeLists.txt * Probably fix workflow taking wrong commit for building * Fix CMake building tools into bin/Debug on Windows * Added cmd for fetching all slots nicks (without 16 commands) * Fix type and use temp directory instead cwd (https://github.com/RfidResearchGroup/ChameleonUltra/pull/261) * Fix endian for mfu_read_emu_counter_data and mfu_write_emu_counter_data * Fix --key interpreted as list
113 lines
3.3 KiB
C
Executable File
113 lines
3.3 KiB
C
Executable File
//-----------------------------------------------------------------------------
|
|
// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// See LICENSE.txt for the text of the license.
|
|
//-----------------------------------------------------------------------------
|
|
// Parity functions
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// all functions defined in header file by purpose. Allows compiler optimizations.
|
|
#include <string.h>
|
|
#ifndef __PARITY_H
|
|
#define __PARITY_H
|
|
#define _CRT_NONSTDC_NO_WARNINGS
|
|
#define _CRT_SECURE_NO_WARNINGS
|
|
#define _CRT_NON_CONFORMING_SWPRINTFS
|
|
|
|
#define restrict __restrict
|
|
#define inline __inline
|
|
#include <stdio.h>
|
|
#include <stdint.h>
|
|
|
|
static const uint8_t g_odd_byte_parity[256] = {
|
|
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
|
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
|
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
|
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
|
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
|
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
|
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
|
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
|
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
|
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
|
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
|
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
|
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
|
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
|
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
|
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1
|
|
};
|
|
|
|
#define ODD_PARITY8(x) (g_odd_byte_parity[x])
|
|
#define EVEN_PARITY8(x) (!g_odd_byte_parity[x])
|
|
|
|
static inline uint8_t oddparity8(const uint8_t x) {
|
|
return g_odd_byte_parity[x];
|
|
}
|
|
|
|
static inline uint8_t evenparity8(const uint8_t x) {
|
|
return !g_odd_byte_parity[x];
|
|
}
|
|
|
|
static inline uint8_t evenparity16(uint16_t x) {
|
|
#if !defined __GNUC__
|
|
x ^= x >> 8;
|
|
return EVEN_PARITY8(x);
|
|
#else
|
|
return (__builtin_parity(x) & 0xFF);
|
|
#endif
|
|
}
|
|
|
|
static inline uint8_t oddparity16(uint16_t x) {
|
|
#if !defined __GNUC__
|
|
x ^= x >> 8;
|
|
return ODD_PARITY8(x);
|
|
#else
|
|
return !__builtin_parity(x);
|
|
#endif
|
|
}
|
|
|
|
static inline uint8_t evenparity32(uint32_t x) {
|
|
#if _MSC_VER
|
|
x ^= x >> 16;
|
|
x ^= x >> 8;
|
|
x ^= x >> 4;
|
|
x &= 0xf;
|
|
return (0x6996 >> x) & 1;
|
|
#elif !defined __GNUC__
|
|
x ^= x >> 16;
|
|
x ^= x >> 8;
|
|
return EVEN_PARITY8(x);
|
|
#else
|
|
return (__builtin_parity(x) & 0xFF);
|
|
#endif
|
|
}
|
|
|
|
static inline uint8_t oddparity32(uint32_t x) {
|
|
#if _MSC_VER
|
|
x ^= x >> 16;
|
|
x ^= x >> 8;
|
|
x ^= x >> 4;
|
|
x &= 0xf;
|
|
return ((0x6996 >> x) & 1) ^ 1;
|
|
#elif !defined __GNUC__
|
|
x ^= x >> 16;
|
|
x ^= x >> 8;
|
|
return ODD_PARITY8(x);
|
|
#else
|
|
return !__builtin_parity(x);
|
|
#endif
|
|
}
|
|
|
|
#endif /* __PARITY_H */
|