Skip to content

Commit 8ecef2f

Browse files
Faster wipe traces in spritz_compare
1 parent 90ed6bc commit 8ecef2f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/SpritzCipher.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ spritz_compare(const uint8_t *data_a, const uint8_t *data_b, uint16_t len)
232232
}
233233

234234
#ifdef SPRITZ_WIPE_TRACES_PARANOID
235+
# if !defined(__GNUC__) && !defined(__clang__)
236+
/* Not GCC or Clang, Optimization isn't off. */
235237
/* It may be possible to use `d=!!d;` for performnce,
236238
* But audit the assembly code first.
237239
*/
@@ -243,6 +245,16 @@ spritz_compare(const uint8_t *data_a, const uint8_t *data_b, uint16_t len)
243245
d |= d >> 6; /* |_|S|_|_|_|_|_|D| */
244246
d |= d >> 7; /* |S|_|_|_|_|_|_|D| */
245247
d &= 1; /* |0|0|0|0|0|0|0|D| Zero all bits except LSB */
248+
# else
249+
/* Else if GCC or Clang, no optimization */
250+
/* Timing-safe non-zero value to `1`. */
251+
if (d == 0U) {
252+
d = 0U;
253+
}
254+
else {
255+
d = 1U;
256+
}
257+
# endif
246258
#endif
247259

248260
return d;

0 commit comments

Comments
 (0)