hitag2crack crack3 & crack4 fixed for 32b archs

This commit is contained in:
Philippe Teuwen
2026-02-22 14:11:23 +01:00
parent d8ee084ffe
commit 69d26524cd
5 changed files with 22 additions and 12 deletions

View File

@@ -325,7 +325,7 @@ int main(int argc, char *argv[]) {
// set klowerstart (for debugging)
if (argc > 3) {
klowerstart = strtol(argv[3], NULL, 0);
klowerstart = strtoull(argv[3], NULL, 0);
} else {
klowerstart = 0;
}

View File

@@ -54,7 +54,7 @@ int main(int argc, char *argv[]) {
}
hitag2_init(&hstate, rev64(hexreversetouint64(key)), rev32(hexreversetouint32(uid)), rev32(hexreversetouint32(nr)));
arval = strtol(ar, NULL, 16);
arval = strtoul(ar, NULL, 16);
ks = hitag2_nstep(&hstate, 32);

View File

@@ -325,7 +325,7 @@ static double bit_score(uint64_t s, uint64_t size, uint64_t b) {
// chop away any bits beyond size
chopped = s & ((1l << size) - 1);
chopped = s & ((UINT64_C(1) << size) - 1);
// and pack the remaining bits
packed = packstate(chopped);
@@ -514,7 +514,7 @@ static void score_all_traces(unsigned int size) {
// start the threads
for (i = 0; i < NUM_THREADS; i++) {
if (pthread_create(&(threads[i]), NULL, score_some_traces, (void *)(tdata + i))) {
if (pthread_create(&(threads[i]), NULL, score_some_traces, (void *)(uintptr_t)(tdata + i))) {
printf("cannot start thread %u\n", i);
exit(1);
}
@@ -555,7 +555,7 @@ static void expand_guesses(unsigned int halfsize, unsigned int size) {
unsigned int i, j;
for (i = 0; i < halfsize; i++) {
guesses[i + halfsize].key = guesses[i].key | (1l << size);
guesses[i + halfsize].key = guesses[i].key | (UINT64_C(1) << size);
guesses[i + halfsize].score = guesses[i].score;
for (j = 0; j < num_nRaR; j++) {
guesses[i + halfsize].b0to31[j] = guesses[i].b0to31[j];
@@ -570,7 +570,7 @@ static void check_supplied_testkey(unsigned int size) {
uint64_t partkey;
unsigned int i;
partkey = supplied_testkey & ((1l << size) - 1);
partkey = supplied_testkey & ((UINT64_C(1) << size) - 1);
for (i = 0; i < num_guesses; i++) {
if (guesses[i].key == partkey) {
@@ -620,7 +620,12 @@ static void crack(void) {
// print some metrics
uint64_t revkey = rev64(guesses[0].key);
uint64_t foundkey = ((revkey >> 40) & 0xff) | ((revkey >> 24) & 0xff00) | ((revkey >> 8) & 0xff0000) | ((revkey << 8) & 0xff000000) | ((revkey << 24) & 0xff00000000) | ((revkey << 40) & 0xff0000000000);
uint64_t foundkey = ((revkey >> 40) & UINT64_C(0xff)) |
((revkey >> 24) & UINT64_C(0xff00)) |
((revkey >> 8) & UINT64_C(0xff0000)) |
((revkey << 8) & UINT64_C(0xff000000)) |
((revkey << 24) & UINT64_C(0xff00000000)) |
((revkey << 40) & UINT64_C(0xff0000000000));
fprintf(stderr, " guess=%012" PRIx64 ", num_guesses = %u, top score=%1.10f, min score=%1.10f\n", foundkey, num_guesses, guesses[0].score, guesses[num_guesses - 1].score);
}
}
@@ -828,7 +833,12 @@ int main(int argc, char *argv[]) {
check_key(guesses[i].key, nonces[1].enc_nR, nonces[1].ks)) {
printf("WIN!!! :)\n");
revkey = rev64(guesses[i].key);
foundkey = ((revkey >> 40) & 0xff) | ((revkey >> 24) & 0xff00) | ((revkey >> 8) & 0xff0000) | ((revkey << 8) & 0xff000000) | ((revkey << 24) & 0xff00000000) | ((revkey << 40) & 0xff0000000000);
foundkey = ((revkey >> 40) & UINT64_C(0xff)) |
((revkey >> 24) & UINT64_C(0xff00)) |
((revkey >> 8) & UINT64_C(0xff0000)) |
((revkey << 8) & UINT64_C(0xff000000)) |
((revkey << 24) & UINT64_C(0xff00000000)) |
((revkey << 40) & UINT64_C(0xff0000000000));
printf("key = %012" PRIX64 "\n", foundkey);
exit(0);
}

View File

@@ -149,7 +149,7 @@ int main(int argc, char *argv[]) {
nR1 = rev32(hexreversetouint32(argv[2]));
}
aR1 = strtol(argv[3], NULL, 16);
aR1 = strtoul(argv[3], NULL, 16);
if (!strncmp(argv[4], "0x", 2) || !strncmp(argv[4], "0X", 2)) {
nR2 = rev32(hexreversetouint32(argv[4] + 2));
@@ -157,7 +157,7 @@ int main(int argc, char *argv[]) {
nR2 = rev32(hexreversetouint32(argv[4]));
}
aR2 = strtol(argv[5], NULL, 16);
aR2 = strtoul(argv[5], NULL, 16);
target = ~aR1;
// bitslice inverse target bits

View File

@@ -201,7 +201,7 @@ int main(int argc, char *argv[]) {
nR1 = rev32(hexreversetouint32(argv[2]));
}
aR1 = strtol(argv[3], NULL, 16);
aR1 = strtoul(argv[3], NULL, 16);
if (!strncmp(argv[4], "0x", 2) || !strncmp(argv[4], "0X", 2)) {
nR2 = rev32(hexreversetouint32(argv[4] + 2));
@@ -209,7 +209,7 @@ int main(int argc, char *argv[]) {
nR2 = rev32(hexreversetouint32(argv[4]));
}
aR2 = strtol(argv[5], NULL, 16);
aR2 = strtoul(argv[5], NULL, 16);
target = ~aR1;
// bitslice inverse target bits