X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/0d5ee8e2453c5db01e4a9c6d5187aea3c16f0093..1a4b67382ab95dbfdc3872e1dc94cb7c8f0e2854:/client/cmdhfmfhard.c diff --git a/client/cmdhfmfhard.c b/client/cmdhfmfhard.c index 4427978a..fbfeeb76 100644 --- a/client/cmdhfmfhard.c +++ b/client/cmdhfmfhard.c @@ -286,20 +286,18 @@ static double p_hypergeometric(uint16_t N, uint16_t K, uint16_t n, uint16_t k) static float sum_probability(uint16_t K, uint16_t n, uint16_t k) { const uint16_t N = 256; - - - if (k > K || p_K[K] == 0.0) return 0.0; + if (k > K || p_K[K] == 0.0) return 0.0; - double p_T_is_k_when_S_is_K = p_hypergeometric(N, K, n, k); - double p_S_is_K = p_K[K]; - double p_T_is_k = 0; - for (uint16_t i = 0; i <= 256; i++) { - if (p_K[i] != 0.0) { - p_T_is_k += p_K[i] * p_hypergeometric(N, i, n, k); - } + double p_T_is_k_when_S_is_K = p_hypergeometric(N, K, n, k); + double p_S_is_K = p_K[K]; + double p_T_is_k = 0; + for (uint16_t i = 0; i <= 256; i++) { + if (p_K[i] != 0.0) { + p_T_is_k += p_K[i] * p_hypergeometric(N, i, n, k); } - return(p_T_is_k_when_S_is_K * p_S_is_K / p_T_is_k); + } + return(p_T_is_k_when_S_is_K * p_S_is_K / p_T_is_k); } @@ -514,7 +512,7 @@ static void sort_best_first_bytes(void) // determine how many are above the CONFIDENCE_THRESHOLD uint16_t num_good_nonces = 0; for (uint16_t i = 0; i < 256; i++) { - if (nonces[best_first_bytes[i]].Sum8_prob > CONFIDENCE_THRESHOLD) { + if (nonces[best_first_bytes[i]].Sum8_prob >= CONFIDENCE_THRESHOLD) { ++num_good_nonces; } } @@ -603,7 +601,7 @@ static uint16_t estimate_second_byte_sum(void) uint16_t num_good_nonces = 0; for (uint16_t i = 0; i < 256; i++) { - if (nonces[best_first_bytes[i]].Sum8_prob > CONFIDENCE_THRESHOLD) { + if (nonces[best_first_bytes[i]].Sum8_prob >= CONFIDENCE_THRESHOLD) { ++num_good_nonces; } } @@ -858,8 +856,14 @@ static int acquire_nonces(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_ } if (!initialize) { - if (!WaitForResponseTimeout(CMD_ACK, &resp, 3000)) return 1; - if (resp.arg[0]) return resp.arg[0]; // error during nested_hard + if (!WaitForResponseTimeout(CMD_ACK, &resp, 3000)) { + fclose(fnonces); + return 1; + } + if (resp.arg[0]) { + fclose(fnonces); + return resp.arg[0]; // error during nested_hard + } } initialize = false; @@ -1459,15 +1463,15 @@ int mfnestedhard(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBloc // best_first_bytes[9] ); PrintAndLog("Number of first bytes with confidence > %2.1f%%: %d", CONFIDENCE_THRESHOLD*100.0, num_good_first_bytes); - time_t start_time = clock(); + clock_t start_time = clock(); generate_candidates(first_byte_Sum, nonces[best_first_bytes[0]].Sum8_guess); PrintAndLog("Time for generating key candidates list: %1.0f seconds", (float)(clock() - start_time)/CLOCKS_PER_SEC); brute_force(); - free_nonces_memory(); - free_statelist_cache(); - free_candidates_memory(candidates); - candidates = NULL; + free_nonces_memory(); + free_statelist_cache(); + free_candidates_memory(candidates); + candidates = NULL; } return 0;