From cccee38597a3aac3289d0724d2d98112feedff58 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sat, 29 Aug 2020 14:48:41 +0200 Subject: [PATCH] no printf --- client/src/loclass/hash1_brute.c | 25 ++++++----- client/src/loclass/ikeys.c | 77 ++++++++++++++------------------ 2 files changed, 46 insertions(+), 56 deletions(-) diff --git a/client/src/loclass/hash1_brute.c b/client/src/loclass/hash1_brute.c index 1c944b99e..99e8f49f6 100644 --- a/client/src/loclass/hash1_brute.c +++ b/client/src/loclass/hash1_brute.c @@ -41,34 +41,33 @@ static void calc_score(uint8_t *csn, uint8_t *k) { } if (score >= 2 && badscore < 2) { - printf("CSN\t%02x%02x%02x%02x%02x%02x%02x%02x\t%02x %02x %02x %02x %02x %02x %02x %02x\t" + PrintAndLogEx(NORMAL, "CSN\t%02x%02x%02x%02x%02x%02x%02x%02x\t%02x %02x %02x %02x %02x %02x %02x %02x\t" NOLF , csn[0], csn[1], csn[2], csn[3], csn[4], csn[5], csn[6], csn[7] , k[0], k[1], k[2], k[3], k[4], k[5], k[6], k[7] ); for (i = 0 ; i < score; i++) { - printf("%d,", uniq_vals[i]); + PrintAndLogEx(NORMAL, "%d," NOLF, uniq_vals[i]); } - printf("\tbadscore: %d (%02x)", badscore, badval); - printf("\r\n"); + PrintAndLogEx(NORMAL, "\tbadscore: %d (%02x)" NOLF, badscore, badval); + PrintAndLogEx(NORMAL, ""); } } 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}; uint8_t testcsn[8] = {0x00, 0x0d, 0x0f, 0xfd, 0xf7, 0xff, 0x12, 0xe0} ; uint8_t testkey[8] = {0x05, 0x01, 0x00, 0x10, 0x45, 0x08, 0x45, 0x56} ; calc_score(testcsn, testkey); - printf("Brute forcing hashones\n"); - //exit(1); - for (a = 0; a < 256; a++) { - //if(a > 0)printf("%d/256 done...\n", a); - for (b = 0; b < 256; b++) - for (c = 0; c < 256; c++) - for (d = 0; d < 256; d++) { + PrintAndLogEx(INFO, "Brute forcing hashones"); + + for (uint16_t a = 0; a < 256; a++) { + for (uint16_t b = 0; b < 256; b++) { + for (uint16_t c = 0; c < 256; c++) { + for (uint16_t d = 0; d < 256; d++) { csn[0] = a; csn[1] = b; csn[2] = c; @@ -80,6 +79,8 @@ void brute_hash1(void) { hash1(csn, k); calc_score(csn, k); } + } + } } } diff --git a/client/src/loclass/ikeys.c b/client/src/loclass/ikeys.c index 3adcd97bb..181f23db1 100644 --- a/client/src/loclass/ikeys.c +++ b/client/src/loclass/ikeys.c @@ -333,7 +333,7 @@ void hash0(uint64_t c, uint8_t k[8]) { uint8_t p_i = p >> i & 0x1; if (k[i]) { // yi = 1 - //printf("k[%d] +1\n", i); + // PrintAndLogEx(NORMAL, "k[%d] + 1", i); k[i] |= ~zTilde_i & 0x7E; k[i] |= p_i & 1; k[i] += 1; @@ -399,7 +399,7 @@ static void testPermute(void) { permute(&p_in, x, 0, 4, &out); uint64_t permuted = x_bytes_to_num(outbuffer, 8); - //printf("zTilde 0x%"PRIX64"\n", zTilde); + // PrintAndLogEx(NORMAL, "zTilde 0x%"PRIX64, zTilde); permuted >>= 16; uint8_t res[8] = { getSixBitByte(permuted, 0), @@ -694,28 +694,21 @@ int doKeyTests(void) { /** -void checkParity2(uint8_t* key) -{ +void checkParity2(uint8_t* key) { uint8_t stored_parity = key[7]; - printf("Parity byte: 0x%02x\n", stored_parity); - int i; - int byte; - int fails =0; + PrintAndLogEx(NORMAL, "Parity byte: 0x%02x", stored_parity); + int i, byte, fails = 0; BitstreamIn bits = {key, 56, 0}; - bool parity = 0; - for(i =0 ; i < 56; i++) - { + for (i = 0; i < 56; i++) { - if ( i > 0 && i % 7 == 0) - { + if ( i > 0 && i % 7 == 0){ parity = !parity; bool pbit = stored_parity & (0x80 >> (byte)); - if(parity != pbit) - { - printf("parity2 fail byte %d, should be %d, was %d\n", (i / 7), parity, pbit); + if (parity != pbit) { + PrintAndLogEx(NORMAL, "parity2 fail byte %d, should be %d, was %d", (i / 7), parity, pbit); fails++; } parity =0 ; @@ -723,35 +716,32 @@ void checkParity2(uint8_t* key) } parity = parity ^ headBit(&bits); } - if(fails) - { - printf("parity2 fails: %d\n", fails); - }else - { - printf("Key syntax is with parity bits grouped in the last byte!\n"); + if (fails) { + PrintAndLogEx(FAILED, "parity2 fails: %d", fails); + } else { + PrintAndLogEx(INFO, "Key syntax is with parity bits grouped in the last byte!"); } } -void modifyKey_put_parity_last(uint8_t * key, uint8_t* output) -{ + +void modifyKey_put_parity_last(uint8_t * key, uint8_t* output) { + uint8_t paritybits = 0; bool parity =0; - BitstreamOut out = { output, 0,0}; + BitstreamOut out = { output, 0, 0}; unsigned int bbyte, bbit; - for(bbyte=0; bbyte <8 ; bbyte++ ) - { - for(bbit =0 ; bbit< 7 ; bbit++) - { - bool bit = *(key+bbyte) & (1 << (7-bbit)); - pushBit(&out,bit); + for (bbyte = 0; bbyte <8; bbyte++ ) { + for(bbit = 0; bbit < 7; bbit++) { + bool bit = *(key + bbyte) & (1 << (7 - bbit)); + pushBit(&out, bit); parity ^= bit; } - bool paritybit = *(key+bbyte) & 1; - paritybits |= paritybit << (7-bbyte); + bool paritybit = *(key + bbyte) & 1; + paritybits |= paritybit << (7 - bbyte); parity = 0; } output[7] = paritybits; - printf("Parity byte: %02x\n", paritybits); + PrintAndLogEx(INFO, "Parity byte: %02x", paritybits); } * @brief Modifies a key with parity bits last, so that it is formed with parity @@ -759,25 +749,24 @@ void modifyKey_put_parity_last(uint8_t * key, uint8_t* output) * @param key * @param output -void modifyKey_put_parity_allover(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 out = {output, 0, 0}; + BitstreamIn in = {key, 0, 0}; unsigned int bbyte, bbit; - for(bbit =0 ; bbit < 56 ; bbit++) { - if( bbit > 0 && bbit % 7 == 0) { - pushBit(&out,!parity); + for (bbit = 0; bbit < 56; bbit++) { + if (bbit > 0 && bbit % 7 == 0) { + pushBit(&out, !parity); parity = 0; } bool bit = headBit(&in); - pushBit(&out,bit ); + pushBit(&out, bit); parity ^= bit; } pushBit(&out, !parity); - if( des_key_check_key_parity(output)) - printf("modifyKey_put_parity_allover fail, DES key invalid parity!"); + if (des_key_check_key_parity(output)) + PrintAndLogEx(FAILED, "modifyKey_put_parity_allover fail, DES key invalid parity!"); } */