mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-03-03 19:43:09 +08:00
add: fast 8bit reversal.
This commit is contained in:
parent
60afef3938
commit
ede55a1498
5 changed files with 22 additions and 9 deletions
|
@ -2503,7 +2503,7 @@ void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype ) {
|
|||
if (nt_diff == 0 && first_try)
|
||||
par_low = par[0] & 0xE0; // there is no need to check all parities for other nt_diff. Parity Bits for mf_nr_ar[0..2] won't change
|
||||
|
||||
par_list[nt_diff] = SwapBits(par[0], 8);
|
||||
par_list[nt_diff] = reflect8(par[0]);
|
||||
ks_list[nt_diff] = receivedAnswer[0] ^ 0x05; // xor with NACK value to get keystream
|
||||
|
||||
// Test if the information is complete
|
||||
|
|
|
@ -13,14 +13,19 @@ size_t nbytes(size_t nbits) {
|
|||
return (nbits >> 3)+((nbits % 8) > 0);
|
||||
}
|
||||
|
||||
uint32_t SwapBits(uint32_t value, int nrbits) {
|
||||
// Swap bit order on a uint32_t value. Can be limited by 'b' just use say 8 bits reversal
|
||||
// note: function clears the rest of the bits.
|
||||
uint32_t SwapBits(uint32_t v, int b) {
|
||||
uint32_t newvalue = 0;
|
||||
for(int i = 0; i < nrbits; i++) {
|
||||
newvalue ^= ((value >> i) & 1) << (nrbits - 1 - i);
|
||||
for(int i = 0; i < b; i++) {
|
||||
newvalue ^= ((v >> i) & 1) << (b - 1 - i);
|
||||
}
|
||||
return newvalue;
|
||||
}
|
||||
|
||||
uint8_t reflect8(uint8_t b) {
|
||||
return ((b * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32;
|
||||
}
|
||||
/*
|
||||
ref http://www.csm.ornl.gov/~dunigan/crc.html
|
||||
Returns the value v with the bottom b [0,32] bits reflected.
|
||||
|
|
|
@ -42,6 +42,10 @@
|
|||
size_t nbytes(size_t nbits);
|
||||
uint32_t SwapBits(uint32_t value, int nrbits);
|
||||
uint32_t reflect(uint32_t v, int b);
|
||||
|
||||
// dedicated 8bit reversal
|
||||
uint8_t reflect8(uint8_t b);
|
||||
|
||||
void num_to_bytes(uint64_t n, size_t len, uint8_t* dest);
|
||||
uint64_t bytes_to_num(uint8_t* src, size_t len);
|
||||
void rol(uint8_t *data, const size_t len);
|
||||
|
|
|
@ -729,15 +729,18 @@ void rol(uint8_t *data, const size_t len){
|
|||
data[len-1] = first;
|
||||
}
|
||||
|
||||
// Swap bit order on a uint32_t value. Can be limited by nrbits just use say 8bits reversal
|
||||
// And clears the rest of the bits.
|
||||
uint32_t SwapBits(uint32_t value, int nrbits) {
|
||||
// Swap bit order on a uint32_t value. Can be limited by 'b' just use say 8 bits reversal
|
||||
// note: function clears the rest of the bits.
|
||||
uint32_t SwapBits(uint32_t v, int b) {
|
||||
uint32_t newvalue = 0;
|
||||
for(int i = 0; i < nrbits; i++) {
|
||||
newvalue ^= ((value >> i) & 1) << (nrbits - 1 - i);
|
||||
for(int i = 0; i < b; i++) {
|
||||
newvalue ^= ((v >> i) & 1) << (b - 1 - i);
|
||||
}
|
||||
return newvalue;
|
||||
}
|
||||
uint8_t reflect8(uint8_t b) {
|
||||
return ((b * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32;
|
||||
}
|
||||
/*
|
||||
ref http://www.csm.ornl.gov/~dunigan/crc.html
|
||||
Returns the value v with the bottom b [0,32] bits reflected.
|
||||
|
|
|
@ -204,6 +204,7 @@ extern uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits);
|
|||
extern void rol(uint8_t *data, const size_t len);
|
||||
extern uint32_t SwapBits(uint32_t value, int nrbits);
|
||||
extern uint32_t reflect(uint32_t v, int b);
|
||||
extern uint8_t reflect8(uint8_t b); // dedicated 8bit reversal
|
||||
extern uint64_t HornerScheme(uint64_t num, uint64_t divider, uint64_t factor);
|
||||
|
||||
extern int num_CPUs(void); // number of logical CPUs
|
||||
|
|
Loading…
Reference in a new issue