mirror of
https://github.com/henrydcase/pqc.git
synced 2024-11-29 19:01:22 +00:00
Fix linter complaints
This commit is contained in:
parent
53ac90861c
commit
8e7cf2b5cd
@ -19,7 +19,7 @@ typedef struct {
|
|||||||
} AES256_CTR_DRBG_struct;
|
} AES256_CTR_DRBG_struct;
|
||||||
|
|
||||||
static AES256_CTR_DRBG_struct DRBG_ctx;
|
static AES256_CTR_DRBG_struct DRBG_ctx;
|
||||||
static void AES256_CTR_DRBG_Update(uint8_t *provided_data, uint8_t *Key, uint8_t *V);
|
static void AES256_CTR_DRBG_Update(const uint8_t *provided_data, uint8_t *Key, uint8_t *V);
|
||||||
|
|
||||||
// Use whatever AES implementation you have. This uses AES from openSSL library
|
// Use whatever AES implementation you have. This uses AES from openSSL library
|
||||||
// key - 256-bit AES key
|
// key - 256-bit AES key
|
||||||
@ -31,23 +31,24 @@ static void AES256_ECB(uint8_t *key, uint8_t *ctr, uint8_t *buffer) {
|
|||||||
aes256_ecb(buffer, ctr, 1, &ctx);
|
aes256_ecb(buffer, ctr, 1, &ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nist_kat_init(uint8_t *entropy_input, uint8_t *personalization_string, int security_strength);
|
void nist_kat_init(uint8_t *entropy_input, const uint8_t *personalization_string, int security_strength);
|
||||||
void nist_kat_init(uint8_t *entropy_input, uint8_t *personalization_string, int security_strength) {
|
void nist_kat_init(uint8_t *entropy_input, const uint8_t *personalization_string, int security_strength) {
|
||||||
uint8_t seed_material[48];
|
uint8_t seed_material[48];
|
||||||
|
|
||||||
assert(security_strength == 256);
|
assert(security_strength == 256);
|
||||||
memcpy(seed_material, entropy_input, 48);
|
memcpy(seed_material, entropy_input, 48);
|
||||||
if (personalization_string)
|
if (personalization_string) {
|
||||||
for (int i = 0; i < 48; i++) {
|
for (int i = 0; i < 48; i++) {
|
||||||
seed_material[i] ^= personalization_string[i];
|
seed_material[i] ^= personalization_string[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
memset(DRBG_ctx.Key, 0x00, 32);
|
memset(DRBG_ctx.Key, 0x00, 32);
|
||||||
memset(DRBG_ctx.V, 0x00, 16);
|
memset(DRBG_ctx.V, 0x00, 16);
|
||||||
AES256_CTR_DRBG_Update(seed_material, DRBG_ctx.Key, DRBG_ctx.V);
|
AES256_CTR_DRBG_Update(seed_material, DRBG_ctx.Key, DRBG_ctx.V);
|
||||||
DRBG_ctx.reseed_counter = 1;
|
DRBG_ctx.reseed_counter = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int randombytes(uint8_t *x, size_t xlen) {
|
int randombytes(uint8_t *buf, size_t xlen) {
|
||||||
uint8_t block[16];
|
uint8_t block[16];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
@ -63,11 +64,11 @@ int randombytes(uint8_t *x, size_t xlen) {
|
|||||||
}
|
}
|
||||||
AES256_ECB(DRBG_ctx.Key, DRBG_ctx.V, block);
|
AES256_ECB(DRBG_ctx.Key, DRBG_ctx.V, block);
|
||||||
if (xlen > 15) {
|
if (xlen > 15) {
|
||||||
memcpy(x + i, block, 16);
|
memcpy(buf + i, block, 16);
|
||||||
i += 16;
|
i += 16;
|
||||||
xlen -= 16;
|
xlen -= 16;
|
||||||
} else {
|
} else {
|
||||||
memcpy(x + i, block, xlen);
|
memcpy(buf + i, block, xlen);
|
||||||
xlen = 0;
|
xlen = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,7 +77,7 @@ int randombytes(uint8_t *x, size_t xlen) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AES256_CTR_DRBG_Update(uint8_t *provided_data, uint8_t *Key, uint8_t *V) {
|
static void AES256_CTR_DRBG_Update(const uint8_t *provided_data, uint8_t *Key, uint8_t *V) {
|
||||||
uint8_t temp[48];
|
uint8_t temp[48];
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
@ -92,10 +93,11 @@ static void AES256_CTR_DRBG_Update(uint8_t *provided_data, uint8_t *Key, uint8_t
|
|||||||
|
|
||||||
AES256_ECB(Key, V, temp + 16 * i);
|
AES256_ECB(Key, V, temp + 16 * i);
|
||||||
}
|
}
|
||||||
if (provided_data != NULL)
|
if (provided_data != NULL) {
|
||||||
for (int i = 0; i < 48; i++) {
|
for (int i = 0; i < 48; i++) {
|
||||||
temp[i] ^= provided_data[i];
|
temp[i] ^= provided_data[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
memcpy(Key, temp, 32);
|
memcpy(Key, temp, 32);
|
||||||
memcpy(V, temp + 32, 16);
|
memcpy(V, temp + 32, 16);
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ void PQCLEAN_FRODOKEM1344AES_CLEAN_sample_n(uint16_t *s, size_t n) {
|
|||||||
// Fills vector s with n samples from the noise distribution which requires 16 bits to sample.
|
// Fills vector s with n samples from the noise distribution which requires 16 bits to sample.
|
||||||
// The distribution is specified by its CDF.
|
// The distribution is specified by its CDF.
|
||||||
// Input: pseudo-random values (2*n bytes) passed in s. The input is overwritten by the output.
|
// Input: pseudo-random values (2*n bytes) passed in s. The input is overwritten by the output.
|
||||||
unsigned int i, j;
|
size_t i, j;
|
||||||
|
|
||||||
for (i = 0; i < n; ++i) {
|
for (i = 0; i < n; ++i) {
|
||||||
uint8_t sample = 0;
|
uint8_t sample = 0;
|
||||||
|
@ -16,7 +16,7 @@ void PQCLEAN_FRODOKEM1344SHAKE_CLEAN_sample_n(uint16_t *s, size_t n) {
|
|||||||
// Fills vector s with n samples from the noise distribution which requires 16 bits to sample.
|
// Fills vector s with n samples from the noise distribution which requires 16 bits to sample.
|
||||||
// The distribution is specified by its CDF.
|
// The distribution is specified by its CDF.
|
||||||
// Input: pseudo-random values (2*n bytes) passed in s. The input is overwritten by the output.
|
// Input: pseudo-random values (2*n bytes) passed in s. The input is overwritten by the output.
|
||||||
unsigned int i, j;
|
size_t i, j;
|
||||||
|
|
||||||
for (i = 0; i < n; ++i) {
|
for (i = 0; i < n; ++i) {
|
||||||
uint8_t sample = 0;
|
uint8_t sample = 0;
|
||||||
|
@ -16,7 +16,7 @@ void PQCLEAN_FRODOKEM640AES_CLEAN_sample_n(uint16_t *s, size_t n) {
|
|||||||
// Fills vector s with n samples from the noise distribution which requires 16 bits to sample.
|
// Fills vector s with n samples from the noise distribution which requires 16 bits to sample.
|
||||||
// The distribution is specified by its CDF.
|
// The distribution is specified by its CDF.
|
||||||
// Input: pseudo-random values (2*n bytes) passed in s. The input is overwritten by the output.
|
// Input: pseudo-random values (2*n bytes) passed in s. The input is overwritten by the output.
|
||||||
unsigned int i, j;
|
size_t i, j;
|
||||||
|
|
||||||
for (i = 0; i < n; ++i) {
|
for (i = 0; i < n; ++i) {
|
||||||
uint8_t sample = 0;
|
uint8_t sample = 0;
|
||||||
|
@ -16,7 +16,7 @@ void PQCLEAN_FRODOKEM640SHAKE_CLEAN_sample_n(uint16_t *s, size_t n) {
|
|||||||
// Fills vector s with n samples from the noise distribution which requires 16 bits to sample.
|
// Fills vector s with n samples from the noise distribution which requires 16 bits to sample.
|
||||||
// The distribution is specified by its CDF.
|
// The distribution is specified by its CDF.
|
||||||
// Input: pseudo-random values (2*n bytes) passed in s. The input is overwritten by the output.
|
// Input: pseudo-random values (2*n bytes) passed in s. The input is overwritten by the output.
|
||||||
unsigned int i, j;
|
size_t i, j;
|
||||||
|
|
||||||
for (i = 0; i < n; ++i) {
|
for (i = 0; i < n; ++i) {
|
||||||
uint8_t sample = 0;
|
uint8_t sample = 0;
|
||||||
|
@ -16,7 +16,7 @@ void PQCLEAN_FRODOKEM976AES_CLEAN_sample_n(uint16_t *s, size_t n) {
|
|||||||
// Fills vector s with n samples from the noise distribution which requires 16 bits to sample.
|
// Fills vector s with n samples from the noise distribution which requires 16 bits to sample.
|
||||||
// The distribution is specified by its CDF.
|
// The distribution is specified by its CDF.
|
||||||
// Input: pseudo-random values (2*n bytes) passed in s. The input is overwritten by the output.
|
// Input: pseudo-random values (2*n bytes) passed in s. The input is overwritten by the output.
|
||||||
unsigned int i, j;
|
size_t i, j;
|
||||||
|
|
||||||
for (i = 0; i < n; ++i) {
|
for (i = 0; i < n; ++i) {
|
||||||
uint8_t sample = 0;
|
uint8_t sample = 0;
|
||||||
|
@ -16,7 +16,7 @@ void PQCLEAN_FRODOKEM976SHAKE_CLEAN_sample_n(uint16_t *s, size_t n) {
|
|||||||
// Fills vector s with n samples from the noise distribution which requires 16 bits to sample.
|
// Fills vector s with n samples from the noise distribution which requires 16 bits to sample.
|
||||||
// The distribution is specified by its CDF.
|
// The distribution is specified by its CDF.
|
||||||
// Input: pseudo-random values (2*n bytes) passed in s. The input is overwritten by the output.
|
// Input: pseudo-random values (2*n bytes) passed in s. The input is overwritten by the output.
|
||||||
unsigned int i, j;
|
size_t i, j;
|
||||||
|
|
||||||
for (i = 0; i < n; ++i) {
|
for (i = 0; i < n; ++i) {
|
||||||
uint8_t sample = 0;
|
uint8_t sample = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user