Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/RP.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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]);
Expand All @@ -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);
}
}
14 changes: 8 additions & 6 deletions src/coeffs.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,30 +254,32 @@ 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);

mpf_add(fp, fp, tmp);

mpf_clear(tmp);
mpf_clear(tmp2);
}

gmp_printf("f(%.2lf) = %.10Ff\n", p, fp);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -399,4 +401,4 @@ void compute_combined_final_proba(mpf_t epsilon, mpf_t mu){

mpf_clear(tmp);

}
}