Skip to content

Commit

Permalink
Updated poly_tomsg to prevent a compiler from using DIV. Thanks to Go…
Browse files Browse the repository at this point in the history
…utam Tamvada, Karthikeyan Bhargavan, and Franziskus Kiefer @cryspen for pointing this out
  • Loading branch information
cryptojedi committed Dec 1, 2023
1 parent a621b8d commit dda29cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ref/poly.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,19 @@ void poly_frommsg(poly *r, const uint8_t msg[KYBER_INDCPA_MSGBYTES])
void poly_tomsg(uint8_t msg[KYBER_INDCPA_MSGBYTES], const poly *a)
{
unsigned int i,j;
uint16_t t;
uint32_t t;

for(i=0;i<KYBER_N/8;i++) {
msg[i] = 0;
for(j=0;j<8;j++) {
t = a->coeffs[8*i+j];
t += ((int16_t)t >> 15) & KYBER_Q;
t = (((t << 1) + KYBER_Q/2)/KYBER_Q) & 1;
// t += ((int16_t)t >> 15) & KYBER_Q;
// t = (((t << 1) + KYBER_Q/2)/KYBER_Q) & 1;
t <<= 1;
t += 1665;
t *= 80635;
t >>= 28;
t &= 1;
msg[i] |= t << j;
}
}
Expand Down
1 change: 1 addition & 0 deletions runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ else
fi

if [ "$ARCH" = "amd64" -o "$ARCH" = "arm64" ]; then
export CC="clang"
export CFLAGS="-fsanitize=address,undefined ${CFLAGS}"
fi

Expand Down

0 comments on commit dda29cc

Please sign in to comment.