Simplify crypto_verify_*()

Do not expect any modern compiler not to be able to inline this.
This commit is contained in:
Frank Denis
2017-07-15 18:31:21 +02:00
parent 37e99aa4fc
commit 94a8b3327f
+25 -38
View File
@@ -6,52 +6,27 @@
#include "crypto_verify_32.h"
#include "crypto_verify_64.h"
int
crypto_verify_16(const unsigned char *x_, const unsigned char *y_)
{
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];
}
return (1 & ((d - 1) >> 8)) - 1;
}
size_t
crypto_verify_16_bytes(void)
{
return crypto_verify_16_BYTES;
}
int
crypto_verify_32(const unsigned char *x_, const unsigned char *y_)
{
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];
}
return (1 & ((d - 1) >> 8)) - 1;
}
size_t
crypto_verify_32_bytes(void)
{
return crypto_verify_32_BYTES;
}
int
crypto_verify_64(const unsigned char *x_, const unsigned char *y_)
size_t
crypto_verify_64_bytes(void)
{
return crypto_verify_64_BYTES;
}
static inline int
crypto_verify_n(const unsigned char *x_, const unsigned char *y_,
const size_t n)
{
const volatile unsigned char *volatile x =
(const volatile unsigned char *volatile) x_;
@@ -60,14 +35,26 @@ crypto_verify_64(const unsigned char *x_, const unsigned char *y_)
volatile uint_fast16_t d = 0U;
int i;
for (i = 0; i < 64; i++) {
for (i = 0; i < n; i++) {
d |= x[i] ^ y[i];
}
return (1 & ((d - 1) >> 8)) - 1;
}
size_t
crypto_verify_64_bytes(void)
int
crypto_verify_16(const unsigned char *x, const unsigned char *y)
{
return crypto_verify_64_BYTES;
return crypto_verify_n(x, y, crypto_verify_16_BYTES);
}
int
crypto_verify_32(const unsigned char *x, const unsigned char *y)
{
return crypto_verify_n(x, y, crypto_verify_32_BYTES);
}
int
crypto_verify_64(const unsigned char *x, const unsigned char *y)
{
return crypto_verify_n(x, y, crypto_verify_64_BYTES);
}