ms compiler changes for reed_solomon.c

This commit is contained in:
John M. Schanck 2020-09-14 15:45:24 -04:00 committad av Kris Kwiatkowski
förälder 84005fd23a
incheckning d2415c6b09
6 ändrade filer med 72 tillägg och 54 borttagningar

Visa fil

@ -32,27 +32,30 @@ static void correct_errors(uint8_t *cdw, const uint16_t *error_values);
* @param[in] msg Array of size VEC_K_SIZE_64 storing the message * @param[in] msg Array of size VEC_K_SIZE_64 storing the message
*/ */
void PQCLEAN_HQCRMRS128_AVX2_reed_solomon_encode(uint8_t *cdw, const uint8_t *msg) { void PQCLEAN_HQCRMRS128_AVX2_reed_solomon_encode(uint8_t *cdw, const uint8_t *msg) {
size_t i, j, k;
uint8_t gate_value = 0; uint8_t gate_value = 0;
uint16_t tmp[PARAM_G] = {0}; uint16_t tmp[PARAM_G] = {0};
uint16_t PARAM_RS_POLY [] = {RS_POLY_COEFS}; uint16_t PARAM_RS_POLY [] = {RS_POLY_COEFS};
uint8_t prev, x;
for (size_t i = 0; i < PARAM_N1; i++) { for (i = 0; i < PARAM_N1; ++i) {
cdw[i] = 0; cdw[i] = 0;
} }
for (int i = PARAM_K - 1; i >= 0; --i) { for (i = 0; i < PARAM_K; ++i) {
gate_value = msg[i] ^ cdw[PARAM_N1 - PARAM_K - 1]; gate_value = msg[PARAM_K - 1 - i] ^ cdw[PARAM_N1 - PARAM_K - 1];
for (size_t j = 0; j < PARAM_G; ++j) { for (j = 0; j < PARAM_G; ++j) {
tmp[j] = PQCLEAN_HQCRMRS128_AVX2_gf_mul(gate_value, PARAM_RS_POLY[j]); tmp[j] = PQCLEAN_HQCRMRS128_AVX2_gf_mul(gate_value, PARAM_RS_POLY[j]);
} }
for (size_t k = PARAM_N1 - PARAM_K - 1; k; --k) { prev = 0;
cdw[k] = cdw[k - 1] ^ tmp[k]; for (k = 0; k < PARAM_N1 - PARAM_K; k++) {
x = cdw[k];
cdw[k] = (uint8_t) prev ^ tmp[k];
prev = x;
} }
cdw[0] = tmp[0];
} }
memcpy(cdw + PARAM_N1 - PARAM_K, msg, PARAM_K); memcpy(cdw + PARAM_N1 - PARAM_K, msg, PARAM_K);
@ -99,7 +102,7 @@ static uint16_t compute_elp(uint16_t *sigma, const uint16_t *syndromes) {
uint16_t deg_sigma_copy = 0; uint16_t deg_sigma_copy = 0;
uint16_t sigma_copy[PARAM_DELTA + 1] = {0}; uint16_t sigma_copy[PARAM_DELTA + 1] = {0};
uint16_t X_sigma_p[PARAM_DELTA + 1] = {0, 1}; uint16_t X_sigma_p[PARAM_DELTA + 1] = {0, 1};
uint16_t pp = -1; // 2*rho uint16_t pp = (uint16_t) -1; // 2*rho
uint16_t d_p = 1; uint16_t d_p = 1;
uint16_t d = syndromes[0]; uint16_t d = syndromes[0];

Visa fil

@ -32,27 +32,30 @@ static void correct_errors(uint8_t *cdw, const uint16_t *error_values);
* @param[in] msg Array of size VEC_K_SIZE_64 storing the message * @param[in] msg Array of size VEC_K_SIZE_64 storing the message
*/ */
void PQCLEAN_HQCRMRS128_CLEAN_reed_solomon_encode(uint8_t *cdw, const uint8_t *msg) { void PQCLEAN_HQCRMRS128_CLEAN_reed_solomon_encode(uint8_t *cdw, const uint8_t *msg) {
size_t i, j, k;
uint8_t gate_value = 0; uint8_t gate_value = 0;
uint16_t tmp[PARAM_G] = {0}; uint16_t tmp[PARAM_G] = {0};
uint16_t PARAM_RS_POLY [] = {RS_POLY_COEFS}; uint16_t PARAM_RS_POLY [] = {RS_POLY_COEFS};
uint8_t prev, x;
for (size_t i = 0; i < PARAM_N1; i++) { for (i = 0; i < PARAM_N1; ++i) {
cdw[i] = 0; cdw[i] = 0;
} }
for (int i = PARAM_K - 1; i >= 0; --i) { for (i = 0; i < PARAM_K; ++i) {
gate_value = msg[i] ^ cdw[PARAM_N1 - PARAM_K - 1]; gate_value = msg[PARAM_K - 1 - i] ^ cdw[PARAM_N1 - PARAM_K - 1];
for (size_t j = 0; j < PARAM_G; ++j) { for (j = 0; j < PARAM_G; ++j) {
tmp[j] = PQCLEAN_HQCRMRS128_CLEAN_gf_mul(gate_value, PARAM_RS_POLY[j]); tmp[j] = PQCLEAN_HQCRMRS128_CLEAN_gf_mul(gate_value, PARAM_RS_POLY[j]);
} }
for (size_t k = PARAM_N1 - PARAM_K - 1; k; --k) { prev = 0;
cdw[k] = cdw[k - 1] ^ tmp[k]; for (k = 0; k < PARAM_N1 - PARAM_K; k++) {
x = cdw[k];
cdw[k] = (uint8_t) prev ^ tmp[k];
prev = x;
} }
cdw[0] = tmp[0];
} }
memcpy(cdw + PARAM_N1 - PARAM_K, msg, PARAM_K); memcpy(cdw + PARAM_N1 - PARAM_K, msg, PARAM_K);
@ -99,7 +102,7 @@ static uint16_t compute_elp(uint16_t *sigma, const uint16_t *syndromes) {
uint16_t deg_sigma_copy = 0; uint16_t deg_sigma_copy = 0;
uint16_t sigma_copy[PARAM_DELTA + 1] = {0}; uint16_t sigma_copy[PARAM_DELTA + 1] = {0};
uint16_t X_sigma_p[PARAM_DELTA + 1] = {0, 1}; uint16_t X_sigma_p[PARAM_DELTA + 1] = {0, 1};
uint16_t pp = -1; // 2*rho uint16_t pp = (uint16_t) -1; // 2*rho
uint16_t d_p = 1; uint16_t d_p = 1;
uint16_t d = syndromes[0]; uint16_t d = syndromes[0];

Visa fil

@ -32,27 +32,30 @@ static void correct_errors(uint8_t *cdw, const uint16_t *error_values);
* @param[in] msg Array of size VEC_K_SIZE_64 storing the message * @param[in] msg Array of size VEC_K_SIZE_64 storing the message
*/ */
void PQCLEAN_HQCRMRS192_AVX2_reed_solomon_encode(uint8_t *cdw, const uint8_t *msg) { void PQCLEAN_HQCRMRS192_AVX2_reed_solomon_encode(uint8_t *cdw, const uint8_t *msg) {
size_t i, j, k;
uint8_t gate_value = 0; uint8_t gate_value = 0;
uint16_t tmp[PARAM_G] = {0}; uint16_t tmp[PARAM_G] = {0};
uint16_t PARAM_RS_POLY [] = {RS_POLY_COEFS}; uint16_t PARAM_RS_POLY [] = {RS_POLY_COEFS};
uint8_t prev, x;
for (size_t i = 0; i < PARAM_N1; i++) { for (i = 0; i < PARAM_N1; ++i) {
cdw[i] = 0; cdw[i] = 0;
} }
for (int i = PARAM_K - 1; i >= 0; --i) { for (i = 0; i < PARAM_K; ++i) {
gate_value = msg[i] ^ cdw[PARAM_N1 - PARAM_K - 1]; gate_value = msg[PARAM_K - 1 - i] ^ cdw[PARAM_N1 - PARAM_K - 1];
for (size_t j = 0; j < PARAM_G; ++j) { for (j = 0; j < PARAM_G; ++j) {
tmp[j] = PQCLEAN_HQCRMRS192_AVX2_gf_mul(gate_value, PARAM_RS_POLY[j]); tmp[j] = PQCLEAN_HQCRMRS192_AVX2_gf_mul(gate_value, PARAM_RS_POLY[j]);
} }
for (size_t k = PARAM_N1 - PARAM_K - 1; k; --k) { prev = 0;
cdw[k] = cdw[k - 1] ^ tmp[k]; for (k = 0; k < PARAM_N1 - PARAM_K; k++) {
x = cdw[k];
cdw[k] = (uint8_t) prev ^ tmp[k];
prev = x;
} }
cdw[0] = tmp[0];
} }
memcpy(cdw + PARAM_N1 - PARAM_K, msg, PARAM_K); memcpy(cdw + PARAM_N1 - PARAM_K, msg, PARAM_K);
@ -99,7 +102,7 @@ static uint16_t compute_elp(uint16_t *sigma, const uint16_t *syndromes) {
uint16_t deg_sigma_copy = 0; uint16_t deg_sigma_copy = 0;
uint16_t sigma_copy[PARAM_DELTA + 1] = {0}; uint16_t sigma_copy[PARAM_DELTA + 1] = {0};
uint16_t X_sigma_p[PARAM_DELTA + 1] = {0, 1}; uint16_t X_sigma_p[PARAM_DELTA + 1] = {0, 1};
uint16_t pp = -1; // 2*rho uint16_t pp = (uint16_t) -1; // 2*rho
uint16_t d_p = 1; uint16_t d_p = 1;
uint16_t d = syndromes[0]; uint16_t d = syndromes[0];

Visa fil

@ -32,27 +32,30 @@ static void correct_errors(uint8_t *cdw, const uint16_t *error_values);
* @param[in] msg Array of size VEC_K_SIZE_64 storing the message * @param[in] msg Array of size VEC_K_SIZE_64 storing the message
*/ */
void PQCLEAN_HQCRMRS192_CLEAN_reed_solomon_encode(uint8_t *cdw, const uint8_t *msg) { void PQCLEAN_HQCRMRS192_CLEAN_reed_solomon_encode(uint8_t *cdw, const uint8_t *msg) {
size_t i, j, k;
uint8_t gate_value = 0; uint8_t gate_value = 0;
uint16_t tmp[PARAM_G] = {0}; uint16_t tmp[PARAM_G] = {0};
uint16_t PARAM_RS_POLY [] = {RS_POLY_COEFS}; uint16_t PARAM_RS_POLY [] = {RS_POLY_COEFS};
uint8_t prev, x;
for (size_t i = 0; i < PARAM_N1; i++) { for (i = 0; i < PARAM_N1; ++i) {
cdw[i] = 0; cdw[i] = 0;
} }
for (int i = PARAM_K - 1; i >= 0; --i) { for (i = 0; i < PARAM_K; ++i) {
gate_value = msg[i] ^ cdw[PARAM_N1 - PARAM_K - 1]; gate_value = msg[PARAM_K - 1 - i] ^ cdw[PARAM_N1 - PARAM_K - 1];
for (size_t j = 0; j < PARAM_G; ++j) { for (j = 0; j < PARAM_G; ++j) {
tmp[j] = PQCLEAN_HQCRMRS192_CLEAN_gf_mul(gate_value, PARAM_RS_POLY[j]); tmp[j] = PQCLEAN_HQCRMRS192_CLEAN_gf_mul(gate_value, PARAM_RS_POLY[j]);
} }
for (size_t k = PARAM_N1 - PARAM_K - 1; k; --k) { prev = 0;
cdw[k] = cdw[k - 1] ^ tmp[k]; for (k = 0; k < PARAM_N1 - PARAM_K; k++) {
x = cdw[k];
cdw[k] = (uint8_t) prev ^ tmp[k];
prev = x;
} }
cdw[0] = tmp[0];
} }
memcpy(cdw + PARAM_N1 - PARAM_K, msg, PARAM_K); memcpy(cdw + PARAM_N1 - PARAM_K, msg, PARAM_K);
@ -99,7 +102,7 @@ static uint16_t compute_elp(uint16_t *sigma, const uint16_t *syndromes) {
uint16_t deg_sigma_copy = 0; uint16_t deg_sigma_copy = 0;
uint16_t sigma_copy[PARAM_DELTA + 1] = {0}; uint16_t sigma_copy[PARAM_DELTA + 1] = {0};
uint16_t X_sigma_p[PARAM_DELTA + 1] = {0, 1}; uint16_t X_sigma_p[PARAM_DELTA + 1] = {0, 1};
uint16_t pp = -1; // 2*rho uint16_t pp = (uint16_t) -1; // 2*rho
uint16_t d_p = 1; uint16_t d_p = 1;
uint16_t d = syndromes[0]; uint16_t d = syndromes[0];

Visa fil

@ -32,27 +32,30 @@ static void correct_errors(uint8_t *cdw, const uint16_t *error_values);
* @param[in] msg Array of size VEC_K_SIZE_64 storing the message * @param[in] msg Array of size VEC_K_SIZE_64 storing the message
*/ */
void PQCLEAN_HQCRMRS256_AVX2_reed_solomon_encode(uint8_t *cdw, const uint8_t *msg) { void PQCLEAN_HQCRMRS256_AVX2_reed_solomon_encode(uint8_t *cdw, const uint8_t *msg) {
size_t i, j, k;
uint8_t gate_value = 0; uint8_t gate_value = 0;
uint16_t tmp[PARAM_G] = {0}; uint16_t tmp[PARAM_G] = {0};
uint16_t PARAM_RS_POLY [] = {RS_POLY_COEFS}; uint16_t PARAM_RS_POLY [] = {RS_POLY_COEFS};
uint8_t prev, x;
for (size_t i = 0; i < PARAM_N1; i++) { for (i = 0; i < PARAM_N1; ++i) {
cdw[i] = 0; cdw[i] = 0;
} }
for (int i = PARAM_K - 1; i >= 0; --i) { for (i = 0; i < PARAM_K; ++i) {
gate_value = msg[i] ^ cdw[PARAM_N1 - PARAM_K - 1]; gate_value = msg[PARAM_K - 1 - i] ^ cdw[PARAM_N1 - PARAM_K - 1];
for (size_t j = 0; j < PARAM_G; ++j) { for (j = 0; j < PARAM_G; ++j) {
tmp[j] = PQCLEAN_HQCRMRS256_AVX2_gf_mul(gate_value, PARAM_RS_POLY[j]); tmp[j] = PQCLEAN_HQCRMRS256_AVX2_gf_mul(gate_value, PARAM_RS_POLY[j]);
} }
for (size_t k = PARAM_N1 - PARAM_K - 1; k; --k) { prev = 0;
cdw[k] = cdw[k - 1] ^ tmp[k]; for (k = 0; k < PARAM_N1 - PARAM_K; k++) {
x = cdw[k];
cdw[k] = (uint8_t) prev ^ tmp[k];
prev = x;
} }
cdw[0] = tmp[0];
} }
memcpy(cdw + PARAM_N1 - PARAM_K, msg, PARAM_K); memcpy(cdw + PARAM_N1 - PARAM_K, msg, PARAM_K);
@ -99,7 +102,7 @@ static uint16_t compute_elp(uint16_t *sigma, const uint16_t *syndromes) {
uint16_t deg_sigma_copy = 0; uint16_t deg_sigma_copy = 0;
uint16_t sigma_copy[PARAM_DELTA + 1] = {0}; uint16_t sigma_copy[PARAM_DELTA + 1] = {0};
uint16_t X_sigma_p[PARAM_DELTA + 1] = {0, 1}; uint16_t X_sigma_p[PARAM_DELTA + 1] = {0, 1};
uint16_t pp = -1; // 2*rho uint16_t pp = (uint16_t) -1; // 2*rho
uint16_t d_p = 1; uint16_t d_p = 1;
uint16_t d = syndromes[0]; uint16_t d = syndromes[0];

Visa fil

@ -32,27 +32,30 @@ static void correct_errors(uint8_t *cdw, const uint16_t *error_values);
* @param[in] msg Array of size VEC_K_SIZE_64 storing the message * @param[in] msg Array of size VEC_K_SIZE_64 storing the message
*/ */
void PQCLEAN_HQCRMRS256_CLEAN_reed_solomon_encode(uint8_t *cdw, const uint8_t *msg) { void PQCLEAN_HQCRMRS256_CLEAN_reed_solomon_encode(uint8_t *cdw, const uint8_t *msg) {
size_t i, j, k;
uint8_t gate_value = 0; uint8_t gate_value = 0;
uint16_t tmp[PARAM_G] = {0}; uint16_t tmp[PARAM_G] = {0};
uint16_t PARAM_RS_POLY [] = {RS_POLY_COEFS}; uint16_t PARAM_RS_POLY [] = {RS_POLY_COEFS};
uint8_t prev, x;
for (size_t i = 0; i < PARAM_N1; i++) { for (i = 0; i < PARAM_N1; ++i) {
cdw[i] = 0; cdw[i] = 0;
} }
for (int i = PARAM_K - 1; i >= 0; --i) { for (i = 0; i < PARAM_K; ++i) {
gate_value = msg[i] ^ cdw[PARAM_N1 - PARAM_K - 1]; gate_value = msg[PARAM_K - 1 - i] ^ cdw[PARAM_N1 - PARAM_K - 1];
for (size_t j = 0; j < PARAM_G; ++j) { for (j = 0; j < PARAM_G; ++j) {
tmp[j] = PQCLEAN_HQCRMRS256_CLEAN_gf_mul(gate_value, PARAM_RS_POLY[j]); tmp[j] = PQCLEAN_HQCRMRS256_CLEAN_gf_mul(gate_value, PARAM_RS_POLY[j]);
} }
for (size_t k = PARAM_N1 - PARAM_K - 1; k; --k) { prev = 0;
cdw[k] = cdw[k - 1] ^ tmp[k]; for (k = 0; k < PARAM_N1 - PARAM_K; k++) {
x = cdw[k];
cdw[k] = (uint8_t) prev ^ tmp[k];
prev = x;
} }
cdw[0] = tmp[0];
} }
memcpy(cdw + PARAM_N1 - PARAM_K, msg, PARAM_K); memcpy(cdw + PARAM_N1 - PARAM_K, msg, PARAM_K);
@ -99,7 +102,7 @@ static uint16_t compute_elp(uint16_t *sigma, const uint16_t *syndromes) {
uint16_t deg_sigma_copy = 0; uint16_t deg_sigma_copy = 0;
uint16_t sigma_copy[PARAM_DELTA + 1] = {0}; uint16_t sigma_copy[PARAM_DELTA + 1] = {0};
uint16_t X_sigma_p[PARAM_DELTA + 1] = {0, 1}; uint16_t X_sigma_p[PARAM_DELTA + 1] = {0, 1};
uint16_t pp = -1; // 2*rho uint16_t pp = (uint16_t) -1; // 2*rho
uint16_t d_p = 1; uint16_t d_p = 1;
uint16_t d = syndromes[0]; uint16_t d = syndromes[0];