rename typedef structs
This commit is contained in:
1 parent
5fce6271ee
commit
f6d88dced2
22 files changed
+406
-406
No files matched your search
+17
-17
@@ -60,14 +60,14 @@ typedef struct {
|
||||
uint8_t r;
|
||||
uint8_t b;
|
||||
uint16_t t;
|
||||
} State;
|
||||
} State_t;
|
||||
|
||||
/**
|
||||
* Definition 2. The feedback function for the top register T : F 16/2 → F 2
|
||||
* is defined as
|
||||
* T (x 0 x 1 . . . . . . x 15 ) = x 0 ⊕ x 1 ⊕ x 5 ⊕ x 7 ⊕ x 10 ⊕ x 11 ⊕ x 14 ⊕ x 15 .
|
||||
**/
|
||||
static bool T(State state) {
|
||||
static bool T(State_t state) {
|
||||
/*
|
||||
bool x0 = state.t & 0x8000;
|
||||
bool x1 = state.t & 0x4000;
|
||||
@@ -93,7 +93,7 @@ static bool T(State state) {
|
||||
* Similarly, the feedback function for the bottom register B : F 8/2 → F 2 is defined as
|
||||
* B(x 0 x 1 . . . x 7 ) = x 1 ⊕ x 2 ⊕ x 3 ⊕ x 7 .
|
||||
**/
|
||||
/*static bool B(State state) {
|
||||
/*static bool B(State_t state) {
|
||||
bool x1 = state.b & 0x40;
|
||||
bool x2 = state.b & 0x20;
|
||||
bool x3 = state.b & 0x10;
|
||||
@@ -169,12 +169,12 @@ static uint8_t _select(bool x, bool y, uint8_t r) {
|
||||
* @param s - state
|
||||
* @param k - array containing 8 bytes
|
||||
**/
|
||||
static State successor(uint8_t *k, State s, bool y) {
|
||||
static State_t successor(uint8_t *k, State_t s, bool y) {
|
||||
bool r0 = s.r >> 7 & 0x1;
|
||||
bool r4 = s.r >> 3 & 0x1;
|
||||
bool r7 = s.r & 0x1;
|
||||
|
||||
State successor = {0, 0, 0, 0};
|
||||
State_t successor = {0, 0, 0, 0};
|
||||
|
||||
successor.t = s.t >> 1;
|
||||
successor.t |= ((T(s)) ^ (r0) ^ (r4)) << 15;
|
||||
@@ -195,7 +195,7 @@ static State successor(uint8_t *k, State s, bool y) {
|
||||
* to multiple bit input x ∈ F n 2 which we define as
|
||||
* @param k - array containing 8 bytes
|
||||
**/
|
||||
static State suc(uint8_t *k, State s, BitstreamIn *bitstream) {
|
||||
static State_t suc(uint8_t *k, State_t s, BitstreamIn_t *bitstream) {
|
||||
if (bitsLeft(bitstream) == 0) {
|
||||
return s;
|
||||
}
|
||||
@@ -211,14 +211,14 @@ static State suc(uint8_t *k, State s, BitstreamIn *bitstream) {
|
||||
* output(k, s, x 0 . . . x n ) = output(s) · output(k, s ′ , x 1 . . . x n )
|
||||
* where s ′ = suc(k, s, x 0 ).
|
||||
**/
|
||||
static void output(uint8_t *k, State s, BitstreamIn *in, BitstreamOut *out) {
|
||||
static void output(uint8_t *k, State_t s, BitstreamIn_t *in, BitstreamOut_t *out) {
|
||||
if (bitsLeft(in) == 0) {
|
||||
return;
|
||||
}
|
||||
pushBit(out, (s.r >> 2) & 1);
|
||||
//Remove first bit
|
||||
uint8_t x0 = headBit(in);
|
||||
State ss = successor(k, s, x0);
|
||||
State_t ss = successor(k, s, x0);
|
||||
output(k, ss, in, out);
|
||||
}
|
||||
|
||||
@@ -227,8 +227,8 @@ static void output(uint8_t *k, State s, BitstreamIn *in, BitstreamOut *out) {
|
||||
* key k ∈ (F 82 ) 8 and outputs the initial cipher state s =< l, r, t, b >
|
||||
**/
|
||||
|
||||
static State init(uint8_t *k) {
|
||||
State s = {
|
||||
static State_t init(uint8_t *k) {
|
||||
State_t s = {
|
||||
((k[0] ^ 0x4c) + 0xEC) & 0xFF,// l
|
||||
((k[0] ^ 0x4c) + 0x21) & 0xFF,// r
|
||||
0x4c, // b
|
||||
@@ -237,10 +237,10 @@ static State init(uint8_t *k) {
|
||||
return s;
|
||||
}
|
||||
|
||||
static void MAC(uint8_t *k, BitstreamIn input, BitstreamOut out) {
|
||||
static void MAC(uint8_t *k, BitstreamIn_t input, BitstreamOut_t out) {
|
||||
uint8_t zeroes_32[] = {0, 0, 0, 0};
|
||||
BitstreamIn input_32_zeroes = {zeroes_32, sizeof(zeroes_32) * 8, 0};
|
||||
State initState = suc(k, init(k), &input);
|
||||
BitstreamIn_t input_32_zeroes = {zeroes_32, sizeof(zeroes_32) * 8, 0};
|
||||
State_t initState = suc(k, init(k), &input);
|
||||
output(k, initState, &input_32_zeroes, &out);
|
||||
}
|
||||
|
||||
@@ -252,9 +252,9 @@ void doMAC(uint8_t *cc_nr_p, uint8_t *div_key_p, uint8_t mac[4]) {
|
||||
memcpy(div_key, div_key_p, 8);
|
||||
|
||||
reverse_arraybytes(cc_nr, 12);
|
||||
BitstreamIn bitstream = {cc_nr, 12 * 8, 0};
|
||||
BitstreamIn_t bitstream = {cc_nr, 12 * 8, 0};
|
||||
uint8_t dest [] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
BitstreamOut out = { dest, sizeof(dest) * 8, 0 };
|
||||
BitstreamOut_t out = { dest, sizeof(dest) * 8, 0 };
|
||||
MAC(div_key, bitstream, out);
|
||||
//The output MAC must also be reversed
|
||||
reverse_arraybytes(dest, sizeof(dest));
|
||||
@@ -270,9 +270,9 @@ void doMAC_N(uint8_t *address_data_p, uint8_t address_data_size, uint8_t *div_ke
|
||||
memcpy(div_key, div_key_p, 8);
|
||||
|
||||
reverse_arraybytes(address_data, address_data_size);
|
||||
BitstreamIn bitstream = {address_data, address_data_size * 8, 0};
|
||||
BitstreamIn_t bitstream = {address_data, address_data_size * 8, 0};
|
||||
uint8_t dest [] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
BitstreamOut out = { dest, sizeof(dest) * 8, 0 };
|
||||
BitstreamOut_t out = { dest, sizeof(dest) * 8, 0 };
|
||||
MAC(div_key, bitstream, out);
|
||||
//The output MAC must also be reversed
|
||||
reverse_arraybytes(dest, sizeof(dest));
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
* @param stream
|
||||
* @return
|
||||
*/
|
||||
bool headBit(BitstreamIn *stream) {
|
||||
bool headBit(BitstreamIn_t *stream) {
|
||||
int bytepos = stream->position >> 3; // divide by 8
|
||||
int bitpos = (stream->position++) & 7; // mask out 00000111
|
||||
return (*(stream->buffer + bytepos) >> (7 - bitpos)) & 1;
|
||||
@@ -59,7 +59,7 @@ bool headBit(BitstreamIn *stream) {
|
||||
* @param stream
|
||||
* @return
|
||||
*/
|
||||
bool tailBit(BitstreamIn *stream) {
|
||||
bool tailBit(BitstreamIn_t *stream) {
|
||||
int bitpos = stream->numbits - 1 - (stream->position++);
|
||||
|
||||
int bytepos = bitpos >> 3;
|
||||
@@ -71,7 +71,7 @@ bool tailBit(BitstreamIn *stream) {
|
||||
* @param stream
|
||||
* @param bit
|
||||
*/
|
||||
void pushBit(BitstreamOut *stream, bool bit) {
|
||||
void pushBit(BitstreamOut_t *stream, bool bit) {
|
||||
int bytepos = stream->position >> 3; // divide by 8
|
||||
int bitpos = stream->position & 7;
|
||||
*(stream->buffer + bytepos) |= (bit) << (7 - bitpos);
|
||||
@@ -85,7 +85,7 @@ void pushBit(BitstreamOut *stream, bool bit) {
|
||||
* @param stream
|
||||
* @param bits
|
||||
*/
|
||||
void push6bits(BitstreamOut *stream, uint8_t bits) {
|
||||
void push6bits(BitstreamOut_t *stream, uint8_t bits) {
|
||||
pushBit(stream, bits & 0x20);
|
||||
pushBit(stream, bits & 0x10);
|
||||
pushBit(stream, bits & 0x08);
|
||||
@@ -99,7 +99,7 @@ void push6bits(BitstreamOut *stream, uint8_t bits) {
|
||||
* @param stream
|
||||
* @return number of bits left in stream
|
||||
*/
|
||||
int bitsLeft(BitstreamIn *stream) {
|
||||
int bitsLeft(BitstreamIn_t *stream) {
|
||||
return stream->numbits - stream->position;
|
||||
}
|
||||
/**
|
||||
@@ -108,7 +108,7 @@ int bitsLeft(BitstreamIn *stream) {
|
||||
* @return Number of bits stored in stream
|
||||
*/
|
||||
/*
|
||||
static int numBits(BitstreamOut *stream) {
|
||||
static int numBits(BitstreamOut_t *stream) {
|
||||
return stream->numbits;
|
||||
}
|
||||
*/
|
||||
@@ -187,8 +187,8 @@ void printarr_human_readable(const char *title, uint8_t *arr, int len) {
|
||||
static int testBitStream(void) {
|
||||
uint8_t input [] = {0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF};
|
||||
uint8_t output [] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
BitstreamIn in = { input, sizeof(input) * 8, 0};
|
||||
BitstreamOut out = { output, 0, 0}
|
||||
BitstreamIn_t in = { input, sizeof(input) * 8, 0};
|
||||
BitstreamOut_t out = { output, 0, 0}
|
||||
;
|
||||
while (bitsLeft(&in) > 0) {
|
||||
pushBit(&out, headBit(&in));
|
||||
@@ -213,10 +213,10 @@ static int testReversedBitstream(void) {
|
||||
uint8_t input [] = {0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF};
|
||||
uint8_t reverse [] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
uint8_t output [] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
BitstreamIn in = { input, sizeof(input) * 8, 0};
|
||||
BitstreamOut out = { output, 0, 0};
|
||||
BitstreamIn reversed_in = { reverse, sizeof(input) * 8, 0};
|
||||
BitstreamOut reversed_out = { reverse, 0, 0};
|
||||
BitstreamIn_t in = { input, sizeof(input) * 8, 0};
|
||||
BitstreamOut_t out = { output, 0, 0};
|
||||
BitstreamIn_t reversed_in = { reverse, sizeof(input) * 8, 0};
|
||||
BitstreamOut_t reversed_out = { reverse, 0, 0};
|
||||
|
||||
while (bitsLeft(&in) > 0) {
|
||||
pushBit(&reversed_out, tailBit(&in));
|
||||
|
||||
@@ -47,22 +47,22 @@ typedef struct {
|
||||
uint8_t *buffer;
|
||||
uint8_t numbits;
|
||||
uint8_t position;
|
||||
} BitstreamIn;
|
||||
} BitstreamIn_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t *buffer;
|
||||
uint8_t numbits;
|
||||
uint8_t position;
|
||||
} BitstreamOut;
|
||||
} BitstreamOut_t;
|
||||
|
||||
bool headBit(BitstreamIn *stream);
|
||||
bool tailBit(BitstreamIn *stream);
|
||||
void pushBit(BitstreamOut *stream, bool bit);
|
||||
int bitsLeft(BitstreamIn *stream);
|
||||
bool headBit(BitstreamIn_t *stream);
|
||||
bool tailBit(BitstreamIn_t *stream);
|
||||
void pushBit(BitstreamOut_t *stream, bool bit);
|
||||
int bitsLeft(BitstreamIn_t *stream);
|
||||
#ifndef ON_DEVICE
|
||||
int testCipherUtils(void);
|
||||
#endif
|
||||
void push6bits(BitstreamOut *stream, uint8_t bits);
|
||||
void push6bits(BitstreamOut_t *stream, uint8_t bits);
|
||||
void EncryptDES(bool key[56], bool outBlk[64], bool inBlk[64], int verbose) ;
|
||||
void x_num_to_bytes(uint64_t n, size_t len, uint8_t *dest);
|
||||
uint64_t x_bytes_to_num(uint8_t *src, size_t len);
|
||||
|
||||
@@ -205,7 +205,7 @@ static uint64_t check(uint64_t z) {
|
||||
return ck1 | ck2 >> 24;
|
||||
}
|
||||
|
||||
static void permute(BitstreamIn *p_in, uint64_t z, int l, int r, BitstreamOut *out) {
|
||||
static void permute(BitstreamIn_t *p_in, uint64_t z, int l, int r, BitstreamOut_t *out) {
|
||||
if (bitsLeft(p_in) == 0)
|
||||
return;
|
||||
|
||||
@@ -290,9 +290,9 @@ void hash0(uint64_t c, uint8_t k[8]) {
|
||||
|
||||
if (g_debugMode > 0) PrintAndLogEx(DEBUG, " p : %02x", p);
|
||||
|
||||
BitstreamIn p_in = { &p, 8, 0 };
|
||||
BitstreamIn_t p_in = { &p, 8, 0 };
|
||||
uint8_t outbuffer[] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
BitstreamOut out = {outbuffer, 0, 0};
|
||||
BitstreamOut_t out = {outbuffer, 0, 0};
|
||||
permute(&p_in, zCaret, 0, 4, &out); //returns 48 bits? or 6 8-bytes
|
||||
|
||||
//Out is now a buffer containing six-bit bytes, should be 48 bits
|
||||
@@ -387,9 +387,9 @@ static void testPermute(void) {
|
||||
printarr("input_perm", mres, 8);
|
||||
|
||||
uint8_t p = ~pi[0];
|
||||
BitstreamIn p_in = { &p, 8, 0 };
|
||||
BitstreamIn_t p_in = { &p, 8, 0 };
|
||||
uint8_t outbuffer[] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
BitstreamOut out = {outbuffer, 0, 0};
|
||||
BitstreamOut_t out = {outbuffer, 0, 0};
|
||||
|
||||
permute(&p_in, x, 0, 4, &out);
|
||||
|
||||
@@ -708,7 +708,7 @@ void checkParity2(uint8_t* key) {
|
||||
uint8_t stored_parity = key[7];
|
||||
PrintAndLogEx(NORMAL, "Parity byte: 0x%02x", stored_parity);
|
||||
int i, byte, fails = 0;
|
||||
BitstreamIn bits = {key, 56, 0};
|
||||
BitstreamIn_t bits = {key, 56, 0};
|
||||
bool parity = 0;
|
||||
|
||||
for (i = 0; i < 56; i++) {
|
||||
@@ -736,7 +736,7 @@ void modifyKey_put_parity_last(uint8_t * key, uint8_t* output) {
|
||||
|
||||
uint8_t paritybits = 0;
|
||||
bool parity =0;
|
||||
BitstreamOut out = { output, 0, 0};
|
||||
BitstreamOut_t out = { output, 0, 0};
|
||||
unsigned int bbyte, bbit;
|
||||
for (bbyte = 0; bbyte <8; bbyte++ ) {
|
||||
for(bbit = 0; bbit < 7; bbit++) {
|
||||
@@ -760,8 +760,8 @@ void modifyKey_put_parity_last(uint8_t * key, uint8_t* output) {
|
||||
|
||||
void modifyKey_put_parity_allover(uint8_t * key, uint8_t* output) {
|
||||
bool parity =0;
|
||||
BitstreamOut out = {output, 0, 0};
|
||||
BitstreamIn in = {key, 0, 0};
|
||||
BitstreamOut_t out = {output, 0, 0};
|
||||
BitstreamIn_t in = {key, 0, 0};
|
||||
unsigned int bbyte, bbit;
|
||||
for (bbit = 0; bbit < 56; bbit++) {
|
||||
if (bbit > 0 && bbit % 7 == 0) {
|
||||
|
||||
Reference in new issue
Block a user