From 92611e300df7316bfba014d1b997a623e6d99f71 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Thu, 1 Aug 2024 14:25:32 +0200 Subject: [PATCH] Start introducing optblockers to prevent unwanted conditional jumps --- src/libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c b/src/libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c index 77184027df..501b9768e7 100644 --- a/src/libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c +++ b/src/libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c @@ -321,6 +321,8 @@ slide_vartime(signed char *r, const unsigned char *a) } } +static volatile unsigned char optblocker_u8; + int ge25519_frombytes(ge25519_p3 *h, const unsigned char *s) { @@ -353,7 +355,7 @@ ge25519_frombytes(ge25519_p3 *h, const unsigned char *s) fe25519_cmov(h->X, x_sqrtm1, 1 - has_m_root); fe25519_neg(negx, h->X); - fe25519_cmov(h->X, negx, fe25519_isnegative(h->X) ^ (s[31] >> 7)); + fe25519_cmov(h->X, negx, fe25519_isnegative(h->X) ^ (((s[31] >> 5) ^ optblocker_u8) >> 2)); fe25519_mul(h->T, h->X, h->Y); return (has_m_root | has_p_root) - 1;