mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-22 14:13:42 -07:00
changed parity calculation from large table to a small function
changed parity calculation to be on-the-fly during tag modulation changed calls to parity function to use smaller function
This commit is contained in:
parent
4e20973b8d
commit
0c03a4f719
5 changed files with 34 additions and 9 deletions
|
@ -226,7 +226,8 @@ static RAMFUNC int OutOfNDecoding(int bit)
|
|||
|
||||
// Calculate the parity bit for the client...
|
||||
Uart.parityBits <<= 1;
|
||||
Uart.parityBits ^= OddByteParity[(Uart.shiftReg & 0xff)];
|
||||
//Uart.parityBits ^= OddByteParity[(Uart.shiftReg & 0xff)];
|
||||
Uart.parityBits ^= oddparity(Uart.shiftReg & 0xff);
|
||||
|
||||
Uart.bitCnt = 0;
|
||||
Uart.shiftReg = 0;
|
||||
|
@ -249,7 +250,8 @@ static RAMFUNC int OutOfNDecoding(int bit)
|
|||
|
||||
// Calculate the parity bit for the client...
|
||||
Uart.parityBits <<= 1;
|
||||
Uart.parityBits ^= OddByteParity[(Uart.dropPosition & 0xff)];
|
||||
//Uart.parityBits ^= OddByteParity[(Uart.dropPosition & 0xff)];
|
||||
Uart.parityBits ^= oddparity((Uart.dropPosition & 0xff));
|
||||
|
||||
Uart.bitCnt = 0;
|
||||
Uart.shiftReg = 0;
|
||||
|
@ -486,7 +488,8 @@ static RAMFUNC int ManchesterDecoding(int v)
|
|||
Demod.output[Demod.len] = 0x0f;
|
||||
Demod.len++;
|
||||
Demod.parityBits <<= 1;
|
||||
Demod.parityBits ^= OddByteParity[0x0f];
|
||||
//Demod.parityBits ^= OddByteParity[0x0f];
|
||||
Demod.parityBits ^= oddparity(0x0f);
|
||||
Demod.state = DEMOD_UNSYNCD;
|
||||
// error = 0x0f;
|
||||
return TRUE;
|
||||
|
@ -611,7 +614,8 @@ static RAMFUNC int ManchesterDecoding(int v)
|
|||
|
||||
// FOR ISO15639 PARITY NOT SEND OTA, JUST CALCULATE IT FOR THE CLIENT
|
||||
Demod.parityBits <<= 1;
|
||||
Demod.parityBits ^= OddByteParity[(Demod.shiftReg & 0xff)];
|
||||
//Demod.parityBits ^= OddByteParity[(Demod.shiftReg & 0xff)];
|
||||
Demod.parityBits ^= oddparity(Demod.shiftReg & 0xff);
|
||||
|
||||
Demod.bitCount = 0;
|
||||
Demod.shiftReg = 0;
|
||||
|
|
|
@ -125,6 +125,8 @@ uint32_t LastProxToAirDuration;
|
|||
#define SEC_Y 0x00
|
||||
#define SEC_Z 0xc0
|
||||
|
||||
//replaced large parity table with small parity generation function - saves flash code
|
||||
/*
|
||||
const uint8_t OddByteParity[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,
|
||||
|
@ -143,8 +145,7 @@ const uint8_t OddByteParity[256] = {
|
|||
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
|
||||
};
|
||||
|
||||
|
||||
*/
|
||||
void iso14a_set_trigger(bool enable) {
|
||||
trigger = enable;
|
||||
}
|
||||
|
@ -166,10 +167,14 @@ void iso14a_set_timeout(uint32_t timeout) {
|
|||
// Generate the parity value for a byte sequence
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
/*
|
||||
byte_t oddparity (const byte_t bt)
|
||||
{
|
||||
return OddByteParity[bt];
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
uint32_t GetParity(const uint8_t * pbtCmd, int iLen)
|
||||
{
|
||||
|
@ -179,7 +184,8 @@ uint32_t GetParity(const uint8_t * pbtCmd, int iLen)
|
|||
// Generate the parity bits
|
||||
for (i = 0; i < iLen; i++) {
|
||||
// and save them to a 32Bit word
|
||||
dwPar |= ((OddByteParity[pbtCmd[i]]) << i);
|
||||
//dwPar |= ((OddByteParity[pbtCmd[i]]) << i);
|
||||
dwPar |= (oddparity(pbtCmd[i]) << i);
|
||||
}
|
||||
return dwPar;
|
||||
}
|
||||
|
@ -648,6 +654,7 @@ void RAMFUNC SnoopIso14443a(uint8_t param) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Prepare tag messages
|
||||
//16/11/2014 - changed to calculate parity on the fly - Peter Fillmore
|
||||
//-----------------------------------------------------------------------------
|
||||
static void CodeIso14443aAsTagPar(const uint8_t *cmd, int len, uint32_t dwParity)
|
||||
{
|
||||
|
@ -684,13 +691,16 @@ static void CodeIso14443aAsTagPar(const uint8_t *cmd, int len, uint32_t dwParity
|
|||
}
|
||||
|
||||
// Get the parity bit
|
||||
if ((dwParity >> i) & 0x01) {
|
||||
// changed to generate parity on the fly
|
||||
//if ((dwParity >> i) & 0x01) {
|
||||
if (oddparity(cmd[i]) & 0x01) {
|
||||
ToSend[++ToSendMax] = SEC_D;
|
||||
LastProxToAirDuration = 8 * ToSendMax - 4;
|
||||
} else {
|
||||
ToSend[++ToSendMax] = SEC_E;
|
||||
LastProxToAirDuration = 8 * ToSendMax;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Send stopbit
|
||||
|
|
|
@ -75,7 +75,7 @@ typedef struct {
|
|||
|
||||
|
||||
|
||||
extern byte_t oddparity (const byte_t bt);
|
||||
//extern uint8_t oddparity(uint8_t bt);
|
||||
extern uint32_t GetParity(const uint8_t *pbtCmd, int iLen);
|
||||
extern void AppendCrc14443a(uint8_t *data, int len);
|
||||
|
||||
|
|
|
@ -44,7 +44,15 @@ uint64_t bytes_to_num(uint8_t* src, size_t len)
|
|||
}
|
||||
return num;
|
||||
}
|
||||
//added here for parity calulations
|
||||
|
||||
uint8_t oddparity(uint8_t bt)
|
||||
{
|
||||
uint16_t v = bt;
|
||||
v ^= v >> 4;
|
||||
v &= 0xF;
|
||||
return ((0x9669 >> v) & 1);
|
||||
}
|
||||
void LEDsoff()
|
||||
{
|
||||
LED_A_OFF();
|
||||
|
|
|
@ -32,6 +32,9 @@ uint32_t SwapBits(uint32_t value, int nrbits);
|
|||
void num_to_bytes(uint64_t n, size_t len, uint8_t* dest);
|
||||
uint64_t bytes_to_num(uint8_t* src, size_t len);
|
||||
|
||||
//added parity generation function here
|
||||
uint8_t oddparity(uint8_t bt);
|
||||
|
||||
void SpinDelay(int ms);
|
||||
void SpinDelayUs(int us);
|
||||
void LED(int led, int ms);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue