From 933b3e8ec1dfa94f9fde1f3c2725c3b6505ea738 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sat, 18 Nov 2017 13:19:00 +0100 Subject: [PATCH] Help compilers with vectorization --- .../crypto_core/ed25519/ref10/ed25519_ref10.c | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c b/src/libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c index 89a531fe..84eed89a 100644 --- a/src/libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c +++ b/src/libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c @@ -985,20 +985,24 @@ ge25519_has_small_order(const unsigned char s[32]) 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f } }; + unsigned char c[7] = { 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 < 31; j++) { - c |= s[j] ^ blacklist[i][j]; - } - c |= (s[j] & 0x7f) ^ blacklist[i][j]; - if (c == 0) { - return 1; + COMPILER_ASSERT(7 == sizeof blacklist / sizeof blacklist[0]); + for (j = 0; j < 31; j++) { + for (i = 0; i < sizeof blacklist / sizeof blacklist[0]; i++) { + c[i] |= s[j] ^ blacklist[i][j]; } } - return 0; + for (i = 0; i < sizeof blacklist / sizeof blacklist[0]; i++) { + c[i] |= (s[j] & 0x7f) ^ blacklist[i][j]; + } + k = 0; + for (i = 0; i < sizeof blacklist / sizeof blacklist[0]; i++) { + k |= (c[i] - 1); + } + return (int) ((k >> 8) & 1); } /*