From 8263a9d0cb4de6cef151bcb3ce263f8290dff19c Mon Sep 17 00:00:00 2001 From: "John M. Schanck" Date: Wed, 28 Oct 2020 23:42:28 -0400 Subject: [PATCH] explicit casts --- crypto_kem/firesaber/META.yml | 4 +-- crypto_kem/firesaber/avx2/pack_unpack.c | 42 +++++++++++------------ crypto_kem/firesaber/clean/pack_unpack.c | 42 +++++++++++------------ crypto_kem/lightsaber/META.yml | 4 +-- crypto_kem/lightsaber/avx2/pack_unpack.c | 42 +++++++++++------------ crypto_kem/lightsaber/clean/pack_unpack.c | 42 +++++++++++------------ crypto_kem/saber/META.yml | 4 +-- crypto_kem/saber/avx2/pack_unpack.c | 38 ++++++++++---------- crypto_kem/saber/clean/pack_unpack.c | 38 ++++++++++---------- 9 files changed, 128 insertions(+), 128 deletions(-) diff --git a/crypto_kem/firesaber/META.yml b/crypto_kem/firesaber/META.yml index 3d1a0a41..24363a85 100644 --- a/crypto_kem/firesaber/META.yml +++ b/crypto_kem/firesaber/META.yml @@ -14,9 +14,9 @@ principal-submitters: - Frederik Vercauteren implementations: - name: clean - version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/90d072e4/saber + version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/3a63008f/saber - name: avx2 - version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/90d072e4/saber + version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/3a63008f/saber supported_platforms: - architecture: x86_64 operating_systems: diff --git a/crypto_kem/firesaber/avx2/pack_unpack.c b/crypto_kem/firesaber/avx2/pack_unpack.c index 82f5a3f0..d5e6b9ba 100644 --- a/crypto_kem/firesaber/avx2/pack_unpack.c +++ b/crypto_kem/firesaber/avx2/pack_unpack.c @@ -8,9 +8,9 @@ void PQCLEAN_FIRESABER_AVX2_POLT2BS(uint8_t bytes[SABER_SCALEBYTES_KEM], const p const uint16_t *in = data->coeffs; uint8_t *out = bytes; for (j = 0; j < SABER_N / 4; j++) { - out[0] = (in[0] & 0x3f) | (in[1] << 6); - out[1] = ((in[1] >> 2) & 0x0f) | (in[2] << 4); - out[2] = ((in[2] >> 4) & 0x03) | (in[3] << 2); + out[0] = (uint8_t) ((in[0] & 0x3f) | (in[1] << 6)); + out[1] = (uint8_t) (((in[1] >> 2) & 0x0f) | (in[2] << 4)); + out[2] = (uint8_t) (((in[2] >> 4) & 0x03) | (in[3] << 2)); in += 4; out += 3; } @@ -36,19 +36,19 @@ static void POLq2BS(uint8_t bytes[SABER_POLYBYTES], const poly *data) { const uint16_t *in = data->coeffs; uint8_t *out = bytes; for (j = 0; j < SABER_N / 8; j++) { - out[0] = in[0]; - out[1] = ((in[0] >> 8) & 0x1f) | (in[1] << 5); - out[2] = in[1] >> 3; - out[3] = ((in[1] >> 11) & 0x03) | (in[2] << 2); - out[4] = ((in[2] >> 6) & 0x7f) | (in[3] << 7); - out[5] = in[3] >> 1; - out[6] = ((in[3] >> 9) & 0x0f) | (in[4] << 4); - out[7] = in[4] >> 4; - out[8] = ((in[4] >> 12) & 0x01) | (in[5] << 1); - out[9] = ((in[5] >> 7) & 0x3f) | (in[6] << 6); - out[10] = in[6] >> 2; - out[11] = ((in[6] >> 10) & 0x07) | (in[7] << 3); - out[12] = in[7] >> 5; + out[0] = (uint8_t) (in[0]); + out[1] = (uint8_t) (((in[0] >> 8) & 0x1f) | (in[1] << 5)); + out[2] = (uint8_t) (in[1] >> 3); + out[3] = (uint8_t) (((in[1] >> 11) & 0x03) | (in[2] << 2)); + out[4] = (uint8_t) (((in[2] >> 6) & 0x7f) | (in[3] << 7)); + out[5] = (uint8_t) (in[3] >> 1); + out[6] = (uint8_t) (((in[3] >> 9) & 0x0f) | (in[4] << 4)); + out[7] = (uint8_t) (in[4] >> 4); + out[8] = (uint8_t) (((in[4] >> 12) & 0x01) | (in[5] << 1)); + out[9] = (uint8_t) (((in[5] >> 7) & 0x3f) | (in[6] << 6)); + out[10] = (uint8_t) (in[6] >> 2); + out[11] = (uint8_t) (((in[6] >> 10) & 0x07) | (in[7] << 3)); + out[12] = (uint8_t) (in[7] >> 5); in += 8; out += 13; } @@ -78,11 +78,11 @@ static void POLp2BS(uint8_t bytes[SABER_POLYCOMPRESSEDBYTES], const poly *data) const uint16_t *in = data->coeffs; uint8_t *out = bytes; for (j = 0; j < SABER_N / 4; j++) { - out[0] = in[0]; - out[1] = ((in[0] >> 8) & 0x03) | (in[1] << 2); - out[2] = ((in[1] >> 6) & 0x0f) | (in[2] << 4); - out[3] = ((in[2] >> 4) & 0x3f) | (in[3] << 6); - out[4] = in[3] >> 2; + out[0] = (uint8_t) (in[0]); + out[1] = (uint8_t) (((in[0] >> 8) & 0x03) | (in[1] << 2)); + out[2] = (uint8_t) (((in[1] >> 6) & 0x0f) | (in[2] << 4)); + out[3] = (uint8_t) (((in[2] >> 4) & 0x3f) | (in[3] << 6)); + out[4] = (uint8_t) (in[3] >> 2); in += 4; out += 5; } diff --git a/crypto_kem/firesaber/clean/pack_unpack.c b/crypto_kem/firesaber/clean/pack_unpack.c index 91ffd723..2d1538ae 100644 --- a/crypto_kem/firesaber/clean/pack_unpack.c +++ b/crypto_kem/firesaber/clean/pack_unpack.c @@ -8,9 +8,9 @@ void PQCLEAN_FIRESABER_CLEAN_POLT2BS(uint8_t bytes[SABER_SCALEBYTES_KEM], const const uint16_t *in = data->coeffs; uint8_t *out = bytes; for (j = 0; j < SABER_N / 4; j++) { - out[0] = (in[0] & 0x3f) | (in[1] << 6); - out[1] = ((in[1] >> 2) & 0x0f) | (in[2] << 4); - out[2] = ((in[2] >> 4) & 0x03) | (in[3] << 2); + out[0] = (uint8_t) ((in[0] & 0x3f) | (in[1] << 6)); + out[1] = (uint8_t) (((in[1] >> 2) & 0x0f) | (in[2] << 4)); + out[2] = (uint8_t) (((in[2] >> 4) & 0x03) | (in[3] << 2)); in += 4; out += 3; } @@ -36,19 +36,19 @@ static void POLq2BS(uint8_t bytes[SABER_POLYBYTES], const poly *data) { const uint16_t *in = data->coeffs; uint8_t *out = bytes; for (j = 0; j < SABER_N / 8; j++) { - out[0] = in[0]; - out[1] = ((in[0] >> 8) & 0x1f) | (in[1] << 5); - out[2] = in[1] >> 3; - out[3] = ((in[1] >> 11) & 0x03) | (in[2] << 2); - out[4] = ((in[2] >> 6) & 0x7f) | (in[3] << 7); - out[5] = in[3] >> 1; - out[6] = ((in[3] >> 9) & 0x0f) | (in[4] << 4); - out[7] = in[4] >> 4; - out[8] = ((in[4] >> 12) & 0x01) | (in[5] << 1); - out[9] = ((in[5] >> 7) & 0x3f) | (in[6] << 6); - out[10] = in[6] >> 2; - out[11] = ((in[6] >> 10) & 0x07) | (in[7] << 3); - out[12] = in[7] >> 5; + out[0] = (uint8_t) (in[0]); + out[1] = (uint8_t) (((in[0] >> 8) & 0x1f) | (in[1] << 5)); + out[2] = (uint8_t) (in[1] >> 3); + out[3] = (uint8_t) (((in[1] >> 11) & 0x03) | (in[2] << 2)); + out[4] = (uint8_t) (((in[2] >> 6) & 0x7f) | (in[3] << 7)); + out[5] = (uint8_t) (in[3] >> 1); + out[6] = (uint8_t) (((in[3] >> 9) & 0x0f) | (in[4] << 4)); + out[7] = (uint8_t) (in[4] >> 4); + out[8] = (uint8_t) (((in[4] >> 12) & 0x01) | (in[5] << 1)); + out[9] = (uint8_t) (((in[5] >> 7) & 0x3f) | (in[6] << 6)); + out[10] = (uint8_t) (in[6] >> 2); + out[11] = (uint8_t) (((in[6] >> 10) & 0x07) | (in[7] << 3)); + out[12] = (uint8_t) (in[7] >> 5); in += 8; out += 13; } @@ -78,11 +78,11 @@ static void POLp2BS(uint8_t bytes[SABER_POLYCOMPRESSEDBYTES], const poly *data) const uint16_t *in = data->coeffs; uint8_t *out = bytes; for (j = 0; j < SABER_N / 4; j++) { - out[0] = in[0]; - out[1] = ((in[0] >> 8) & 0x03) | (in[1] << 2); - out[2] = ((in[1] >> 6) & 0x0f) | (in[2] << 4); - out[3] = ((in[2] >> 4) & 0x3f) | (in[3] << 6); - out[4] = in[3] >> 2; + out[0] = (uint8_t) (in[0]); + out[1] = (uint8_t) (((in[0] >> 8) & 0x03) | (in[1] << 2)); + out[2] = (uint8_t) (((in[1] >> 6) & 0x0f) | (in[2] << 4)); + out[3] = (uint8_t) (((in[2] >> 4) & 0x3f) | (in[3] << 6)); + out[4] = (uint8_t) (in[3] >> 2); in += 4; out += 5; } diff --git a/crypto_kem/lightsaber/META.yml b/crypto_kem/lightsaber/META.yml index 263db2e0..ad9d6acc 100644 --- a/crypto_kem/lightsaber/META.yml +++ b/crypto_kem/lightsaber/META.yml @@ -14,9 +14,9 @@ principal-submitters: - Frederik Vercauteren implementations: - name: clean - version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/90d072e4/saber + version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/3a63008f/saber - name: avx2 - version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/90d072e4/saber + version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/3a63008f/saber supported_platforms: - architecture: x86_64 operating_systems: diff --git a/crypto_kem/lightsaber/avx2/pack_unpack.c b/crypto_kem/lightsaber/avx2/pack_unpack.c index a154d24c..08f7a9d9 100644 --- a/crypto_kem/lightsaber/avx2/pack_unpack.c +++ b/crypto_kem/lightsaber/avx2/pack_unpack.c @@ -8,9 +8,9 @@ void PQCLEAN_LIGHTSABER_AVX2_POLT2BS(uint8_t bytes[SABER_SCALEBYTES_KEM], const const uint16_t *in = data->coeffs; uint8_t *out = bytes; for (j = 0; j < SABER_N / 8; j++) { - out[0] = (in[0] & 0x7) | ((in[1] & 0x7) << 3) | (in[2] << 6); - out[1] = ((in[2] >> 2) & 0x01) | ((in[3] & 0x7) << 1) | ((in[4] & 0x7) << 4) | (in[5] << 7); - out[2] = ((in[5] >> 1) & 0x03) | ((in[6] & 0x7) << 2) | (in[7] << 5); + out[0] = (uint8_t) ((in[0] & 0x7) | ((in[1] & 0x7) << 3) | (in[2] << 6)); + out[1] = (uint8_t) (((in[2] >> 2) & 0x01) | ((in[3] & 0x7) << 1) | ((in[4] & 0x7) << 4) | (in[5] << 7)); + out[2] = (uint8_t) (((in[5] >> 1) & 0x03) | ((in[6] & 0x7) << 2) | (in[7] << 5)); in += 8; out += 3; } @@ -40,19 +40,19 @@ static void POLq2BS(uint8_t bytes[SABER_POLYBYTES], const poly *data) { const uint16_t *in = data->coeffs; uint8_t *out = bytes; for (j = 0; j < SABER_N / 8; j++) { - out[0] = in[0]; - out[1] = ((in[0] >> 8) & 0x1f) | (in[1] << 5); - out[2] = in[1] >> 3; - out[3] = ((in[1] >> 11) & 0x03) | (in[2] << 2); - out[4] = ((in[2] >> 6) & 0x7f) | (in[3] << 7); - out[5] = in[3] >> 1; - out[6] = ((in[3] >> 9) & 0x0f) | (in[4] << 4); - out[7] = in[4] >> 4; - out[8] = ((in[4] >> 12) & 0x01) | (in[5] << 1); - out[9] = ((in[5] >> 7) & 0x3f) | (in[6] << 6); - out[10] = in[6] >> 2; - out[11] = ((in[6] >> 10) & 0x07) | (in[7] << 3); - out[12] = in[7] >> 5; + out[0] = (uint8_t) (in[0]); + out[1] = (uint8_t) (((in[0] >> 8) & 0x1f) | (in[1] << 5)); + out[2] = (uint8_t) (in[1] >> 3); + out[3] = (uint8_t) (((in[1] >> 11) & 0x03) | (in[2] << 2)); + out[4] = (uint8_t) (((in[2] >> 6) & 0x7f) | (in[3] << 7)); + out[5] = (uint8_t) (in[3] >> 1); + out[6] = (uint8_t) (((in[3] >> 9) & 0x0f) | (in[4] << 4)); + out[7] = (uint8_t) (in[4] >> 4); + out[8] = (uint8_t) (((in[4] >> 12) & 0x01) | (in[5] << 1)); + out[9] = (uint8_t) (((in[5] >> 7) & 0x3f) | (in[6] << 6)); + out[10] = (uint8_t) (in[6] >> 2); + out[11] = (uint8_t) (((in[6] >> 10) & 0x07) | (in[7] << 3)); + out[12] = (uint8_t) (in[7] >> 5); in += 8; out += 13; } @@ -82,11 +82,11 @@ static void POLp2BS(uint8_t bytes[SABER_POLYCOMPRESSEDBYTES], const poly *data) const uint16_t *in = data->coeffs; uint8_t *out = bytes; for (j = 0; j < SABER_N / 4; j++) { - out[0] = in[0]; - out[1] = ((in[0] >> 8) & 0x03) | (in[1] << 2); - out[2] = ((in[1] >> 6) & 0x0f) | (in[2] << 4); - out[3] = ((in[2] >> 4) & 0x3f) | (in[3] << 6); - out[4] = in[3] >> 2; + out[0] = (uint8_t) (in[0]); + out[1] = (uint8_t) (((in[0] >> 8) & 0x03) | (in[1] << 2)); + out[2] = (uint8_t) (((in[1] >> 6) & 0x0f) | (in[2] << 4)); + out[3] = (uint8_t) (((in[2] >> 4) & 0x3f) | (in[3] << 6)); + out[4] = (uint8_t) (in[3] >> 2); in += 4; out += 5; } diff --git a/crypto_kem/lightsaber/clean/pack_unpack.c b/crypto_kem/lightsaber/clean/pack_unpack.c index c1c8666c..106a62d4 100644 --- a/crypto_kem/lightsaber/clean/pack_unpack.c +++ b/crypto_kem/lightsaber/clean/pack_unpack.c @@ -8,9 +8,9 @@ void PQCLEAN_LIGHTSABER_CLEAN_POLT2BS(uint8_t bytes[SABER_SCALEBYTES_KEM], const const uint16_t *in = data->coeffs; uint8_t *out = bytes; for (j = 0; j < SABER_N / 8; j++) { - out[0] = (in[0] & 0x7) | ((in[1] & 0x7) << 3) | (in[2] << 6); - out[1] = ((in[2] >> 2) & 0x01) | ((in[3] & 0x7) << 1) | ((in[4] & 0x7) << 4) | (in[5] << 7); - out[2] = ((in[5] >> 1) & 0x03) | ((in[6] & 0x7) << 2) | (in[7] << 5); + out[0] = (uint8_t) ((in[0] & 0x7) | ((in[1] & 0x7) << 3) | (in[2] << 6)); + out[1] = (uint8_t) (((in[2] >> 2) & 0x01) | ((in[3] & 0x7) << 1) | ((in[4] & 0x7) << 4) | (in[5] << 7)); + out[2] = (uint8_t) (((in[5] >> 1) & 0x03) | ((in[6] & 0x7) << 2) | (in[7] << 5)); in += 8; out += 3; } @@ -40,19 +40,19 @@ static void POLq2BS(uint8_t bytes[SABER_POLYBYTES], const poly *data) { const uint16_t *in = data->coeffs; uint8_t *out = bytes; for (j = 0; j < SABER_N / 8; j++) { - out[0] = in[0]; - out[1] = ((in[0] >> 8) & 0x1f) | (in[1] << 5); - out[2] = in[1] >> 3; - out[3] = ((in[1] >> 11) & 0x03) | (in[2] << 2); - out[4] = ((in[2] >> 6) & 0x7f) | (in[3] << 7); - out[5] = in[3] >> 1; - out[6] = ((in[3] >> 9) & 0x0f) | (in[4] << 4); - out[7] = in[4] >> 4; - out[8] = ((in[4] >> 12) & 0x01) | (in[5] << 1); - out[9] = ((in[5] >> 7) & 0x3f) | (in[6] << 6); - out[10] = in[6] >> 2; - out[11] = ((in[6] >> 10) & 0x07) | (in[7] << 3); - out[12] = in[7] >> 5; + out[0] = (uint8_t) (in[0]); + out[1] = (uint8_t) (((in[0] >> 8) & 0x1f) | (in[1] << 5)); + out[2] = (uint8_t) (in[1] >> 3); + out[3] = (uint8_t) (((in[1] >> 11) & 0x03) | (in[2] << 2)); + out[4] = (uint8_t) (((in[2] >> 6) & 0x7f) | (in[3] << 7)); + out[5] = (uint8_t) (in[3] >> 1); + out[6] = (uint8_t) (((in[3] >> 9) & 0x0f) | (in[4] << 4)); + out[7] = (uint8_t) (in[4] >> 4); + out[8] = (uint8_t) (((in[4] >> 12) & 0x01) | (in[5] << 1)); + out[9] = (uint8_t) (((in[5] >> 7) & 0x3f) | (in[6] << 6)); + out[10] = (uint8_t) (in[6] >> 2); + out[11] = (uint8_t) (((in[6] >> 10) & 0x07) | (in[7] << 3)); + out[12] = (uint8_t) (in[7] >> 5); in += 8; out += 13; } @@ -82,11 +82,11 @@ static void POLp2BS(uint8_t bytes[SABER_POLYCOMPRESSEDBYTES], const poly *data) const uint16_t *in = data->coeffs; uint8_t *out = bytes; for (j = 0; j < SABER_N / 4; j++) { - out[0] = in[0]; - out[1] = ((in[0] >> 8) & 0x03) | (in[1] << 2); - out[2] = ((in[1] >> 6) & 0x0f) | (in[2] << 4); - out[3] = ((in[2] >> 4) & 0x3f) | (in[3] << 6); - out[4] = in[3] >> 2; + out[0] = (uint8_t) (in[0]); + out[1] = (uint8_t) (((in[0] >> 8) & 0x03) | (in[1] << 2)); + out[2] = (uint8_t) (((in[1] >> 6) & 0x0f) | (in[2] << 4)); + out[3] = (uint8_t) (((in[2] >> 4) & 0x3f) | (in[3] << 6)); + out[4] = (uint8_t) (in[3] >> 2); in += 4; out += 5; } diff --git a/crypto_kem/saber/META.yml b/crypto_kem/saber/META.yml index 319f4ebf..f6375c71 100644 --- a/crypto_kem/saber/META.yml +++ b/crypto_kem/saber/META.yml @@ -14,9 +14,9 @@ principal-submitters: - Frederik Vercauteren implementations: - name: clean - version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/90d072e4/saber + version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/3a63008f/saber - name: avx2 - version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/90d072e4/saber + version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/3a63008f/saber supported_platforms: - architecture: x86_64 operating_systems: diff --git a/crypto_kem/saber/avx2/pack_unpack.c b/crypto_kem/saber/avx2/pack_unpack.c index a055b7e5..f9315d5d 100644 --- a/crypto_kem/saber/avx2/pack_unpack.c +++ b/crypto_kem/saber/avx2/pack_unpack.c @@ -8,7 +8,7 @@ void PQCLEAN_SABER_AVX2_POLT2BS(uint8_t bytes[SABER_SCALEBYTES_KEM], const poly const uint16_t *in = data->coeffs; uint8_t *out = bytes; for (j = 0; j < SABER_N / 2; j++) { - out[0] = (in[0] & 0x0f) | (in[1] << 4); + out[0] = (uint8_t) ((in[0] & 0x0f) | (in[1] << 4)); in += 2; out += 1; } @@ -32,19 +32,19 @@ static void POLq2BS(uint8_t bytes[SABER_POLYBYTES], const poly *data) { const uint16_t *in = data->coeffs; uint8_t *out = bytes; for (j = 0; j < SABER_N / 8; j++) { - out[0] = in[0]; - out[1] = ((in[0] >> 8) & 0x1f) | (in[1] << 5); - out[2] = in[1] >> 3; - out[3] = ((in[1] >> 11) & 0x03) | (in[2] << 2); - out[4] = ((in[2] >> 6) & 0x7f) | (in[3] << 7); - out[5] = in[3] >> 1; - out[6] = ((in[3] >> 9) & 0x0f) | (in[4] << 4); - out[7] = in[4] >> 4; - out[8] = ((in[4] >> 12) & 0x01) | (in[5] << 1); - out[9] = ((in[5] >> 7) & 0x3f) | (in[6] << 6); - out[10] = in[6] >> 2; - out[11] = ((in[6] >> 10) & 0x07) | (in[7] << 3); - out[12] = in[7] >> 5; + out[0] = (uint8_t) (in[0]); + out[1] = (uint8_t) (((in[0] >> 8) & 0x1f) | (in[1] << 5)); + out[2] = (uint8_t) (in[1] >> 3); + out[3] = (uint8_t) (((in[1] >> 11) & 0x03) | (in[2] << 2)); + out[4] = (uint8_t) (((in[2] >> 6) & 0x7f) | (in[3] << 7)); + out[5] = (uint8_t) (in[3] >> 1); + out[6] = (uint8_t) (((in[3] >> 9) & 0x0f) | (in[4] << 4)); + out[7] = (uint8_t) (in[4] >> 4); + out[8] = (uint8_t) (((in[4] >> 12) & 0x01) | (in[5] << 1)); + out[9] = (uint8_t) (((in[5] >> 7) & 0x3f) | (in[6] << 6)); + out[10] = (uint8_t) (in[6] >> 2); + out[11] = (uint8_t) (((in[6] >> 10) & 0x07) | (in[7] << 3)); + out[12] = (uint8_t) (in[7] >> 5); in += 8; out += 13; } @@ -74,11 +74,11 @@ static void POLp2BS(uint8_t bytes[SABER_POLYCOMPRESSEDBYTES], const poly *data) const uint16_t *in = data->coeffs; uint8_t *out = bytes; for (j = 0; j < SABER_N / 4; j++) { - out[0] = in[0]; - out[1] = ((in[0] >> 8) & 0x03) | (in[1] << 2); - out[2] = ((in[1] >> 6) & 0x0f) | (in[2] << 4); - out[3] = ((in[2] >> 4) & 0x3f) | (in[3] << 6); - out[4] = in[3] >> 2; + out[0] = (uint8_t) (in[0]); + out[1] = (uint8_t) (((in[0] >> 8) & 0x03) | (in[1] << 2)); + out[2] = (uint8_t) (((in[1] >> 6) & 0x0f) | (in[2] << 4)); + out[3] = (uint8_t) (((in[2] >> 4) & 0x3f) | (in[3] << 6)); + out[4] = (uint8_t) (in[3] >> 2); in += 4; out += 5; } diff --git a/crypto_kem/saber/clean/pack_unpack.c b/crypto_kem/saber/clean/pack_unpack.c index 1b5bed81..89a98951 100644 --- a/crypto_kem/saber/clean/pack_unpack.c +++ b/crypto_kem/saber/clean/pack_unpack.c @@ -8,7 +8,7 @@ void PQCLEAN_SABER_CLEAN_POLT2BS(uint8_t bytes[SABER_SCALEBYTES_KEM], const poly const uint16_t *in = data->coeffs; uint8_t *out = bytes; for (j = 0; j < SABER_N / 2; j++) { - out[0] = (in[0] & 0x0f) | (in[1] << 4); + out[0] = (uint8_t) ((in[0] & 0x0f) | (in[1] << 4)); in += 2; out += 1; } @@ -32,19 +32,19 @@ static void POLq2BS(uint8_t bytes[SABER_POLYBYTES], const poly *data) { const uint16_t *in = data->coeffs; uint8_t *out = bytes; for (j = 0; j < SABER_N / 8; j++) { - out[0] = in[0]; - out[1] = ((in[0] >> 8) & 0x1f) | (in[1] << 5); - out[2] = in[1] >> 3; - out[3] = ((in[1] >> 11) & 0x03) | (in[2] << 2); - out[4] = ((in[2] >> 6) & 0x7f) | (in[3] << 7); - out[5] = in[3] >> 1; - out[6] = ((in[3] >> 9) & 0x0f) | (in[4] << 4); - out[7] = in[4] >> 4; - out[8] = ((in[4] >> 12) & 0x01) | (in[5] << 1); - out[9] = ((in[5] >> 7) & 0x3f) | (in[6] << 6); - out[10] = in[6] >> 2; - out[11] = ((in[6] >> 10) & 0x07) | (in[7] << 3); - out[12] = in[7] >> 5; + out[0] = (uint8_t) (in[0]); + out[1] = (uint8_t) (((in[0] >> 8) & 0x1f) | (in[1] << 5)); + out[2] = (uint8_t) (in[1] >> 3); + out[3] = (uint8_t) (((in[1] >> 11) & 0x03) | (in[2] << 2)); + out[4] = (uint8_t) (((in[2] >> 6) & 0x7f) | (in[3] << 7)); + out[5] = (uint8_t) (in[3] >> 1); + out[6] = (uint8_t) (((in[3] >> 9) & 0x0f) | (in[4] << 4)); + out[7] = (uint8_t) (in[4] >> 4); + out[8] = (uint8_t) (((in[4] >> 12) & 0x01) | (in[5] << 1)); + out[9] = (uint8_t) (((in[5] >> 7) & 0x3f) | (in[6] << 6)); + out[10] = (uint8_t) (in[6] >> 2); + out[11] = (uint8_t) (((in[6] >> 10) & 0x07) | (in[7] << 3)); + out[12] = (uint8_t) (in[7] >> 5); in += 8; out += 13; } @@ -74,11 +74,11 @@ static void POLp2BS(uint8_t bytes[SABER_POLYCOMPRESSEDBYTES], const poly *data) const uint16_t *in = data->coeffs; uint8_t *out = bytes; for (j = 0; j < SABER_N / 4; j++) { - out[0] = in[0]; - out[1] = ((in[0] >> 8) & 0x03) | (in[1] << 2); - out[2] = ((in[1] >> 6) & 0x0f) | (in[2] << 4); - out[3] = ((in[2] >> 4) & 0x3f) | (in[3] << 6); - out[4] = in[3] >> 2; + out[0] = (uint8_t) (in[0]); + out[1] = (uint8_t) (((in[0] >> 8) & 0x03) | (in[1] << 2)); + out[2] = (uint8_t) (((in[1] >> 6) & 0x0f) | (in[2] << 4)); + out[3] = (uint8_t) (((in[2] >> 4) & 0x3f) | (in[3] << 6)); + out[4] = (uint8_t) (in[3] >> 2); in += 4; out += 5; }