1
1
mirror of https://github.com/henrydcase/pqc.git synced 2024-11-22 07:35:38 +00:00

simplify pack_unpack.c

This commit is contained in:
John M. Schanck 2020-10-28 23:31:01 -04:00 committed by Kris Kwiatkowski
parent 7b48693ae8
commit 4406f00784
15 changed files with 240 additions and 243 deletions

View File

@ -14,9 +14,9 @@ principal-submitters:
- Frederik Vercauteren - Frederik Vercauteren
implementations: implementations:
- name: clean - name: clean
version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/33e5ed62/saber version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/90d072e4/saber
- name: avx2 - name: avx2
version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/33e5ed62/saber version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/90d072e4/saber
supported_platforms: supported_platforms:
- architecture: x86_64 - architecture: x86_64
operating_systems: operating_systems:

View File

@ -8,23 +8,24 @@ void PQCLEAN_FIRESABER_AVX2_POLT2BS(uint8_t bytes[SABER_SCALEBYTES_KEM], const p
const uint16_t *in = data->coeffs; const uint16_t *in = data->coeffs;
uint8_t *out = bytes; uint8_t *out = bytes;
for (j = 0; j < SABER_N / 4; j++) { for (j = 0; j < SABER_N / 4; j++) {
out[0] = (in[0] & 0x3f) | ((in[1] & 0x03) << 6); out[0] = (in[0] & 0x3f) | (in[1] << 6);
out[1] = ((in[1] >> 2) & 0x0f) | ((in[2] & 0x0f) << 4); out[1] = ((in[1] >> 2) & 0x0f) | (in[2] << 4);
out[2] = ((in[2] >> 4) & 0x03) | ((in[3] & 0x3f) << 2); out[2] = ((in[2] >> 4) & 0x03) | (in[3] << 2);
in += 4; in += 4;
out += 3; out += 3;
} }
} }
void PQCLEAN_FIRESABER_AVX2_BS2POLT(poly *data, const uint8_t bytes[SABER_SCALEBYTES_KEM]) { void PQCLEAN_FIRESABER_AVX2_BS2POLT(poly *data, const uint8_t bytes[SABER_SCALEBYTES_KEM]) {
/* This function does not reduce its output mod T */
size_t j; size_t j;
const uint8_t *in = bytes; const uint8_t *in = bytes;
uint16_t *out = data->coeffs; uint16_t *out = data->coeffs;
for (j = 0; j < SABER_N / 4; j++) { for (j = 0; j < SABER_N / 4; j++) {
out[0] = in[0] & 0x3f; out[0] = in[0];
out[1] = ((in[0] >> 6) & 0x03) | ((in[1] & 0x0f) << 2); out[1] = (in[0] >> 6) | (in[1] << 2);
out[2] = ((in[1] & 0xff) >> 4) | ((in[2] & 0x03) << 4); out[2] = (in[1] >> 4) | (in[2] << 4);
out[3] = ((in[2] & 0xff) >> 2); out[3] = (in[2] >> 2);
in += 3; in += 3;
out += 4; out += 4;
} }
@ -35,37 +36,38 @@ static void POLq2BS(uint8_t bytes[SABER_POLYBYTES], const poly *data) {
const uint16_t *in = data->coeffs; const uint16_t *in = data->coeffs;
uint8_t *out = bytes; uint8_t *out = bytes;
for (j = 0; j < SABER_N / 8; j++) { for (j = 0; j < SABER_N / 8; j++) {
out[0] = (in[0] & (0xff)); out[0] = in[0];
out[1] = ((in[0] >> 8) & 0x1f) | ((in[1] & 0x07) << 5); out[1] = ((in[0] >> 8) & 0x1f) | (in[1] << 5);
out[2] = ((in[1] >> 3) & 0xff); out[2] = in[1] >> 3;
out[3] = ((in[1] >> 11) & 0x03) | ((in[2] & 0x3f) << 2); out[3] = ((in[1] >> 11) & 0x03) | (in[2] << 2);
out[4] = ((in[2] >> 6) & 0x7f) | ((in[3] & 0x01) << 7); out[4] = ((in[2] >> 6) & 0x7f) | (in[3] << 7);
out[5] = ((in[3] >> 1) & 0xff); out[5] = in[3] >> 1;
out[6] = ((in[3] >> 9) & 0x0f) | ((in[4] & 0x0f) << 4); out[6] = ((in[3] >> 9) & 0x0f) | (in[4] << 4);
out[7] = ((in[4] >> 4) & 0xff); out[7] = in[4] >> 4;
out[8] = ((in[4] >> 12) & 0x01) | ((in[5] & 0x7f) << 1); out[8] = ((in[4] >> 12) & 0x01) | (in[5] << 1);
out[9] = ((in[5] >> 7) & 0x3f) | ((in[6] & 0x03) << 6); out[9] = ((in[5] >> 7) & 0x3f) | (in[6] << 6);
out[10] = ((in[6] >> 2) & 0xff); out[10] = in[6] >> 2;
out[11] = ((in[6] >> 10) & 0x07) | ((in[7] & 0x1f) << 3); out[11] = ((in[6] >> 10) & 0x07) | (in[7] << 3);
out[12] = ((in[7] >> 5) & 0xff); out[12] = in[7] >> 5;
in += 8; in += 8;
out += 13; out += 13;
} }
} }
static void BS2POLq(poly *data, const uint8_t bytes[SABER_POLYBYTES]) { static void BS2POLq(poly *data, const uint8_t bytes[SABER_POLYBYTES]) {
/* This function does not reduce its output mod Q */
size_t j; size_t j;
const uint8_t *in = bytes; const uint8_t *in = bytes;
uint16_t *out = data->coeffs; uint16_t *out = data->coeffs;
for (j = 0; j < SABER_N / 8; j++) { for (j = 0; j < SABER_N / 8; j++) {
out[0] = (in[0] & (0xff)) | ((in[1] & 0x1f) << 8); out[0] = (in[0]) | (in[1] << 8);
out[1] = (in[1] >> 5 & (0x07)) | ((in[2] & 0xff) << 3) | ((in[3] & 0x03) << 11); out[1] = (in[1] >> 5) | (in[2] << 3) | (in[3] << 11);
out[2] = (in[3] >> 2 & (0x3f)) | ((in[4] & 0x7f) << 6); out[2] = (in[3] >> 2) | (in[4] << 6);
out[3] = (in[4] >> 7 & (0x01)) | ((in[5] & 0xff) << 1) | ((in[6] & 0x0f) << 9); out[3] = (in[4] >> 7) | (in[5] << 1) | (in[6] << 9);
out[4] = (in[6] >> 4 & (0x0f)) | ((in[7] & 0xff) << 4) | ((in[8] & 0x01) << 12); out[4] = (in[6] >> 4) | (in[7] << 4) | (in[8] << 12);
out[5] = (in[8] >> 1 & (0x7f)) | ((in[9] & 0x3f) << 7); out[5] = (in[8] >> 1) | (in[9] << 7);
out[6] = (in[9] >> 6 & (0x03)) | ((in[10] & 0xff) << 2) | ((in[11] & 0x07) << 10); out[6] = (in[9] >> 6) | (in[10] << 2) | (in[11] << 10);
out[7] = (in[11] >> 3 & (0x1f)) | ((in[12] & 0xff) << 5); out[7] = (in[11] >> 3) | (in[12] << 5);
in += 13; in += 13;
out += 8; out += 8;
} }
@ -76,11 +78,11 @@ static void POLp2BS(uint8_t bytes[SABER_POLYCOMPRESSEDBYTES], const poly *data)
const uint16_t *in = data->coeffs; const uint16_t *in = data->coeffs;
uint8_t *out = bytes; uint8_t *out = bytes;
for (j = 0; j < SABER_N / 4; j++) { for (j = 0; j < SABER_N / 4; j++) {
out[0] = (in[0] & (0xff)); out[0] = in[0];
out[1] = ((in[0] >> 8) & 0x03) | ((in[1] & 0x3f) << 2); out[1] = ((in[0] >> 8) & 0x03) | (in[1] << 2);
out[2] = ((in[1] >> 6) & 0x0f) | ((in[2] & 0x0f) << 4); out[2] = ((in[1] >> 6) & 0x0f) | (in[2] << 4);
out[3] = ((in[2] >> 4) & 0x3f) | ((in[3] & 0x03) << 6); out[3] = ((in[2] >> 4) & 0x3f) | (in[3] << 6);
out[4] = ((in[3] >> 2) & 0xff); out[4] = in[3] >> 2;
in += 4; in += 4;
out += 5; out += 5;
} }
@ -91,10 +93,10 @@ static void BS2POLp(poly *data, const uint8_t bytes[SABER_POLYCOMPRESSEDBYTES])
const uint8_t *in = bytes; const uint8_t *in = bytes;
uint16_t *out = data->coeffs; uint16_t *out = data->coeffs;
for (j = 0; j < SABER_N / 4; j++) { for (j = 0; j < SABER_N / 4; j++) {
out[0] = (in[0] & (0xff)) | ((in[1] & 0x03) << 8); out[0] = in[0] | (in[1] << 8);
out[1] = ((in[1] >> 2) & (0x3f)) | ((in[2] & 0x0f) << 6); out[1] = (in[1] >> 2) | (in[2] << 6);
out[2] = ((in[2] >> 4) & (0x0f)) | ((in[3] & 0x3f) << 4); out[2] = (in[2] >> 4) | (in[3] << 4);
out[3] = ((in[3] >> 6) & (0x03)) | ((in[4] & 0xff) << 2); out[3] = (in[3] >> 6) | (in[4] << 2);
in += 5; in += 5;
out += 4; out += 4;
} }

View File

@ -8,23 +8,24 @@ void PQCLEAN_FIRESABER_CLEAN_POLT2BS(uint8_t bytes[SABER_SCALEBYTES_KEM], const
const uint16_t *in = data->coeffs; const uint16_t *in = data->coeffs;
uint8_t *out = bytes; uint8_t *out = bytes;
for (j = 0; j < SABER_N / 4; j++) { for (j = 0; j < SABER_N / 4; j++) {
out[0] = (in[0] & 0x3f) | ((in[1] & 0x03) << 6); out[0] = (in[0] & 0x3f) | (in[1] << 6);
out[1] = ((in[1] >> 2) & 0x0f) | ((in[2] & 0x0f) << 4); out[1] = ((in[1] >> 2) & 0x0f) | (in[2] << 4);
out[2] = ((in[2] >> 4) & 0x03) | ((in[3] & 0x3f) << 2); out[2] = ((in[2] >> 4) & 0x03) | (in[3] << 2);
in += 4; in += 4;
out += 3; out += 3;
} }
} }
void PQCLEAN_FIRESABER_CLEAN_BS2POLT(poly *data, const uint8_t bytes[SABER_SCALEBYTES_KEM]) { void PQCLEAN_FIRESABER_CLEAN_BS2POLT(poly *data, const uint8_t bytes[SABER_SCALEBYTES_KEM]) {
/* This function does not reduce its output mod T */
size_t j; size_t j;
const uint8_t *in = bytes; const uint8_t *in = bytes;
uint16_t *out = data->coeffs; uint16_t *out = data->coeffs;
for (j = 0; j < SABER_N / 4; j++) { for (j = 0; j < SABER_N / 4; j++) {
out[0] = in[0] & 0x3f; out[0] = in[0];
out[1] = ((in[0] >> 6) & 0x03) | ((in[1] & 0x0f) << 2); out[1] = (in[0] >> 6) | (in[1] << 2);
out[2] = ((in[1] & 0xff) >> 4) | ((in[2] & 0x03) << 4); out[2] = (in[1] >> 4) | (in[2] << 4);
out[3] = ((in[2] & 0xff) >> 2); out[3] = (in[2] >> 2);
in += 3; in += 3;
out += 4; out += 4;
} }
@ -35,37 +36,38 @@ static void POLq2BS(uint8_t bytes[SABER_POLYBYTES], const poly *data) {
const uint16_t *in = data->coeffs; const uint16_t *in = data->coeffs;
uint8_t *out = bytes; uint8_t *out = bytes;
for (j = 0; j < SABER_N / 8; j++) { for (j = 0; j < SABER_N / 8; j++) {
out[0] = (in[0] & (0xff)); out[0] = in[0];
out[1] = ((in[0] >> 8) & 0x1f) | ((in[1] & 0x07) << 5); out[1] = ((in[0] >> 8) & 0x1f) | (in[1] << 5);
out[2] = ((in[1] >> 3) & 0xff); out[2] = in[1] >> 3;
out[3] = ((in[1] >> 11) & 0x03) | ((in[2] & 0x3f) << 2); out[3] = ((in[1] >> 11) & 0x03) | (in[2] << 2);
out[4] = ((in[2] >> 6) & 0x7f) | ((in[3] & 0x01) << 7); out[4] = ((in[2] >> 6) & 0x7f) | (in[3] << 7);
out[5] = ((in[3] >> 1) & 0xff); out[5] = in[3] >> 1;
out[6] = ((in[3] >> 9) & 0x0f) | ((in[4] & 0x0f) << 4); out[6] = ((in[3] >> 9) & 0x0f) | (in[4] << 4);
out[7] = ((in[4] >> 4) & 0xff); out[7] = in[4] >> 4;
out[8] = ((in[4] >> 12) & 0x01) | ((in[5] & 0x7f) << 1); out[8] = ((in[4] >> 12) & 0x01) | (in[5] << 1);
out[9] = ((in[5] >> 7) & 0x3f) | ((in[6] & 0x03) << 6); out[9] = ((in[5] >> 7) & 0x3f) | (in[6] << 6);
out[10] = ((in[6] >> 2) & 0xff); out[10] = in[6] >> 2;
out[11] = ((in[6] >> 10) & 0x07) | ((in[7] & 0x1f) << 3); out[11] = ((in[6] >> 10) & 0x07) | (in[7] << 3);
out[12] = ((in[7] >> 5) & 0xff); out[12] = in[7] >> 5;
in += 8; in += 8;
out += 13; out += 13;
} }
} }
static void BS2POLq(poly *data, const uint8_t bytes[SABER_POLYBYTES]) { static void BS2POLq(poly *data, const uint8_t bytes[SABER_POLYBYTES]) {
/* This function does not reduce its output mod Q */
size_t j; size_t j;
const uint8_t *in = bytes; const uint8_t *in = bytes;
uint16_t *out = data->coeffs; uint16_t *out = data->coeffs;
for (j = 0; j < SABER_N / 8; j++) { for (j = 0; j < SABER_N / 8; j++) {
out[0] = (in[0] & (0xff)) | ((in[1] & 0x1f) << 8); out[0] = (in[0]) | (in[1] << 8);
out[1] = (in[1] >> 5 & (0x07)) | ((in[2] & 0xff) << 3) | ((in[3] & 0x03) << 11); out[1] = (in[1] >> 5) | (in[2] << 3) | (in[3] << 11);
out[2] = (in[3] >> 2 & (0x3f)) | ((in[4] & 0x7f) << 6); out[2] = (in[3] >> 2) | (in[4] << 6);
out[3] = (in[4] >> 7 & (0x01)) | ((in[5] & 0xff) << 1) | ((in[6] & 0x0f) << 9); out[3] = (in[4] >> 7) | (in[5] << 1) | (in[6] << 9);
out[4] = (in[6] >> 4 & (0x0f)) | ((in[7] & 0xff) << 4) | ((in[8] & 0x01) << 12); out[4] = (in[6] >> 4) | (in[7] << 4) | (in[8] << 12);
out[5] = (in[8] >> 1 & (0x7f)) | ((in[9] & 0x3f) << 7); out[5] = (in[8] >> 1) | (in[9] << 7);
out[6] = (in[9] >> 6 & (0x03)) | ((in[10] & 0xff) << 2) | ((in[11] & 0x07) << 10); out[6] = (in[9] >> 6) | (in[10] << 2) | (in[11] << 10);
out[7] = (in[11] >> 3 & (0x1f)) | ((in[12] & 0xff) << 5); out[7] = (in[11] >> 3) | (in[12] << 5);
in += 13; in += 13;
out += 8; out += 8;
} }
@ -76,11 +78,11 @@ static void POLp2BS(uint8_t bytes[SABER_POLYCOMPRESSEDBYTES], const poly *data)
const uint16_t *in = data->coeffs; const uint16_t *in = data->coeffs;
uint8_t *out = bytes; uint8_t *out = bytes;
for (j = 0; j < SABER_N / 4; j++) { for (j = 0; j < SABER_N / 4; j++) {
out[0] = (in[0] & (0xff)); out[0] = in[0];
out[1] = ((in[0] >> 8) & 0x03) | ((in[1] & 0x3f) << 2); out[1] = ((in[0] >> 8) & 0x03) | (in[1] << 2);
out[2] = ((in[1] >> 6) & 0x0f) | ((in[2] & 0x0f) << 4); out[2] = ((in[1] >> 6) & 0x0f) | (in[2] << 4);
out[3] = ((in[2] >> 4) & 0x3f) | ((in[3] & 0x03) << 6); out[3] = ((in[2] >> 4) & 0x3f) | (in[3] << 6);
out[4] = ((in[3] >> 2) & 0xff); out[4] = in[3] >> 2;
in += 4; in += 4;
out += 5; out += 5;
} }
@ -91,10 +93,10 @@ static void BS2POLp(poly *data, const uint8_t bytes[SABER_POLYCOMPRESSEDBYTES])
const uint8_t *in = bytes; const uint8_t *in = bytes;
uint16_t *out = data->coeffs; uint16_t *out = data->coeffs;
for (j = 0; j < SABER_N / 4; j++) { for (j = 0; j < SABER_N / 4; j++) {
out[0] = (in[0] & (0xff)) | ((in[1] & 0x03) << 8); out[0] = in[0] | (in[1] << 8);
out[1] = ((in[1] >> 2) & (0x3f)) | ((in[2] & 0x0f) << 6); out[1] = (in[1] >> 2) | (in[2] << 6);
out[2] = ((in[2] >> 4) & (0x0f)) | ((in[3] & 0x3f) << 4); out[2] = (in[2] >> 4) | (in[3] << 4);
out[3] = ((in[3] >> 6) & (0x03)) | ((in[4] & 0xff) << 2); out[3] = (in[3] >> 6) | (in[4] << 2);
in += 5; in += 5;
out += 4; out += 4;
} }

View File

@ -14,9 +14,9 @@ principal-submitters:
- Frederik Vercauteren - Frederik Vercauteren
implementations: implementations:
- name: clean - name: clean
version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/33e5ed62/saber version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/90d072e4/saber
- name: avx2 - name: avx2
version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/33e5ed62/saber version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/90d072e4/saber
supported_platforms: supported_platforms:
- architecture: x86_64 - architecture: x86_64
operating_systems: operating_systems:

View File

@ -8,27 +8,28 @@ void PQCLEAN_LIGHTSABER_AVX2_POLT2BS(uint8_t bytes[SABER_SCALEBYTES_KEM], const
const uint16_t *in = data->coeffs; const uint16_t *in = data->coeffs;
uint8_t *out = bytes; uint8_t *out = bytes;
for (j = 0; j < SABER_N / 8; j++) { for (j = 0; j < SABER_N / 8; j++) {
out[0] = (in[0] & 0x7) | ((in[1] & 0x7) << 3) | ((in[2] & 0x3) << 6); 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]) & 0x01) << 7); 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] & 0x7) << 5); out[2] = ((in[5] >> 1) & 0x03) | ((in[6] & 0x7) << 2) | (in[7] << 5);
in += 8; in += 8;
out += 3; out += 3;
} }
} }
void PQCLEAN_LIGHTSABER_AVX2_BS2POLT(poly *data, const uint8_t bytes[SABER_SCALEBYTES_KEM]) { void PQCLEAN_LIGHTSABER_AVX2_BS2POLT(poly *data, const uint8_t bytes[SABER_SCALEBYTES_KEM]) {
/* This function does not reduce its output mod T */
size_t j; size_t j;
const uint8_t *in = bytes; const uint8_t *in = bytes;
uint16_t *out = data->coeffs; uint16_t *out = data->coeffs;
for (j = 0; j < SABER_N / 8; j++) { for (j = 0; j < SABER_N / 8; j++) {
out[0] = (in[0]) & 0x07; out[0] = in[0];
out[1] = ((in[0]) >> 3) & 0x07; out[1] = in[0] >> 3;
out[2] = (((in[0]) >> 6) & 0x03) | (((in[1]) & 0x01) << 2); out[2] = (in[0] >> 6) | (in[1] << 2);
out[3] = ((in[1]) >> 1) & 0x07; out[3] = in[1] >> 1;
out[4] = ((in[1]) >> 4) & 0x07; out[4] = in[1] >> 4;
out[5] = (((in[1]) >> 7) & 0x01) | (((in[2]) & 0x03) << 1); out[5] = (in[1] >> 7) | (in[2] << 1);
out[6] = ((in[2] >> 2) & 0x07); out[6] = in[2] >> 2;
out[7] = ((in[2] >> 5) & 0x07); out[7] = in[2] >> 5;
in += 3; in += 3;
out += 8; out += 8;
} }
@ -39,37 +40,38 @@ static void POLq2BS(uint8_t bytes[SABER_POLYBYTES], const poly *data) {
const uint16_t *in = data->coeffs; const uint16_t *in = data->coeffs;
uint8_t *out = bytes; uint8_t *out = bytes;
for (j = 0; j < SABER_N / 8; j++) { for (j = 0; j < SABER_N / 8; j++) {
out[0] = (in[0] & (0xff)); out[0] = in[0];
out[1] = ((in[0] >> 8) & 0x1f) | ((in[1] & 0x07) << 5); out[1] = ((in[0] >> 8) & 0x1f) | (in[1] << 5);
out[2] = ((in[1] >> 3) & 0xff); out[2] = in[1] >> 3;
out[3] = ((in[1] >> 11) & 0x03) | ((in[2] & 0x3f) << 2); out[3] = ((in[1] >> 11) & 0x03) | (in[2] << 2);
out[4] = ((in[2] >> 6) & 0x7f) | ((in[3] & 0x01) << 7); out[4] = ((in[2] >> 6) & 0x7f) | (in[3] << 7);
out[5] = ((in[3] >> 1) & 0xff); out[5] = in[3] >> 1;
out[6] = ((in[3] >> 9) & 0x0f) | ((in[4] & 0x0f) << 4); out[6] = ((in[3] >> 9) & 0x0f) | (in[4] << 4);
out[7] = ((in[4] >> 4) & 0xff); out[7] = in[4] >> 4;
out[8] = ((in[4] >> 12) & 0x01) | ((in[5] & 0x7f) << 1); out[8] = ((in[4] >> 12) & 0x01) | (in[5] << 1);
out[9] = ((in[5] >> 7) & 0x3f) | ((in[6] & 0x03) << 6); out[9] = ((in[5] >> 7) & 0x3f) | (in[6] << 6);
out[10] = ((in[6] >> 2) & 0xff); out[10] = in[6] >> 2;
out[11] = ((in[6] >> 10) & 0x07) | ((in[7] & 0x1f) << 3); out[11] = ((in[6] >> 10) & 0x07) | (in[7] << 3);
out[12] = ((in[7] >> 5) & 0xff); out[12] = in[7] >> 5;
in += 8; in += 8;
out += 13; out += 13;
} }
} }
static void BS2POLq(poly *data, const uint8_t bytes[SABER_POLYBYTES]) { static void BS2POLq(poly *data, const uint8_t bytes[SABER_POLYBYTES]) {
/* This function does not reduce its output mod Q */
size_t j; size_t j;
const uint8_t *in = bytes; const uint8_t *in = bytes;
uint16_t *out = data->coeffs; uint16_t *out = data->coeffs;
for (j = 0; j < SABER_N / 8; j++) { for (j = 0; j < SABER_N / 8; j++) {
out[0] = (in[0] & (0xff)) | ((in[1] & 0x1f) << 8); out[0] = (in[0]) | (in[1] << 8);
out[1] = (in[1] >> 5 & (0x07)) | ((in[2] & 0xff) << 3) | ((in[3] & 0x03) << 11); out[1] = (in[1] >> 5) | (in[2] << 3) | (in[3] << 11);
out[2] = (in[3] >> 2 & (0x3f)) | ((in[4] & 0x7f) << 6); out[2] = (in[3] >> 2) | (in[4] << 6);
out[3] = (in[4] >> 7 & (0x01)) | ((in[5] & 0xff) << 1) | ((in[6] & 0x0f) << 9); out[3] = (in[4] >> 7) | (in[5] << 1) | (in[6] << 9);
out[4] = (in[6] >> 4 & (0x0f)) | ((in[7] & 0xff) << 4) | ((in[8] & 0x01) << 12); out[4] = (in[6] >> 4) | (in[7] << 4) | (in[8] << 12);
out[5] = (in[8] >> 1 & (0x7f)) | ((in[9] & 0x3f) << 7); out[5] = (in[8] >> 1) | (in[9] << 7);
out[6] = (in[9] >> 6 & (0x03)) | ((in[10] & 0xff) << 2) | ((in[11] & 0x07) << 10); out[6] = (in[9] >> 6) | (in[10] << 2) | (in[11] << 10);
out[7] = (in[11] >> 3 & (0x1f)) | ((in[12] & 0xff) << 5); out[7] = (in[11] >> 3) | (in[12] << 5);
in += 13; in += 13;
out += 8; out += 8;
} }
@ -80,11 +82,11 @@ static void POLp2BS(uint8_t bytes[SABER_POLYCOMPRESSEDBYTES], const poly *data)
const uint16_t *in = data->coeffs; const uint16_t *in = data->coeffs;
uint8_t *out = bytes; uint8_t *out = bytes;
for (j = 0; j < SABER_N / 4; j++) { for (j = 0; j < SABER_N / 4; j++) {
out[0] = (in[0] & (0xff)); out[0] = in[0];
out[1] = ((in[0] >> 8) & 0x03) | ((in[1] & 0x3f) << 2); out[1] = ((in[0] >> 8) & 0x03) | (in[1] << 2);
out[2] = ((in[1] >> 6) & 0x0f) | ((in[2] & 0x0f) << 4); out[2] = ((in[1] >> 6) & 0x0f) | (in[2] << 4);
out[3] = ((in[2] >> 4) & 0x3f) | ((in[3] & 0x03) << 6); out[3] = ((in[2] >> 4) & 0x3f) | (in[3] << 6);
out[4] = ((in[3] >> 2) & 0xff); out[4] = in[3] >> 2;
in += 4; in += 4;
out += 5; out += 5;
} }
@ -95,10 +97,10 @@ static void BS2POLp(poly *data, const uint8_t bytes[SABER_POLYCOMPRESSEDBYTES])
const uint8_t *in = bytes; const uint8_t *in = bytes;
uint16_t *out = data->coeffs; uint16_t *out = data->coeffs;
for (j = 0; j < SABER_N / 4; j++) { for (j = 0; j < SABER_N / 4; j++) {
out[0] = (in[0] & (0xff)) | ((in[1] & 0x03) << 8); out[0] = in[0] | (in[1] << 8);
out[1] = ((in[1] >> 2) & (0x3f)) | ((in[2] & 0x0f) << 6); out[1] = (in[1] >> 2) | (in[2] << 6);
out[2] = ((in[2] >> 4) & (0x0f)) | ((in[3] & 0x3f) << 4); out[2] = (in[2] >> 4) | (in[3] << 4);
out[3] = ((in[3] >> 6) & (0x03)) | ((in[4] & 0xff) << 2); out[3] = (in[3] >> 6) | (in[4] << 2);
in += 5; in += 5;
out += 4; out += 4;
} }

View File

@ -8,27 +8,28 @@ void PQCLEAN_LIGHTSABER_CLEAN_POLT2BS(uint8_t bytes[SABER_SCALEBYTES_KEM], const
const uint16_t *in = data->coeffs; const uint16_t *in = data->coeffs;
uint8_t *out = bytes; uint8_t *out = bytes;
for (j = 0; j < SABER_N / 8; j++) { for (j = 0; j < SABER_N / 8; j++) {
out[0] = (in[0] & 0x7) | ((in[1] & 0x7) << 3) | ((in[2] & 0x3) << 6); 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]) & 0x01) << 7); 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] & 0x7) << 5); out[2] = ((in[5] >> 1) & 0x03) | ((in[6] & 0x7) << 2) | (in[7] << 5);
in += 8; in += 8;
out += 3; out += 3;
} }
} }
void PQCLEAN_LIGHTSABER_CLEAN_BS2POLT(poly *data, const uint8_t bytes[SABER_SCALEBYTES_KEM]) { void PQCLEAN_LIGHTSABER_CLEAN_BS2POLT(poly *data, const uint8_t bytes[SABER_SCALEBYTES_KEM]) {
/* This function does not reduce its output mod T */
size_t j; size_t j;
const uint8_t *in = bytes; const uint8_t *in = bytes;
uint16_t *out = data->coeffs; uint16_t *out = data->coeffs;
for (j = 0; j < SABER_N / 8; j++) { for (j = 0; j < SABER_N / 8; j++) {
out[0] = (in[0]) & 0x07; out[0] = in[0];
out[1] = ((in[0]) >> 3) & 0x07; out[1] = in[0] >> 3;
out[2] = (((in[0]) >> 6) & 0x03) | (((in[1]) & 0x01) << 2); out[2] = (in[0] >> 6) | (in[1] << 2);
out[3] = ((in[1]) >> 1) & 0x07; out[3] = in[1] >> 1;
out[4] = ((in[1]) >> 4) & 0x07; out[4] = in[1] >> 4;
out[5] = (((in[1]) >> 7) & 0x01) | (((in[2]) & 0x03) << 1); out[5] = (in[1] >> 7) | (in[2] << 1);
out[6] = ((in[2] >> 2) & 0x07); out[6] = in[2] >> 2;
out[7] = ((in[2] >> 5) & 0x07); out[7] = in[2] >> 5;
in += 3; in += 3;
out += 8; out += 8;
} }
@ -39,37 +40,38 @@ static void POLq2BS(uint8_t bytes[SABER_POLYBYTES], const poly *data) {
const uint16_t *in = data->coeffs; const uint16_t *in = data->coeffs;
uint8_t *out = bytes; uint8_t *out = bytes;
for (j = 0; j < SABER_N / 8; j++) { for (j = 0; j < SABER_N / 8; j++) {
out[0] = (in[0] & (0xff)); out[0] = in[0];
out[1] = ((in[0] >> 8) & 0x1f) | ((in[1] & 0x07) << 5); out[1] = ((in[0] >> 8) & 0x1f) | (in[1] << 5);
out[2] = ((in[1] >> 3) & 0xff); out[2] = in[1] >> 3;
out[3] = ((in[1] >> 11) & 0x03) | ((in[2] & 0x3f) << 2); out[3] = ((in[1] >> 11) & 0x03) | (in[2] << 2);
out[4] = ((in[2] >> 6) & 0x7f) | ((in[3] & 0x01) << 7); out[4] = ((in[2] >> 6) & 0x7f) | (in[3] << 7);
out[5] = ((in[3] >> 1) & 0xff); out[5] = in[3] >> 1;
out[6] = ((in[3] >> 9) & 0x0f) | ((in[4] & 0x0f) << 4); out[6] = ((in[3] >> 9) & 0x0f) | (in[4] << 4);
out[7] = ((in[4] >> 4) & 0xff); out[7] = in[4] >> 4;
out[8] = ((in[4] >> 12) & 0x01) | ((in[5] & 0x7f) << 1); out[8] = ((in[4] >> 12) & 0x01) | (in[5] << 1);
out[9] = ((in[5] >> 7) & 0x3f) | ((in[6] & 0x03) << 6); out[9] = ((in[5] >> 7) & 0x3f) | (in[6] << 6);
out[10] = ((in[6] >> 2) & 0xff); out[10] = in[6] >> 2;
out[11] = ((in[6] >> 10) & 0x07) | ((in[7] & 0x1f) << 3); out[11] = ((in[6] >> 10) & 0x07) | (in[7] << 3);
out[12] = ((in[7] >> 5) & 0xff); out[12] = in[7] >> 5;
in += 8; in += 8;
out += 13; out += 13;
} }
} }
static void BS2POLq(poly *data, const uint8_t bytes[SABER_POLYBYTES]) { static void BS2POLq(poly *data, const uint8_t bytes[SABER_POLYBYTES]) {
/* This function does not reduce its output mod Q */
size_t j; size_t j;
const uint8_t *in = bytes; const uint8_t *in = bytes;
uint16_t *out = data->coeffs; uint16_t *out = data->coeffs;
for (j = 0; j < SABER_N / 8; j++) { for (j = 0; j < SABER_N / 8; j++) {
out[0] = (in[0] & (0xff)) | ((in[1] & 0x1f) << 8); out[0] = (in[0]) | (in[1] << 8);
out[1] = (in[1] >> 5 & (0x07)) | ((in[2] & 0xff) << 3) | ((in[3] & 0x03) << 11); out[1] = (in[1] >> 5) | (in[2] << 3) | (in[3] << 11);
out[2] = (in[3] >> 2 & (0x3f)) | ((in[4] & 0x7f) << 6); out[2] = (in[3] >> 2) | (in[4] << 6);
out[3] = (in[4] >> 7 & (0x01)) | ((in[5] & 0xff) << 1) | ((in[6] & 0x0f) << 9); out[3] = (in[4] >> 7) | (in[5] << 1) | (in[6] << 9);
out[4] = (in[6] >> 4 & (0x0f)) | ((in[7] & 0xff) << 4) | ((in[8] & 0x01) << 12); out[4] = (in[6] >> 4) | (in[7] << 4) | (in[8] << 12);
out[5] = (in[8] >> 1 & (0x7f)) | ((in[9] & 0x3f) << 7); out[5] = (in[8] >> 1) | (in[9] << 7);
out[6] = (in[9] >> 6 & (0x03)) | ((in[10] & 0xff) << 2) | ((in[11] & 0x07) << 10); out[6] = (in[9] >> 6) | (in[10] << 2) | (in[11] << 10);
out[7] = (in[11] >> 3 & (0x1f)) | ((in[12] & 0xff) << 5); out[7] = (in[11] >> 3) | (in[12] << 5);
in += 13; in += 13;
out += 8; out += 8;
} }
@ -80,11 +82,11 @@ static void POLp2BS(uint8_t bytes[SABER_POLYCOMPRESSEDBYTES], const poly *data)
const uint16_t *in = data->coeffs; const uint16_t *in = data->coeffs;
uint8_t *out = bytes; uint8_t *out = bytes;
for (j = 0; j < SABER_N / 4; j++) { for (j = 0; j < SABER_N / 4; j++) {
out[0] = (in[0] & (0xff)); out[0] = in[0];
out[1] = ((in[0] >> 8) & 0x03) | ((in[1] & 0x3f) << 2); out[1] = ((in[0] >> 8) & 0x03) | (in[1] << 2);
out[2] = ((in[1] >> 6) & 0x0f) | ((in[2] & 0x0f) << 4); out[2] = ((in[1] >> 6) & 0x0f) | (in[2] << 4);
out[3] = ((in[2] >> 4) & 0x3f) | ((in[3] & 0x03) << 6); out[3] = ((in[2] >> 4) & 0x3f) | (in[3] << 6);
out[4] = ((in[3] >> 2) & 0xff); out[4] = in[3] >> 2;
in += 4; in += 4;
out += 5; out += 5;
} }
@ -95,10 +97,10 @@ static void BS2POLp(poly *data, const uint8_t bytes[SABER_POLYCOMPRESSEDBYTES])
const uint8_t *in = bytes; const uint8_t *in = bytes;
uint16_t *out = data->coeffs; uint16_t *out = data->coeffs;
for (j = 0; j < SABER_N / 4; j++) { for (j = 0; j < SABER_N / 4; j++) {
out[0] = (in[0] & (0xff)) | ((in[1] & 0x03) << 8); out[0] = in[0] | (in[1] << 8);
out[1] = ((in[1] >> 2) & (0x3f)) | ((in[2] & 0x0f) << 6); out[1] = (in[1] >> 2) | (in[2] << 6);
out[2] = ((in[2] >> 4) & (0x0f)) | ((in[3] & 0x3f) << 4); out[2] = (in[2] >> 4) | (in[3] << 4);
out[3] = ((in[3] >> 6) & (0x03)) | ((in[4] & 0xff) << 2); out[3] = (in[3] >> 6) | (in[4] << 2);
in += 5; in += 5;
out += 4; out += 4;
} }

View File

@ -14,9 +14,9 @@ principal-submitters:
- Frederik Vercauteren - Frederik Vercauteren
implementations: implementations:
- name: clean - name: clean
version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/33e5ed62/saber version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/90d072e4/saber
- name: avx2 - name: avx2
version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/33e5ed62/saber version: https://github.com/KULeuven-COSIC/SABER/tree/509cc5ec3a7e12a751ccdd2ef5bd6e54e00bd350 via https://github.com/jschanck/package-pqclean/tree/90d072e4/saber
supported_platforms: supported_platforms:
- architecture: x86_64 - architecture: x86_64
operating_systems: operating_systems:

View File

@ -8,19 +8,20 @@ void PQCLEAN_SABER_AVX2_POLT2BS(uint8_t bytes[SABER_SCALEBYTES_KEM], const poly
const uint16_t *in = data->coeffs; const uint16_t *in = data->coeffs;
uint8_t *out = bytes; uint8_t *out = bytes;
for (j = 0; j < SABER_N / 2; j++) { for (j = 0; j < SABER_N / 2; j++) {
out[0] = (in[0] & 0x0f) | ((in[1] & 0x0f) << 4); out[0] = (in[0] & 0x0f) | (in[1] << 4);
in += 2; in += 2;
out += 1; out += 1;
} }
} }
void PQCLEAN_SABER_AVX2_BS2POLT(poly *data, const uint8_t bytes[SABER_SCALEBYTES_KEM]) { void PQCLEAN_SABER_AVX2_BS2POLT(poly *data, const uint8_t bytes[SABER_SCALEBYTES_KEM]) {
/* This function does not reduce its output mod T */
size_t j; size_t j;
const uint8_t *in = bytes; const uint8_t *in = bytes;
uint16_t *out = data->coeffs; uint16_t *out = data->coeffs;
for (j = 0; j < SABER_N / 2; j++) { for (j = 0; j < SABER_N / 2; j++) {
out[0] = in[0] & 0x0f; out[0] = in[0];
out[1] = (in[0] >> 4) & 0x0f; out[1] = in[0] >> 4;
in += 1; in += 1;
out += 2; out += 2;
} }
@ -31,37 +32,38 @@ static void POLq2BS(uint8_t bytes[SABER_POLYBYTES], const poly *data) {
const uint16_t *in = data->coeffs; const uint16_t *in = data->coeffs;
uint8_t *out = bytes; uint8_t *out = bytes;
for (j = 0; j < SABER_N / 8; j++) { for (j = 0; j < SABER_N / 8; j++) {
out[0] = (in[0] & (0xff)); out[0] = in[0];
out[1] = ((in[0] >> 8) & 0x1f) | ((in[1] & 0x07) << 5); out[1] = ((in[0] >> 8) & 0x1f) | (in[1] << 5);
out[2] = ((in[1] >> 3) & 0xff); out[2] = in[1] >> 3;
out[3] = ((in[1] >> 11) & 0x03) | ((in[2] & 0x3f) << 2); out[3] = ((in[1] >> 11) & 0x03) | (in[2] << 2);
out[4] = ((in[2] >> 6) & 0x7f) | ((in[3] & 0x01) << 7); out[4] = ((in[2] >> 6) & 0x7f) | (in[3] << 7);
out[5] = ((in[3] >> 1) & 0xff); out[5] = in[3] >> 1;
out[6] = ((in[3] >> 9) & 0x0f) | ((in[4] & 0x0f) << 4); out[6] = ((in[3] >> 9) & 0x0f) | (in[4] << 4);
out[7] = ((in[4] >> 4) & 0xff); out[7] = in[4] >> 4;
out[8] = ((in[4] >> 12) & 0x01) | ((in[5] & 0x7f) << 1); out[8] = ((in[4] >> 12) & 0x01) | (in[5] << 1);
out[9] = ((in[5] >> 7) & 0x3f) | ((in[6] & 0x03) << 6); out[9] = ((in[5] >> 7) & 0x3f) | (in[6] << 6);
out[10] = ((in[6] >> 2) & 0xff); out[10] = in[6] >> 2;
out[11] = ((in[6] >> 10) & 0x07) | ((in[7] & 0x1f) << 3); out[11] = ((in[6] >> 10) & 0x07) | (in[7] << 3);
out[12] = ((in[7] >> 5) & 0xff); out[12] = in[7] >> 5;
in += 8; in += 8;
out += 13; out += 13;
} }
} }
static void BS2POLq(poly *data, const uint8_t bytes[SABER_POLYBYTES]) { static void BS2POLq(poly *data, const uint8_t bytes[SABER_POLYBYTES]) {
/* This function does not reduce its output mod Q */
size_t j; size_t j;
const uint8_t *in = bytes; const uint8_t *in = bytes;
uint16_t *out = data->coeffs; uint16_t *out = data->coeffs;
for (j = 0; j < SABER_N / 8; j++) { for (j = 0; j < SABER_N / 8; j++) {
out[0] = (in[0] & (0xff)) | ((in[1] & 0x1f) << 8); out[0] = (in[0]) | (in[1] << 8);
out[1] = (in[1] >> 5 & (0x07)) | ((in[2] & 0xff) << 3) | ((in[3] & 0x03) << 11); out[1] = (in[1] >> 5) | (in[2] << 3) | (in[3] << 11);
out[2] = (in[3] >> 2 & (0x3f)) | ((in[4] & 0x7f) << 6); out[2] = (in[3] >> 2) | (in[4] << 6);
out[3] = (in[4] >> 7 & (0x01)) | ((in[5] & 0xff) << 1) | ((in[6] & 0x0f) << 9); out[3] = (in[4] >> 7) | (in[5] << 1) | (in[6] << 9);
out[4] = (in[6] >> 4 & (0x0f)) | ((in[7] & 0xff) << 4) | ((in[8] & 0x01) << 12); out[4] = (in[6] >> 4) | (in[7] << 4) | (in[8] << 12);
out[5] = (in[8] >> 1 & (0x7f)) | ((in[9] & 0x3f) << 7); out[5] = (in[8] >> 1) | (in[9] << 7);
out[6] = (in[9] >> 6 & (0x03)) | ((in[10] & 0xff) << 2) | ((in[11] & 0x07) << 10); out[6] = (in[9] >> 6) | (in[10] << 2) | (in[11] << 10);
out[7] = (in[11] >> 3 & (0x1f)) | ((in[12] & 0xff) << 5); out[7] = (in[11] >> 3) | (in[12] << 5);
in += 13; in += 13;
out += 8; out += 8;
} }
@ -72,11 +74,11 @@ static void POLp2BS(uint8_t bytes[SABER_POLYCOMPRESSEDBYTES], const poly *data)
const uint16_t *in = data->coeffs; const uint16_t *in = data->coeffs;
uint8_t *out = bytes; uint8_t *out = bytes;
for (j = 0; j < SABER_N / 4; j++) { for (j = 0; j < SABER_N / 4; j++) {
out[0] = (in[0] & (0xff)); out[0] = in[0];
out[1] = ((in[0] >> 8) & 0x03) | ((in[1] & 0x3f) << 2); out[1] = ((in[0] >> 8) & 0x03) | (in[1] << 2);
out[2] = ((in[1] >> 6) & 0x0f) | ((in[2] & 0x0f) << 4); out[2] = ((in[1] >> 6) & 0x0f) | (in[2] << 4);
out[3] = ((in[2] >> 4) & 0x3f) | ((in[3] & 0x03) << 6); out[3] = ((in[2] >> 4) & 0x3f) | (in[3] << 6);
out[4] = ((in[3] >> 2) & 0xff); out[4] = in[3] >> 2;
in += 4; in += 4;
out += 5; out += 5;
} }
@ -87,10 +89,10 @@ static void BS2POLp(poly *data, const uint8_t bytes[SABER_POLYCOMPRESSEDBYTES])
const uint8_t *in = bytes; const uint8_t *in = bytes;
uint16_t *out = data->coeffs; uint16_t *out = data->coeffs;
for (j = 0; j < SABER_N / 4; j++) { for (j = 0; j < SABER_N / 4; j++) {
out[0] = (in[0] & (0xff)) | ((in[1] & 0x03) << 8); out[0] = in[0] | (in[1] << 8);
out[1] = ((in[1] >> 2) & (0x3f)) | ((in[2] & 0x0f) << 6); out[1] = (in[1] >> 2) | (in[2] << 6);
out[2] = ((in[2] >> 4) & (0x0f)) | ((in[3] & 0x3f) << 4); out[2] = (in[2] >> 4) | (in[3] << 4);
out[3] = ((in[3] >> 6) & (0x03)) | ((in[4] & 0xff) << 2); out[3] = (in[3] >> 6) | (in[4] << 2);
in += 5; in += 5;
out += 4; out += 4;
} }

View File

@ -8,19 +8,20 @@ void PQCLEAN_SABER_CLEAN_POLT2BS(uint8_t bytes[SABER_SCALEBYTES_KEM], const poly
const uint16_t *in = data->coeffs; const uint16_t *in = data->coeffs;
uint8_t *out = bytes; uint8_t *out = bytes;
for (j = 0; j < SABER_N / 2; j++) { for (j = 0; j < SABER_N / 2; j++) {
out[0] = (in[0] & 0x0f) | ((in[1] & 0x0f) << 4); out[0] = (in[0] & 0x0f) | (in[1] << 4);
in += 2; in += 2;
out += 1; out += 1;
} }
} }
void PQCLEAN_SABER_CLEAN_BS2POLT(poly *data, const uint8_t bytes[SABER_SCALEBYTES_KEM]) { void PQCLEAN_SABER_CLEAN_BS2POLT(poly *data, const uint8_t bytes[SABER_SCALEBYTES_KEM]) {
/* This function does not reduce its output mod T */
size_t j; size_t j;
const uint8_t *in = bytes; const uint8_t *in = bytes;
uint16_t *out = data->coeffs; uint16_t *out = data->coeffs;
for (j = 0; j < SABER_N / 2; j++) { for (j = 0; j < SABER_N / 2; j++) {
out[0] = in[0] & 0x0f; out[0] = in[0];
out[1] = (in[0] >> 4) & 0x0f; out[1] = in[0] >> 4;
in += 1; in += 1;
out += 2; out += 2;
} }
@ -31,37 +32,38 @@ static void POLq2BS(uint8_t bytes[SABER_POLYBYTES], const poly *data) {
const uint16_t *in = data->coeffs; const uint16_t *in = data->coeffs;
uint8_t *out = bytes; uint8_t *out = bytes;
for (j = 0; j < SABER_N / 8; j++) { for (j = 0; j < SABER_N / 8; j++) {
out[0] = (in[0] & (0xff)); out[0] = in[0];
out[1] = ((in[0] >> 8) & 0x1f) | ((in[1] & 0x07) << 5); out[1] = ((in[0] >> 8) & 0x1f) | (in[1] << 5);
out[2] = ((in[1] >> 3) & 0xff); out[2] = in[1] >> 3;
out[3] = ((in[1] >> 11) & 0x03) | ((in[2] & 0x3f) << 2); out[3] = ((in[1] >> 11) & 0x03) | (in[2] << 2);
out[4] = ((in[2] >> 6) & 0x7f) | ((in[3] & 0x01) << 7); out[4] = ((in[2] >> 6) & 0x7f) | (in[3] << 7);
out[5] = ((in[3] >> 1) & 0xff); out[5] = in[3] >> 1;
out[6] = ((in[3] >> 9) & 0x0f) | ((in[4] & 0x0f) << 4); out[6] = ((in[3] >> 9) & 0x0f) | (in[4] << 4);
out[7] = ((in[4] >> 4) & 0xff); out[7] = in[4] >> 4;
out[8] = ((in[4] >> 12) & 0x01) | ((in[5] & 0x7f) << 1); out[8] = ((in[4] >> 12) & 0x01) | (in[5] << 1);
out[9] = ((in[5] >> 7) & 0x3f) | ((in[6] & 0x03) << 6); out[9] = ((in[5] >> 7) & 0x3f) | (in[6] << 6);
out[10] = ((in[6] >> 2) & 0xff); out[10] = in[6] >> 2;
out[11] = ((in[6] >> 10) & 0x07) | ((in[7] & 0x1f) << 3); out[11] = ((in[6] >> 10) & 0x07) | (in[7] << 3);
out[12] = ((in[7] >> 5) & 0xff); out[12] = in[7] >> 5;
in += 8; in += 8;
out += 13; out += 13;
} }
} }
static void BS2POLq(poly *data, const uint8_t bytes[SABER_POLYBYTES]) { static void BS2POLq(poly *data, const uint8_t bytes[SABER_POLYBYTES]) {
/* This function does not reduce its output mod Q */
size_t j; size_t j;
const uint8_t *in = bytes; const uint8_t *in = bytes;
uint16_t *out = data->coeffs; uint16_t *out = data->coeffs;
for (j = 0; j < SABER_N / 8; j++) { for (j = 0; j < SABER_N / 8; j++) {
out[0] = (in[0] & (0xff)) | ((in[1] & 0x1f) << 8); out[0] = (in[0]) | (in[1] << 8);
out[1] = (in[1] >> 5 & (0x07)) | ((in[2] & 0xff) << 3) | ((in[3] & 0x03) << 11); out[1] = (in[1] >> 5) | (in[2] << 3) | (in[3] << 11);
out[2] = (in[3] >> 2 & (0x3f)) | ((in[4] & 0x7f) << 6); out[2] = (in[3] >> 2) | (in[4] << 6);
out[3] = (in[4] >> 7 & (0x01)) | ((in[5] & 0xff) << 1) | ((in[6] & 0x0f) << 9); out[3] = (in[4] >> 7) | (in[5] << 1) | (in[6] << 9);
out[4] = (in[6] >> 4 & (0x0f)) | ((in[7] & 0xff) << 4) | ((in[8] & 0x01) << 12); out[4] = (in[6] >> 4) | (in[7] << 4) | (in[8] << 12);
out[5] = (in[8] >> 1 & (0x7f)) | ((in[9] & 0x3f) << 7); out[5] = (in[8] >> 1) | (in[9] << 7);
out[6] = (in[9] >> 6 & (0x03)) | ((in[10] & 0xff) << 2) | ((in[11] & 0x07) << 10); out[6] = (in[9] >> 6) | (in[10] << 2) | (in[11] << 10);
out[7] = (in[11] >> 3 & (0x1f)) | ((in[12] & 0xff) << 5); out[7] = (in[11] >> 3) | (in[12] << 5);
in += 13; in += 13;
out += 8; out += 8;
} }
@ -72,11 +74,11 @@ static void POLp2BS(uint8_t bytes[SABER_POLYCOMPRESSEDBYTES], const poly *data)
const uint16_t *in = data->coeffs; const uint16_t *in = data->coeffs;
uint8_t *out = bytes; uint8_t *out = bytes;
for (j = 0; j < SABER_N / 4; j++) { for (j = 0; j < SABER_N / 4; j++) {
out[0] = (in[0] & (0xff)); out[0] = in[0];
out[1] = ((in[0] >> 8) & 0x03) | ((in[1] & 0x3f) << 2); out[1] = ((in[0] >> 8) & 0x03) | (in[1] << 2);
out[2] = ((in[1] >> 6) & 0x0f) | ((in[2] & 0x0f) << 4); out[2] = ((in[1] >> 6) & 0x0f) | (in[2] << 4);
out[3] = ((in[2] >> 4) & 0x3f) | ((in[3] & 0x03) << 6); out[3] = ((in[2] >> 4) & 0x3f) | (in[3] << 6);
out[4] = ((in[3] >> 2) & 0xff); out[4] = in[3] >> 2;
in += 4; in += 4;
out += 5; out += 5;
} }
@ -87,10 +89,10 @@ static void BS2POLp(poly *data, const uint8_t bytes[SABER_POLYCOMPRESSEDBYTES])
const uint8_t *in = bytes; const uint8_t *in = bytes;
uint16_t *out = data->coeffs; uint16_t *out = data->coeffs;
for (j = 0; j < SABER_N / 4; j++) { for (j = 0; j < SABER_N / 4; j++) {
out[0] = (in[0] & (0xff)) | ((in[1] & 0x03) << 8); out[0] = in[0] | (in[1] << 8);
out[1] = ((in[1] >> 2) & (0x3f)) | ((in[2] & 0x0f) << 6); out[1] = (in[1] >> 2) | (in[2] << 6);
out[2] = ((in[2] >> 4) & (0x0f)) | ((in[3] & 0x3f) << 4); out[2] = (in[2] >> 4) | (in[3] << 4);
out[3] = ((in[3] >> 6) & (0x03)) | ((in[4] & 0xff) << 2); out[3] = (in[3] >> 6) | (in[4] << 2);
in += 5; in += 5;
out += 4; out += 4;
} }

View File

@ -6,7 +6,6 @@ consistency_checks:
- api.h - api.h
- cbd.h - cbd.h
- pack_unpack.h - pack_unpack.h
- kem.h
- SABER_indcpa.h - SABER_indcpa.h
- SABER_params.h - SABER_params.h
- verify.h - verify.h

View File

@ -5,7 +5,6 @@ consistency_checks:
files: files:
- api.h - api.h
- cbd.h - cbd.h
- poly_mul.h
- pack_unpack.h - pack_unpack.h
- SABER_indcpa.h - SABER_indcpa.h
- SABER_params.h - SABER_params.h

View File

@ -6,7 +6,6 @@ consistency_checks:
- api.h - api.h
- cbd.h - cbd.h
- pack_unpack.h - pack_unpack.h
- kem.h
- SABER_indcpa.h - SABER_indcpa.h
- SABER_params.h - SABER_params.h
- verify.h - verify.h
@ -20,7 +19,6 @@ consistency_checks:
files: files:
- cbd.h - cbd.h
- pack_unpack.h - pack_unpack.h
- kem.h
- SABER_indcpa.h - SABER_indcpa.h
- verify.h - verify.h
- kem.c - kem.c
@ -30,7 +28,6 @@ consistency_checks:
implementation: avx2 implementation: avx2
files: files:
- cbd.h - cbd.h
- kem.h
- pack_unpack.h - pack_unpack.h
- poly.h - poly.h
- SABER_indcpa.h - SABER_indcpa.h
@ -46,7 +43,6 @@ consistency_checks:
files: files:
- cbd.h - cbd.h
- pack_unpack.h - pack_unpack.h
- kem.h
- SABER_indcpa.h - SABER_indcpa.h
- verify.h - verify.h
- kem.c - kem.c
@ -56,7 +52,6 @@ consistency_checks:
implementation: avx2 implementation: avx2
files: files:
- cbd.h - cbd.h
- kem.h
- pack_unpack.h - pack_unpack.h
- poly.h - poly.h
- SABER_indcpa.h - SABER_indcpa.h

View File

@ -5,7 +5,6 @@ consistency_checks:
files: files:
- api.h - api.h
- cbd.h - cbd.h
- poly_mul.h
- pack_unpack.h - pack_unpack.h
- SABER_indcpa.h - SABER_indcpa.h
- SABER_params.h - SABER_params.h
@ -34,7 +33,6 @@ consistency_checks:
implementation: avx2 implementation: avx2
files: files:
- cbd.h - cbd.h
- poly_mul.h
- pack_unpack.h - pack_unpack.h
- SABER_indcpa.h - SABER_indcpa.h
- verify.h - verify.h
@ -60,7 +58,6 @@ consistency_checks:
implementation: avx2 implementation: avx2
files: files:
- cbd.h - cbd.h
- poly_mul.h
- pack_unpack.h - pack_unpack.h
- SABER_indcpa.h - SABER_indcpa.h
- verify.h - verify.h

View File

@ -6,7 +6,6 @@ consistency_checks:
- api.h - api.h
- cbd.h - cbd.h
- pack_unpack.h - pack_unpack.h
- kem.h
- SABER_indcpa.h - SABER_indcpa.h
- SABER_params.h - SABER_params.h
- verify.h - verify.h
@ -20,7 +19,6 @@ consistency_checks:
files: files:
- cbd.h - cbd.h
- pack_unpack.h - pack_unpack.h
- kem.h
- SABER_indcpa.h - SABER_indcpa.h
- verify.h - verify.h
- kem.c - kem.c
@ -30,7 +28,6 @@ consistency_checks:
implementation: avx2 implementation: avx2
files: files:
- cbd.h - cbd.h
- kem.h
- pack_unpack.h - pack_unpack.h
- poly.h - poly.h
- SABER_indcpa.h - SABER_indcpa.h

View File

@ -5,7 +5,6 @@ consistency_checks:
files: files:
- api.h - api.h
- cbd.h - cbd.h
- poly_mul.h
- pack_unpack.h - pack_unpack.h
- SABER_indcpa.h - SABER_indcpa.h
- SABER_params.h - SABER_params.h
@ -34,7 +33,6 @@ consistency_checks:
implementation: avx2 implementation: avx2
files: files:
- cbd.h - cbd.h
- poly_mul.h
- pack_unpack.h - pack_unpack.h
- SABER_indcpa.h - SABER_indcpa.h
- verify.h - verify.h