1
1
mirror of https://github.com/henrydcase/pqc.git synced 2024-11-22 23:48:58 +00:00

Fix overflowing mults in NTRUHRSS701

This commit is contained in:
Thom Wiggers 2020-03-09 18:02:44 -04:00
parent 39fa1ccfc7
commit bc86182b93
No known key found for this signature in database
GPG Key ID: 001BB0A7CE26E363

View File

@ -37,14 +37,14 @@ void PQCLEAN_NTRUHRSS701_CLEAN_sample_iid_plus(poly *r, const unsigned char unif
/* s = <x*r, r>. (r[n-1] = 0) */
for (i = 0; i < NTRU_N - 1; i++) {
s += r->coeffs[i + 1] * r->coeffs[i];
s += (uint16_t)((uint32_t)r->coeffs[i + 1] * (uint32_t)r->coeffs[i]);
}
/* Extract sign of s (sign(0) = 1) */
s = 1 | (-(s >> 15));
for (i = 0; i < NTRU_N; i += 2) {
r->coeffs[i] = s * r->coeffs[i];
r->coeffs[i] = (uint16_t)((uint32_t)s * (uint32_t)r->coeffs[i]);
}
/* Map {0,1,2^16-1} -> {0, 1, 2} */