Make it more difficult for the compiler to optimize crypto_verify_*()

This commit is contained in:
Frank Denis 2017-07-15 18:17:44 +02:00
parent c746eb2776
commit 37e99aa4fc

View File

@ -7,10 +7,14 @@
#include "crypto_verify_64.h" #include "crypto_verify_64.h"
int 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; const volatile unsigned char *volatile x =
int i; (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++) { for (i = 0; i < 16; i++) {
d |= x[i] ^ y[i]; d |= x[i] ^ y[i];
@ -25,10 +29,14 @@ crypto_verify_16_bytes(void)
} }
int 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; const volatile unsigned char *volatile x =
int i; (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++) { for (i = 0; i < 32; i++) {
d |= x[i] ^ y[i]; d |= x[i] ^ y[i];
@ -43,10 +51,14 @@ crypto_verify_32_bytes(void)
} }
int 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; const volatile unsigned char *volatile x =
int i; (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++) { for (i = 0; i < 64; i++) {
d |= x[i] ^ y[i]; d |= x[i] ^ y[i];