pqc/crypto_kem/kyber512/clean/verify.c

48 lines
1.5 KiB
C
Raw Normal View History

Kyberv2 (#150) * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * More fixes for MS compiler * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * More fixes for MS compiler * Started more cleanup work on Kyber768 * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * Making MS compiler happy * More fixes for MS compiler * More fixes for MS compiler * Started more cleanup work on Kyber768 * Kyber768 passing all tests locally * Kyber512 passes all tests locally * Kyber1024 now also passing all tests locally * Now passing all tests with -Wmissing-prototypes * Local tests (on Linux) passing again
2019-05-06 13:50:27 +01:00
#include "verify.h"
#include <stddef.h>
Kyberv2 (#150) * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * More fixes for MS compiler * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * More fixes for MS compiler * Started more cleanup work on Kyber768 * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * Making MS compiler happy * More fixes for MS compiler * More fixes for MS compiler * Started more cleanup work on Kyber768 * Kyber768 passing all tests locally * Kyber512 passes all tests locally * Kyber1024 now also passing all tests locally * Now passing all tests with -Wmissing-prototypes * Local tests (on Linux) passing again
2019-05-06 13:50:27 +01:00
#include <stdint.h>
/*************************************************
* Name: PQCLEAN_KYBER512_CLEAN_verify
Kyberv2 (#150) * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * More fixes for MS compiler * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * More fixes for MS compiler * Started more cleanup work on Kyber768 * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * Making MS compiler happy * More fixes for MS compiler * More fixes for MS compiler * Started more cleanup work on Kyber768 * Kyber768 passing all tests locally * Kyber512 passes all tests locally * Kyber1024 now also passing all tests locally * Now passing all tests with -Wmissing-prototypes * Local tests (on Linux) passing again
2019-05-06 13:50:27 +01:00
*
* Description: Compare two arrays for equality in constant time.
*
* Arguments: const uint8_t *a: pointer to first byte array
* const uint8_t *b: pointer to second byte array
* size_t len: length of the byte arrays
Kyberv2 (#150) * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * More fixes for MS compiler * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * More fixes for MS compiler * Started more cleanup work on Kyber768 * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * Making MS compiler happy * More fixes for MS compiler * More fixes for MS compiler * Started more cleanup work on Kyber768 * Kyber768 passing all tests locally * Kyber512 passes all tests locally * Kyber1024 now also passing all tests locally * Now passing all tests with -Wmissing-prototypes * Local tests (on Linux) passing again
2019-05-06 13:50:27 +01:00
*
* Returns 0 if the byte arrays are equal, 1 otherwise
**************************************************/
int PQCLEAN_KYBER512_CLEAN_verify(const uint8_t *a, const uint8_t *b, size_t len) {
size_t i;
uint8_t r = 0;
Kyberv2 (#150) * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * More fixes for MS compiler * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * More fixes for MS compiler * Started more cleanup work on Kyber768 * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * Making MS compiler happy * More fixes for MS compiler * More fixes for MS compiler * Started more cleanup work on Kyber768 * Kyber768 passing all tests locally * Kyber512 passes all tests locally * Kyber1024 now also passing all tests locally * Now passing all tests with -Wmissing-prototypes * Local tests (on Linux) passing again
2019-05-06 13:50:27 +01:00
for (i = 0; i < len; i++) {
r |= a[i] ^ b[i];
}
return (-(uint64_t)r) >> 63;
Kyberv2 (#150) * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * More fixes for MS compiler * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * More fixes for MS compiler * Started more cleanup work on Kyber768 * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * Making MS compiler happy * More fixes for MS compiler * More fixes for MS compiler * Started more cleanup work on Kyber768 * Kyber768 passing all tests locally * Kyber512 passes all tests locally * Kyber1024 now also passing all tests locally * Now passing all tests with -Wmissing-prototypes * Local tests (on Linux) passing again
2019-05-06 13:50:27 +01:00
}
/*************************************************
* Name: PQCLEAN_KYBER512_CLEAN_cmov
Kyberv2 (#150) * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * More fixes for MS compiler * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * More fixes for MS compiler * Started more cleanup work on Kyber768 * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * Making MS compiler happy * More fixes for MS compiler * More fixes for MS compiler * Started more cleanup work on Kyber768 * Kyber768 passing all tests locally * Kyber512 passes all tests locally * Kyber1024 now also passing all tests locally * Now passing all tests with -Wmissing-prototypes * Local tests (on Linux) passing again
2019-05-06 13:50:27 +01:00
*
* Description: Copy len bytes from x to r if b is 1;
* don't modify x if b is 0. Requires b to be in {0,1};
* assumes two's complement representation of negative integers.
* Runs in constant time.
*
* Arguments: uint8_t *r: pointer to output byte array
* const uint8_t *x: pointer to input byte array
* size_t len: Amount of bytes to be copied
* uint8_t b: Condition bit; has to be in {0,1}
Kyberv2 (#150) * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * More fixes for MS compiler * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * More fixes for MS compiler * Started more cleanup work on Kyber768 * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * Making MS compiler happy * More fixes for MS compiler * More fixes for MS compiler * Started more cleanup work on Kyber768 * Kyber768 passing all tests locally * Kyber512 passes all tests locally * Kyber1024 now also passing all tests locally * Now passing all tests with -Wmissing-prototypes * Local tests (on Linux) passing again
2019-05-06 13:50:27 +01:00
**************************************************/
void PQCLEAN_KYBER512_CLEAN_cmov(uint8_t *r, const uint8_t *x, size_t len, uint8_t b) {
size_t i;
Kyberv2 (#150) * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * More fixes for MS compiler * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * More fixes for MS compiler * Started more cleanup work on Kyber768 * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * Making MS compiler happy * More fixes for MS compiler * More fixes for MS compiler * Started more cleanup work on Kyber768 * Kyber768 passing all tests locally * Kyber512 passes all tests locally * Kyber1024 now also passing all tests locally * Now passing all tests with -Wmissing-prototypes * Local tests (on Linux) passing again
2019-05-06 13:50:27 +01:00
b = -b;
for (i = 0; i < len; i++) {
r[i] ^= b & (r[i] ^ x[i]);
Kyberv2 (#150) * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * More fixes for MS compiler * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * More fixes for MS compiler * Started more cleanup work on Kyber768 * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Replaced round-1 Kyber code with round-2 Kyber code (not yet cleaned/namespaced) * Namespacing for Kyber * Some more work on round-2 Kyber (more namespacing) * Added missing files * Round-2 Kyber768 now passing all tests under Linux * Various small tweaks to make MS compiler happy * Two more tweaks for MS compiler * Added Kyber512 and Kyber1024 (round-2 versions) * Making MS compiler happy * Making MS compiler happy * More fixes for MS compiler * More fixes for MS compiler * Started more cleanup work on Kyber768 * Kyber768 passing all tests locally * Kyber512 passes all tests locally * Kyber1024 now also passing all tests locally * Now passing all tests with -Wmissing-prototypes * Local tests (on Linux) passing again
2019-05-06 13:50:27 +01:00
}
}