Switch for int and unsigned char to size_to and uint8_t
This commit is contained in:
parent
06973e6127
commit
4162be0401
@ -10,8 +10,8 @@ void PQCLEAN_FRODOKEM640SHAKE_CLEAN_add(uint16_t *out, const uint16_t *a, const
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_sub(uint16_t *out, const uint16_t *a, const uint16_t *b);
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_key_encode(uint16_t *out, const uint16_t *in);
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_key_decode(uint16_t *out, const uint16_t *in);
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_pack(unsigned char *out, size_t outlen, const uint16_t *in, size_t inlen, unsigned char lsb);
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_unpack(uint16_t *out, size_t outlen, const unsigned char *in, size_t inlen, unsigned char lsb);
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_pack(uint8_t *out, size_t outlen, const uint16_t *in, size_t inlen, uint8_t lsb);
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_unpack(uint16_t *out, size_t outlen, const uint8_t *in, size_t inlen, uint8_t lsb);
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_clear_bytes(uint8_t *mem, size_t n);
|
||||
uint16_t PQCLEAN_FRODOKEM640SHAKE_CLEAN_LE_TO_UINT16(uint16_t n);
|
||||
uint16_t PQCLEAN_FRODOKEM640SHAKE_CLEAN_UINT16_TO_LE(uint16_t n);
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include "common.h"
|
||||
#include "params.h"
|
||||
|
||||
int PQCLEAN_FRODOKEM640SHAKE_CLEAN_crypto_kem_keypair(unsigned char *pk, unsigned char *sk) {
|
||||
int PQCLEAN_FRODOKEM640SHAKE_CLEAN_crypto_kem_keypair(uint8_t *pk, uint8_t *sk) {
|
||||
// FrodoKEM's key generation
|
||||
// Outputs: public key pk ( BYTES_SEED_A + (PARAMS_LOGQ*PARAMS_N*PARAMS_NBAR)/8 bytes)
|
||||
// secret key sk (CRYPTO_BYTES + BYTES_SEED_A + (PARAMS_LOGQ*PARAMS_N*PARAMS_NBAR)/8 + 2*PARAMS_N*PARAMS_NBAR + BYTES_PKHASH bytes)
|
||||
@ -71,7 +71,7 @@ int PQCLEAN_FRODOKEM640SHAKE_CLEAN_crypto_kem_keypair(unsigned char *pk, unsigne
|
||||
}
|
||||
|
||||
|
||||
int PQCLEAN_FRODOKEM640SHAKE_CLEAN_crypto_kem_enc(unsigned char *ct, unsigned char *ss, const unsigned char *pk) {
|
||||
int PQCLEAN_FRODOKEM640SHAKE_CLEAN_crypto_kem_enc(uint8_t *ct, uint8_t *ss, const uint8_t *pk) {
|
||||
// FrodoKEM's key encapsulation
|
||||
const uint8_t *pk_seedA = &pk[0];
|
||||
const uint8_t *pk_b = &pk[BYTES_SEED_A];
|
||||
@ -140,7 +140,7 @@ int PQCLEAN_FRODOKEM640SHAKE_CLEAN_crypto_kem_enc(unsigned char *ct, unsigned ch
|
||||
}
|
||||
|
||||
|
||||
int PQCLEAN_FRODOKEM640SHAKE_CLEAN_crypto_kem_dec(unsigned char *ss, const unsigned char *ct, const unsigned char *sk) {
|
||||
int PQCLEAN_FRODOKEM640SHAKE_CLEAN_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const uint8_t *sk) {
|
||||
// FrodoKEM's key decapsulation
|
||||
uint16_t B[PARAMS_N * PARAMS_NBAR] = {0};
|
||||
uint16_t Bp[PARAMS_N * PARAMS_NBAR] = {0};
|
||||
@ -210,7 +210,7 @@ int PQCLEAN_FRODOKEM640SHAKE_CLEAN_crypto_kem_dec(unsigned char *ss, const unsig
|
||||
memcpy(Fin_ct, ct, CRYPTO_CIPHERTEXTBYTES);
|
||||
|
||||
// Reducing BBp modulo q
|
||||
for (int i = 0; i < PARAMS_N * PARAMS_NBAR; i++) {
|
||||
for (size_t i = 0; i < PARAMS_N * PARAMS_NBAR; i++) {
|
||||
BBp[i] = BBp[i] & ((1 << PARAMS_LOGQ) - 1);
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ int PQCLEAN_FRODOKEM640SHAKE_CLEAN_mul_add_as_plus_e(uint16_t *out, const uint16
|
||||
memcpy(&seed_A_separated[2], seed_A, BYTES_SEED_A);
|
||||
for (i = 0; i < PARAMS_N; i++) {
|
||||
seed_A_origin[0] = PQCLEAN_FRODOKEM640SHAKE_CLEAN_UINT16_TO_LE((uint16_t) i);
|
||||
shake128((unsigned char *)(A + i * PARAMS_N), (unsigned long long)(2 * PARAMS_N), seed_A_separated, 2 + BYTES_SEED_A);
|
||||
shake128((uint8_t *)(A + i * PARAMS_N), (unsigned long long)(2 * PARAMS_N), seed_A_separated, 2 + BYTES_SEED_A);
|
||||
}
|
||||
for (i = 0; i < PARAMS_N * PARAMS_N; i++) {
|
||||
A[i] = PQCLEAN_FRODOKEM640SHAKE_CLEAN_LE_TO_UINT16(A[i]);
|
||||
@ -58,7 +58,7 @@ int PQCLEAN_FRODOKEM640SHAKE_CLEAN_mul_add_sa_plus_e(uint16_t *out, const uint16
|
||||
memcpy(&seed_A_separated[2], seed_A, BYTES_SEED_A);
|
||||
for (i = 0; i < PARAMS_N; i++) {
|
||||
seed_A_origin[0] = PQCLEAN_FRODOKEM640SHAKE_CLEAN_UINT16_TO_LE((uint16_t) i);
|
||||
shake128((unsigned char *)(A + i * PARAMS_N), (unsigned long long)(2 * PARAMS_N), seed_A_separated, 2 + BYTES_SEED_A);
|
||||
shake128((uint8_t *)(A + i * PARAMS_N), (unsigned long long)(2 * PARAMS_N), seed_A_separated, 2 + BYTES_SEED_A);
|
||||
}
|
||||
for (i = 0; i < PARAMS_N * PARAMS_N; i++) {
|
||||
A[i] = PQCLEAN_FRODOKEM640SHAKE_CLEAN_LE_TO_UINT16(A[i]);
|
||||
|
@ -65,7 +65,7 @@ void PQCLEAN_FRODOKEM640SHAKE_CLEAN_add(uint16_t *out, const uint16_t *a, const
|
||||
// Inputs: a, b (N_BAR x N_BAR)
|
||||
// Output: c = a + b
|
||||
|
||||
for (int i = 0; i < (PARAMS_NBAR * PARAMS_NBAR); i++) {
|
||||
for (size_t i = 0; i < (PARAMS_NBAR * PARAMS_NBAR); i++) {
|
||||
out[i] = (a[i] + b[i]) & ((1 << PARAMS_LOGQ) - 1);
|
||||
}
|
||||
}
|
||||
@ -76,7 +76,7 @@ void PQCLEAN_FRODOKEM640SHAKE_CLEAN_sub(uint16_t *out, const uint16_t *a, const
|
||||
// Inputs: a, b (N_BAR x N_BAR)
|
||||
// Output: c = a - b
|
||||
|
||||
for (int i = 0; i < (PARAMS_NBAR * PARAMS_NBAR); i++) {
|
||||
for (size_t i = 0; i < (PARAMS_NBAR * PARAMS_NBAR); i++) {
|
||||
out[i] = (a[i] - b[i]) & ((1 << PARAMS_LOGQ) - 1);
|
||||
}
|
||||
}
|
||||
@ -125,7 +125,7 @@ void PQCLEAN_FRODOKEM640SHAKE_CLEAN_key_decode(uint16_t *out, const uint16_t *in
|
||||
}
|
||||
|
||||
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_pack(unsigned char *out, const size_t outlen, const uint16_t *in, const size_t inlen, const unsigned char lsb) {
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_pack(uint8_t *out, const size_t outlen, const uint16_t *in, const size_t inlen, const uint8_t lsb) {
|
||||
// Pack the input uint16 vector into a char output vector, copying lsb bits from each input element.
|
||||
// If inlen * lsb / 8 > outlen, only outlen * 8 bits are copied.
|
||||
memset(out, 0, outlen);
|
||||
@ -133,7 +133,7 @@ void PQCLEAN_FRODOKEM640SHAKE_CLEAN_pack(unsigned char *out, const size_t outlen
|
||||
size_t i = 0; // whole bytes already filled in
|
||||
size_t j = 0; // whole uint16_t already copied
|
||||
uint16_t w = 0; // the leftover, not yet copied
|
||||
unsigned char bits = 0; // the number of lsb in w
|
||||
uint8_t bits = 0; // the number of lsb in w
|
||||
|
||||
while (i < outlen && (j < inlen || ((j == inlen) && (bits > 0)))) {
|
||||
/*
|
||||
@ -147,14 +147,14 @@ void PQCLEAN_FRODOKEM640SHAKE_CLEAN_pack(unsigned char *out, const size_t outlen
|
||||
^^
|
||||
ib
|
||||
*/
|
||||
unsigned char b = 0; // bits in out[i] already filled in
|
||||
uint8_t b = 0; // bits in out[i] already filled in
|
||||
while (b < 8) {
|
||||
int nbits = min(8 - b, bits);
|
||||
uint16_t mask = (1 << nbits) - 1;
|
||||
unsigned char t = (unsigned char) ((w >> (bits - nbits)) & mask); // the bits to copy from w to out
|
||||
uint8_t t = (uint8_t) ((w >> (bits - nbits)) & mask); // the bits to copy from w to out
|
||||
out[i] = out[i] + (t << (8 - b - nbits));
|
||||
b += (unsigned char) nbits;
|
||||
bits -= (unsigned char) nbits;
|
||||
b += (uint8_t) nbits;
|
||||
bits -= (uint8_t) nbits;
|
||||
w &= ~(mask << bits); // not strictly necessary; mostly for debugging
|
||||
|
||||
if (bits == 0) {
|
||||
@ -174,15 +174,15 @@ void PQCLEAN_FRODOKEM640SHAKE_CLEAN_pack(unsigned char *out, const size_t outlen
|
||||
}
|
||||
|
||||
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_unpack(uint16_t *out, const size_t outlen, const unsigned char *in, const size_t inlen, const unsigned char lsb) {
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_unpack(uint16_t *out, const size_t outlen, const uint8_t *in, const size_t inlen, const uint8_t lsb) {
|
||||
// Unpack the input char vector into a uint16_t output vector, copying lsb bits
|
||||
// for each output element from input. outlen must be at least ceil(inlen * 8 / lsb).
|
||||
memset(out, 0, outlen * sizeof(uint16_t));
|
||||
|
||||
size_t i = 0; // whole uint16_t already filled in
|
||||
size_t j = 0; // whole bytes already copied
|
||||
unsigned char w = 0; // the leftover, not yet copied
|
||||
unsigned char bits = 0; // the number of lsb bits of w
|
||||
uint8_t w = 0; // the leftover, not yet copied
|
||||
uint8_t bits = 0; // the number of lsb bits of w
|
||||
|
||||
while (i < outlen && (j < inlen || ((j == inlen) && (bits > 0)))) {
|
||||
/*
|
||||
@ -196,14 +196,14 @@ void PQCLEAN_FRODOKEM640SHAKE_CLEAN_unpack(uint16_t *out, const size_t outlen, c
|
||||
^ ^
|
||||
i b
|
||||
*/
|
||||
unsigned char b = 0; // bits in out[i] already filled in
|
||||
uint8_t b = 0; // bits in out[i] already filled in
|
||||
while (b < lsb) {
|
||||
int nbits = min(lsb - b, bits);
|
||||
uint16_t mask = (1 << nbits) - 1;
|
||||
unsigned char t = (w >> (bits - nbits)) & mask; // the bits to copy from w to out
|
||||
uint8_t t = (w >> (bits - nbits)) & mask; // the bits to copy from w to out
|
||||
out[i] = out[i] + (t << (lsb - b - nbits));
|
||||
b += (unsigned char) nbits;
|
||||
bits -= (unsigned char) nbits;
|
||||
b += (uint8_t) nbits;
|
||||
bits -= (uint8_t) nbits;
|
||||
w &= ~(mask << bits); // not strictly necessary; mostly for debugging
|
||||
|
||||
if (bits == 0) {
|
||||
|
@ -15,13 +15,13 @@ const uint8_t canary[8] = {
|
||||
* make sure it is not touched by the implementations.
|
||||
*/
|
||||
static void write_canary(uint8_t *d) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
d[i] = canary[i];
|
||||
}
|
||||
}
|
||||
|
||||
static int check_canary(const uint8_t *d) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
if (d[i] != canary[i]) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -17,13 +17,13 @@ const uint8_t canary[8] = {
|
||||
* make sure it is not touched by the implementations.
|
||||
*/
|
||||
static void write_canary(uint8_t *d) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
d[i] = canary[i];
|
||||
}
|
||||
}
|
||||
|
||||
static int check_canary(const uint8_t *d) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
if (d[i] != canary[i]) {
|
||||
return -1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user