mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 21:33:47 -07:00
coverity: separate crypto1 fcts ARM<>host into create/destroy and init/deinit
This commit is contained in:
parent
5fcb5f0ca5
commit
39fd6b1910
8 changed files with 49 additions and 43 deletions
|
@ -857,7 +857,7 @@ int e_MifareECardLoad(uint32_t numofsectors, uint8_t keytype) {
|
||||||
DbprintfEx(FLAG_NEWLINE, "Halt error");
|
DbprintfEx(FLAG_NEWLINE, "Halt error");
|
||||||
};
|
};
|
||||||
|
|
||||||
crypto1_destroy(pcs);
|
crypto1_deinit(pcs);
|
||||||
|
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
|
|
||||||
|
@ -894,12 +894,12 @@ int cjat91_saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, ui
|
||||||
SpinDelayUs(AUTHENTICATION_TIMEOUT);
|
SpinDelayUs(AUTHENTICATION_TIMEOUT);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
crypto1_destroy(pcs);
|
crypto1_deinit(pcs);
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
*key = ui64Key;
|
*key = ui64Key;
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
crypto1_destroy(pcs);
|
crypto1_deinit(pcs);
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -195,12 +195,12 @@ static int saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, ui
|
||||||
SpinDelayUs(AUTHENTICATION_TIMEOUT);
|
SpinDelayUs(AUTHENTICATION_TIMEOUT);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
crypto1_destroy(pcs);
|
crypto1_deinit(pcs);
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
*key = ui64Key;
|
*key = ui64Key;
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
crypto1_destroy(pcs);
|
crypto1_deinit(pcs);
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -103,7 +103,7 @@ void MifareReadBlock(uint8_t blockNo, uint8_t keyType, uint8_t *datain) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
crypto1_destroy(pcs);
|
crypto1_deinit(pcs);
|
||||||
|
|
||||||
if (DBGLEVEL >= 2) DbpString("READ BLOCK FINISHED");
|
if (DBGLEVEL >= 2) DbpString("READ BLOCK FINISHED");
|
||||||
|
|
||||||
|
@ -264,7 +264,7 @@ void MifareReadSector(uint8_t arg0, uint8_t arg1, uint8_t *datain) {
|
||||||
|
|
||||||
if (DBGLEVEL >= 2) DbpString("READ SECTOR FINISHED");
|
if (DBGLEVEL >= 2) DbpString("READ SECTOR FINISHED");
|
||||||
|
|
||||||
crypto1_destroy(pcs);
|
crypto1_deinit(pcs);
|
||||||
|
|
||||||
LED_B_ON();
|
LED_B_ON();
|
||||||
reply_old(CMD_ACK, isOK, 0, 0, dataoutbuf, 16 * NumBlocksPerSector(sectorNo));
|
reply_old(CMD_ACK, isOK, 0, 0, dataoutbuf, 16 * NumBlocksPerSector(sectorNo));
|
||||||
|
@ -430,7 +430,7 @@ void MifareWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
crypto1_destroy(pcs);
|
crypto1_deinit(pcs);
|
||||||
|
|
||||||
if (DBGLEVEL >= 2) DbpString("WRITE BLOCK FINISHED");
|
if (DBGLEVEL >= 2) DbpString("WRITE BLOCK FINISHED");
|
||||||
|
|
||||||
|
@ -847,7 +847,7 @@ void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags,
|
||||||
}
|
}
|
||||||
|
|
||||||
LED_C_OFF();
|
LED_C_OFF();
|
||||||
crypto1_destroy(pcs);
|
crypto1_deinit(pcs);
|
||||||
LED_B_ON();
|
LED_B_ON();
|
||||||
reply_old(CMD_ACK, isOK, cuid, num_nonces, buf, sizeof(buf));
|
reply_old(CMD_ACK, isOK, cuid, num_nonces, buf, sizeof(buf));
|
||||||
LED_B_OFF();
|
LED_B_OFF();
|
||||||
|
@ -1061,7 +1061,7 @@ void MifareNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo, uint8
|
||||||
|
|
||||||
LED_C_OFF();
|
LED_C_OFF();
|
||||||
|
|
||||||
crypto1_destroy(pcs);
|
crypto1_deinit(pcs);
|
||||||
|
|
||||||
struct p {
|
struct p {
|
||||||
int16_t isOK;
|
int16_t isOK;
|
||||||
|
@ -1510,7 +1510,7 @@ void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *da
|
||||||
OUT:
|
OUT:
|
||||||
LEDsoff();
|
LEDsoff();
|
||||||
|
|
||||||
crypto1_destroy(pcs);
|
crypto1_deinit(pcs);
|
||||||
|
|
||||||
// All keys found, send to client, or last keychunk from client
|
// All keys found, send to client, or last keychunk from client
|
||||||
if (foundkeys == allkeys || lastchunk) {
|
if (foundkeys == allkeys || lastchunk) {
|
||||||
|
@ -1660,7 +1660,7 @@ void MifareChkKeys(uint8_t *datain) {
|
||||||
LEDsoff();
|
LEDsoff();
|
||||||
|
|
||||||
set_tracing(false);
|
set_tracing(false);
|
||||||
crypto1_destroy(pcs);
|
crypto1_deinit(pcs);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -1780,7 +1780,7 @@ int MifareECardLoad(uint8_t numSectors, uint8_t keyType) {
|
||||||
if (DBGLEVEL >= DBG_INFO) DbpString("Emulator fill sectors finished");
|
if (DBGLEVEL >= DBG_INFO) DbpString("Emulator fill sectors finished");
|
||||||
|
|
||||||
out:
|
out:
|
||||||
crypto1_destroy(pcs);
|
crypto1_deinit(pcs);
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
LEDsoff();
|
LEDsoff();
|
||||||
set_tracing(false);
|
set_tracing(false);
|
||||||
|
@ -2110,7 +2110,7 @@ void MifareSetMod(uint8_t *datain) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
crypto1_destroy(pcs);
|
crypto1_deinit(pcs);
|
||||||
|
|
||||||
LED_B_ON();
|
LED_B_ON();
|
||||||
reply_ng(CMD_HF_MIFARE_SETMOD, isOK, NULL, 0);
|
reply_ng(CMD_HF_MIFARE_SETMOD, isOK, NULL, 0);
|
||||||
|
|
|
@ -571,7 +571,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
EmSendPrecompiledCmd(&responses[ATQA]);
|
EmSendPrecompiledCmd(&responses[ATQA]);
|
||||||
|
|
||||||
// init crypto block
|
// init crypto block
|
||||||
crypto1_destroy(pcs);
|
crypto1_deinit(pcs);
|
||||||
cardAUTHKEY = AUTHKEYNONE;
|
cardAUTHKEY = AUTHKEYNONE;
|
||||||
nonce = prng_successor(selTimer, 32);
|
nonce = prng_successor(selTimer, 32);
|
||||||
// prepare NT for nested authentication
|
// prepare NT for nested authentication
|
||||||
|
@ -743,10 +743,10 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] KEY %c: %012" PRIx64, (cardAUTHKEY == 0) ? 'A' : 'B', emlGetKey(cardAUTHSC, cardAUTHKEY));
|
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] KEY %c: %012" PRIx64, (cardAUTHKEY == 0) ? 'A' : 'B', emlGetKey(cardAUTHSC, cardAUTHKEY));
|
||||||
|
|
||||||
// first authentication
|
// first authentication
|
||||||
crypto1_destroy(pcs);
|
crypto1_deinit(pcs);
|
||||||
|
|
||||||
// Load key into crypto
|
// Load key into crypto
|
||||||
crypto1_create(pcs, emlGetKey(cardAUTHSC, cardAUTHKEY));
|
crypto1_init(pcs, emlGetKey(cardAUTHSC, cardAUTHKEY));
|
||||||
|
|
||||||
if (!encrypted_data) {
|
if (!encrypted_data) {
|
||||||
// Receive Cmd in clear txt
|
// Receive Cmd in clear txt
|
||||||
|
|
|
@ -149,10 +149,10 @@ int mifare_classic_authex(struct Crypto1State *pcs, uint32_t uid, uint8_t blockN
|
||||||
|
|
||||||
// ----------------------------- crypto1 create
|
// ----------------------------- crypto1 create
|
||||||
if (isNested)
|
if (isNested)
|
||||||
crypto1_destroy(pcs);
|
crypto1_deinit(pcs);
|
||||||
|
|
||||||
// Init cipher with key
|
// Init cipher with key
|
||||||
crypto1_create(pcs, ui64Key);
|
crypto1_init(pcs, ui64Key);
|
||||||
|
|
||||||
if (isNested == AUTH_NESTED) {
|
if (isNested == AUTH_NESTED) {
|
||||||
// decrypt nt with help of new key
|
// decrypt nt with help of new key
|
||||||
|
|
|
@ -124,6 +124,9 @@ recover(uint32_t *o_head, uint32_t *o_tail, uint32_t oks,
|
||||||
|
|
||||||
return sl;
|
return sl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(__arm__) || defined(__linux__) || defined(_WIN32) || defined(__APPLE__) // bare metal ARM Proxmark lacks malloc()/free()
|
||||||
/** lfsr_recovery
|
/** lfsr_recovery
|
||||||
* recover the state of the lfsr given 32 bits of the keystream
|
* recover the state of the lfsr given 32 bits of the keystream
|
||||||
* additionally you can use the in parameter to specify the value
|
* additionally you can use the in parameter to specify the value
|
||||||
|
@ -286,6 +289,7 @@ continue2:
|
||||||
}
|
}
|
||||||
return statelist;
|
return statelist;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/** lfsr_rollback_bit
|
/** lfsr_rollback_bit
|
||||||
* Rollback the shift register in order to get previous states
|
* Rollback the shift register in order to get previous states
|
||||||
|
@ -465,7 +469,7 @@ static struct Crypto1State *check_pfx_parity(uint32_t prefix, uint32_t rresp, ui
|
||||||
return sl + good;
|
return sl + good;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(__arm__) || defined(__linux__) || defined(_WIN32) || defined(__APPLE__) // bare metal ARM Proxmark lacks malloc()/free()
|
||||||
/** lfsr_common_prefix
|
/** lfsr_common_prefix
|
||||||
* Implentation of the common prefix attack.
|
* Implentation of the common prefix attack.
|
||||||
* Requires the 28 bit constant prefix used as reader nonce (pfx)
|
* Requires the 28 bit constant prefix used as reader nonce (pfx)
|
||||||
|
@ -504,3 +508,4 @@ out:
|
||||||
free(even);
|
free(even);
|
||||||
return statelist;
|
return statelist;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -25,23 +25,25 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
struct Crypto1State {uint32_t odd, even;};
|
struct Crypto1State {uint32_t odd, even;};
|
||||||
#if defined(__arm__) && !defined(__linux__) && !defined(_WIN32) && !defined(__APPLE__) // bare metal ARM Proxmark lacks malloc()/free()
|
void crypto1_init(struct Crypto1State *s, uint64_t key);
|
||||||
void crypto1_create(struct Crypto1State *s, uint64_t key);
|
void crypto1_deinit(struct Crypto1State *);
|
||||||
#else
|
#if !defined(__arm__) || defined(__linux__) || defined(_WIN32) || defined(__APPLE__) // bare metal ARM Proxmark lacks malloc()/free()
|
||||||
struct Crypto1State *crypto1_create(uint64_t key);
|
struct Crypto1State *crypto1_create(uint64_t key);
|
||||||
#endif
|
|
||||||
void crypto1_destroy(struct Crypto1State *);
|
void crypto1_destroy(struct Crypto1State *);
|
||||||
|
#endif
|
||||||
void crypto1_get_lfsr(struct Crypto1State *, uint64_t *);
|
void crypto1_get_lfsr(struct Crypto1State *, uint64_t *);
|
||||||
uint8_t crypto1_bit(struct Crypto1State *, uint8_t, int);
|
uint8_t crypto1_bit(struct Crypto1State *, uint8_t, int);
|
||||||
uint8_t crypto1_byte(struct Crypto1State *, uint8_t, int);
|
uint8_t crypto1_byte(struct Crypto1State *, uint8_t, int);
|
||||||
uint32_t crypto1_word(struct Crypto1State *, uint32_t, int);
|
uint32_t crypto1_word(struct Crypto1State *, uint32_t, int);
|
||||||
uint32_t prng_successor(uint32_t x, uint32_t n);
|
uint32_t prng_successor(uint32_t x, uint32_t n);
|
||||||
|
|
||||||
|
#if !defined(__arm__) || defined(__linux__) || defined(_WIN32) || defined(__APPLE__) // bare metal ARM Proxmark lacks malloc()/free()
|
||||||
struct Crypto1State *lfsr_recovery32(uint32_t ks2, uint32_t in);
|
struct Crypto1State *lfsr_recovery32(uint32_t ks2, uint32_t in);
|
||||||
struct Crypto1State *lfsr_recovery64(uint32_t ks2, uint32_t ks3);
|
struct Crypto1State *lfsr_recovery64(uint32_t ks2, uint32_t ks3);
|
||||||
uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd);
|
|
||||||
struct Crypto1State *
|
struct Crypto1State *
|
||||||
lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8], uint32_t no_par);
|
lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8], uint32_t no_par);
|
||||||
|
#endif
|
||||||
|
uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd);
|
||||||
|
|
||||||
|
|
||||||
uint8_t lfsr_rollback_bit(struct Crypto1State *s, uint32_t in, int fb);
|
uint8_t lfsr_rollback_bit(struct Crypto1State *s, uint32_t in, int fb);
|
||||||
|
|
|
@ -25,38 +25,37 @@
|
||||||
#define SWAPENDIAN(x)\
|
#define SWAPENDIAN(x)\
|
||||||
(x = (x >> 8 & 0xff00ff) | (x & 0xff00ff) << 8, x = x >> 16 | x << 16)
|
(x = (x >> 8 & 0xff00ff) | (x & 0xff00ff) << 8, x = x >> 16 | x << 16)
|
||||||
|
|
||||||
#if defined(__arm__) && !defined(__linux__) && !defined(_WIN32) && !defined(__APPLE__) // bare metal ARM Proxmark lacks malloc()/free()
|
void crypto1_init(struct Crypto1State *state, uint64_t key) {
|
||||||
void crypto1_create(struct Crypto1State *s, uint64_t key) {
|
state->odd = 0;
|
||||||
|
state->even = 0;
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 47; s && i > 0; i -= 2) {
|
for (i = 47; state && i > 0; i -= 2) {
|
||||||
s->odd = s->odd << 1 | BIT(key, (i - 1) ^ 7);
|
state->odd = state->odd << 1 | BIT(key, (i - 1) ^ 7);
|
||||||
s->even = s->even << 1 | BIT(key, i ^ 7);
|
state->even = state->even << 1 | BIT(key, i ^ 7);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void crypto1_destroy(struct Crypto1State *state) {
|
|
||||||
|
void crypto1_deinit(struct Crypto1State *state) {
|
||||||
state->odd = 0;
|
state->odd = 0;
|
||||||
state->even = 0;
|
state->even = 0;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
|
#if !defined(__arm__) || defined(__linux__) || defined(_WIN32) || defined(__APPLE__) // bare metal ARM Proxmark lacks malloc()/free()
|
||||||
struct Crypto1State *crypto1_create(uint64_t key) {
|
struct Crypto1State *crypto1_create(uint64_t key) {
|
||||||
struct Crypto1State *s = malloc(sizeof(*s));
|
struct Crypto1State *state = malloc(sizeof(*state));
|
||||||
if (!s) return NULL;
|
if (!state) return NULL;
|
||||||
|
crypto1_init(state, key);
|
||||||
s->odd = s->even = 0;
|
return state;
|
||||||
|
|
||||||
int i;
|
|
||||||
for (i = 47; i > 0; i -= 2) {
|
|
||||||
s->odd = s->odd << 1 | BIT(key, (i - 1) ^ 7);
|
|
||||||
s->even = s->even << 1 | BIT(key, i ^ 7);
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void crypto1_destroy(struct Crypto1State *state) {
|
void crypto1_destroy(struct Crypto1State *state) {
|
||||||
free(state);
|
free(state);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void crypto1_get_lfsr(struct Crypto1State *state, uint64_t *lfsr) {
|
void crypto1_get_lfsr(struct Crypto1State *state, uint64_t *lfsr) {
|
||||||
int i;
|
int i;
|
||||||
for (*lfsr = 0, i = 23; i >= 0; --i) {
|
for (*lfsr = 0, i = 23; i >= 0; --i) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue