From 686c6a210d1dd516813e2b7dff792e4c7ffdcbf5 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sat, 18 Nov 2017 13:09:13 +0100 Subject: [PATCH] Help compilers vectorize --- .../curve25519/ref10/x25519_ref10.c | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c b/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c index 89fefbd6..022a7474 100644 --- a/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c +++ b/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c @@ -26,19 +26,21 @@ has_small_order(const unsigned char s[32]) { 0xda, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, { 0xdb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } }; + unsigned char c[12] = { 0 }; + unsigned int k; size_t i, j; - unsigned char c; - for (i = 0; i < sizeof blacklist / sizeof blacklist[0]; i++) { - c = 0; - for (j = 0; j < 32; j++) { - c |= s[j] ^ blacklist[i][j]; - } - if (c == 0) { - return 1; + COMPILER_ASSERT(12 == sizeof blacklist / sizeof blacklist[0]); + for (j = 0; j < 32; j++) { + for (i = 0; i < sizeof blacklist / sizeof blacklist[0]; i++) { + c[i] |= s[j] ^ blacklist[i][j]; } } - return 0; + k = 0; + for (i = 0; i < sizeof blacklist / sizeof blacklist[0]; i++) { + k |= (c[i] - 1); + } + return (int) ((k >> 8) & 1); } static int