references/NIST-PQ-Submission-Kyber-20201001/Additional_Implementations/avx2/crypto_kem/kyber768/poly.c
/*************************************************
* Name:        poly_tomsg
*
* Description: Convert polynomial to 32-byte message
*
* Arguments:   - uint8_t *msg: pointer to output message
*              - poly *a:      pointer to input polynomial
**************************************************/
poly_tomsg
Description: Convert polynomial to 32-byte message

- uint8_t *msg: pointer to output message
poly *a:      pointer to input polynomial
poly_tomsg Description : Convert polynomial to 32 - byte message - uint8_t * msg : pointer to output message poly * a : pointer to input polynomial
void poly_tomsg(uint8_t msg[KYBER_INDCPA_MSGBYTES], poly * restrict a)
{
  unsigned int i;
  uint32_t small;
  __m256i f0, f1, g0, g1;
  const __m256i hqs = _mm256_set1_epi16((KYBER_Q - 1)/2);
  const __m256i hhqs = _mm256_set1_epi16((KYBER_Q - 5)/4);
  for(i=0;i<KYBER_N/32;i++) {
    f0 = _mm256_load_si256((__m256i *)&a->coeffs[32*i]);
    f1 = _mm256_load_si256((__m256i *)&a->coeffs[32*i+16]);
    f0 = _mm256_sub_epi16(hqs, f0);
    f1 = _mm256_sub_epi16(hqs, f1);
    g0 = _mm256_srai_epi16(f0, 15);
    g1 = _mm256_srai_epi16(f1, 15);
    f0 = _mm256_xor_si256(f0, g0);
    f1 = _mm256_xor_si256(f1, g1);
    f0 = _mm256_sub_epi16(hhqs, f0);
    f1 = _mm256_sub_epi16(hhqs, f1);
    f0 = _mm256_packs_epi16(f0, f1);
    small = _mm256_movemask_epi8(f0);
    small = ~small;
    msg[4*i+0] = small;
    msg[4*i+1] = small >> 16;
    msg[4*i+2] = small >>  8;
    msg[4*i+3] = small >> 24;
  }
}
void poly_tomsg ( uint8_t msg [ KYBER_INDCPA_MSGBYTES ] , poly * restrict a ) { unsigned int i ; uint32_t small ; __m256i f0 , f1 , g0 , g1 ; const __m256i hqs = _mm256_set1_epi16 ( ( KYBER_Q - 1 ) / 2 ) ; const __m256i hhqs = _mm256_set1_epi16 ( ( KYBER_Q - 5 ) / 4 ) ; for ( i = 0 ; i < KYBER_N / 32 ; i ++ ) { f0 = _mm256_load_si256 ( ( __m256i * ) & a -> coeffs [ 32 * i ] ) ; f1 = _mm256_load_si256 ( ( __m256i * ) & a -> coeffs [ 32 * i + 16 ] ) ; f0 = _mm256_sub_epi16 ( hqs , f0 ) ; f1 = _mm256_sub_epi16 ( hqs , f1 ) ; g0 = _mm256_srai_epi16 ( f0 , 15 ) ; g1 = _mm256_srai_epi16 ( f1 , 15 ) ; f0 = _mm256_xor_si256 ( f0 , g0 ) ; f1 = _mm256_xor_si256 ( f1 , g1 ) ; f0 = _mm256_sub_epi16 ( hhqs , f0 ) ; f1 = _mm256_sub_epi16 ( hhqs , f1 ) ; f0 = _mm256_packs_epi16 ( f0 , f1 ) ; small = _mm256_movemask_epi8 ( f0 ) ; small = ~ small ; msg [ 4 * i + 0 ] = small ; msg [ 4 * i + 1 ] = small >> 16 ; msg [ 4 * i + 2 ] = small >> 8 ; msg [ 4 * i + 3 ] = small >> 24 ; } }
Name:        poly_tomsg
Description: Convert polynomial to 32-byte message
Name : poly_tomsg Description : Convert polynomial to 32 - byte message