mirror of
https://github.com/open-quantum-safe/liboqs.git
synced 2025-10-07 00:10:54 -04:00
Revert to fix globalspace pollution warnings
This commit is contained in:
parent
b91c93098f
commit
1bd6ef012f
@ -76,7 +76,7 @@ AM_CONDITIONAL([USE_SIDH_IQC], [test "x$sidhiqc" = xtrue])
|
||||
|
||||
|
||||
|
||||
AM_CPPFLAGS="-g -std=gnu11 -Werror -Wpedantic -Wall -Wextra -DCONSTANT_TIME"
|
||||
AM_CPPFLAGS="-g -std=gnu11 -Wno-unused-function -Werror -Wpedantic -Wall -Wextra -DCONSTANT_TIME"
|
||||
AC_CANONICAL_HOST
|
||||
# Check for which host we are on and setup a few things
|
||||
# specifically based on the host
|
||||
|
@ -8,7 +8,8 @@
|
||||
#include "poly.c"
|
||||
// clang-format on
|
||||
|
||||
static void encode_a(unsigned char *r, const poly *pk, const unsigned char *seed) {
|
||||
static void encode_a(unsigned char *r, const poly *pk,
|
||||
const unsigned char *seed) {
|
||||
int i;
|
||||
poly_tobytes(r, pk);
|
||||
for (i = 0; i < NEWHOPE_SEEDBYTES; i++) {
|
||||
@ -28,7 +29,9 @@ static void encode_b(unsigned char *r, const poly *b, const poly *c) {
|
||||
int i;
|
||||
poly_tobytes(r, b);
|
||||
for (i = 0; i < PARAM_N / 4; i++) {
|
||||
r[POLY_BYTES + i] = c->coeffs[4 * i] | (c->coeffs[4 * i + 1] << 2) | (c->coeffs[4 * i + 2] << 4) | (c->coeffs[4 * i + 3] << 6);
|
||||
r[POLY_BYTES + i] = c->coeffs[4 * i] | (c->coeffs[4 * i + 1] << 2) |
|
||||
(c->coeffs[4 * i + 2] << 4) |
|
||||
(c->coeffs[4 * i + 3] << 6);
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,13 +46,11 @@ static void decode_b(poly *b, poly *c, const unsigned char *r) {
|
||||
}
|
||||
}
|
||||
|
||||
static void gen_a(poly *a, const unsigned char *seed) {
|
||||
poly_uniform(a, seed);
|
||||
}
|
||||
static void gen_a(poly *a, const unsigned char *seed) { poly_uniform(a, seed); }
|
||||
|
||||
// API FUNCTIONS
|
||||
|
||||
void keygen(unsigned char *send, poly *sk, OQS_RAND *rand) {
|
||||
static void keygen(unsigned char *send, poly *sk, OQS_RAND *rand) {
|
||||
poly a, e, r, pk;
|
||||
unsigned char seed[NEWHOPE_SEEDBYTES];
|
||||
|
||||
@ -69,7 +70,8 @@ void keygen(unsigned char *send, poly *sk, OQS_RAND *rand) {
|
||||
encode_a(send, &pk, seed);
|
||||
}
|
||||
|
||||
void sharedb(unsigned char *sharedkey, unsigned char *send, const unsigned char *received, OQS_RAND *rand) {
|
||||
static void sharedb(unsigned char *sharedkey, unsigned char *send,
|
||||
const unsigned char *received, OQS_RAND *rand) {
|
||||
poly sp, ep, v, a, pka, c, epp, bp;
|
||||
unsigned char seed[NEWHOPE_SEEDBYTES];
|
||||
|
||||
@ -101,7 +103,8 @@ void sharedb(unsigned char *sharedkey, unsigned char *send, const unsigned char
|
||||
#endif
|
||||
}
|
||||
|
||||
void shareda(unsigned char *sharedkey, const poly *sk, const unsigned char *received) {
|
||||
static void shareda(unsigned char *sharedkey, const poly *sk,
|
||||
const unsigned char *received) {
|
||||
poly v, bp, c;
|
||||
|
||||
decode_b(&bp, &c, received);
|
||||
@ -115,4 +118,3 @@ void shareda(unsigned char *sharedkey, const poly *sk, const unsigned char *rece
|
||||
OQS_SHA3_sha3256(sharedkey, sharedkey, 32);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,8 @@ static void ntt(uint16_t *a, const uint16_t *omega) {
|
||||
W = omega[jTwiddle++];
|
||||
temp = a[j];
|
||||
a[j] = (temp + a[j + distance]); // Omit reduction (be lazy)
|
||||
a[j + distance] = montgomery_reduce((W * ((uint32_t) temp + 3 * PARAM_Q - a[j + distance])));
|
||||
a[j + distance] = montgomery_reduce(
|
||||
(W * ((uint32_t)temp + 3 * PARAM_Q - a[j + distance])));
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,28 +81,36 @@ static void ntt(uint16_t *a, const uint16_t *omega) {
|
||||
W = omega[jTwiddle++];
|
||||
temp = a[j];
|
||||
a[j] = barrett_reduce((temp + a[j + distance]));
|
||||
a[j + distance] = montgomery_reduce((W * ((uint32_t) temp + 3 * PARAM_Q - a[j + distance])));
|
||||
a[j + distance] = montgomery_reduce(
|
||||
(W * ((uint32_t)temp + 3 * PARAM_Q - a[j + distance])));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void poly_frombytes(poly *r, const unsigned char *a) {
|
||||
static void poly_frombytes(poly *r, const unsigned char *a) {
|
||||
int i;
|
||||
for (i = 0; i < PARAM_N / 4; i++) {
|
||||
r->coeffs[4 * i + 0] = a[7 * i + 0] | (((uint16_t) a[7 * i + 1] & 0x3f) << 8);
|
||||
r->coeffs[4 * i + 1] = (a[7 * i + 1] >> 6) | (((uint16_t) a[7 * i + 2]) << 2) | (((uint16_t) a[7 * i + 3] & 0x0f) << 10);
|
||||
r->coeffs[4 * i + 2] = (a[7 * i + 3] >> 4) | (((uint16_t) a[7 * i + 4]) << 4) | (((uint16_t) a[7 * i + 5] & 0x03) << 12);
|
||||
r->coeffs[4 * i + 3] = (a[7 * i + 5] >> 2) | (((uint16_t) a[7 * i + 6]) << 6);
|
||||
r->coeffs[4 * i + 0] =
|
||||
a[7 * i + 0] | (((uint16_t)a[7 * i + 1] & 0x3f) << 8);
|
||||
r->coeffs[4 * i + 1] = (a[7 * i + 1] >> 6) |
|
||||
(((uint16_t)a[7 * i + 2]) << 2) |
|
||||
(((uint16_t)a[7 * i + 3] & 0x0f) << 10);
|
||||
r->coeffs[4 * i + 2] = (a[7 * i + 3] >> 4) |
|
||||
(((uint16_t)a[7 * i + 4]) << 4) |
|
||||
(((uint16_t)a[7 * i + 5] & 0x03) << 12);
|
||||
r->coeffs[4 * i + 3] =
|
||||
(a[7 * i + 5] >> 2) | (((uint16_t)a[7 * i + 6]) << 6);
|
||||
}
|
||||
}
|
||||
|
||||
void poly_tobytes(unsigned char *r, const poly *p) {
|
||||
static void poly_tobytes(unsigned char *r, const poly *p) {
|
||||
int i;
|
||||
uint16_t t0, t1, t2, t3, m;
|
||||
int16_t c;
|
||||
for (i = 0; i < PARAM_N / 4; i++) {
|
||||
t0 = barrett_reduce(p->coeffs[4 * i + 0]); //Make sure that coefficients have only 14 bits
|
||||
t0 = barrett_reduce(
|
||||
p->coeffs[4 * i + 0]); // Make sure that coefficients have only 14 bits
|
||||
t1 = barrett_reduce(p->coeffs[4 * i + 1]);
|
||||
t2 = barrett_reduce(p->coeffs[4 * i + 2]);
|
||||
t3 = barrett_reduce(p->coeffs[4 * i + 3]);
|
||||
@ -136,7 +145,7 @@ void poly_tobytes(unsigned char *r, const poly *p) {
|
||||
}
|
||||
}
|
||||
|
||||
void poly_uniform(poly *a, const unsigned char *seed) {
|
||||
static void poly_uniform(poly *a, const unsigned char *seed) {
|
||||
unsigned int pos = 0, ctr = 0;
|
||||
uint16_t val;
|
||||
uint64_t state[OQS_SHA3_STATESIZE];
|
||||
@ -148,7 +157,8 @@ void poly_uniform(poly *a, const unsigned char *seed) {
|
||||
OQS_SHA3_shake128_squeezeblocks((unsigned char *)buf, nblocks, state);
|
||||
|
||||
while (ctr < PARAM_N) {
|
||||
val = (buf[pos] | ((uint16_t) buf[pos + 1] << 8)) & 0x3fff; // Specialized for q = 12889
|
||||
val = (buf[pos] | ((uint16_t)buf[pos + 1] << 8)) &
|
||||
0x3fff; // Specialized for q = 12889
|
||||
if (val < PARAM_Q) {
|
||||
a->coeffs[ctr++] = val;
|
||||
}
|
||||
@ -161,7 +171,7 @@ void poly_uniform(poly *a, const unsigned char *seed) {
|
||||
}
|
||||
}
|
||||
|
||||
void poly_getnoise(poly *r, OQS_RAND *rand) {
|
||||
static void poly_getnoise(poly *r, OQS_RAND *rand) {
|
||||
#if PARAM_K != 16
|
||||
#error "poly_getnoise in poly.c only supports k=16"
|
||||
#endif
|
||||
@ -186,28 +196,30 @@ void poly_getnoise(poly *r, OQS_RAND *rand) {
|
||||
}
|
||||
}
|
||||
|
||||
void poly_pointwise(poly *r, const poly *a, const poly *b) {
|
||||
static void poly_pointwise(poly *r, const poly *a, const poly *b) {
|
||||
int i;
|
||||
uint16_t t;
|
||||
for (i = 0; i < PARAM_N; i++) {
|
||||
t = montgomery_reduce(3186 * b->coeffs[i]); /* t is now in Montgomery domain */
|
||||
r->coeffs[i] = montgomery_reduce(a->coeffs[i] * t); /* r->coeffs[i] is back in normal domain */
|
||||
t = montgomery_reduce(3186 *
|
||||
b->coeffs[i]); /* t is now in Montgomery domain */
|
||||
r->coeffs[i] = montgomery_reduce(
|
||||
a->coeffs[i] * t); /* r->coeffs[i] is back in normal domain */
|
||||
}
|
||||
}
|
||||
|
||||
void poly_add(poly *r, const poly *a, const poly *b) {
|
||||
static void poly_add(poly *r, const poly *a, const poly *b) {
|
||||
int i;
|
||||
for (i = 0; i < PARAM_N; i++) {
|
||||
r->coeffs[i] = barrett_reduce(a->coeffs[i] + b->coeffs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void poly_ntt(poly *r) {
|
||||
static void poly_ntt(poly *r) {
|
||||
mul_coefficients(r->coeffs, psis_bitrev_montgomery);
|
||||
ntt((uint16_t *)r->coeffs, omegas_montgomery);
|
||||
}
|
||||
|
||||
void poly_invntt(poly *r) {
|
||||
static void poly_invntt(poly *r) {
|
||||
bitrev_vector(r->coeffs);
|
||||
ntt((uint16_t *)r->coeffs, omegas_inv_montgomery);
|
||||
mul_coefficients(r->coeffs, psis_inv_montgomery);
|
||||
@ -274,7 +286,7 @@ static int16_t LDDecode(int32_t xi0, int32_t xi1, int32_t xi2, int32_t xi3) {
|
||||
return t & 1;
|
||||
}
|
||||
|
||||
void helprec(poly *c, const poly *v, OQS_RAND *oqs_rand) {
|
||||
static void helprec(poly *c, const poly *v, OQS_RAND *oqs_rand) {
|
||||
int32_t v0[4], v1[4], v_tmp[4], k;
|
||||
unsigned char rbit;
|
||||
unsigned char rand[32];
|
||||
@ -304,7 +316,7 @@ void helprec(poly *c, const poly *v, OQS_RAND *oqs_rand) {
|
||||
}
|
||||
}
|
||||
|
||||
void rec(unsigned char *key, const poly *v, const poly *c) {
|
||||
static void rec(unsigned char *key, const poly *v, const poly *c) {
|
||||
int i;
|
||||
int32_t tmp[4];
|
||||
|
||||
@ -313,10 +325,14 @@ void rec(unsigned char *key, const poly *v, const poly *c) {
|
||||
}
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
tmp[0] = 16 * PARAM_Q + 8 * (int32_t) v->coeffs[0 + i] - PARAM_Q * (2 * c->coeffs[0 + i] + c->coeffs[768 + i]);
|
||||
tmp[1] = 16 * PARAM_Q + 8 * (int32_t) v->coeffs[256 + i] - PARAM_Q * (2 * c->coeffs[256 + i] + c->coeffs[768 + i]);
|
||||
tmp[2] = 16 * PARAM_Q + 8 * (int32_t) v->coeffs[512 + i] - PARAM_Q * (2 * c->coeffs[512 + i] + c->coeffs[768 + i]);
|
||||
tmp[3] = 16 * PARAM_Q + 8 * (int32_t) v->coeffs[768 + i] - PARAM_Q * (c->coeffs[768 + i]);
|
||||
tmp[0] = 16 * PARAM_Q + 8 * (int32_t)v->coeffs[0 + i] -
|
||||
PARAM_Q * (2 * c->coeffs[0 + i] + c->coeffs[768 + i]);
|
||||
tmp[1] = 16 * PARAM_Q + 8 * (int32_t)v->coeffs[256 + i] -
|
||||
PARAM_Q * (2 * c->coeffs[256 + i] + c->coeffs[768 + i]);
|
||||
tmp[2] = 16 * PARAM_Q + 8 * (int32_t)v->coeffs[512 + i] -
|
||||
PARAM_Q * (2 * c->coeffs[512 + i] + c->coeffs[768 + i]);
|
||||
tmp[3] = 16 * PARAM_Q + 8 * (int32_t)v->coeffs[768 + i] -
|
||||
PARAM_Q * (c->coeffs[768 + i]);
|
||||
|
||||
key[i >> 3] |= LDDecode(tmp[0], tmp[1], tmp[2], tmp[3]) << (i & 7);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user