mirror of
https://github.com/henrydcase/pqc.git
synced 2024-11-26 09:21:28 +00:00
NTRU Prime: Match the NIST submission's sequence of calls to randombytes
This commit is contained in:
parent
70543bba37
commit
5982bdffcc
@ -107,11 +107,25 @@ static void Hash(unsigned char *out, const unsigned char *in, int inlen) {
|
||||
|
||||
/* ----- higher-level randomness */
|
||||
|
||||
static uint32 urandom32(void) {
|
||||
unsigned char c[4];
|
||||
uint32 out[4];
|
||||
|
||||
randombytes(c, 4);
|
||||
out[0] = (uint32)c[0];
|
||||
out[1] = ((uint32)c[1]) << 8;
|
||||
out[2] = ((uint32)c[2]) << 16;
|
||||
out[3] = ((uint32)c[3]) << 24;
|
||||
return out[0] + out[1] + out[2] + out[3];
|
||||
}
|
||||
|
||||
static void Short_random(small *out) {
|
||||
uint32 L[p];
|
||||
int i;
|
||||
|
||||
randombytes((unsigned char *) L, sizeof L);
|
||||
crypto_decode_pxint32(L, (unsigned char *) L);
|
||||
for (i = 0; i < p; ++i) {
|
||||
L[i] = urandom32();
|
||||
}
|
||||
Short_fromlist(out, L);
|
||||
}
|
||||
|
||||
|
@ -107,11 +107,25 @@ static void Hash(unsigned char *out, const unsigned char *in, int inlen) {
|
||||
|
||||
/* ----- higher-level randomness */
|
||||
|
||||
static uint32 urandom32(void) {
|
||||
unsigned char c[4];
|
||||
uint32 out[4];
|
||||
|
||||
randombytes(c, 4);
|
||||
out[0] = (uint32)c[0];
|
||||
out[1] = ((uint32)c[1]) << 8;
|
||||
out[2] = ((uint32)c[2]) << 16;
|
||||
out[3] = ((uint32)c[3]) << 24;
|
||||
return out[0] + out[1] + out[2] + out[3];
|
||||
}
|
||||
|
||||
static void Short_random(small *out) {
|
||||
uint32 L[p];
|
||||
int i;
|
||||
|
||||
randombytes((unsigned char *) L, sizeof L);
|
||||
crypto_decode_pxint32(L, (unsigned char *) L);
|
||||
for (i = 0; i < p; ++i) {
|
||||
L[i] = urandom32();
|
||||
}
|
||||
Short_fromlist(out, L);
|
||||
}
|
||||
|
||||
|
@ -107,11 +107,25 @@ static void Hash(unsigned char *out, const unsigned char *in, int inlen) {
|
||||
|
||||
/* ----- higher-level randomness */
|
||||
|
||||
static uint32 urandom32(void) {
|
||||
unsigned char c[4];
|
||||
uint32 out[4];
|
||||
|
||||
randombytes(c, 4);
|
||||
out[0] = (uint32)c[0];
|
||||
out[1] = ((uint32)c[1]) << 8;
|
||||
out[2] = ((uint32)c[2]) << 16;
|
||||
out[3] = ((uint32)c[3]) << 24;
|
||||
return out[0] + out[1] + out[2] + out[3];
|
||||
}
|
||||
|
||||
static void Short_random(small *out) {
|
||||
uint32 L[p];
|
||||
int i;
|
||||
|
||||
randombytes((unsigned char *) L, sizeof L);
|
||||
crypto_decode_pxint32(L, (unsigned char *) L);
|
||||
for (i = 0; i < p; ++i) {
|
||||
L[i] = urandom32();
|
||||
}
|
||||
Short_fromlist(out, L);
|
||||
}
|
||||
|
||||
|
@ -107,11 +107,25 @@ static void Hash(unsigned char *out, const unsigned char *in, int inlen) {
|
||||
|
||||
/* ----- higher-level randomness */
|
||||
|
||||
static uint32 urandom32(void) {
|
||||
unsigned char c[4];
|
||||
uint32 out[4];
|
||||
|
||||
randombytes(c, 4);
|
||||
out[0] = (uint32)c[0];
|
||||
out[1] = ((uint32)c[1]) << 8;
|
||||
out[2] = ((uint32)c[2]) << 16;
|
||||
out[3] = ((uint32)c[3]) << 24;
|
||||
return out[0] + out[1] + out[2] + out[3];
|
||||
}
|
||||
|
||||
static void Short_random(small *out) {
|
||||
uint32 L[p];
|
||||
int i;
|
||||
|
||||
randombytes((unsigned char *) L, sizeof L);
|
||||
crypto_decode_pxint32(L, (unsigned char *) L);
|
||||
for (i = 0; i < p; ++i) {
|
||||
L[i] = urandom32();
|
||||
}
|
||||
Short_fromlist(out, L);
|
||||
}
|
||||
|
||||
|
@ -107,11 +107,25 @@ static void Hash(unsigned char *out, const unsigned char *in, int inlen) {
|
||||
|
||||
/* ----- higher-level randomness */
|
||||
|
||||
static uint32 urandom32(void) {
|
||||
unsigned char c[4];
|
||||
uint32 out[4];
|
||||
|
||||
randombytes(c, 4);
|
||||
out[0] = (uint32)c[0];
|
||||
out[1] = ((uint32)c[1]) << 8;
|
||||
out[2] = ((uint32)c[2]) << 16;
|
||||
out[3] = ((uint32)c[3]) << 24;
|
||||
return out[0] + out[1] + out[2] + out[3];
|
||||
}
|
||||
|
||||
static void Short_random(small *out) {
|
||||
uint32 L[p];
|
||||
int i;
|
||||
|
||||
randombytes((unsigned char *) L, sizeof L);
|
||||
crypto_decode_pxint32(L, (unsigned char *) L);
|
||||
for (i = 0; i < p; ++i) {
|
||||
L[i] = urandom32();
|
||||
}
|
||||
Short_fromlist(out, L);
|
||||
}
|
||||
|
||||
|
@ -107,11 +107,25 @@ static void Hash(unsigned char *out, const unsigned char *in, int inlen) {
|
||||
|
||||
/* ----- higher-level randomness */
|
||||
|
||||
static uint32 urandom32(void) {
|
||||
unsigned char c[4];
|
||||
uint32 out[4];
|
||||
|
||||
randombytes(c, 4);
|
||||
out[0] = (uint32)c[0];
|
||||
out[1] = ((uint32)c[1]) << 8;
|
||||
out[2] = ((uint32)c[2]) << 16;
|
||||
out[3] = ((uint32)c[3]) << 24;
|
||||
return out[0] + out[1] + out[2] + out[3];
|
||||
}
|
||||
|
||||
static void Short_random(small *out) {
|
||||
uint32 L[p];
|
||||
int i;
|
||||
|
||||
randombytes((unsigned char *) L, sizeof L);
|
||||
crypto_decode_pxint32(L, (unsigned char *) L);
|
||||
for (i = 0; i < p; ++i) {
|
||||
L[i] = urandom32();
|
||||
}
|
||||
Short_fromlist(out, L);
|
||||
}
|
||||
|
||||
|
@ -73,12 +73,25 @@ static void Hash(unsigned char *out, const unsigned char *in, int inlen) {
|
||||
|
||||
/* ----- higher-level randomness */
|
||||
|
||||
static uint32 urandom32(void) {
|
||||
unsigned char c[4];
|
||||
uint32 out[4];
|
||||
|
||||
randombytes(c, 4);
|
||||
out[0] = (uint32)c[0];
|
||||
out[1] = ((uint32)c[1]) << 8;
|
||||
out[2] = ((uint32)c[2]) << 16;
|
||||
out[3] = ((uint32)c[3]) << 24;
|
||||
return out[0] + out[1] + out[2] + out[3];
|
||||
}
|
||||
|
||||
static void Short_random(small *out) {
|
||||
uint32 L[ppadsort];
|
||||
int i;
|
||||
|
||||
randombytes((unsigned char *) L, 4 * p);
|
||||
crypto_decode_pxint32(L, (unsigned char *) L);
|
||||
for (i = 0; i < ppadsort; ++i) {
|
||||
L[i] = urandom32();
|
||||
}
|
||||
for (i = 0; i < w; ++i) {
|
||||
L[i] = L[i] & (uint32) - 2;
|
||||
}
|
||||
@ -98,8 +111,9 @@ static void Small_random(small *out) {
|
||||
uint32 L[p];
|
||||
int i;
|
||||
|
||||
randombytes((unsigned char *) L, sizeof L);
|
||||
crypto_decode_pxint32(L, (unsigned char *) L);
|
||||
for (i = 0; i < p; ++i) {
|
||||
L[i] = urandom32();
|
||||
}
|
||||
for (i = 0; i < p; ++i) {
|
||||
out[i] = (((L[i] & 0x3fffffff) * 3) >> 30) - 1;
|
||||
}
|
||||
|
@ -73,12 +73,25 @@ static void Hash(unsigned char *out, const unsigned char *in, int inlen) {
|
||||
|
||||
/* ----- higher-level randomness */
|
||||
|
||||
static uint32 urandom32(void) {
|
||||
unsigned char c[4];
|
||||
uint32 out[4];
|
||||
|
||||
randombytes(c, 4);
|
||||
out[0] = (uint32)c[0];
|
||||
out[1] = ((uint32)c[1]) << 8;
|
||||
out[2] = ((uint32)c[2]) << 16;
|
||||
out[3] = ((uint32)c[3]) << 24;
|
||||
return out[0] + out[1] + out[2] + out[3];
|
||||
}
|
||||
|
||||
static void Short_random(small *out) {
|
||||
uint32 L[ppadsort];
|
||||
int i;
|
||||
|
||||
randombytes((unsigned char *) L, 4 * p);
|
||||
crypto_decode_pxint32(L, (unsigned char *) L);
|
||||
for (i = 0; i < ppadsort; ++i) {
|
||||
L[i] = urandom32();
|
||||
}
|
||||
for (i = 0; i < w; ++i) {
|
||||
L[i] = L[i] & (uint32) - 2;
|
||||
}
|
||||
@ -98,8 +111,9 @@ static void Small_random(small *out) {
|
||||
uint32 L[p];
|
||||
int i;
|
||||
|
||||
randombytes((unsigned char *) L, sizeof L);
|
||||
crypto_decode_pxint32(L, (unsigned char *) L);
|
||||
for (i = 0; i < p; ++i) {
|
||||
L[i] = urandom32();
|
||||
}
|
||||
for (i = 0; i < p; ++i) {
|
||||
out[i] = (((L[i] & 0x3fffffff) * 3) >> 30) - 1;
|
||||
}
|
||||
|
@ -73,12 +73,25 @@ static void Hash(unsigned char *out, const unsigned char *in, int inlen) {
|
||||
|
||||
/* ----- higher-level randomness */
|
||||
|
||||
static uint32 urandom32(void) {
|
||||
unsigned char c[4];
|
||||
uint32 out[4];
|
||||
|
||||
randombytes(c, 4);
|
||||
out[0] = (uint32)c[0];
|
||||
out[1] = ((uint32)c[1]) << 8;
|
||||
out[2] = ((uint32)c[2]) << 16;
|
||||
out[3] = ((uint32)c[3]) << 24;
|
||||
return out[0] + out[1] + out[2] + out[3];
|
||||
}
|
||||
|
||||
static void Short_random(small *out) {
|
||||
uint32 L[ppadsort];
|
||||
int i;
|
||||
|
||||
randombytes((unsigned char *) L, 4 * p);
|
||||
crypto_decode_pxint32(L, (unsigned char *) L);
|
||||
for (i = 0; i < ppadsort; ++i) {
|
||||
L[i] = urandom32();
|
||||
}
|
||||
for (i = 0; i < w; ++i) {
|
||||
L[i] = L[i] & (uint32) - 2;
|
||||
}
|
||||
@ -98,8 +111,9 @@ static void Small_random(small *out) {
|
||||
uint32 L[p];
|
||||
int i;
|
||||
|
||||
randombytes((unsigned char *) L, sizeof L);
|
||||
crypto_decode_pxint32(L, (unsigned char *) L);
|
||||
for (i = 0; i < p; ++i) {
|
||||
L[i] = urandom32();
|
||||
}
|
||||
for (i = 0; i < p; ++i) {
|
||||
out[i] = (((L[i] & 0x3fffffff) * 3) >> 30) - 1;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@
|
||||
#define q 4591
|
||||
#define w 286
|
||||
|
||||
#define ppadsort 768
|
||||
#define ppadsort 761
|
||||
|
||||
#define crypto_verify_clen PQCLEAN_SNTRUP761_AVX2_crypto_verify_1039
|
||||
|
||||
|
@ -73,12 +73,25 @@ static void Hash(unsigned char *out, const unsigned char *in, int inlen) {
|
||||
|
||||
/* ----- higher-level randomness */
|
||||
|
||||
static uint32 urandom32(void) {
|
||||
unsigned char c[4];
|
||||
uint32 out[4];
|
||||
|
||||
randombytes(c, 4);
|
||||
out[0] = (uint32)c[0];
|
||||
out[1] = ((uint32)c[1]) << 8;
|
||||
out[2] = ((uint32)c[2]) << 16;
|
||||
out[3] = ((uint32)c[3]) << 24;
|
||||
return out[0] + out[1] + out[2] + out[3];
|
||||
}
|
||||
|
||||
static void Short_random(small *out) {
|
||||
uint32 L[ppadsort];
|
||||
int i;
|
||||
|
||||
randombytes((unsigned char *) L, 4 * p);
|
||||
crypto_decode_pxint32(L, (unsigned char *) L);
|
||||
for (i = 0; i < ppadsort; ++i) {
|
||||
L[i] = urandom32();
|
||||
}
|
||||
for (i = 0; i < w; ++i) {
|
||||
L[i] = L[i] & (uint32) - 2;
|
||||
}
|
||||
@ -98,8 +111,9 @@ static void Small_random(small *out) {
|
||||
uint32 L[p];
|
||||
int i;
|
||||
|
||||
randombytes((unsigned char *) L, sizeof L);
|
||||
crypto_decode_pxint32(L, (unsigned char *) L);
|
||||
for (i = 0; i < p; ++i) {
|
||||
L[i] = urandom32();
|
||||
}
|
||||
for (i = 0; i < p; ++i) {
|
||||
out[i] = (((L[i] & 0x3fffffff) * 3) >> 30) - 1;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
#define q 4591
|
||||
#define w 286
|
||||
|
||||
#define ppadsort 768
|
||||
#define ppadsort 761
|
||||
|
||||
#define crypto_verify_clen PQCLEAN_SNTRUP761_CLEAN_crypto_verify_1039
|
||||
|
||||
|
@ -73,12 +73,25 @@ static void Hash(unsigned char *out, const unsigned char *in, int inlen) {
|
||||
|
||||
/* ----- higher-level randomness */
|
||||
|
||||
static uint32 urandom32(void) {
|
||||
unsigned char c[4];
|
||||
uint32 out[4];
|
||||
|
||||
randombytes(c, 4);
|
||||
out[0] = (uint32)c[0];
|
||||
out[1] = ((uint32)c[1]) << 8;
|
||||
out[2] = ((uint32)c[2]) << 16;
|
||||
out[3] = ((uint32)c[3]) << 24;
|
||||
return out[0] + out[1] + out[2] + out[3];
|
||||
}
|
||||
|
||||
static void Short_random(small *out) {
|
||||
uint32 L[ppadsort];
|
||||
int i;
|
||||
|
||||
randombytes((unsigned char *) L, 4 * p);
|
||||
crypto_decode_pxint32(L, (unsigned char *) L);
|
||||
for (i = 0; i < ppadsort; ++i) {
|
||||
L[i] = urandom32();
|
||||
}
|
||||
for (i = 0; i < w; ++i) {
|
||||
L[i] = L[i] & (uint32) - 2;
|
||||
}
|
||||
@ -98,8 +111,9 @@ static void Small_random(small *out) {
|
||||
uint32 L[p];
|
||||
int i;
|
||||
|
||||
randombytes((unsigned char *) L, sizeof L);
|
||||
crypto_decode_pxint32(L, (unsigned char *) L);
|
||||
for (i = 0; i < p; ++i) {
|
||||
L[i] = urandom32();
|
||||
}
|
||||
for (i = 0; i < p; ++i) {
|
||||
out[i] = (((L[i] & 0x3fffffff) * 3) >> 30) - 1;
|
||||
}
|
||||
|
@ -73,12 +73,25 @@ static void Hash(unsigned char *out, const unsigned char *in, int inlen) {
|
||||
|
||||
/* ----- higher-level randomness */
|
||||
|
||||
static uint32 urandom32(void) {
|
||||
unsigned char c[4];
|
||||
uint32 out[4];
|
||||
|
||||
randombytes(c, 4);
|
||||
out[0] = (uint32)c[0];
|
||||
out[1] = ((uint32)c[1]) << 8;
|
||||
out[2] = ((uint32)c[2]) << 16;
|
||||
out[3] = ((uint32)c[3]) << 24;
|
||||
return out[0] + out[1] + out[2] + out[3];
|
||||
}
|
||||
|
||||
static void Short_random(small *out) {
|
||||
uint32 L[ppadsort];
|
||||
int i;
|
||||
|
||||
randombytes((unsigned char *) L, 4 * p);
|
||||
crypto_decode_pxint32(L, (unsigned char *) L);
|
||||
for (i = 0; i < ppadsort; ++i) {
|
||||
L[i] = urandom32();
|
||||
}
|
||||
for (i = 0; i < w; ++i) {
|
||||
L[i] = L[i] & (uint32) - 2;
|
||||
}
|
||||
@ -98,8 +111,9 @@ static void Small_random(small *out) {
|
||||
uint32 L[p];
|
||||
int i;
|
||||
|
||||
randombytes((unsigned char *) L, sizeof L);
|
||||
crypto_decode_pxint32(L, (unsigned char *) L);
|
||||
for (i = 0; i < p; ++i) {
|
||||
L[i] = urandom32();
|
||||
}
|
||||
for (i = 0; i < p; ++i) {
|
||||
out[i] = (((L[i] & 0x3fffffff) * 3) >> 30) - 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user