diff options
-rw-r--r-- | curve25519-hacl64.c | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/curve25519-hacl64.c b/curve25519-hacl64.c index 2f1ba14..258d1e9 100644 --- a/curve25519-hacl64.c +++ b/curve25519-hacl64.c @@ -20,24 +20,16 @@ static __always_inline void normalize_secret(u8 secret[CURVE25519_POINT_SIZE]) } typedef __uint128_t u128; - static __always_inline u64 u64_eq_mask(u64 x, u64 y) { - x = ~(x ^ y); - x &= x << 32; - x &= x << 16; - x &= x << 8; - x &= x << 4; - x &= x << 2; - x &= x << 1; - return ((s64)x) >> 63; + x ^= y; + x |= -x; + return (x >> 63) - 1; } static __always_inline u64 u64_gte_mask(u64 x, u64 y) { - u64 low63 = ~((u64)((s64)((s64)(x & 0x7fffffffffffffffLLU) - (s64)(y & 0x7fffffffffffffffLLU)) >> 63)); - u64 high_bit = ~((u64)((s64)((s64)(x & 0x8000000000000000LLU) - (s64)(y & 0x8000000000000000LLU)) >> 63)); - return low63 & high_bit; + return ((x ^ ((x ^ y) | ((x - y) ^ y))) >> 63) - 1; } static __always_inline void modulo_carry_top(u64 *b) |