fix coverity CID 301400|301401
[RRG-proxmark3.git] / client / src / loclass / hash1_brute.c
blob2f2842b2f9afffdbb789cea3b033a95b39c9c0d7
1 #include "hash1_brute.h"
2 #include <stdio.h>
3 #include "cipherutils.h"
4 #include <stdint.h>
5 #include <stdbool.h>
6 #include <string.h>
7 #include <unistd.h>
8 #include <ctype.h>
9 #include "elite_crack.h"
10 #include "ui.h"
12 static void calc_score(uint8_t *csn, uint8_t *k) {
13 uint8_t score = 0 ;
14 uint8_t i;
15 uint8_t goodvals[16] = {0};
16 uint8_t uniq_vals[8] = {0};
17 memset(goodvals, 0x00, 16);
18 memset(uniq_vals, 0x00, 8);
19 uint8_t badval = 0;
20 int badscore = 0;
21 for (i = 0; i < 8 ; i++) {
22 if (k[i] == 0x01) continue;
23 if (k[i] == 0x00) continue;
24 if (k[i] == 0x45) continue;
25 if (k[i] < 16) {
26 goodvals[k[i]] = 1;
28 // if(k[i] ==9 || k[i]==2){
29 // goodvals[k[i]] = 1;
30 // }
32 // else if (k[i] >= 16) {
33 else {
34 badscore++;
35 badval = k[i];
38 for (i = 0; i < 16; i++) {
39 if (goodvals[i]) {
40 uniq_vals[score] = i;
41 score += 1;
45 if (score >= 2 && badscore < 2) {
46 PrintAndLogEx(NORMAL, "CSN\t%02x%02x%02x%02x%02x%02x%02x%02x\t%02x %02x %02x %02x %02x %02x %02x %02x\t" NOLF
47 , csn[0], csn[1], csn[2], csn[3], csn[4], csn[5], csn[6], csn[7]
48 , k[0], k[1], k[2], k[3], k[4], k[5], k[6], k[7]
51 for (i = 0 ; i < score; i++) {
52 PrintAndLogEx(NORMAL, "%d," NOLF, uniq_vals[i]);
54 PrintAndLogEx(NORMAL, "\tbadscore: %d (%02x)" NOLF, badscore, badval);
55 PrintAndLogEx(NORMAL, "");
59 void brute_hash1(void) {
61 uint8_t csn[8] = {0, 0, 0, 0, 0xf7, 0xff, 0x12, 0xe0};
62 uint8_t k[8] = {0, 0, 0, 0, 0, 0, 0, 0};
63 uint8_t testcsn[8] = {0x00, 0x0d, 0x0f, 0xfd, 0xf7, 0xff, 0x12, 0xe0} ;
64 uint8_t testkey[8] = {0x05, 0x01, 0x00, 0x10, 0x45, 0x08, 0x45, 0x56} ;
65 calc_score(testcsn, testkey);
67 PrintAndLogEx(INFO, "Brute forcing hashones");
69 for (uint16_t a = 0; a < 256; a++) {
70 for (uint16_t b = 0; b < 256; b++) {
71 for (uint16_t c = 0; c < 256; c++) {
72 for (uint16_t d = 0; d < 256; d++) {
73 csn[0] = a;
74 csn[1] = b;
75 csn[2] = c;
76 csn[3] = d;
77 csn[4] = 0xf7;
78 csn[5] = 0xff;
79 csn[6] = 0x12;
80 csn[7] = 0xe0;
81 hash1(csn, k);
82 calc_score(csn, k);