Files
Thom WiggersandGitHub 60f4825f49 Update Classic McEliece (#469)
* Update Classic McEliece

This updates classic mceliece to the SUPERCOP-20221025 version.
I'm generating this version from the SUPERCOP source code, and apply
patches that are listed in the repository.

The repository where this codes is coming from can be found at
https://github.com/thomwiggers/mceliece-clean.

* Fix linting warning in controlbits

* MacOS compatibility fixes

* Fix more MacOS conflicts

* Fix strict prototypes problem
2023-05-15 11:08:14 -04:00

66 lines
2.9 KiB
C

#include "crypto_int32.h"
crypto_int32 crypto_int32_negative_mask(crypto_int32 crypto_int32_x) {
return crypto_int32_x >> 31;
}
crypto_int32 crypto_int32_nonzero_mask(crypto_int32 crypto_int32_x) {
return crypto_int32_negative_mask(crypto_int32_x) | crypto_int32_negative_mask(-crypto_int32_x);
}
crypto_int32 crypto_int32_zero_mask(crypto_int32 crypto_int32_x) {
return ~crypto_int32_nonzero_mask(crypto_int32_x);
}
crypto_int32 crypto_int32_positive_mask(crypto_int32 crypto_int32_x) {
crypto_int32 crypto_int32_z = -crypto_int32_x;
crypto_int32_z ^= crypto_int32_x & crypto_int32_z;
return crypto_int32_negative_mask(crypto_int32_z);
}
crypto_int32 crypto_int32_unequal_mask(crypto_int32 crypto_int32_x, crypto_int32 crypto_int32_y) {
crypto_int32 crypto_int32_xy = crypto_int32_x ^ crypto_int32_y;
return crypto_int32_nonzero_mask(crypto_int32_xy);
}
crypto_int32 crypto_int32_equal_mask(crypto_int32 crypto_int32_x, crypto_int32 crypto_int32_y) {
return ~crypto_int32_unequal_mask(crypto_int32_x, crypto_int32_y);
}
crypto_int32 crypto_int32_smaller_mask(crypto_int32 crypto_int32_x, crypto_int32 crypto_int32_y) {
crypto_int32 crypto_int32_xy = crypto_int32_x ^ crypto_int32_y;
crypto_int32 crypto_int32_z = crypto_int32_x - crypto_int32_y;
crypto_int32_z ^= crypto_int32_xy & (crypto_int32_z ^ crypto_int32_x);
return crypto_int32_negative_mask(crypto_int32_z);
}
crypto_int32 crypto_int32_min(crypto_int32 crypto_int32_x, crypto_int32 crypto_int32_y) {
crypto_int32 crypto_int32_xy = crypto_int32_y ^ crypto_int32_x;
crypto_int32 crypto_int32_z = crypto_int32_y - crypto_int32_x;
crypto_int32_z ^= crypto_int32_xy & (crypto_int32_z ^ crypto_int32_y);
crypto_int32_z = crypto_int32_negative_mask(crypto_int32_z);
crypto_int32_z &= crypto_int32_xy;
return crypto_int32_x ^ crypto_int32_z;
}
crypto_int32 crypto_int32_max(crypto_int32 crypto_int32_x, crypto_int32 crypto_int32_y) {
crypto_int32 crypto_int32_xy = crypto_int32_y ^ crypto_int32_x;
crypto_int32 crypto_int32_z = crypto_int32_y - crypto_int32_x;
crypto_int32_z ^= crypto_int32_xy & (crypto_int32_z ^ crypto_int32_y);
crypto_int32_z = crypto_int32_negative_mask(crypto_int32_z);
crypto_int32_z &= crypto_int32_xy;
return crypto_int32_y ^ crypto_int32_z;
}
void crypto_int32_minmax(crypto_int32 *crypto_int32_a, crypto_int32 *crypto_int32_b) {
crypto_int32 crypto_int32_x = *crypto_int32_a;
crypto_int32 crypto_int32_y = *crypto_int32_b;
crypto_int32 crypto_int32_xy = crypto_int32_y ^ crypto_int32_x;
crypto_int32 crypto_int32_z = crypto_int32_y - crypto_int32_x;
crypto_int32_z ^= crypto_int32_xy & (crypto_int32_z ^ crypto_int32_y);
crypto_int32_z = crypto_int32_negative_mask(crypto_int32_z);
crypto_int32_z &= crypto_int32_xy;
*crypto_int32_a = crypto_int32_x ^ crypto_int32_z;
*crypto_int32_b = crypto_int32_y ^ crypto_int32_z;
}