diff --git a/src/RP.c b/src/RP.c index b03fb48..f899c15 100644 --- a/src/RP.c +++ b/src/RP.c @@ -52,6 +52,7 @@ void compute_RP_coeffs(Circuit* circuit, int cores, int coeff_max, int opt_incom } else { DimRedData* dim_red_data = remove_elementary_wires(circuit, true); + int original_coeff_max = coeff_max; int coeff_max_main_loop = coeff_max == -1 ? circuit->length : coeff_max > circuit->length ? circuit->length : coeff_max; @@ -93,7 +94,7 @@ void compute_RP_coeffs(Circuit* circuit, int cores, int coeff_max, int opt_incom if (size > 0) { printf("%"PRIu64", ", coeffs[size]); fflush(stdout); } - } + } for (int i = coeff_max_main_loop+1; i < dim_red_data->old_circuit->total_wires; i++) { printf("%"PRIu64", ", coeffs[i]); @@ -114,7 +115,7 @@ void compute_RP_coeffs(Circuit* circuit, int cores, int coeff_max, int opt_incom printf("pmin = %.10f -- log2(pmin) = %.10f\n", p_min, log2(p_min)); printf("\n"); - get_failure_proba(coeffs, circuit->total_wires+1, 0.01, coeff_max_main_loop); + get_failure_proba(coeffs, circuit->total_wires+1, 0.01, original_coeff_max); free_dim_red_data(dim_red_data); } } diff --git a/src/coeffs.c b/src/coeffs.c index 8b82d34..b1d5e2c 100644 --- a/src/coeffs.c +++ b/src/coeffs.c @@ -254,23 +254,24 @@ void get_failure_proba(uint64_t* coeffs, int len, double p, int coeff_max){ mpf_init_set_ui(coeffs_max[i], coeffs[i]); } - if(coeff_max != -1){ + if (coeff_max != -1) { for (int i = coeff_max+1; i < len; i++) { n_choose_k_gmp(i, len-1, coeffs_max[i]); } } mpf_t fp; - mpf_init(fp); + mpf_init_set_d(fp, 0.0); + for (int i = 1; i < len; i++) { mpf_t tmp, tmp2; mpf_init_set_d(tmp, p); mpf_pow_ui(tmp, tmp, i); - + mpf_init_set_d(tmp2, 1.0-p); - mpf_pow_ui(tmp2, tmp2, len-i); + mpf_pow_ui(tmp2, tmp2, len-i-1); mpf_mul(tmp, tmp, coeffs_max[i]); mpf_mul(tmp, tmp, tmp2); @@ -278,6 +279,7 @@ void get_failure_proba(uint64_t* coeffs, int len, double p, int coeff_max){ mpf_add(fp, fp, tmp); mpf_clear(tmp); + mpf_clear(tmp2); } gmp_printf("f(%.2lf) = %.10Ff\n", p, fp); @@ -321,7 +323,7 @@ void compute_combined_intermediate_leakage_proba(uint64_t* coeffs, int k, int to mpf_mul(tmp, tmp, coeffs_mpf[i]); mpf_mul(tmp, tmp, tmp2); - + mpf_add(fp_tmp, fp_tmp, tmp); mpf_clear(tmp); @@ -399,4 +401,4 @@ void compute_combined_final_proba(mpf_t epsilon, mpf_t mu){ mpf_clear(tmp); -} \ No newline at end of file +}