FIX: 'hf mf hardnested' @matrix e0828439bf

This commit is contained in:
iceman1001 2016-11-08 13:27:50 +01:00
parent 0b53530a10
commit 71ac327ba8

View file

@ -280,15 +280,16 @@ static float sum_probability(uint16_t K, uint16_t n, uint16_t k)
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);
if (p_T_is_k_when_S_is_K == 0.0) return 0.0;
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) {
double tmp = p_hypergeometric(N, i, n, k);
if (tmp != 0.0)
p_T_is_k += p_K[i] * tmp;
p_T_is_k += p_K[i] * p_hypergeometric(N, i, n, k);
}
}
if (p_T_is_k == 0.0) return 0.0;
return(p_T_is_k_when_S_is_K * p_S_is_K / p_T_is_k);
}
@ -1157,7 +1158,7 @@ static int add_matching_states(statelist_t *candidates, uint16_t part_sum_a0, ui
for (uint32_t *p1 = partial_statelist[part_sum_a0].states[odd_even]; *p1 != END_OF_LIST_MARKER; p1++) {
uint32_t search_mask = 0x000ffff0;
uint32_t *p2 = find_first_state((*p1 << 4), search_mask, &partial_statelist[part_sum_a8], odd_even);
if (p2 != NULL) {
if (p1 != NULL && p2 != NULL) {
while (((*p1 << 4) & search_mask) == (*p2 & search_mask) && *p2 != END_OF_LIST_MARKER) {
if ((nonces[best_first_bytes[0]].BitFlip[odd_even] && find_first_state((*p1 << 4) | *p2, 0x000fffff, &statelist_bitflip, 0))
|| !nonces[best_first_bytes[0]].BitFlip[odd_even]) {
@ -1195,6 +1196,8 @@ static statelist_t *add_more_candidates(statelist_t *current_candidates)
} else {
new_candidates = current_candidates->next = (statelist_t *)malloc(sizeof(statelist_t));
}
if (!new_candidates) return NULL;
new_candidates->next = NULL;
new_candidates->len[ODD_STATE] = 0;
new_candidates->len[EVEN_STATE] = 0;
@ -1287,7 +1290,7 @@ static bool generate_candidates(uint16_t sum_a0, uint16_t sum_a8)
for (uint16_t s = 0; s <= 16; s += 2) {
if (r*(16-s) + (16-r)*s == sum_a8) {
current_candidates = add_more_candidates(current_candidates);
if (current_candidates) {
if (current_candidates != NULL) {
// check for the smallest partial statelist. Try this first - it might give 0 candidates
// and eliminate the need to calculate the other part
if (MIN(partial_statelist[p].len[ODD_STATE], partial_statelist[r].len[ODD_STATE])