Skip to content

Commit dda29cc

Browse files
committed
Updated poly_tomsg to prevent a compiler from using DIV. Thanks to Goutam Tamvada, Karthikeyan Bhargavan, and Franziskus Kiefer @cryspen for pointing this out
1 parent a621b8d commit dda29cc

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

ref/poly.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,19 @@ void poly_frommsg(poly *r, const uint8_t msg[KYBER_INDCPA_MSGBYTES])
180180
void poly_tomsg(uint8_t msg[KYBER_INDCPA_MSGBYTES], const poly *a)
181181
{
182182
unsigned int i,j;
183-
uint16_t t;
183+
uint32_t t;
184184

185185
for(i=0;i<KYBER_N/8;i++) {
186186
msg[i] = 0;
187187
for(j=0;j<8;j++) {
188188
t = a->coeffs[8*i+j];
189-
t += ((int16_t)t >> 15) & KYBER_Q;
190-
t = (((t << 1) + KYBER_Q/2)/KYBER_Q) & 1;
189+
// t += ((int16_t)t >> 15) & KYBER_Q;
190+
// t = (((t << 1) + KYBER_Q/2)/KYBER_Q) & 1;
191+
t <<= 1;
192+
t += 1665;
193+
t *= 80635;
194+
t >>= 28;
195+
t &= 1;
191196
msg[i] |= t << j;
192197
}
193198
}

runtests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ else
1010
fi
1111

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

0 commit comments

Comments
 (0)