1
1
mirror of https://github.com/henrydcase/pqc.git synced 2024-11-23 07:59:01 +00:00
pqcrypto/crypto_kem/saber/clean/verify.c

35 lines
1.0 KiB
C
Raw Normal View History

2019-06-18 10:00:33 +01:00
/*-------------------------------------------------
This file has been adapted from the implementation
(available at https://github.com/pq-crystals/kyber) of
"CRYSTALS Kyber: a CCA-secure module-lattice-based KEM"
by : Joppe Bos, Leo Ducas, Eike Kiltz, Tancrede Lepoint,
Vadim Lyubashevsky, John M. Schanck, Peter Schwabe & Damien stehle
----------------------------------------------------*/
#include "verify.h"
#include <stdint.h>
/* returns 0 for equal strings, 1 for non-equal strings */
2019-06-18 11:07:48 +01:00
unsigned char PQCLEAN_SABER_CLEAN_verify(const unsigned char *a, const unsigned char *b, size_t len) {
2019-06-18 10:00:33 +01:00
uint64_t r;
size_t i;
2019-06-18 13:20:59 +01:00
r = 0;
2019-06-18 10:00:33 +01:00
for (i = 0; i < len; i++) {
r |= a[i] ^ b[i];
}
2019-06-18 13:20:59 +01:00
r = (~r + 1); // Two's complement
r >>= 63;
return (unsigned char)r;
2019-06-18 10:00:33 +01:00
}
/* b = 1 means mov, b = 0 means don't mov*/
void PQCLEAN_SABER_CLEAN_cmov(unsigned char *r, const unsigned char *x, size_t len, unsigned char b) {
size_t i;
b = -b;
for (i = 0; i < len; i++) {
r[i] ^= b & (x[i] ^ r[i]);
}
}