mirror of
https://github.com/henrydcase/pqc.git
synced 2024-11-22 23:48:58 +00:00
Apply astyle
This commit is contained in:
parent
a2399091a7
commit
7485f35366
@ -14,8 +14,8 @@
|
||||
#include "params.h"
|
||||
#include "common.h"
|
||||
|
||||
int PQCLEAN_FRODOKEM640SHAKE_CLEAN_crypto_kem_keypair(unsigned char* pk, unsigned char* sk)
|
||||
{ // FrodoKEM's key generation
|
||||
int PQCLEAN_FRODOKEM640SHAKE_CLEAN_crypto_kem_keypair(unsigned char *pk, unsigned char *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)
|
||||
uint8_t *pk_seedA = &pk[0];
|
||||
@ -65,8 +65,8 @@ 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)
|
||||
{ // FrodoKEM's key encapsulation
|
||||
int PQCLEAN_FRODOKEM640SHAKE_CLEAN_crypto_kem_enc(unsigned char *ct, unsigned char *ss, const unsigned char *pk) {
|
||||
// FrodoKEM's key encapsulation
|
||||
const uint8_t *pk_seedA = &pk[0];
|
||||
const uint8_t *pk_b = &pk[BYTES_SEED_A];
|
||||
uint8_t *ct_c1 = &ct[0];
|
||||
@ -131,8 +131,8 @@ 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)
|
||||
{ // FrodoKEM's key decapsulation
|
||||
int PQCLEAN_FRODOKEM640SHAKE_CLEAN_crypto_kem_dec(unsigned char *ss, const unsigned char *ct, const unsigned char *sk) {
|
||||
// FrodoKEM's key decapsulation
|
||||
uint16_t B[PARAMS_N * PARAMS_NBAR] = {0};
|
||||
uint16_t Bp[PARAMS_N * PARAMS_NBAR] = {0};
|
||||
uint16_t W[PARAMS_NBAR * PARAMS_NBAR] = {0}; // contains secret data
|
||||
@ -193,7 +193,9 @@ 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++) BBp[i] = BBp[i] & ((1 << PARAMS_LOGQ)-1);
|
||||
for (int i = 0; i < PARAMS_N * PARAMS_NBAR; i++) {
|
||||
BBp[i] = BBp[i] & ((1 << PARAMS_LOGQ) - 1);
|
||||
}
|
||||
|
||||
// Is (Bp == BBp & C == CC) = true
|
||||
if (memcmp(Bp, BBp, 2 * PARAMS_N * PARAMS_NBAR) == 0 && memcmp(C, CC, 2 * PARAMS_NBAR * PARAMS_NBAR) == 0) {
|
||||
|
@ -12,8 +12,8 @@
|
||||
#include "api.h"
|
||||
#include "params.h"
|
||||
|
||||
int PQCLEAN_FRODOKEM640SHAKE_CLEAN_mul_add_as_plus_e(uint16_t *out, const uint16_t *s, const uint16_t *e, const uint8_t *seed_A)
|
||||
{ // Generate-and-multiply: generate matrix A (N x N) row-wise, multiply by s on the right.
|
||||
int PQCLEAN_FRODOKEM640SHAKE_CLEAN_mul_add_as_plus_e(uint16_t *out, const uint16_t *s, const uint16_t *e, const uint8_t *seed_A) {
|
||||
// Generate-and-multiply: generate matrix A (N x N) row-wise, multiply by s on the right.
|
||||
// Inputs: s, e (N x N_BAR)
|
||||
// Output: out = A*s + e (N x N_BAR)
|
||||
int i, j, k;
|
||||
@ -42,8 +42,8 @@ int PQCLEAN_FRODOKEM640SHAKE_CLEAN_mul_add_as_plus_e(uint16_t *out, const uint16
|
||||
}
|
||||
|
||||
|
||||
int PQCLEAN_FRODOKEM640SHAKE_CLEAN_mul_add_sa_plus_e(uint16_t *out, const uint16_t *s, const uint16_t *e, const uint8_t *seed_A)
|
||||
{ // Generate-and-multiply: generate matrix A (N x N) column-wise, multiply by s' on the left.
|
||||
int PQCLEAN_FRODOKEM640SHAKE_CLEAN_mul_add_sa_plus_e(uint16_t *out, const uint16_t *s, const uint16_t *e, const uint8_t *seed_A) {
|
||||
// Generate-and-multiply: generate matrix A (N x N) column-wise, multiply by s' on the left.
|
||||
// Inputs: s', e' (N_BAR x N)
|
||||
// Output: out = s'*A + e' (N_BAR x N)
|
||||
int i, j, k;
|
||||
|
@ -11,8 +11,8 @@
|
||||
|
||||
static uint16_t CDF_TABLE[CDF_TABLE_LEN] = CDF_TABLE_DATA;
|
||||
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_sample_n(uint16_t *s, const size_t n)
|
||||
{ // Fills vector s with n samples from the noise distribution which requires 16 bits to sample.
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_sample_n(uint16_t *s, const size_t n) {
|
||||
// Fills vector s with n samples from the noise distribution which requires 16 bits to sample.
|
||||
// The distribution is specified by its CDF.
|
||||
// Input: pseudo-random values (2*n bytes) passed in s. The input is overwritten by the output.
|
||||
unsigned int i, j;
|
||||
|
@ -13,8 +13,8 @@
|
||||
#define min(x, y) (((x) < (y)) ? (x) : (y))
|
||||
|
||||
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_mul_bs(uint16_t *out, const uint16_t *b, const uint16_t *s)
|
||||
{ // Multiply by s on the right
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_mul_bs(uint16_t *out, const uint16_t *b, const uint16_t *s) {
|
||||
// Multiply by s on the right
|
||||
// Inputs: b (N_BAR x N), s (N x N_BAR)
|
||||
// Output: out = b*s (N_BAR x N_BAR)
|
||||
int i, j, k;
|
||||
@ -31,8 +31,8 @@ void PQCLEAN_FRODOKEM640SHAKE_CLEAN_mul_bs(uint16_t *out, const uint16_t *b, con
|
||||
}
|
||||
|
||||
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_mul_add_sb_plus_e(uint16_t *out, const uint16_t *b, const uint16_t *s, const uint16_t *e)
|
||||
{ // Multiply by s on the left
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_mul_add_sb_plus_e(uint16_t *out, const uint16_t *b, const uint16_t *s, const uint16_t *e) {
|
||||
// Multiply by s on the left
|
||||
// Inputs: b (N x N_BAR), s (N_BAR x N), e (N_BAR x N_BAR)
|
||||
// Output: out = s*b + e (N_BAR x N_BAR)
|
||||
int i, j, k;
|
||||
@ -49,8 +49,8 @@ void PQCLEAN_FRODOKEM640SHAKE_CLEAN_mul_add_sb_plus_e(uint16_t *out, const uint1
|
||||
}
|
||||
|
||||
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_add(uint16_t *out, const uint16_t *a, const uint16_t *b)
|
||||
{ // Add a and b
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_add(uint16_t *out, const uint16_t *a, const uint16_t *b) {
|
||||
// Add a and b
|
||||
// Inputs: a, b (N_BAR x N_BAR)
|
||||
// Output: c = a + b
|
||||
|
||||
@ -60,8 +60,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)
|
||||
{ // Subtract a and b
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_sub(uint16_t *out, const uint16_t *a, const uint16_t *b) {
|
||||
// Subtract a and b
|
||||
// Inputs: a, b (N_BAR x N_BAR)
|
||||
// Output: c = a - b
|
||||
|
||||
@ -71,8 +71,8 @@ void PQCLEAN_FRODOKEM640SHAKE_CLEAN_sub(uint16_t *out, const uint16_t *a, const
|
||||
}
|
||||
|
||||
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_key_encode(uint16_t *out, const uint16_t *in)
|
||||
{ // Encoding
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_key_encode(uint16_t *out, const uint16_t *in) {
|
||||
// Encoding
|
||||
unsigned int i, j, npieces_word = 8;
|
||||
unsigned int nwords = (PARAMS_NBAR * PARAMS_NBAR) / 8;
|
||||
uint64_t temp, mask = ((uint64_t)1 << PARAMS_EXTRACTED_BITS) - 1;
|
||||
@ -80,8 +80,9 @@ void PQCLEAN_FRODOKEM640SHAKE_CLEAN_key_encode(uint16_t *out, const uint16_t *in
|
||||
|
||||
for (i = 0; i < nwords; i++) {
|
||||
temp = 0;
|
||||
for(j = 0; j < PARAMS_EXTRACTED_BITS; j++)
|
||||
for (j = 0; j < PARAMS_EXTRACTED_BITS; j++) {
|
||||
temp |= ((uint64_t)((uint8_t *)in)[i * PARAMS_EXTRACTED_BITS + j]) << (8 * j);
|
||||
}
|
||||
for (j = 0; j < npieces_word; j++) {
|
||||
*pos = (uint16_t)((temp & mask) << (PARAMS_LOGQ - PARAMS_EXTRACTED_BITS));
|
||||
temp >>= PARAMS_EXTRACTED_BITS;
|
||||
@ -91,8 +92,8 @@ 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)
|
||||
{ // Decoding
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_key_decode(uint16_t *out, const uint16_t *in) {
|
||||
// Decoding
|
||||
unsigned int i, j, index = 0, npieces_word = 8;
|
||||
unsigned int nwords = (PARAMS_NBAR * PARAMS_NBAR) / 8;
|
||||
uint16_t temp, maskex = ((uint16_t)1 << PARAMS_EXTRACTED_BITS) - 1, maskq = ((uint16_t)1 << PARAMS_LOGQ) - 1;
|
||||
@ -106,14 +107,15 @@ void PQCLEAN_FRODOKEM640SHAKE_CLEAN_key_decode(uint16_t *out, const uint16_t *in
|
||||
templong |= ((uint64_t)(temp & maskex)) << (PARAMS_EXTRACTED_BITS * j);
|
||||
index++;
|
||||
}
|
||||
for(j = 0; j < PARAMS_EXTRACTED_BITS; j++)
|
||||
for (j = 0; j < PARAMS_EXTRACTED_BITS; j++) {
|
||||
pos[i * PARAMS_EXTRACTED_BITS + j] = (templong >> (8 * j)) & 0xFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_pack(unsigned char *out, const size_t outlen, const uint16_t *in, const size_t inlen, const unsigned char lsb)
|
||||
{ // Pack the input uint16 vector into a char output vector, copying lsb bits from each input element.
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_pack(unsigned char *out, const size_t outlen, const uint16_t *in, const size_t inlen, const unsigned char 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);
|
||||
|
||||
@ -161,8 +163,8 @@ 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)
|
||||
{ // Unpack the input char vector into a uint16_t output vector, copying lsb bits
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_unpack(uint16_t *out, const size_t outlen, const unsigned char *in, const size_t inlen, const unsigned char 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));
|
||||
|
||||
@ -210,8 +212,8 @@ void PQCLEAN_FRODOKEM640SHAKE_CLEAN_unpack(uint16_t *out, const size_t outlen, c
|
||||
}
|
||||
|
||||
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_clear_bytes(uint8_t *mem, size_t n)
|
||||
{ // Clear 8-bit bytes from memory. "n" indicates the number of bytes to be zeroed.
|
||||
void PQCLEAN_FRODOKEM640SHAKE_CLEAN_clear_bytes(uint8_t *mem, size_t n) {
|
||||
// Clear 8-bit bytes from memory. "n" indicates the number of bytes to be zeroed.
|
||||
// This function uses the volatile type qualifier to inform the compiler not to optimize out the memory clearing.
|
||||
volatile uint8_t *v = mem;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user