diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-08-07 18:17:13 -0700 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-08-07 18:17:28 -0700 |
commit | d39c221f7e1ed9b4b17edb20803df792fc2f3465 (patch) | |
tree | ee3e7d0aa8bbbd53cd7c42f08a8284b54a03494c | |
parent | Inline all functions (diff) | |
download | kbench9000-d39c221f7e1ed9b4b17edb20803df792fc2f3465.tar.xz kbench9000-d39c221f7e1ed9b4b17edb20803df792fc2f3465.zip |
hacl64: better bittricks from samuel
-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) |