ENC: fix encryption

It was actually broken, since we did overwrite the
out-coefficients instead of adding to them. Fixing this
again causes the same problems as described in the
inline comment, no matter which implementation we use.
This commit is contained in:
hasufell 2014-05-29 16:46:35 +02:00
parent a050b8853a
commit bdc3aad651
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
1 changed files with 4 additions and 17 deletions

View File

@ -59,23 +59,10 @@ ntru_encrypt_poly(
fmpz_poly_zero(out);
poly_starmultiply(pub_key, rnd, out, ctx, ctx->q);
/*
* using the flint functions
* fmpz_poly_add(out, out, tmp_poly_msg);
* fmpz_poly_mod_unsigned(out, ctx->q);
* here instead caused very rare glitches in some cases,
* TODO: investigate
*/
for (uint32_t i = 0; i < ctx->N; i++) {
fmpz_t e_coeff_i;
fmpz *m_coeff_i = fmpz_poly_get_coeff_ptr(tmp_poly_msg, i);
fmpz_init(e_coeff_i);
fmpz_add_n(e_coeff_i, e_coeff_i, m_coeff_i);
fmpz_mod_ui(e_coeff_i, e_coeff_i, ctx->q);
fmpz_poly_set_coeff_fmpz_n(out, i, e_coeff_i);
}
/* FIXME: causes rare junk chars in some cases,
* which is perfectly reproducible, so this is not UB */
fmpz_poly_add(out, out, tmp_poly_msg);
fmpz_poly_mod_unsigned(out, ctx->q);
fmpz_poly_clear(tmp_poly_msg);