From cd1c930508a4566614116c57171c5c977d1363ef Mon Sep 17 00:00:00 2001 From: "John M. Schanck" Date: Mon, 14 Sep 2020 15:45:24 -0400 Subject: [PATCH] ms compiler changes for reed_solomon.c --- crypto_kem/hqc-rmrs-128/avx2/reed_solomon.c | 21 +++++++++++--------- crypto_kem/hqc-rmrs-128/clean/reed_solomon.c | 21 +++++++++++--------- crypto_kem/hqc-rmrs-192/avx2/reed_solomon.c | 21 +++++++++++--------- crypto_kem/hqc-rmrs-192/clean/reed_solomon.c | 21 +++++++++++--------- crypto_kem/hqc-rmrs-256/avx2/reed_solomon.c | 21 +++++++++++--------- crypto_kem/hqc-rmrs-256/clean/reed_solomon.c | 21 +++++++++++--------- 6 files changed, 72 insertions(+), 54 deletions(-) diff --git a/crypto_kem/hqc-rmrs-128/avx2/reed_solomon.c b/crypto_kem/hqc-rmrs-128/avx2/reed_solomon.c index 68090f0f..c5cd8a7c 100644 --- a/crypto_kem/hqc-rmrs-128/avx2/reed_solomon.c +++ b/crypto_kem/hqc-rmrs-128/avx2/reed_solomon.c @@ -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 */ void PQCLEAN_HQCRMRS128_AVX2_reed_solomon_encode(uint8_t *cdw, const uint8_t *msg) { + size_t i, j, k; uint8_t gate_value = 0; uint16_t tmp[PARAM_G] = {0}; 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; } - for (int i = PARAM_K - 1; i >= 0; --i) { - gate_value = msg[i] ^ cdw[PARAM_N1 - PARAM_K - 1]; + for (i = 0; i < PARAM_K; ++i) { + 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]); } - for (size_t k = PARAM_N1 - PARAM_K - 1; k; --k) { - cdw[k] = cdw[k - 1] ^ tmp[k]; + prev = 0; + 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); @@ -99,7 +102,7 @@ static uint16_t compute_elp(uint16_t *sigma, const uint16_t *syndromes) { uint16_t deg_sigma_copy = 0; uint16_t sigma_copy[PARAM_DELTA + 1] = {0}; 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 = syndromes[0]; diff --git a/crypto_kem/hqc-rmrs-128/clean/reed_solomon.c b/crypto_kem/hqc-rmrs-128/clean/reed_solomon.c index 476079d1..d3adc92e 100644 --- a/crypto_kem/hqc-rmrs-128/clean/reed_solomon.c +++ b/crypto_kem/hqc-rmrs-128/clean/reed_solomon.c @@ -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 */ void PQCLEAN_HQCRMRS128_CLEAN_reed_solomon_encode(uint8_t *cdw, const uint8_t *msg) { + size_t i, j, k; uint8_t gate_value = 0; uint16_t tmp[PARAM_G] = {0}; 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; } - for (int i = PARAM_K - 1; i >= 0; --i) { - gate_value = msg[i] ^ cdw[PARAM_N1 - PARAM_K - 1]; + for (i = 0; i < PARAM_K; ++i) { + 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]); } - for (size_t k = PARAM_N1 - PARAM_K - 1; k; --k) { - cdw[k] = cdw[k - 1] ^ tmp[k]; + prev = 0; + 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); @@ -99,7 +102,7 @@ static uint16_t compute_elp(uint16_t *sigma, const uint16_t *syndromes) { uint16_t deg_sigma_copy = 0; uint16_t sigma_copy[PARAM_DELTA + 1] = {0}; 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 = syndromes[0]; diff --git a/crypto_kem/hqc-rmrs-192/avx2/reed_solomon.c b/crypto_kem/hqc-rmrs-192/avx2/reed_solomon.c index 4d60602f..d0c7d20e 100644 --- a/crypto_kem/hqc-rmrs-192/avx2/reed_solomon.c +++ b/crypto_kem/hqc-rmrs-192/avx2/reed_solomon.c @@ -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 */ void PQCLEAN_HQCRMRS192_AVX2_reed_solomon_encode(uint8_t *cdw, const uint8_t *msg) { + size_t i, j, k; uint8_t gate_value = 0; uint16_t tmp[PARAM_G] = {0}; 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; } - for (int i = PARAM_K - 1; i >= 0; --i) { - gate_value = msg[i] ^ cdw[PARAM_N1 - PARAM_K - 1]; + for (i = 0; i < PARAM_K; ++i) { + 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]); } - for (size_t k = PARAM_N1 - PARAM_K - 1; k; --k) { - cdw[k] = cdw[k - 1] ^ tmp[k]; + prev = 0; + 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); @@ -99,7 +102,7 @@ static uint16_t compute_elp(uint16_t *sigma, const uint16_t *syndromes) { uint16_t deg_sigma_copy = 0; uint16_t sigma_copy[PARAM_DELTA + 1] = {0}; 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 = syndromes[0]; diff --git a/crypto_kem/hqc-rmrs-192/clean/reed_solomon.c b/crypto_kem/hqc-rmrs-192/clean/reed_solomon.c index ca676736..5e0c215f 100644 --- a/crypto_kem/hqc-rmrs-192/clean/reed_solomon.c +++ b/crypto_kem/hqc-rmrs-192/clean/reed_solomon.c @@ -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 */ void PQCLEAN_HQCRMRS192_CLEAN_reed_solomon_encode(uint8_t *cdw, const uint8_t *msg) { + size_t i, j, k; uint8_t gate_value = 0; uint16_t tmp[PARAM_G] = {0}; 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; } - for (int i = PARAM_K - 1; i >= 0; --i) { - gate_value = msg[i] ^ cdw[PARAM_N1 - PARAM_K - 1]; + for (i = 0; i < PARAM_K; ++i) { + 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]); } - for (size_t k = PARAM_N1 - PARAM_K - 1; k; --k) { - cdw[k] = cdw[k - 1] ^ tmp[k]; + prev = 0; + 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); @@ -99,7 +102,7 @@ static uint16_t compute_elp(uint16_t *sigma, const uint16_t *syndromes) { uint16_t deg_sigma_copy = 0; uint16_t sigma_copy[PARAM_DELTA + 1] = {0}; 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 = syndromes[0]; diff --git a/crypto_kem/hqc-rmrs-256/avx2/reed_solomon.c b/crypto_kem/hqc-rmrs-256/avx2/reed_solomon.c index 390315b0..ef25404e 100644 --- a/crypto_kem/hqc-rmrs-256/avx2/reed_solomon.c +++ b/crypto_kem/hqc-rmrs-256/avx2/reed_solomon.c @@ -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 */ void PQCLEAN_HQCRMRS256_AVX2_reed_solomon_encode(uint8_t *cdw, const uint8_t *msg) { + size_t i, j, k; uint8_t gate_value = 0; uint16_t tmp[PARAM_G] = {0}; 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; } - for (int i = PARAM_K - 1; i >= 0; --i) { - gate_value = msg[i] ^ cdw[PARAM_N1 - PARAM_K - 1]; + for (i = 0; i < PARAM_K; ++i) { + 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]); } - for (size_t k = PARAM_N1 - PARAM_K - 1; k; --k) { - cdw[k] = cdw[k - 1] ^ tmp[k]; + prev = 0; + 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); @@ -99,7 +102,7 @@ static uint16_t compute_elp(uint16_t *sigma, const uint16_t *syndromes) { uint16_t deg_sigma_copy = 0; uint16_t sigma_copy[PARAM_DELTA + 1] = {0}; 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 = syndromes[0]; diff --git a/crypto_kem/hqc-rmrs-256/clean/reed_solomon.c b/crypto_kem/hqc-rmrs-256/clean/reed_solomon.c index 83efc764..d1b1f497 100644 --- a/crypto_kem/hqc-rmrs-256/clean/reed_solomon.c +++ b/crypto_kem/hqc-rmrs-256/clean/reed_solomon.c @@ -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 */ void PQCLEAN_HQCRMRS256_CLEAN_reed_solomon_encode(uint8_t *cdw, const uint8_t *msg) { + size_t i, j, k; uint8_t gate_value = 0; uint16_t tmp[PARAM_G] = {0}; 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; } - for (int i = PARAM_K - 1; i >= 0; --i) { - gate_value = msg[i] ^ cdw[PARAM_N1 - PARAM_K - 1]; + for (i = 0; i < PARAM_K; ++i) { + 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]); } - for (size_t k = PARAM_N1 - PARAM_K - 1; k; --k) { - cdw[k] = cdw[k - 1] ^ tmp[k]; + prev = 0; + 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); @@ -99,7 +102,7 @@ static uint16_t compute_elp(uint16_t *sigma, const uint16_t *syndromes) { uint16_t deg_sigma_copy = 0; uint16_t sigma_copy[PARAM_DELTA + 1] = {0}; 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 = syndromes[0];