From 37e99aa4fc684570f3fbd847a5963ba042f60a78 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sat, 15 Jul 2017 18:17:44 +0200 Subject: [PATCH] Make it more difficult for the compiler to optimize crypto_verify_*() --- src/libsodium/crypto_verify/sodium/verify.c | 30 ++++++++++++++------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/libsodium/crypto_verify/sodium/verify.c b/src/libsodium/crypto_verify/sodium/verify.c index f7626cf8..de06a3ea 100644 --- a/src/libsodium/crypto_verify/sodium/verify.c +++ b/src/libsodium/crypto_verify/sodium/verify.c @@ -7,10 +7,14 @@ #include "crypto_verify_64.h" int -crypto_verify_16(const unsigned char *x, const unsigned char *y) +crypto_verify_16(const unsigned char *x_, const unsigned char *y_) { - uint_fast16_t d = 0U; - int i; + const volatile unsigned char *volatile x = + (const volatile unsigned char *volatile) x_; + const volatile unsigned char *volatile y = + (const volatile unsigned char *volatile) y_; + volatile uint_fast16_t d = 0U; + int i; for (i = 0; i < 16; i++) { d |= x[i] ^ y[i]; @@ -25,10 +29,14 @@ crypto_verify_16_bytes(void) } int -crypto_verify_32(const unsigned char *x, const unsigned char *y) +crypto_verify_32(const unsigned char *x_, const unsigned char *y_) { - uint_fast16_t d = 0U; - int i; + const volatile unsigned char *volatile x = + (const volatile unsigned char *volatile) x_; + const volatile unsigned char *volatile y = + (const volatile unsigned char *volatile) y_; + volatile uint_fast16_t d = 0U; + int i; for (i = 0; i < 32; i++) { d |= x[i] ^ y[i]; @@ -43,10 +51,14 @@ crypto_verify_32_bytes(void) } int -crypto_verify_64(const unsigned char *x, const unsigned char *y) +crypto_verify_64(const unsigned char *x_, const unsigned char *y_) { - uint_fast16_t d = 0U; - int i; + const volatile unsigned char *volatile x = + (const volatile unsigned char *volatile) x_; + const volatile unsigned char *volatile y = + (const volatile unsigned char *volatile) y_; + volatile uint_fast16_t d = 0U; + int i; for (i = 0; i < 64; i++) { d |= x[i] ^ y[i];