mirror of
https://github.com/henrydcase/pqc.git
synced 2024-11-22 23:48:58 +00:00
Some cosmetic changes to appease clang-tidy.
This commit is contained in:
parent
192e72144b
commit
87bc13c761
@ -75,7 +75,7 @@ PQCLEAN_FALCON1024_CLEAN_modq_encode(
|
|||||||
size_t
|
size_t
|
||||||
PQCLEAN_FALCON1024_CLEAN_modq_decode(
|
PQCLEAN_FALCON1024_CLEAN_modq_decode(
|
||||||
uint16_t *x, unsigned logn,
|
uint16_t *x, unsigned logn,
|
||||||
const void *in, size_t in_max_len) {
|
const void *in, size_t max_in_len) {
|
||||||
size_t n, in_len, u;
|
size_t n, in_len, u;
|
||||||
const uint8_t *buf;
|
const uint8_t *buf;
|
||||||
uint32_t acc;
|
uint32_t acc;
|
||||||
@ -83,7 +83,7 @@ PQCLEAN_FALCON1024_CLEAN_modq_decode(
|
|||||||
|
|
||||||
n = (size_t)1 << logn;
|
n = (size_t)1 << logn;
|
||||||
in_len = ((n * 14) + 7) >> 3;
|
in_len = ((n * 14) + 7) >> 3;
|
||||||
if (in_len > in_max_len) {
|
if (in_len > max_in_len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
buf = in;
|
buf = in;
|
||||||
@ -132,7 +132,8 @@ PQCLEAN_FALCON1024_CLEAN_trim_i16_encode(
|
|||||||
out_len = ((n * bits) + 7) >> 3;
|
out_len = ((n * bits) + 7) >> 3;
|
||||||
if (out == NULL) {
|
if (out == NULL) {
|
||||||
return out_len;
|
return out_len;
|
||||||
} else if (out_len > max_out_len) {
|
}
|
||||||
|
if (out_len > max_out_len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
buf = out;
|
buf = out;
|
||||||
@ -157,7 +158,7 @@ PQCLEAN_FALCON1024_CLEAN_trim_i16_encode(
|
|||||||
size_t
|
size_t
|
||||||
PQCLEAN_FALCON1024_CLEAN_trim_i16_decode(
|
PQCLEAN_FALCON1024_CLEAN_trim_i16_decode(
|
||||||
int16_t *x, unsigned logn, unsigned bits,
|
int16_t *x, unsigned logn, unsigned bits,
|
||||||
const void *in, size_t in_max_len) {
|
const void *in, size_t max_in_len) {
|
||||||
size_t n, in_len;
|
size_t n, in_len;
|
||||||
const uint8_t *buf;
|
const uint8_t *buf;
|
||||||
size_t u;
|
size_t u;
|
||||||
@ -166,7 +167,7 @@ PQCLEAN_FALCON1024_CLEAN_trim_i16_decode(
|
|||||||
|
|
||||||
n = (size_t)1 << logn;
|
n = (size_t)1 << logn;
|
||||||
in_len = ((n * bits) + 7) >> 3;
|
in_len = ((n * bits) + 7) >> 3;
|
||||||
if (in_len > in_max_len) {
|
if (in_len > max_in_len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
buf = in;
|
buf = in;
|
||||||
@ -225,7 +226,8 @@ PQCLEAN_FALCON1024_CLEAN_trim_i8_encode(
|
|||||||
out_len = ((n * bits) + 7) >> 3;
|
out_len = ((n * bits) + 7) >> 3;
|
||||||
if (out == NULL) {
|
if (out == NULL) {
|
||||||
return out_len;
|
return out_len;
|
||||||
} else if (out_len > max_out_len) {
|
}
|
||||||
|
if (out_len > max_out_len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
buf = out;
|
buf = out;
|
||||||
@ -250,7 +252,7 @@ PQCLEAN_FALCON1024_CLEAN_trim_i8_encode(
|
|||||||
size_t
|
size_t
|
||||||
PQCLEAN_FALCON1024_CLEAN_trim_i8_decode(
|
PQCLEAN_FALCON1024_CLEAN_trim_i8_decode(
|
||||||
int8_t *x, unsigned logn, unsigned bits,
|
int8_t *x, unsigned logn, unsigned bits,
|
||||||
const void *in, size_t in_max_len) {
|
const void *in, size_t max_in_len) {
|
||||||
size_t n, in_len;
|
size_t n, in_len;
|
||||||
const uint8_t *buf;
|
const uint8_t *buf;
|
||||||
size_t u;
|
size_t u;
|
||||||
@ -259,7 +261,7 @@ PQCLEAN_FALCON1024_CLEAN_trim_i8_decode(
|
|||||||
|
|
||||||
n = (size_t)1 << logn;
|
n = (size_t)1 << logn;
|
||||||
in_len = ((n * bits) + 7) >> 3;
|
in_len = ((n * bits) + 7) >> 3;
|
||||||
if (in_len > in_max_len) {
|
if (in_len > max_in_len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
buf = in;
|
buf = in;
|
||||||
@ -395,7 +397,7 @@ PQCLEAN_FALCON1024_CLEAN_comp_encode(
|
|||||||
size_t
|
size_t
|
||||||
PQCLEAN_FALCON1024_CLEAN_comp_decode(
|
PQCLEAN_FALCON1024_CLEAN_comp_decode(
|
||||||
int16_t *x, unsigned logn,
|
int16_t *x, unsigned logn,
|
||||||
const void *in, size_t in_max_len) {
|
const void *in, size_t max_in_len) {
|
||||||
const uint8_t *buf;
|
const uint8_t *buf;
|
||||||
size_t n, u, v;
|
size_t n, u, v;
|
||||||
uint32_t acc;
|
uint32_t acc;
|
||||||
@ -413,7 +415,7 @@ PQCLEAN_FALCON1024_CLEAN_comp_decode(
|
|||||||
* Get next eight bits: sign and low seven bits of the
|
* Get next eight bits: sign and low seven bits of the
|
||||||
* absolute value.
|
* absolute value.
|
||||||
*/
|
*/
|
||||||
if (v >= in_max_len) {
|
if (v >= max_in_len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
acc = (acc << 8) | (uint32_t)buf[v ++];
|
acc = (acc << 8) | (uint32_t)buf[v ++];
|
||||||
@ -426,7 +428,7 @@ PQCLEAN_FALCON1024_CLEAN_comp_decode(
|
|||||||
*/
|
*/
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (acc_len == 0) {
|
if (acc_len == 0) {
|
||||||
if (v >= in_max_len) {
|
if (v >= max_in_len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
acc = (acc << 8) | (uint32_t)buf[v ++];
|
acc = (acc << 8) | (uint32_t)buf[v ++];
|
||||||
|
@ -237,7 +237,7 @@ PQCLEAN_FALCON1024_CLEAN_is_short(
|
|||||||
/* see inner.h */
|
/* see inner.h */
|
||||||
int
|
int
|
||||||
PQCLEAN_FALCON1024_CLEAN_is_short_half(
|
PQCLEAN_FALCON1024_CLEAN_is_short_half(
|
||||||
uint32_t sqn, const int16_t *a, unsigned logn) {
|
uint32_t sqn, const int16_t *s2, unsigned logn) {
|
||||||
size_t n, u;
|
size_t n, u;
|
||||||
uint32_t ng;
|
uint32_t ng;
|
||||||
|
|
||||||
@ -246,7 +246,7 @@ PQCLEAN_FALCON1024_CLEAN_is_short_half(
|
|||||||
for (u = 0; u < n; u ++) {
|
for (u = 0; u < n; u ++) {
|
||||||
int32_t z;
|
int32_t z;
|
||||||
|
|
||||||
z = a[u];
|
z = s2[u];
|
||||||
sqn += (uint32_t)(z * z);
|
sqn += (uint32_t)(z * z);
|
||||||
ng |= sqn;
|
ng |= sqn;
|
||||||
}
|
}
|
||||||
|
@ -243,8 +243,7 @@ static inline int64_t
|
|||||||
fpr_rint(fpr x) {
|
fpr_rint(fpr x) {
|
||||||
uint64_t m, d;
|
uint64_t m, d;
|
||||||
int e;
|
int e;
|
||||||
uint32_t s, dd;
|
uint32_t s, dd, f;
|
||||||
unsigned f;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We assume that the value fits in -(2^63-1)..+(2^63-1). We can
|
* We assume that the value fits in -(2^63-1)..+(2^63-1). We can
|
||||||
@ -278,7 +277,7 @@ fpr_rint(fpr x) {
|
|||||||
*/
|
*/
|
||||||
d = fpr_ulsh(m, 63 - e);
|
d = fpr_ulsh(m, 63 - e);
|
||||||
dd = (uint32_t)d | ((uint32_t)(d >> 32) & 0x1FFFFFFF);
|
dd = (uint32_t)d | ((uint32_t)(d >> 32) & 0x1FFFFFFF);
|
||||||
f = (unsigned)(d >> 61) | (unsigned)((dd | -dd) >> 31);
|
f = (uint32_t)(d >> 61) | ((dd | -dd) >> 31);
|
||||||
m = fpr_ursh(m, e) + (uint64_t)((0xC8U >> f) & 1U);
|
m = fpr_ursh(m, e) + (uint64_t)((0xC8U >> f) & 1U);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -343,12 +343,12 @@ int PQCLEAN_FALCON1024_CLEAN_get_seed(void *seed, size_t seed_len);
|
|||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
union {
|
union {
|
||||||
unsigned char d[512]; /* MUST be 512, exactly */
|
uint8_t d[512]; /* MUST be 512, exactly */
|
||||||
uint64_t dummy_u64;
|
uint64_t dummy_u64;
|
||||||
} buf;
|
} buf;
|
||||||
size_t ptr;
|
size_t ptr;
|
||||||
union {
|
union {
|
||||||
unsigned char d[256];
|
uint8_t d[256];
|
||||||
uint64_t dummy_u64;
|
uint64_t dummy_u64;
|
||||||
} state;
|
} state;
|
||||||
int type;
|
int type;
|
||||||
@ -567,7 +567,7 @@ void PQCLEAN_FALCON1024_CLEAN_poly_LDLmv_fft(fpr *restrict d11, fpr *restrict l1
|
|||||||
* f = f0(x^2) + x*f1(x^2), for half-size polynomials f0 and f1
|
* f = f0(x^2) + x*f1(x^2), for half-size polynomials f0 and f1
|
||||||
* (polynomials modulo X^(N/2)+1). f0, f1 and f MUST NOT overlap.
|
* (polynomials modulo X^(N/2)+1). f0, f1 and f MUST NOT overlap.
|
||||||
*/
|
*/
|
||||||
void PQCLEAN_FALCON1024_CLEAN_poly_split_fft(fpr *restrict t0, fpr *restrict t1,
|
void PQCLEAN_FALCON1024_CLEAN_poly_split_fft(fpr *restrict f0, fpr *restrict f1,
|
||||||
const fpr *restrict f, unsigned logn);
|
const fpr *restrict f, unsigned logn);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2183,7 +2183,7 @@ get_rng_u64(shake256_context *rng) {
|
|||||||
* We enforce little-endian representation.
|
* We enforce little-endian representation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned char tmp[8];
|
uint8_t tmp[8];
|
||||||
|
|
||||||
shake256_extract(rng, tmp, sizeof tmp);
|
shake256_extract(rng, tmp, sizeof tmp);
|
||||||
return (uint64_t)tmp[0]
|
return (uint64_t)tmp[0]
|
||||||
@ -2414,7 +2414,7 @@ poly_small_sqnorm(const int8_t *f, unsigned logn) {
|
|||||||
*/
|
*/
|
||||||
static fpr *
|
static fpr *
|
||||||
align_fpr(void *base, void *data) {
|
align_fpr(void *base, void *data) {
|
||||||
unsigned char *cb, *cd;
|
uint8_t *cb, *cd;
|
||||||
size_t k, km;
|
size_t k, km;
|
||||||
|
|
||||||
cb = base;
|
cb = base;
|
||||||
@ -2433,7 +2433,7 @@ align_fpr(void *base, void *data) {
|
|||||||
*/
|
*/
|
||||||
static uint32_t *
|
static uint32_t *
|
||||||
align_u32(void *base, void *data) {
|
align_u32(void *base, void *data) {
|
||||||
unsigned char *cb, *cd;
|
uint8_t *cb, *cd;
|
||||||
size_t k, km;
|
size_t k, km;
|
||||||
|
|
||||||
cb = base;
|
cb = base;
|
||||||
|
@ -42,7 +42,7 @@ PQCLEAN_FALCON1024_CLEAN_prng_init(prng *p, shake256_context *src) {
|
|||||||
* must enforce little-endian interpretation of
|
* must enforce little-endian interpretation of
|
||||||
* the state words.
|
* the state words.
|
||||||
*/
|
*/
|
||||||
unsigned char tmp[56];
|
uint8_t tmp[56];
|
||||||
uint64_t th, tl;
|
uint64_t th, tl;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -148,13 +148,13 @@ PQCLEAN_FALCON1024_CLEAN_prng_refill(prng *p) {
|
|||||||
*/
|
*/
|
||||||
for (v = 0; v < 16; v ++) {
|
for (v = 0; v < 16; v ++) {
|
||||||
p->buf.d[(u << 2) + (v << 5) + 0] =
|
p->buf.d[(u << 2) + (v << 5) + 0] =
|
||||||
(unsigned char)state[v];
|
(uint8_t)state[v];
|
||||||
p->buf.d[(u << 2) + (v << 5) + 1] =
|
p->buf.d[(u << 2) + (v << 5) + 1] =
|
||||||
(unsigned char)(state[v] >> 8);
|
(uint8_t)(state[v] >> 8);
|
||||||
p->buf.d[(u << 2) + (v << 5) + 2] =
|
p->buf.d[(u << 2) + (v << 5) + 2] =
|
||||||
(unsigned char)(state[v] >> 16);
|
(uint8_t)(state[v] >> 16);
|
||||||
p->buf.d[(u << 2) + (v << 5) + 3] =
|
p->buf.d[(u << 2) + (v << 5) + 3] =
|
||||||
(unsigned char)(state[v] >> 24);
|
(uint8_t)(state[v] >> 24);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*(uint64_t *)(p->state.d + 48) = cc;
|
*(uint64_t *)(p->state.d + 48) = cc;
|
||||||
@ -166,7 +166,7 @@ PQCLEAN_FALCON1024_CLEAN_prng_refill(prng *p) {
|
|||||||
/* see inner.h */
|
/* see inner.h */
|
||||||
void
|
void
|
||||||
PQCLEAN_FALCON1024_CLEAN_prng_get_bytes(prng *p, void *dst, size_t len) {
|
PQCLEAN_FALCON1024_CLEAN_prng_get_bytes(prng *p, void *dst, size_t len) {
|
||||||
unsigned char *buf;
|
uint8_t *buf;
|
||||||
|
|
||||||
buf = dst;
|
buf = dst;
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
|
@ -224,46 +224,46 @@ skoff_tree(unsigned logn) {
|
|||||||
|
|
||||||
/* see inner.h */
|
/* see inner.h */
|
||||||
void
|
void
|
||||||
PQCLEAN_FALCON1024_CLEAN_expand_privkey(fpr *restrict sk,
|
PQCLEAN_FALCON1024_CLEAN_expand_privkey(fpr *restrict expanded_key,
|
||||||
const int8_t *f_src, const int8_t *g_src,
|
const int8_t *f, const int8_t *g,
|
||||||
const int8_t *F_src, const int8_t *G_src,
|
const int8_t *F, const int8_t *G,
|
||||||
unsigned logn, uint8_t *restrict tmp) {
|
unsigned logn, uint8_t *restrict tmp) {
|
||||||
size_t n;
|
size_t n;
|
||||||
fpr *f, *g, *F, *G;
|
fpr *rf, *rg, *rF, *rG;
|
||||||
fpr *b00, *b01, *b10, *b11;
|
fpr *b00, *b01, *b10, *b11;
|
||||||
fpr *g00, *g01, *g11, *gxx;
|
fpr *g00, *g01, *g11, *gxx;
|
||||||
fpr *tree;
|
fpr *tree;
|
||||||
|
|
||||||
n = MKN(logn);
|
n = MKN(logn);
|
||||||
b00 = sk + skoff_b00(logn);
|
b00 = expanded_key + skoff_b00(logn);
|
||||||
b01 = sk + skoff_b01(logn);
|
b01 = expanded_key + skoff_b01(logn);
|
||||||
b10 = sk + skoff_b10(logn);
|
b10 = expanded_key + skoff_b10(logn);
|
||||||
b11 = sk + skoff_b11(logn);
|
b11 = expanded_key + skoff_b11(logn);
|
||||||
tree = sk + skoff_tree(logn);
|
tree = expanded_key + skoff_tree(logn);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We load the private key elements directly into the B0 matrix,
|
* We load the private key elements directly into the B0 matrix,
|
||||||
* since B0 = [[g, -f], [G, -F]].
|
* since B0 = [[g, -f], [G, -F]].
|
||||||
*/
|
*/
|
||||||
f = b01;
|
rf = b01;
|
||||||
g = b00;
|
rg = b00;
|
||||||
F = b11;
|
rF = b11;
|
||||||
G = b10;
|
rG = b10;
|
||||||
|
|
||||||
smallints_to_fpr(f, f_src, logn);
|
smallints_to_fpr(rf, f, logn);
|
||||||
smallints_to_fpr(g, g_src, logn);
|
smallints_to_fpr(rg, g, logn);
|
||||||
smallints_to_fpr(F, F_src, logn);
|
smallints_to_fpr(rF, F, logn);
|
||||||
smallints_to_fpr(G, G_src, logn);
|
smallints_to_fpr(rG, G, logn);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Compute the FFT for the key elements, and negate f and F.
|
* Compute the FFT for the key elements, and negate f and F.
|
||||||
*/
|
*/
|
||||||
PQCLEAN_FALCON1024_CLEAN_FFT(f, logn);
|
PQCLEAN_FALCON1024_CLEAN_FFT(rf, logn);
|
||||||
PQCLEAN_FALCON1024_CLEAN_FFT(g, logn);
|
PQCLEAN_FALCON1024_CLEAN_FFT(rg, logn);
|
||||||
PQCLEAN_FALCON1024_CLEAN_FFT(F, logn);
|
PQCLEAN_FALCON1024_CLEAN_FFT(rF, logn);
|
||||||
PQCLEAN_FALCON1024_CLEAN_FFT(G, logn);
|
PQCLEAN_FALCON1024_CLEAN_FFT(rG, logn);
|
||||||
PQCLEAN_FALCON1024_CLEAN_poly_neg(f, logn);
|
PQCLEAN_FALCON1024_CLEAN_poly_neg(rf, logn);
|
||||||
PQCLEAN_FALCON1024_CLEAN_poly_neg(F, logn);
|
PQCLEAN_FALCON1024_CLEAN_poly_neg(rF, logn);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The Gram matrix is G = B·B*. Formulas are:
|
* The Gram matrix is G = B·B*. Formulas are:
|
||||||
|
@ -75,7 +75,7 @@ PQCLEAN_FALCON512_CLEAN_modq_encode(
|
|||||||
size_t
|
size_t
|
||||||
PQCLEAN_FALCON512_CLEAN_modq_decode(
|
PQCLEAN_FALCON512_CLEAN_modq_decode(
|
||||||
uint16_t *x, unsigned logn,
|
uint16_t *x, unsigned logn,
|
||||||
const void *in, size_t in_max_len) {
|
const void *in, size_t max_in_len) {
|
||||||
size_t n, in_len, u;
|
size_t n, in_len, u;
|
||||||
const uint8_t *buf;
|
const uint8_t *buf;
|
||||||
uint32_t acc;
|
uint32_t acc;
|
||||||
@ -83,7 +83,7 @@ PQCLEAN_FALCON512_CLEAN_modq_decode(
|
|||||||
|
|
||||||
n = (size_t)1 << logn;
|
n = (size_t)1 << logn;
|
||||||
in_len = ((n * 14) + 7) >> 3;
|
in_len = ((n * 14) + 7) >> 3;
|
||||||
if (in_len > in_max_len) {
|
if (in_len > max_in_len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
buf = in;
|
buf = in;
|
||||||
@ -132,7 +132,8 @@ PQCLEAN_FALCON512_CLEAN_trim_i16_encode(
|
|||||||
out_len = ((n * bits) + 7) >> 3;
|
out_len = ((n * bits) + 7) >> 3;
|
||||||
if (out == NULL) {
|
if (out == NULL) {
|
||||||
return out_len;
|
return out_len;
|
||||||
} else if (out_len > max_out_len) {
|
}
|
||||||
|
if (out_len > max_out_len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
buf = out;
|
buf = out;
|
||||||
@ -157,7 +158,7 @@ PQCLEAN_FALCON512_CLEAN_trim_i16_encode(
|
|||||||
size_t
|
size_t
|
||||||
PQCLEAN_FALCON512_CLEAN_trim_i16_decode(
|
PQCLEAN_FALCON512_CLEAN_trim_i16_decode(
|
||||||
int16_t *x, unsigned logn, unsigned bits,
|
int16_t *x, unsigned logn, unsigned bits,
|
||||||
const void *in, size_t in_max_len) {
|
const void *in, size_t max_in_len) {
|
||||||
size_t n, in_len;
|
size_t n, in_len;
|
||||||
const uint8_t *buf;
|
const uint8_t *buf;
|
||||||
size_t u;
|
size_t u;
|
||||||
@ -166,7 +167,7 @@ PQCLEAN_FALCON512_CLEAN_trim_i16_decode(
|
|||||||
|
|
||||||
n = (size_t)1 << logn;
|
n = (size_t)1 << logn;
|
||||||
in_len = ((n * bits) + 7) >> 3;
|
in_len = ((n * bits) + 7) >> 3;
|
||||||
if (in_len > in_max_len) {
|
if (in_len > max_in_len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
buf = in;
|
buf = in;
|
||||||
@ -225,7 +226,8 @@ PQCLEAN_FALCON512_CLEAN_trim_i8_encode(
|
|||||||
out_len = ((n * bits) + 7) >> 3;
|
out_len = ((n * bits) + 7) >> 3;
|
||||||
if (out == NULL) {
|
if (out == NULL) {
|
||||||
return out_len;
|
return out_len;
|
||||||
} else if (out_len > max_out_len) {
|
}
|
||||||
|
if (out_len > max_out_len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
buf = out;
|
buf = out;
|
||||||
@ -250,7 +252,7 @@ PQCLEAN_FALCON512_CLEAN_trim_i8_encode(
|
|||||||
size_t
|
size_t
|
||||||
PQCLEAN_FALCON512_CLEAN_trim_i8_decode(
|
PQCLEAN_FALCON512_CLEAN_trim_i8_decode(
|
||||||
int8_t *x, unsigned logn, unsigned bits,
|
int8_t *x, unsigned logn, unsigned bits,
|
||||||
const void *in, size_t in_max_len) {
|
const void *in, size_t max_in_len) {
|
||||||
size_t n, in_len;
|
size_t n, in_len;
|
||||||
const uint8_t *buf;
|
const uint8_t *buf;
|
||||||
size_t u;
|
size_t u;
|
||||||
@ -259,7 +261,7 @@ PQCLEAN_FALCON512_CLEAN_trim_i8_decode(
|
|||||||
|
|
||||||
n = (size_t)1 << logn;
|
n = (size_t)1 << logn;
|
||||||
in_len = ((n * bits) + 7) >> 3;
|
in_len = ((n * bits) + 7) >> 3;
|
||||||
if (in_len > in_max_len) {
|
if (in_len > max_in_len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
buf = in;
|
buf = in;
|
||||||
@ -395,7 +397,7 @@ PQCLEAN_FALCON512_CLEAN_comp_encode(
|
|||||||
size_t
|
size_t
|
||||||
PQCLEAN_FALCON512_CLEAN_comp_decode(
|
PQCLEAN_FALCON512_CLEAN_comp_decode(
|
||||||
int16_t *x, unsigned logn,
|
int16_t *x, unsigned logn,
|
||||||
const void *in, size_t in_max_len) {
|
const void *in, size_t max_in_len) {
|
||||||
const uint8_t *buf;
|
const uint8_t *buf;
|
||||||
size_t n, u, v;
|
size_t n, u, v;
|
||||||
uint32_t acc;
|
uint32_t acc;
|
||||||
@ -413,7 +415,7 @@ PQCLEAN_FALCON512_CLEAN_comp_decode(
|
|||||||
* Get next eight bits: sign and low seven bits of the
|
* Get next eight bits: sign and low seven bits of the
|
||||||
* absolute value.
|
* absolute value.
|
||||||
*/
|
*/
|
||||||
if (v >= in_max_len) {
|
if (v >= max_in_len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
acc = (acc << 8) | (uint32_t)buf[v ++];
|
acc = (acc << 8) | (uint32_t)buf[v ++];
|
||||||
@ -426,7 +428,7 @@ PQCLEAN_FALCON512_CLEAN_comp_decode(
|
|||||||
*/
|
*/
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (acc_len == 0) {
|
if (acc_len == 0) {
|
||||||
if (v >= in_max_len) {
|
if (v >= max_in_len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
acc = (acc << 8) | (uint32_t)buf[v ++];
|
acc = (acc << 8) | (uint32_t)buf[v ++];
|
||||||
|
@ -237,7 +237,7 @@ PQCLEAN_FALCON512_CLEAN_is_short(
|
|||||||
/* see inner.h */
|
/* see inner.h */
|
||||||
int
|
int
|
||||||
PQCLEAN_FALCON512_CLEAN_is_short_half(
|
PQCLEAN_FALCON512_CLEAN_is_short_half(
|
||||||
uint32_t sqn, const int16_t *a, unsigned logn) {
|
uint32_t sqn, const int16_t *s2, unsigned logn) {
|
||||||
size_t n, u;
|
size_t n, u;
|
||||||
uint32_t ng;
|
uint32_t ng;
|
||||||
|
|
||||||
@ -246,7 +246,7 @@ PQCLEAN_FALCON512_CLEAN_is_short_half(
|
|||||||
for (u = 0; u < n; u ++) {
|
for (u = 0; u < n; u ++) {
|
||||||
int32_t z;
|
int32_t z;
|
||||||
|
|
||||||
z = a[u];
|
z = s2[u];
|
||||||
sqn += (uint32_t)(z * z);
|
sqn += (uint32_t)(z * z);
|
||||||
ng |= sqn;
|
ng |= sqn;
|
||||||
}
|
}
|
||||||
|
@ -243,8 +243,7 @@ static inline int64_t
|
|||||||
fpr_rint(fpr x) {
|
fpr_rint(fpr x) {
|
||||||
uint64_t m, d;
|
uint64_t m, d;
|
||||||
int e;
|
int e;
|
||||||
uint32_t s, dd;
|
uint32_t s, dd, f;
|
||||||
unsigned f;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We assume that the value fits in -(2^63-1)..+(2^63-1). We can
|
* We assume that the value fits in -(2^63-1)..+(2^63-1). We can
|
||||||
@ -278,7 +277,7 @@ fpr_rint(fpr x) {
|
|||||||
*/
|
*/
|
||||||
d = fpr_ulsh(m, 63 - e);
|
d = fpr_ulsh(m, 63 - e);
|
||||||
dd = (uint32_t)d | ((uint32_t)(d >> 32) & 0x1FFFFFFF);
|
dd = (uint32_t)d | ((uint32_t)(d >> 32) & 0x1FFFFFFF);
|
||||||
f = (unsigned)(d >> 61) | (unsigned)((dd | -dd) >> 31);
|
f = (uint32_t)(d >> 61) | ((dd | -dd) >> 31);
|
||||||
m = fpr_ursh(m, e) + (uint64_t)((0xC8U >> f) & 1U);
|
m = fpr_ursh(m, e) + (uint64_t)((0xC8U >> f) & 1U);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -343,12 +343,12 @@ int PQCLEAN_FALCON512_CLEAN_get_seed(void *seed, size_t seed_len);
|
|||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
union {
|
union {
|
||||||
unsigned char d[512]; /* MUST be 512, exactly */
|
uint8_t d[512]; /* MUST be 512, exactly */
|
||||||
uint64_t dummy_u64;
|
uint64_t dummy_u64;
|
||||||
} buf;
|
} buf;
|
||||||
size_t ptr;
|
size_t ptr;
|
||||||
union {
|
union {
|
||||||
unsigned char d[256];
|
uint8_t d[256];
|
||||||
uint64_t dummy_u64;
|
uint64_t dummy_u64;
|
||||||
} state;
|
} state;
|
||||||
int type;
|
int type;
|
||||||
@ -567,7 +567,7 @@ void PQCLEAN_FALCON512_CLEAN_poly_LDLmv_fft(fpr *restrict d11, fpr *restrict l10
|
|||||||
* f = f0(x^2) + x*f1(x^2), for half-size polynomials f0 and f1
|
* f = f0(x^2) + x*f1(x^2), for half-size polynomials f0 and f1
|
||||||
* (polynomials modulo X^(N/2)+1). f0, f1 and f MUST NOT overlap.
|
* (polynomials modulo X^(N/2)+1). f0, f1 and f MUST NOT overlap.
|
||||||
*/
|
*/
|
||||||
void PQCLEAN_FALCON512_CLEAN_poly_split_fft(fpr *restrict t0, fpr *restrict t1,
|
void PQCLEAN_FALCON512_CLEAN_poly_split_fft(fpr *restrict f0, fpr *restrict f1,
|
||||||
const fpr *restrict f, unsigned logn);
|
const fpr *restrict f, unsigned logn);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2183,7 +2183,7 @@ get_rng_u64(shake256_context *rng) {
|
|||||||
* We enforce little-endian representation.
|
* We enforce little-endian representation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned char tmp[8];
|
uint8_t tmp[8];
|
||||||
|
|
||||||
shake256_extract(rng, tmp, sizeof tmp);
|
shake256_extract(rng, tmp, sizeof tmp);
|
||||||
return (uint64_t)tmp[0]
|
return (uint64_t)tmp[0]
|
||||||
@ -2414,7 +2414,7 @@ poly_small_sqnorm(const int8_t *f, unsigned logn) {
|
|||||||
*/
|
*/
|
||||||
static fpr *
|
static fpr *
|
||||||
align_fpr(void *base, void *data) {
|
align_fpr(void *base, void *data) {
|
||||||
unsigned char *cb, *cd;
|
uint8_t *cb, *cd;
|
||||||
size_t k, km;
|
size_t k, km;
|
||||||
|
|
||||||
cb = base;
|
cb = base;
|
||||||
@ -2433,7 +2433,7 @@ align_fpr(void *base, void *data) {
|
|||||||
*/
|
*/
|
||||||
static uint32_t *
|
static uint32_t *
|
||||||
align_u32(void *base, void *data) {
|
align_u32(void *base, void *data) {
|
||||||
unsigned char *cb, *cd;
|
uint8_t *cb, *cd;
|
||||||
size_t k, km;
|
size_t k, km;
|
||||||
|
|
||||||
cb = base;
|
cb = base;
|
||||||
|
@ -42,7 +42,7 @@ PQCLEAN_FALCON512_CLEAN_prng_init(prng *p, shake256_context *src) {
|
|||||||
* must enforce little-endian interpretation of
|
* must enforce little-endian interpretation of
|
||||||
* the state words.
|
* the state words.
|
||||||
*/
|
*/
|
||||||
unsigned char tmp[56];
|
uint8_t tmp[56];
|
||||||
uint64_t th, tl;
|
uint64_t th, tl;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -148,13 +148,13 @@ PQCLEAN_FALCON512_CLEAN_prng_refill(prng *p) {
|
|||||||
*/
|
*/
|
||||||
for (v = 0; v < 16; v ++) {
|
for (v = 0; v < 16; v ++) {
|
||||||
p->buf.d[(u << 2) + (v << 5) + 0] =
|
p->buf.d[(u << 2) + (v << 5) + 0] =
|
||||||
(unsigned char)state[v];
|
(uint8_t)state[v];
|
||||||
p->buf.d[(u << 2) + (v << 5) + 1] =
|
p->buf.d[(u << 2) + (v << 5) + 1] =
|
||||||
(unsigned char)(state[v] >> 8);
|
(uint8_t)(state[v] >> 8);
|
||||||
p->buf.d[(u << 2) + (v << 5) + 2] =
|
p->buf.d[(u << 2) + (v << 5) + 2] =
|
||||||
(unsigned char)(state[v] >> 16);
|
(uint8_t)(state[v] >> 16);
|
||||||
p->buf.d[(u << 2) + (v << 5) + 3] =
|
p->buf.d[(u << 2) + (v << 5) + 3] =
|
||||||
(unsigned char)(state[v] >> 24);
|
(uint8_t)(state[v] >> 24);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*(uint64_t *)(p->state.d + 48) = cc;
|
*(uint64_t *)(p->state.d + 48) = cc;
|
||||||
@ -166,7 +166,7 @@ PQCLEAN_FALCON512_CLEAN_prng_refill(prng *p) {
|
|||||||
/* see inner.h */
|
/* see inner.h */
|
||||||
void
|
void
|
||||||
PQCLEAN_FALCON512_CLEAN_prng_get_bytes(prng *p, void *dst, size_t len) {
|
PQCLEAN_FALCON512_CLEAN_prng_get_bytes(prng *p, void *dst, size_t len) {
|
||||||
unsigned char *buf;
|
uint8_t *buf;
|
||||||
|
|
||||||
buf = dst;
|
buf = dst;
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
|
@ -224,46 +224,46 @@ skoff_tree(unsigned logn) {
|
|||||||
|
|
||||||
/* see inner.h */
|
/* see inner.h */
|
||||||
void
|
void
|
||||||
PQCLEAN_FALCON512_CLEAN_expand_privkey(fpr *restrict sk,
|
PQCLEAN_FALCON512_CLEAN_expand_privkey(fpr *restrict expanded_key,
|
||||||
const int8_t *f_src, const int8_t *g_src,
|
const int8_t *f, const int8_t *g,
|
||||||
const int8_t *F_src, const int8_t *G_src,
|
const int8_t *F, const int8_t *G,
|
||||||
unsigned logn, uint8_t *restrict tmp) {
|
unsigned logn, uint8_t *restrict tmp) {
|
||||||
size_t n;
|
size_t n;
|
||||||
fpr *f, *g, *F, *G;
|
fpr *rf, *rg, *rF, *rG;
|
||||||
fpr *b00, *b01, *b10, *b11;
|
fpr *b00, *b01, *b10, *b11;
|
||||||
fpr *g00, *g01, *g11, *gxx;
|
fpr *g00, *g01, *g11, *gxx;
|
||||||
fpr *tree;
|
fpr *tree;
|
||||||
|
|
||||||
n = MKN(logn);
|
n = MKN(logn);
|
||||||
b00 = sk + skoff_b00(logn);
|
b00 = expanded_key + skoff_b00(logn);
|
||||||
b01 = sk + skoff_b01(logn);
|
b01 = expanded_key + skoff_b01(logn);
|
||||||
b10 = sk + skoff_b10(logn);
|
b10 = expanded_key + skoff_b10(logn);
|
||||||
b11 = sk + skoff_b11(logn);
|
b11 = expanded_key + skoff_b11(logn);
|
||||||
tree = sk + skoff_tree(logn);
|
tree = expanded_key + skoff_tree(logn);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We load the private key elements directly into the B0 matrix,
|
* We load the private key elements directly into the B0 matrix,
|
||||||
* since B0 = [[g, -f], [G, -F]].
|
* since B0 = [[g, -f], [G, -F]].
|
||||||
*/
|
*/
|
||||||
f = b01;
|
rf = b01;
|
||||||
g = b00;
|
rg = b00;
|
||||||
F = b11;
|
rF = b11;
|
||||||
G = b10;
|
rG = b10;
|
||||||
|
|
||||||
smallints_to_fpr(f, f_src, logn);
|
smallints_to_fpr(rf, f, logn);
|
||||||
smallints_to_fpr(g, g_src, logn);
|
smallints_to_fpr(rg, g, logn);
|
||||||
smallints_to_fpr(F, F_src, logn);
|
smallints_to_fpr(rF, F, logn);
|
||||||
smallints_to_fpr(G, G_src, logn);
|
smallints_to_fpr(rG, G, logn);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Compute the FFT for the key elements, and negate f and F.
|
* Compute the FFT for the key elements, and negate f and F.
|
||||||
*/
|
*/
|
||||||
PQCLEAN_FALCON512_CLEAN_FFT(f, logn);
|
PQCLEAN_FALCON512_CLEAN_FFT(rf, logn);
|
||||||
PQCLEAN_FALCON512_CLEAN_FFT(g, logn);
|
PQCLEAN_FALCON512_CLEAN_FFT(rg, logn);
|
||||||
PQCLEAN_FALCON512_CLEAN_FFT(F, logn);
|
PQCLEAN_FALCON512_CLEAN_FFT(rF, logn);
|
||||||
PQCLEAN_FALCON512_CLEAN_FFT(G, logn);
|
PQCLEAN_FALCON512_CLEAN_FFT(rG, logn);
|
||||||
PQCLEAN_FALCON512_CLEAN_poly_neg(f, logn);
|
PQCLEAN_FALCON512_CLEAN_poly_neg(rf, logn);
|
||||||
PQCLEAN_FALCON512_CLEAN_poly_neg(F, logn);
|
PQCLEAN_FALCON512_CLEAN_poly_neg(rF, logn);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The Gram matrix is G = B·B*. Formulas are:
|
* The Gram matrix is G = B·B*. Formulas are:
|
||||||
|
Loading…
Reference in New Issue
Block a user