From cdc3a7daadeb2bc7a155a8a8e73d6a2d7aa022e8 Mon Sep 17 00:00:00 2001 From: Pin Lin Date: Sun, 16 Apr 2023 04:10:53 +0800 Subject: [PATCH] Stop when collected enough nonces --- holycard_collect.c | 83 ++-------------------------------------------- 1 file changed, 3 insertions(+), 80 deletions(-) diff --git a/holycard_collect.c b/holycard_collect.c index 3049eb5..15ac716 100755 --- a/holycard_collect.c +++ b/holycard_collect.c @@ -534,15 +534,9 @@ void notify_status_online(int sig){ printf(VT100_cleareol "Collected %zu nonces... ", nonces_collected); } else { printf(VT100_cleareol "Collected %zu nonces... leftover complexity %"llu" (~2^%0.2f)", nonces_collected, total_states, log(total_states) / log(2)); - char c; - if(scanf("%c", &c) == 1 || total_states < CUTOFF){ - printf(" - initializing brute-force phase...\n"); - alarm(0); - stop_collection = true; - return; - } else { - printf(" - press enter to start brute-force phase"); - } + alarm(0); + stop_collection = true; + return; } alarm(1); fflush(stdout); @@ -663,76 +657,5 @@ int main (int argc, const char * argv[]) { fclose(fp); } nfc_close(pnd); - - if(!space){ - space = craptev1_get_space(nonces, 95, uid); - } - if(space){ - total_states = craptev1_sizeof_space(space); - } else { - total_states = 0; - } - if(!total_states){ - fprintf(stderr, "No solution found :(\n"); - return 1; - } - -#ifndef __WIN32 - thread_count = sysconf(_SC_NPROCESSORS_CONF); -#else - thread_count = 1; -#endif - // append some zeroes to the end of the space to make sure threads don't go off into the wild - size_t j = 0; - for(j = 0; space[j]; j+=5){ - } - size_t fill = j + (5*thread_count); - for(; j < fill; j++) { - space[j] = 0; - } - pthread_t threads[thread_count]; - - crypto1_bs_init(); - - uint8_t rollback_byte = **space; - // convert to 32 bit little-endian - crypto1_bs_bitslice_value32(rev32((rollback_byte)), bitsliced_rollback_byte, 8); - - for(size_t tests = 0; tests < NONCE_TESTS; tests++){ - // pre-xor the uid into the decrypted nonces, and also pre-xor the uid parity into the encrypted parity bits - otherwise an exta xor is required in the decryption routine - uint32_t test_nonce = uid^rev32(nonces[tests]); - uint32_t test_parity = (nonces[tests]>>32)^rev32(uid); - test_parity = ((parity(test_parity >> 24 & 0xff) & 1) | (parity(test_parity>>16 & 0xff) & 1)<<1 | (parity(test_parity>>8 & 0xff) & 1)<<2 | (parity(test_parity & 0xff) & 1) << 3); - crypto1_bs_bitslice_value32(test_nonce, bitsliced_encrypted_nonces[tests], 32); - // convert to 32 bit little-endian - crypto1_bs_bitslice_value32(~(test_parity)<<24, bitsliced_encrypted_parity_bits[tests], 4); - } - - printf("Starting %zu threads to test %"llu" states using %u-way bitslicing\n", thread_count, total_states, MAX_BITSLICES); - total_states_tested = 0; - keys_found = 0; - signal(SIGALRM, notify_status_offline); - - notify_status_offline(0); - alarm(1); - - size_t i; - for(i = 0; i < thread_count; i++){ - pthread_create(&threads[i], NULL, crack_states_thread, (void*) i); - } - for(i = 0; i < thread_count; i++){ - pthread_join(threads[i], 0); - } - alarm(0); - printf("\n"); - if(!keys_found){ - fprintf(stderr, "No solution found :(\n"); - return 1; - } else { - printf("Found key: %012"PRIx64"\n", found_key); - } - printf("Tested %"llu" states\n", total_states_tested); - - craptev1_destroy_space(space); return 0; }