mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
make style
This commit is contained in:
parent
44d7c54be7
commit
ee8b9ca74b
14 changed files with 229 additions and 170 deletions
|
@ -270,9 +270,9 @@ static uint64_t **unpredictable_nested(NtpKs1List *pNKL, uint32_t keyCounts[]) {
|
|||
if (thread_status[i]) activeThreads++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pthread_mutex_unlock(&status_mutex);
|
||||
printf("\33[2K\rProgress: %02.1f%%", (double)(startPos+1)*100 /pNKL->NtDataList[0].sizeNK);
|
||||
printf("\33[2K\rProgress: %02.1f%%", (double)(startPos + 1) * 100 / pNKL->NtDataList[0].sizeNK);
|
||||
printf(" keys[%d]:%9i", 0, keyCounts[0]);
|
||||
for (uint32_t nonce_index = 1; nonce_index < pNKL->nr_nonces; nonce_index++) {
|
||||
printf(" keys[%d]:%5i", nonce_index, keyCounts[nonce_index]);
|
||||
|
@ -309,14 +309,14 @@ static uint64_t **unpredictable_nested(NtpKs1List *pNKL, uint32_t keyCounts[]) {
|
|||
// Function to compare keys and keep track of their occurrences
|
||||
static void analyze_keys(uint64_t **keys, uint32_t keyCounts[MAX_NR_NONCES], uint32_t nr_nonces) {
|
||||
// Assuming the maximum possible keys
|
||||
#define MAX_KEYS (MAX_NR_NONCES * KEY_SPACE_SIZE_STEP2)
|
||||
#define MAX_KEYS (MAX_NR_NONCES * KEY_SPACE_SIZE_STEP2)
|
||||
uint64_t combined_keys[MAX_KEYS] = {0};
|
||||
uint32_t combined_counts[MAX_KEYS] = {0};
|
||||
uint32_t combined_length = 0;
|
||||
|
||||
printf("Analyzing keys...\n");
|
||||
for (uint32_t i = 0; i < nr_nonces; i++) {
|
||||
if (i==0) {
|
||||
if (i == 0) {
|
||||
printf("nT(%i): %i key candidates\n", i, keyCounts[i]);
|
||||
continue;
|
||||
} else {
|
||||
|
@ -344,7 +344,7 @@ static void analyze_keys(uint64_t **keys, uint32_t keyCounts[MAX_NR_NONCES], uin
|
|||
|
||||
for (uint32_t i = 0; i < combined_length; i++) {
|
||||
if (combined_counts[i] > 1) {
|
||||
printf("Key %012" PRIx64 " found in %d arrays: 0", combined_keys[i], combined_counts[i]+1);
|
||||
printf("Key %012" PRIx64 " found in %d arrays: 0", combined_keys[i], combined_counts[i] + 1);
|
||||
for (uint32_t ii = 1; ii < nr_nonces; ii++) {
|
||||
for (uint32_t j = 0; j < keyCounts[ii]; j++) {
|
||||
if (combined_keys[i] == keys[ii][j]) {
|
||||
|
@ -382,7 +382,7 @@ int main(int argc, char *const argv[]) {
|
|||
NtpKs1List NKL = {0};
|
||||
uint64_t **keys = NULL;
|
||||
uint32_t keyCounts[MAX_NR_NONCES] = {0};
|
||||
|
||||
|
||||
uint32_t authuid = hex_to_uint32(argv[1]);
|
||||
// process all args.
|
||||
printf("Generating nonce candidates...\n");
|
||||
|
@ -418,9 +418,9 @@ int main(int argc, char *const argv[]) {
|
|||
nttest = prng_successor(nttest, 1);
|
||||
}
|
||||
printf("uid=%08x nt_enc=%08x nt_par_err=%i%i%i%i nt_par_enc=%i%i%i%i %i/%i: %d\n", authuid, nt_enc,
|
||||
nt_par_err_arr[0], nt_par_err_arr[1], nt_par_err_arr[2], nt_par_err_arr[3],
|
||||
(nt_par_enc >> 3)&1, (nt_par_enc >> 2)&1, (nt_par_enc >> 1)&1, nt_par_enc&1,
|
||||
NKL.nr_nonces + 1, (argc - 1) / 3, j);
|
||||
nt_par_err_arr[0], nt_par_err_arr[1], nt_par_err_arr[2], nt_par_err_arr[3],
|
||||
(nt_par_enc >> 3) & 1, (nt_par_enc >> 2) & 1, (nt_par_enc >> 1) & 1, nt_par_enc & 1,
|
||||
NKL.nr_nonces + 1, (argc - 1) / 3, j);
|
||||
|
||||
pNtData->authuid = authuid;
|
||||
pNtData->sizeNK = j;
|
||||
|
@ -437,7 +437,7 @@ int main(int argc, char *const argv[]) {
|
|||
free(NKL.NtDataList[k].pNK);
|
||||
|
||||
analyze_keys(keys, keyCounts, NKL.nr_nonces);
|
||||
FILE* fptr;
|
||||
FILE *fptr;
|
||||
// opening the file in read mode
|
||||
fptr = fopen("keys.dic", "w");
|
||||
if (fptr != NULL) {
|
||||
|
|
|
@ -119,7 +119,7 @@ int main(int argc, char *const argv[]) {
|
|||
}
|
||||
uint64_t *keys = NULL;
|
||||
uint32_t keyCount = 0;
|
||||
|
||||
|
||||
uint32_t authuid = hex_to_uint32(argv[1]);
|
||||
uint32_t sector = hex_to_uint32(argv[2]);
|
||||
uint32_t nt = hex_to_uint32(argv[3]);
|
||||
|
@ -129,20 +129,20 @@ int main(int argc, char *const argv[]) {
|
|||
return 1;
|
||||
}
|
||||
uint8_t nt_par_enc = ((nt_par_err_arr[0] ^ oddparity8((nt_enc >> 24) & 0xFF)) << 3) |
|
||||
((nt_par_err_arr[1] ^ oddparity8((nt_enc >> 16) & 0xFF)) << 2) |
|
||||
((nt_par_err_arr[2] ^ oddparity8((nt_enc >> 8) & 0xFF)) << 1) |
|
||||
((nt_par_err_arr[3] ^ oddparity8((nt_enc >> 0) & 0xFF)) << 0);
|
||||
((nt_par_err_arr[1] ^ oddparity8((nt_enc >> 16) & 0xFF)) << 2) |
|
||||
((nt_par_err_arr[2] ^ oddparity8((nt_enc >> 8) & 0xFF)) << 1) |
|
||||
((nt_par_err_arr[3] ^ oddparity8((nt_enc >> 0) & 0xFF)) << 0);
|
||||
printf("uid=%08x nt=%08x nt_enc=%08x nt_par_err=%i%i%i%i nt_par_enc=%i%i%i%i ks1=%08x\n", authuid, nt, nt_enc,
|
||||
nt_par_err_arr[0], nt_par_err_arr[1], nt_par_err_arr[2], nt_par_err_arr[3],
|
||||
(nt_par_enc >> 3)&1, (nt_par_enc >> 2)&1, (nt_par_enc >> 1)&1, nt_par_enc&1,
|
||||
nt ^ nt_enc);
|
||||
nt_par_err_arr[0], nt_par_err_arr[1], nt_par_err_arr[2], nt_par_err_arr[3],
|
||||
(nt_par_enc >> 3) & 1, (nt_par_enc >> 2) & 1, (nt_par_enc >> 1) & 1, nt_par_enc & 1,
|
||||
nt ^ nt_enc);
|
||||
|
||||
|
||||
printf("Finding key candidates...\n");
|
||||
keys = generate_keys(authuid, nt, nt_enc, nt_par_enc, &keyCount);
|
||||
printf("Finding phase complete, found %i keys\n", keyCount);
|
||||
|
||||
FILE* fptr;
|
||||
FILE *fptr;
|
||||
char filename[30];
|
||||
snprintf(filename, sizeof(filename), "keys_%08x_%02i_%08x.dic", authuid, sector, nt);
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ uint16_t s_lfsr16[1 << 16] = {0};
|
|||
|
||||
static void init_lfsr16_table(void) {
|
||||
uint16_t x = 1;
|
||||
for (uint16_t i=1; i; ++i) {
|
||||
for (uint16_t i = 1; i; ++i) {
|
||||
i_lfsr16[(x & 0xff) << 8 | x >> 8] = i;
|
||||
s_lfsr16[i] = (x & 0xff) << 8 | x >> 8;
|
||||
x = x >> 1 | (x ^ x >> 2 ^ x >> 3 ^ x >> 5) << 15;
|
||||
|
@ -35,7 +35,7 @@ static void init_lfsr16_table(void) {
|
|||
// }
|
||||
|
||||
static uint16_t prev_lfsr16(uint16_t nonce) {
|
||||
return s_lfsr16[(i_lfsr16[nonce]-1) % 65535];
|
||||
return s_lfsr16[(i_lfsr16[nonce] - 1) % 65535];
|
||||
}
|
||||
|
||||
static uint16_t compute_seednt16_nt32(uint32_t nt32, uint64_t key) {
|
||||
|
@ -43,13 +43,13 @@ static uint16_t compute_seednt16_nt32(uint32_t nt32, uint64_t key) {
|
|||
uint8_t b[] = {0, 13, 1, 14, 4, 10, 15, 7, 5, 3, 8, 6, 9, 2, 12, 11};
|
||||
uint16_t nt = nt32 >> 16;
|
||||
uint8_t prev = 14;
|
||||
for (uint8_t i=0; i<prev; i++) {
|
||||
for (uint8_t i = 0; i < prev; i++) {
|
||||
nt = prev_lfsr16(nt);
|
||||
}
|
||||
uint8_t prevoff = 8;
|
||||
bool odd = 1;
|
||||
|
||||
for (uint8_t i=0; i<6*8; i+=8) {
|
||||
for (uint8_t i = 0; i < 6 * 8; i += 8) {
|
||||
if (odd) {
|
||||
nt ^= (a[(key >> i) & 0xF]);
|
||||
nt ^= (b[(key >> i >> 4) & 0xF]) << 4;
|
||||
|
@ -59,7 +59,7 @@ static uint16_t compute_seednt16_nt32(uint32_t nt32, uint64_t key) {
|
|||
}
|
||||
odd ^= 1;
|
||||
prev += prevoff;
|
||||
for (uint8_t j=0; j<prevoff; j++) {
|
||||
for (uint8_t j = 0; j < prevoff; j++) {
|
||||
nt = prev_lfsr16(nt);
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ int main(int argc, char *const argv[]) {
|
|||
}
|
||||
|
||||
uint32_t uid1, sector1, nt1, uid2, sector2, nt2;
|
||||
char *filename1 = argv[1], *filename2= argv[2];
|
||||
char *filename1 = argv[1], *filename2 = argv[2];
|
||||
|
||||
int result;
|
||||
result = sscanf(filename1, "keys_%8x_%2d_%8x.dic", &uid1, §or1, &nt1);
|
||||
|
@ -105,13 +105,13 @@ int main(int argc, char *const argv[]) {
|
|||
init_lfsr16_table();
|
||||
|
||||
uint32_t keycount1 = 0;
|
||||
uint64_t* keys1 = NULL;
|
||||
uint8_t* filter_keys1 = NULL;
|
||||
uint16_t* seednt1 = NULL;
|
||||
uint64_t *keys1 = NULL;
|
||||
uint8_t *filter_keys1 = NULL;
|
||||
uint16_t *seednt1 = NULL;
|
||||
uint32_t keycount2 = 0;
|
||||
uint64_t* keys2 = NULL;
|
||||
uint8_t* filter_keys2 = NULL;
|
||||
FILE* fptr;
|
||||
uint64_t *keys2 = NULL;
|
||||
uint8_t *filter_keys2 = NULL;
|
||||
FILE *fptr;
|
||||
|
||||
fptr = fopen(filename1, "r");
|
||||
if (fptr != NULL) {
|
||||
|
@ -120,9 +120,9 @@ int main(int argc, char *const argv[]) {
|
|||
keycount1++;
|
||||
}
|
||||
|
||||
keys1 = (uint64_t*)malloc(keycount1 * sizeof(uint64_t));
|
||||
filter_keys1 = (uint8_t*)calloc(keycount1, sizeof(uint8_t));
|
||||
if ((keys1 == NULL)||(filter_keys1 == NULL)) {
|
||||
keys1 = (uint64_t *)malloc(keycount1 * sizeof(uint64_t));
|
||||
filter_keys1 = (uint8_t *)calloc(keycount1, sizeof(uint8_t));
|
||||
if ((keys1 == NULL) || (filter_keys1 == NULL)) {
|
||||
perror("Failed to allocate memory");
|
||||
fclose(fptr);
|
||||
goto end;
|
||||
|
@ -149,9 +149,9 @@ int main(int argc, char *const argv[]) {
|
|||
keycount2++;
|
||||
}
|
||||
|
||||
keys2 = (uint64_t*)malloc(keycount2 * sizeof(uint64_t));
|
||||
filter_keys2 = (uint8_t*)calloc(keycount2, sizeof(uint8_t));
|
||||
if ((keys2 == NULL)||(filter_keys2 == NULL)) {
|
||||
keys2 = (uint64_t *)malloc(keycount2 * sizeof(uint64_t));
|
||||
filter_keys2 = (uint8_t *)calloc(keycount2, sizeof(uint8_t));
|
||||
if ((keys2 == NULL) || (filter_keys2 == NULL)) {
|
||||
perror("Failed to allocate memory");
|
||||
fclose(fptr);
|
||||
goto end;
|
||||
|
@ -174,7 +174,7 @@ int main(int argc, char *const argv[]) {
|
|||
printf("%s: %i keys loaded\n", filename1, keycount1);
|
||||
printf("%s: %i keys loaded\n", filename2, keycount2);
|
||||
|
||||
seednt1 = (uint16_t*)malloc(keycount1 * sizeof(uint16_t));
|
||||
seednt1 = (uint16_t *)malloc(keycount1 * sizeof(uint16_t));
|
||||
if (seednt1 == NULL) {
|
||||
perror("Failed to allocate memory");
|
||||
goto end;
|
||||
|
|
|
@ -25,7 +25,7 @@ uint16_t s_lfsr16[1 << 16] = {0};
|
|||
|
||||
static void init_lfsr16_table(void) {
|
||||
uint16_t x = 1;
|
||||
for (uint16_t i=1; i; ++i) {
|
||||
for (uint16_t i = 1; i; ++i) {
|
||||
i_lfsr16[(x & 0xff) << 8 | x >> 8] = i;
|
||||
s_lfsr16[i] = (x & 0xff) << 8 | x >> 8;
|
||||
x = x >> 1 | (x ^ x >> 2 ^ x >> 3 ^ x >> 5) << 15;
|
||||
|
@ -37,7 +37,7 @@ static void init_lfsr16_table(void) {
|
|||
// }
|
||||
|
||||
static uint16_t prev_lfsr16(uint16_t nonce) {
|
||||
return s_lfsr16[(i_lfsr16[nonce]-1) % 65535];
|
||||
return s_lfsr16[(i_lfsr16[nonce] - 1) % 65535];
|
||||
}
|
||||
|
||||
static uint16_t compute_seednt16_nt32(uint32_t nt32, uint64_t key) {
|
||||
|
@ -45,13 +45,13 @@ static uint16_t compute_seednt16_nt32(uint32_t nt32, uint64_t key) {
|
|||
uint8_t b[] = {0, 13, 1, 14, 4, 10, 15, 7, 5, 3, 8, 6, 9, 2, 12, 11};
|
||||
uint16_t nt = nt32 >> 16;
|
||||
uint8_t prev = 14;
|
||||
for (uint8_t i=0; i<prev; i++) {
|
||||
for (uint8_t i = 0; i < prev; i++) {
|
||||
nt = prev_lfsr16(nt);
|
||||
}
|
||||
uint8_t prevoff = 8;
|
||||
bool odd = 1;
|
||||
|
||||
for (uint8_t i=0; i<6*8; i+=8) {
|
||||
for (uint8_t i = 0; i < 6 * 8; i += 8) {
|
||||
if (odd) {
|
||||
nt ^= (a[(key >> i) & 0xF]);
|
||||
nt ^= (b[(key >> i >> 4) & 0xF]) << 4;
|
||||
|
@ -61,7 +61,7 @@ static uint16_t compute_seednt16_nt32(uint32_t nt32, uint64_t key) {
|
|||
}
|
||||
odd ^= 1;
|
||||
prev += prevoff;
|
||||
for (uint8_t j=0; j<prevoff; j++) {
|
||||
for (uint8_t j = 0; j < prevoff; j++) {
|
||||
nt = prev_lfsr16(nt);
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ int main(int argc, char *const argv[]) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
char *filename= argv[3];
|
||||
char *filename = argv[3];
|
||||
uint32_t uid, sector, nt2;
|
||||
|
||||
int result;
|
||||
|
@ -99,16 +99,16 @@ int main(int argc, char *const argv[]) {
|
|||
init_lfsr16_table();
|
||||
|
||||
uint32_t keycount2 = 0;
|
||||
uint64_t* keys2 = NULL;
|
||||
uint64_t *keys2 = NULL;
|
||||
|
||||
FILE* fptr = fopen(filename, "r");
|
||||
FILE *fptr = fopen(filename, "r");
|
||||
if (fptr != NULL) {
|
||||
uint64_t buffer;
|
||||
while (fscanf(fptr, "%012" PRIx64, &buffer) == 1) {
|
||||
keycount2++;
|
||||
}
|
||||
|
||||
keys2 = (uint64_t*)malloc(keycount2 * sizeof(uint64_t));
|
||||
keys2 = (uint64_t *)malloc(keycount2 * sizeof(uint64_t));
|
||||
if (keys2 == NULL) {
|
||||
perror("Failed to allocate memory");
|
||||
fclose(fptr);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue