Slightly faster verify_{16,32,64}

This commit is contained in:
Frank Denis
2015-11-25 12:19:17 +01:00
parent d5fd75dcc7
commit 65fbe15fa3
3 changed files with 72 additions and 124 deletions
+24 -20
View File
@@ -1,24 +1,28 @@
#include <stddef.h>
#include <stdint.h>
#include "crypto_verify_16.h"
int crypto_verify_16(const unsigned char *x,const unsigned char *y)
int
crypto_verify_16(const unsigned char *x, const unsigned char *y)
{
unsigned int differentbits = 0;
#define F(i) differentbits |= x[i] ^ y[i];
F(0)
F(1)
F(2)
F(3)
F(4)
F(5)
F(6)
F(7)
F(8)
F(9)
F(10)
F(11)
F(12)
F(13)
F(14)
F(15)
return (1 & ((differentbits - 1) >> 8)) - 1;
#ifdef CPU_UNALIGNED_ACCESS
uint_fast64_t d = 0U;
int i;
for (i = 0; i < 16; i += 4) {
d |= *((const uint32_t *) (const void *) &x[i]) ^
*((const uint32_t *) (const void *) &y[i]);
}
return (1 & ((d - 1) >> 32)) - 1;
#else
uint_fast16_t d = 0U;
int i;
for (i = 0; i < 16; i++) {
d |= x[i] ^ y[i];
}
return (1 & ((d - 1) >> 8)) - 1;
#endif
}
+24 -36
View File
@@ -1,40 +1,28 @@
#include <stddef.h>
#include <stdint.h>
#include "crypto_verify_32.h"
int crypto_verify_32(const unsigned char *x,const unsigned char *y)
int
crypto_verify_32(const unsigned char *x, const unsigned char *y)
{
unsigned int differentbits = 0;
#define F(i) differentbits |= x[i] ^ y[i];
F(0)
F(1)
F(2)
F(3)
F(4)
F(5)
F(6)
F(7)
F(8)
F(9)
F(10)
F(11)
F(12)
F(13)
F(14)
F(15)
F(16)
F(17)
F(18)
F(19)
F(20)
F(21)
F(22)
F(23)
F(24)
F(25)
F(26)
F(27)
F(28)
F(29)
F(30)
F(31)
return (1 & ((differentbits - 1) >> 8)) - 1;
#ifdef CPU_UNALIGNED_ACCESS
uint_fast64_t d = 0U;
int i;
for (i = 0; i < 32; i += 4) {
d |= *((const uint32_t *) (const void *) &x[i]) ^
*((const uint32_t *) (const void *) &y[i]);
}
return (1 & ((d - 1) >> 32)) - 1;
#else
uint_fast16_t d = 0U;
int i;
for (i = 0; i < 32; i++) {
d |= x[i] ^ y[i];
}
return (1 & ((d - 1) >> 8)) - 1;
#endif
}
+24 -68
View File
@@ -1,72 +1,28 @@
#include <stddef.h>
#include <stdint.h>
#include "crypto_verify_64.h"
int crypto_verify_64(const unsigned char *x,const unsigned char *y)
int
crypto_verify_64(const unsigned char *x, const unsigned char *y)
{
unsigned int differentbits = 0;
#define F(i) differentbits |= x[i] ^ y[i];
F(0)
F(1)
F(2)
F(3)
F(4)
F(5)
F(6)
F(7)
F(8)
F(9)
F(10)
F(11)
F(12)
F(13)
F(14)
F(15)
F(16)
F(17)
F(18)
F(19)
F(20)
F(21)
F(22)
F(23)
F(24)
F(25)
F(26)
F(27)
F(28)
F(29)
F(30)
F(31)
F(32)
F(33)
F(34)
F(35)
F(36)
F(37)
F(38)
F(39)
F(40)
F(41)
F(42)
F(43)
F(44)
F(45)
F(46)
F(47)
F(48)
F(49)
F(50)
F(51)
F(52)
F(53)
F(54)
F(55)
F(56)
F(57)
F(58)
F(59)
F(60)
F(61)
F(62)
F(63)
return (1 & ((differentbits - 1) >> 8)) - 1;
#ifdef CPU_UNALIGNED_ACCESS
uint_fast64_t d = 0U;
int i;
for (i = 0; i < 64; i += 4) {
d |= *((const uint32_t *) (const void *) &x[i]) ^
*((const uint32_t *) (const void *) &y[i]);
}
return (1 & ((d - 1) >> 32)) - 1;
#else
uint_fast16_t d = 0U;
int i;
for (i = 0; i < 64; i++) {
d |= x[i] ^ y[i];
}
return (1 & ((d - 1) >> 8)) - 1;
#endif
}