From 333248de0326aac49425da3fe6bec4818a5d641d Mon Sep 17 00:00:00 2001 From: "John M. Schanck" Date: Tue, 1 Sep 2020 17:15:01 -0400 Subject: [PATCH] NTRU Prime: more unary negations --- crypto_kem/sntrup653/clean/crypto_core_invsntrup653.c | 2 +- crypto_kem/sntrup761/clean/crypto_core_invsntrup761.c | 2 +- crypto_kem/sntrup857/clean/crypto_core_invsntrup857.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crypto_kem/sntrup653/clean/crypto_core_invsntrup653.c b/crypto_kem/sntrup653/clean/crypto_core_invsntrup653.c index 572abb39..98705b0f 100644 --- a/crypto_kem/sntrup653/clean/crypto_core_invsntrup653.c +++ b/crypto_kem/sntrup653/clean/crypto_core_invsntrup653.c @@ -15,7 +15,7 @@ static int int16_nonzero_mask(int16 x) { uint16 u = (uint16) x; /* 0, else 1...65535 */ uint32 v = u; /* 0, else 1...65535 */ - v = -v; /* 0, else 2^32-65535...2^32-1 */ + v = ~v + 1; /* 0, else 2^32-65535...2^32-1 */ v >>= 31; /* 0, else 1 */ return -(int) v; /* 0, else -1 */ } diff --git a/crypto_kem/sntrup761/clean/crypto_core_invsntrup761.c b/crypto_kem/sntrup761/clean/crypto_core_invsntrup761.c index 16afe697..dab970d4 100644 --- a/crypto_kem/sntrup761/clean/crypto_core_invsntrup761.c +++ b/crypto_kem/sntrup761/clean/crypto_core_invsntrup761.c @@ -15,7 +15,7 @@ static int int16_nonzero_mask(int16 x) { uint16 u = (uint16) x; /* 0, else 1...65535 */ uint32 v = u; /* 0, else 1...65535 */ - v = -v; /* 0, else 2^32-65535...2^32-1 */ + v = ~v + 1; /* 0, else 2^32-65535...2^32-1 */ v >>= 31; /* 0, else 1 */ return -(int) v; /* 0, else -1 */ } diff --git a/crypto_kem/sntrup857/clean/crypto_core_invsntrup857.c b/crypto_kem/sntrup857/clean/crypto_core_invsntrup857.c index 383f2951..a8737a97 100644 --- a/crypto_kem/sntrup857/clean/crypto_core_invsntrup857.c +++ b/crypto_kem/sntrup857/clean/crypto_core_invsntrup857.c @@ -15,7 +15,7 @@ static int int16_nonzero_mask(int16 x) { uint16 u = (uint16) x; /* 0, else 1...65535 */ uint32 v = u; /* 0, else 1...65535 */ - v = -v; /* 0, else 2^32-65535...2^32-1 */ + v = ~v + 1; /* 0, else 2^32-65535...2^32-1 */ v >>= 31; /* 0, else 1 */ return -(int) v; /* 0, else -1 */ }