| 1 |
#include <string.h> |
| 2 |
#include "compare.h" |
| 3 |
|
| 4 |
/* Const-time comparison from SUPERCOP, but here it's only used for |
| 5 |
signature verification, so doesn't need to be const-time. But |
| 6 |
copied the nacl version anyways. */ |
| 7 |
int crypto_verify_32_ref(const unsigned char *x, const unsigned char *y) |
| 8 |
{ |
| 9 |
unsigned int differentbits = 0; |
| 10 |
#define F(i) differentbits |= x[i] ^ y[i]; |
| 11 |
F(0) |
| 12 |
F(1) |
| 13 |
F(2) |
| 14 |
F(3) |
| 15 |
F(4) |
| 16 |
F(5) |
| 17 |
F(6) |
| 18 |
F(7) |
| 19 |
F(8) |
| 20 |
F(9) |
| 21 |
F(10) |
| 22 |
F(11) |
| 23 |
F(12) |
| 24 |
F(13) |
| 25 |
F(14) |
| 26 |
F(15) |
| 27 |
F(16) |
| 28 |
F(17) |
| 29 |
F(18) |
| 30 |
F(19) |
| 31 |
F(20) |
| 32 |
F(21) |
| 33 |
F(22) |
| 34 |
F(23) |
| 35 |
F(24) |
| 36 |
F(25) |
| 37 |
F(26) |
| 38 |
F(27) |
| 39 |
F(28) |
| 40 |
F(29) |
| 41 |
F(30) |
| 42 |
F(31) |
| 43 |
return (1 & ((differentbits - 1) >> 8)) - 1; |
| 44 |
} |