Skip to content

Commit 67a429f

Browse files
Suppress a harmless variable-time optimization by clang in _int_cmov
Follow up on 52a0351
1 parent 5b19633 commit 67a429f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/util.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,15 @@ static SECP256K1_INLINE void memczero(void *s, size_t len, int flag) {
197197
/** If flag is true, set *r equal to *a; otherwise leave it. Constant-time. Both *r and *a must be initialized and non-negative.*/
198198
static SECP256K1_INLINE void secp256k1_int_cmov(int *r, const int *a, int flag) {
199199
unsigned int mask0, mask1, r_masked, a_masked;
200+
/* Access flag with a volatile-qualified lvalue.
201+
This prevents clang from figuring out (after inlining) that flag can
202+
take only be 0 or 1, which leads to variable time code. */
203+
volatile int vflag = flag;
204+
200205
/* Casting a negative int to unsigned and back to int is implementation defined behavior */
201206
VERIFY_CHECK(*r >= 0 && *a >= 0);
202207

203-
mask0 = (unsigned int)flag + ~0u;
208+
mask0 = (unsigned int)vflag + ~0u;
204209
mask1 = ~mask0;
205210
r_masked = ((unsigned int)*r & mask0);
206211
a_masked = ((unsigned int)*a & mask1);

0 commit comments

Comments
 (0)