use more static and fix [-Wmissing-prototypes], ongoing...
This commit is contained in:
@@ -67,7 +67,7 @@ typedef struct {
|
||||
* 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 .
|
||||
**/
|
||||
bool T(State state) {
|
||||
static bool T(State state) {
|
||||
bool x0 = state.t & 0x8000;
|
||||
bool x1 = state.t & 0x4000;
|
||||
bool x5 = state.t & 0x0400;
|
||||
@@ -82,7 +82,7 @@ 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 .
|
||||
**/
|
||||
bool B(State state) {
|
||||
static bool B(State state) {
|
||||
bool x1 = state.b & 0x40;
|
||||
bool x2 = state.b & 0x20;
|
||||
bool x3 = state.b & 0x10;
|
||||
@@ -98,7 +98,7 @@ bool B(State state) {
|
||||
* z 1 = (r 0 ∨ r 2 ) ⊕ (r 5 ∨ r 7 ) ⊕ r 1 ⊕ r 6 ⊕ x ⊕ y
|
||||
* z 2 = (r 3 ∧ r 5 ) ⊕ (r 4 ∧ r 6 ) ⊕ r 7 ⊕ x
|
||||
**/
|
||||
uint8_t _select(bool x, bool y, uint8_t r) {
|
||||
static uint8_t _select(bool x, bool y, uint8_t r) {
|
||||
bool r0 = r >> 7 & 0x1;
|
||||
bool r1 = r >> 6 & 0x1;
|
||||
bool r2 = r >> 5 & 0x1;
|
||||
@@ -134,7 +134,7 @@ uint8_t _select(bool x, bool y, uint8_t r) {
|
||||
* @param s - state
|
||||
* @param k - array containing 8 bytes
|
||||
**/
|
||||
State successor(uint8_t *k, State s, bool y) {
|
||||
static State successor(uint8_t *k, State s, bool y) {
|
||||
bool r0 = s.r >> 7 & 0x1;
|
||||
bool r4 = s.r >> 3 & 0x1;
|
||||
bool r7 = s.r & 0x1;
|
||||
@@ -160,7 +160,7 @@ 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
|
||||
**/
|
||||
State suc(uint8_t *k, State s, BitstreamIn *bitstream) {
|
||||
static State suc(uint8_t *k, State s, BitstreamIn *bitstream) {
|
||||
if (bitsLeft(bitstream) == 0) {
|
||||
return s;
|
||||
}
|
||||
@@ -176,7 +176,7 @@ 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 ).
|
||||
**/
|
||||
void output(uint8_t *k, State s, BitstreamIn *in, BitstreamOut *out) {
|
||||
static void output(uint8_t *k, State s, BitstreamIn *in, BitstreamOut *out) {
|
||||
if (bitsLeft(in) == 0) {
|
||||
return;
|
||||
}
|
||||
@@ -192,7 +192,7 @@ 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 >
|
||||
**/
|
||||
|
||||
State init(uint8_t *k) {
|
||||
static State init(uint8_t *k) {
|
||||
State s = {
|
||||
((k[0] ^ 0x4c) + 0xEC) & 0xFF,// l
|
||||
((k[0] ^ 0x4c) + 0x21) & 0xFF,// r
|
||||
@@ -201,7 +201,8 @@ State init(uint8_t *k) {
|
||||
};
|
||||
return s;
|
||||
}
|
||||
void MAC(uint8_t *k, BitstreamIn input, BitstreamOut out) {
|
||||
|
||||
static void MAC(uint8_t *k, BitstreamIn input, BitstreamOut 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);
|
||||
|
||||
@@ -104,10 +104,11 @@ int bitsLeft(BitstreamIn *stream) {
|
||||
* @param stream
|
||||
* @return Number of bits stored in stream
|
||||
*/
|
||||
int numBits(BitstreamOut *stream) {
|
||||
/*
|
||||
static int numBits(BitstreamOut *stream) {
|
||||
return stream->numbits;
|
||||
}
|
||||
|
||||
*/
|
||||
void x_num_to_bytes(uint64_t n, size_t len, uint8_t *dest) {
|
||||
while (len--) {
|
||||
dest[len] = (uint8_t) n;
|
||||
@@ -187,7 +188,7 @@ void printarr_human_readable(const char *title, uint8_t *arr, int len) {
|
||||
//-----------------------------
|
||||
|
||||
#ifndef ON_DEVICE
|
||||
int testBitStream() {
|
||||
static int testBitStream() {
|
||||
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};
|
||||
@@ -212,7 +213,7 @@ int testBitStream() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int testReversedBitstream() {
|
||||
static int testReversedBitstream() {
|
||||
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};
|
||||
|
||||
@@ -162,7 +162,7 @@ Definition 14. Define the rotate key function rk : (F 82 ) 8 × N → (F 82 ) 8
|
||||
rk(x [0] . . . x [7] , 0) = x [0] . . . x [7]
|
||||
rk(x [0] . . . x [7] , n + 1) = rk(rl(x [0] ) . . . rl(x [7] ), n)
|
||||
**/
|
||||
void rk(uint8_t *key, uint8_t n, uint8_t *outp_key) {
|
||||
static void rk(uint8_t *key, uint8_t n, uint8_t *outp_key) {
|
||||
memcpy(outp_key, key, 8);
|
||||
uint8_t j;
|
||||
while (n-- > 0) {
|
||||
@@ -175,14 +175,14 @@ void rk(uint8_t *key, uint8_t n, uint8_t *outp_key) {
|
||||
static mbedtls_des_context ctx_enc;
|
||||
static mbedtls_des_context ctx_dec;
|
||||
|
||||
void desdecrypt_iclass(uint8_t *iclass_key, uint8_t *input, uint8_t *output) {
|
||||
static void desdecrypt_iclass(uint8_t *iclass_key, uint8_t *input, uint8_t *output) {
|
||||
uint8_t key_std_format[8] = {0};
|
||||
permutekey_rev(iclass_key, key_std_format);
|
||||
mbedtls_des_setkey_dec(&ctx_dec, key_std_format);
|
||||
mbedtls_des_crypt_ecb(&ctx_dec, input, output);
|
||||
}
|
||||
|
||||
void desencrypt_iclass(uint8_t *iclass_key, uint8_t *input, uint8_t *output) {
|
||||
static void desencrypt_iclass(uint8_t *iclass_key, uint8_t *input, uint8_t *output) {
|
||||
uint8_t key_std_format[8] = {0};
|
||||
permutekey_rev(iclass_key, key_std_format);
|
||||
mbedtls_des_setkey_enc(&ctx_enc, key_std_format);
|
||||
@@ -266,7 +266,8 @@ void hash2(uint8_t *key64, uint8_t *outp_keytable) {
|
||||
* @param i the number to read. Should be less than 127, or something is wrong...
|
||||
* @return
|
||||
*/
|
||||
int _readFromDump(uint8_t dump[], dumpdata *item, uint8_t i) {
|
||||
/*
|
||||
static int _readFromDump(uint8_t dump[], dumpdata *item, uint8_t i) {
|
||||
size_t itemsize = sizeof(dumpdata);
|
||||
memcpy(item, dump + i * itemsize, itemsize);
|
||||
|
||||
@@ -277,7 +278,7 @@ int _readFromDump(uint8_t dump[], dumpdata *item, uint8_t i) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
*/
|
||||
//static uint32_t startvalue = 0;
|
||||
/**
|
||||
* @brief Performs brute force attack against a dump-data item, containing csn, cc_nr and mac.
|
||||
@@ -580,7 +581,7 @@ int bruteforceFileNoKeys(const char *filename) {
|
||||
// ----------------------------------------------------------------------------
|
||||
// TEST CODE BELOW
|
||||
// ----------------------------------------------------------------------------
|
||||
int _testBruteforce() {
|
||||
static int _testBruteforce() {
|
||||
int errors = 0;
|
||||
if (true) {
|
||||
// First test
|
||||
@@ -617,7 +618,7 @@ int _testBruteforce() {
|
||||
return errors;
|
||||
}
|
||||
|
||||
int _test_iclass_key_permutation() {
|
||||
static int _test_iclass_key_permutation() {
|
||||
uint8_t testcase[8] = {0x6c, 0x8d, 0x44, 0xf9, 0x2a, 0x2d, 0x01, 0xbf};
|
||||
uint8_t testcase_output[8] = {0};
|
||||
uint8_t testcase_output_correct[8] = {0x8a, 0x0d, 0xb9, 0x88, 0xbb, 0xa7, 0x90, 0xea};
|
||||
@@ -643,7 +644,7 @@ int _test_iclass_key_permutation() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _testHash1() {
|
||||
static int _testHash1() {
|
||||
uint8_t expected[8] = {0x7E, 0x72, 0x2F, 0x40, 0x2D, 0x02, 0x51, 0x42};
|
||||
uint8_t csn[8] = {0x01, 0x02, 0x03, 0x04, 0xF7, 0xFF, 0x12, 0xE0};
|
||||
uint8_t k[8] = {0};
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
#include <ctype.h>
|
||||
#include "elite_crack.h"
|
||||
|
||||
void calc_score(uint8_t *csn, uint8_t *k) {
|
||||
/*
|
||||
static void calc_score(uint8_t *csn, uint8_t *k) {
|
||||
uint8_t score = 0 ;
|
||||
uint8_t i;
|
||||
uint8_t goodvals[16] = {0};
|
||||
@@ -53,7 +54,7 @@ void calc_score(uint8_t *csn, uint8_t *k) {
|
||||
}
|
||||
}
|
||||
|
||||
void brute_hash1(void) {
|
||||
static void brute_hash1(void) {
|
||||
uint16_t a, b, c, d;
|
||||
uint8_t csn[8] = {0, 0, 0, 0, 0xf7, 0xff, 0x12, 0xe0};
|
||||
uint8_t k[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
@@ -81,4 +82,4 @@ void brute_hash1(void) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
@@ -85,7 +85,7 @@ static int debug_print = 0;
|
||||
* @param n bitnumber
|
||||
* @return
|
||||
*/
|
||||
uint8_t getSixBitByte(uint64_t c, int n) {
|
||||
static uint8_t getSixBitByte(uint64_t c, int n) {
|
||||
return (c >> (42 - 6 * n)) & 0x3F;
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ uint8_t getSixBitByte(uint64_t c, int n) {
|
||||
* @param z the value to place there
|
||||
* @param n bitnumber.
|
||||
*/
|
||||
void pushbackSixBitByte(uint64_t *c, uint8_t z, int n) {
|
||||
static void pushbackSixBitByte(uint64_t *c, uint8_t z, int n) {
|
||||
//0x XXXX YYYY ZZZZ ZZZZ ZZZZ
|
||||
// ^z0 ^z7
|
||||
//z0: 1111 1100 0000 0000
|
||||
@@ -120,7 +120,7 @@ void pushbackSixBitByte(uint64_t *c, uint8_t z, int n) {
|
||||
* @param c
|
||||
* @return
|
||||
*/
|
||||
uint64_t swapZvalues(uint64_t c) {
|
||||
static uint64_t swapZvalues(uint64_t c) {
|
||||
uint64_t newz = 0;
|
||||
pushbackSixBitByte(&newz, getSixBitByte(c, 0), 7);
|
||||
pushbackSixBitByte(&newz, getSixBitByte(c, 1), 6);
|
||||
@@ -137,7 +137,7 @@ uint64_t swapZvalues(uint64_t c) {
|
||||
/**
|
||||
* @return 4 six-bit bytes chunked into a uint64_t,as 00..00a0a1a2a3
|
||||
*/
|
||||
uint64_t ck(int i, int j, uint64_t z) {
|
||||
static uint64_t ck(int i, int j, uint64_t z) {
|
||||
if (i == 1 && j == -1) {
|
||||
// ck(1, −1, z [0] . . . z [3] ) = z [0] . . . z [3]
|
||||
return z;
|
||||
@@ -179,7 +179,7 @@ uint64_t ck(int i, int j, uint64_t z) {
|
||||
otherwise.
|
||||
**/
|
||||
|
||||
uint64_t check(uint64_t z) {
|
||||
static uint64_t check(uint64_t z) {
|
||||
//These 64 bits are divided as c = x, y, z [0] , . . . , z [7]
|
||||
|
||||
// ck(3, 2, z [0] . . . z [3] )
|
||||
@@ -197,7 +197,7 @@ uint64_t check(uint64_t z) {
|
||||
|
||||
}
|
||||
|
||||
void permute(BitstreamIn *p_in, uint64_t z, int l, int r, BitstreamOut *out) {
|
||||
static void permute(BitstreamIn *p_in, uint64_t z, int l, int r, BitstreamOut *out) {
|
||||
if (bitsLeft(p_in) == 0)
|
||||
return;
|
||||
|
||||
@@ -214,14 +214,14 @@ void permute(BitstreamIn *p_in, uint64_t z, int l, int r, BitstreamOut *out) {
|
||||
permute(p_in, z, l, r + 1, out);
|
||||
}
|
||||
}
|
||||
void printbegin() {
|
||||
static void printbegin() {
|
||||
if (debug_print < 2)
|
||||
return;
|
||||
|
||||
PrintAndLogDevice(NORMAL, " | x| y|z0|z1|z2|z3|z4|z5|z6|z7|");
|
||||
}
|
||||
|
||||
void printState(const char *desc, uint64_t c) {
|
||||
static void printState(const char *desc, uint64_t c) {
|
||||
if (debug_print < 2)
|
||||
return;
|
||||
|
||||
@@ -366,8 +366,8 @@ void diversifyKey(uint8_t csn[8], uint8_t key[8], uint8_t div_key[8]) {
|
||||
|
||||
hash0(crypt_csn, div_key);
|
||||
}
|
||||
|
||||
void testPermute() {
|
||||
/*
|
||||
static void testPermute() {
|
||||
uint64_t x = 0;
|
||||
pushbackSixBitByte(&x, 0x00, 0);
|
||||
pushbackSixBitByte(&x, 0x01, 1);
|
||||
@@ -411,7 +411,7 @@ void testPermute() {
|
||||
};
|
||||
printarr("permuted", res, 8);
|
||||
}
|
||||
|
||||
*/
|
||||
// These testcases are
|
||||
// { UID , TEMP_KEY, DIV_KEY} using the specific key
|
||||
typedef struct {
|
||||
@@ -420,7 +420,7 @@ typedef struct {
|
||||
uint8_t div_key[8];
|
||||
} Testcase;
|
||||
|
||||
int testDES(Testcase testcase, mbedtls_des_context ctx_enc, mbedtls_des_context ctx_dec) {
|
||||
static int testDES(Testcase testcase, mbedtls_des_context ctx_enc, mbedtls_des_context ctx_dec) {
|
||||
uint8_t des_encrypted_csn[8] = {0};
|
||||
uint8_t decrypted[8] = {0};
|
||||
uint8_t div_key[8] = {0};
|
||||
@@ -456,7 +456,7 @@ int testDES(Testcase testcase, mbedtls_des_context ctx_enc, mbedtls_des_context
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
bool des_getParityBitFromKey(uint8_t key) {
|
||||
static bool des_getParityBitFromKey(uint8_t key) {
|
||||
// The top 7 bits is used
|
||||
bool parity = ((key & 0x80) >> 7)
|
||||
^ ((key & 0x40) >> 6) ^ ((key & 0x20) >> 5)
|
||||
@@ -465,7 +465,7 @@ bool des_getParityBitFromKey(uint8_t key) {
|
||||
return !parity;
|
||||
}
|
||||
|
||||
void des_checkParity(uint8_t *key) {
|
||||
static void des_checkParity(uint8_t *key) {
|
||||
int i;
|
||||
int fails = 0;
|
||||
for (i = 0; i < 8; i++) {
|
||||
@@ -553,7 +553,7 @@ Testcase testcases[] = {
|
||||
{{0}, {0}, {0}}
|
||||
};
|
||||
|
||||
int testKeyDiversificationWithMasterkeyTestcases() {
|
||||
static int testKeyDiversificationWithMasterkeyTestcases() {
|
||||
int i, error = 0;
|
||||
uint8_t empty[8] = {0};
|
||||
|
||||
@@ -569,11 +569,11 @@ int testKeyDiversificationWithMasterkeyTestcases() {
|
||||
return error;
|
||||
}
|
||||
|
||||
void print64bits(const char *name, uint64_t val) {
|
||||
static void print64bits(const char *name, uint64_t val) {
|
||||
printf("%s%08x%08x\n", name, (uint32_t)(val >> 32), (uint32_t)(val & 0xFFFFFFFF));
|
||||
}
|
||||
|
||||
uint64_t testCryptedCSN(uint64_t crypted_csn, uint64_t expected) {
|
||||
static uint64_t testCryptedCSN(uint64_t crypted_csn, uint64_t expected) {
|
||||
int retval = 0;
|
||||
uint8_t result[8] = {0};
|
||||
if (debug_print) PrintAndLogDevice(DEBUG, "debug_print %d", debug_print);
|
||||
@@ -626,7 +626,7 @@ int testDES2(uint64_t csn, uint64_t expected) {
|
||||
* @brief doTestsWithKnownInputs
|
||||
* @return
|
||||
*/
|
||||
int doTestsWithKnownInputs() {
|
||||
static int doTestsWithKnownInputs() {
|
||||
// KSel from http://www.proxmark.org/forum/viewtopic.php?pid=10977#p10977
|
||||
int errors = 0;
|
||||
PrintAndLogDevice(SUCCESS, "Testing DES encryption");
|
||||
|
||||
Reference in New Issue
Block a user