in src/decode/decode.c [219:280]
ret_t decode(OUT e_t *e, IN const ct_t *ct, IN const sk_t *sk)
{
// Initialize the decode methods struct
decode_ctx ctx;
decode_ctx_init(&ctx);
DEFER_CLEANUP(e_t black_e = {0}, e_cleanup);
DEFER_CLEANUP(e_t gray_e = {0}, e_cleanup);
DEFER_CLEANUP(pad_r_t c0 = {0}, pad_r_cleanup);
DEFER_CLEANUP(pad_r_t h0 = {0}, pad_r_cleanup);
pad_r_t pk = {0};
// Pad ciphertext (c0), secret key (h0), and public key (h)
c0.val = ct->c0;
h0.val = sk->bin[0];
pk.val = sk->pk;
DEFER_CLEANUP(syndrome_t s = {0}, syndrome_cleanup);
DMSG(" Computing s.\n");
GUARD(compute_syndrome(&s, &c0, &h0, &ctx));
ctx.dup(&s);
// Reset (init) the error because it is xored in the find_err functions.
bike_memset(e, 0, sizeof(*e));
for(uint32_t iter = 0; iter < MAX_IT; iter++) {
const uint8_t threshold = get_threshold(&s);
DMSG(" Iteration: %d\n", iter);
DMSG(" Weight of e: %lu\n",
r_bits_vector_weight(&e->val[0]) + r_bits_vector_weight(&e->val[1]));
DMSG(" Weight of syndrome: %lu\n", r_bits_vector_weight((r_t *)s.qw));
find_err1(e, &black_e, &gray_e, &s, sk->wlist, threshold, &ctx);
GUARD(recompute_syndrome(&s, &c0, &h0, &pk, e, &ctx));
#if defined(BGF_DECODER)
if(iter >= 1) {
continue;
}
#endif
DMSG(" Weight of e: %lu\n",
r_bits_vector_weight(&e->val[0]) + r_bits_vector_weight(&e->val[1]));
DMSG(" Weight of syndrome: %lu\n", r_bits_vector_weight((r_t *)s.qw));
find_err2(e, &black_e, &s, sk->wlist, ((D + 1) / 2) + 1, &ctx);
GUARD(recompute_syndrome(&s, &c0, &h0, &pk, e, &ctx));
DMSG(" Weight of e: %lu\n",
r_bits_vector_weight(&e->val[0]) + r_bits_vector_weight(&e->val[1]));
DMSG(" Weight of syndrome: %lu\n", r_bits_vector_weight((r_t *)s.qw));
find_err2(e, &gray_e, &s, sk->wlist, ((D + 1) / 2) + 1, &ctx);
GUARD(recompute_syndrome(&s, &c0, &h0, &pk, e, &ctx));
}
if(r_bits_vector_weight((r_t *)s.qw) > 0) {
BIKE_ERROR(E_DECODING_FAILURE);
}
return SUCCESS;
}