| 1 |
#include <immintrin.h> |
| 2 |
#include "crypto_core.h" |
| 3 |
|
| 4 |
#include "crypto_int16.h" |
| 5 |
#define int16 crypto_int16 |
| 6 |
#include "crypto_decode_int16.h" |
| 7 |
|
| 8 |
#include "params.h" |
| 9 |
|
| 10 |
/* out = in if bottom bits of in have weight w */ |
| 11 |
/* otherwise out = (1,1,...,1,0,0,...,0) */ |
| 12 |
void crypto_core(unsigned char *out,const unsigned char *in,const unsigned char *kbytes,const unsigned char *cbytes) |
| 13 |
{ |
| 14 |
int16 weight; |
| 15 |
int16 mask; |
| 16 |
__m256i maskvec; |
| 17 |
int i; |
| 18 |
|
| 19 |
crypto_core_weight((unsigned char *) &weight,in,0,0); |
| 20 |
crypto_decode_int16(&weight,(unsigned char *) &weight); |
| 21 |
|
| 22 |
mask = crypto_int16_equal_mask(weight,w); |
| 23 |
maskvec = _mm256_set1_epi16(mask); |
| 24 |
|
| 25 |
i = w-32; |
| 26 |
for (;;) { |
| 27 |
do { |
| 28 |
__m256i x = _mm256_loadu_si256((__m256i *) in); |
| 29 |
x ^= _mm256_set1_epi8(1); |
| 30 |
x &= maskvec; |
| 31 |
x ^= _mm256_set1_epi8(1); |
| 32 |
_mm256_storeu_si256((__m256i *) out,x); |
| 33 |
in += 32; |
| 34 |
out += 32; |
| 35 |
i -= 32; |
| 36 |
} while (i >= 0); |
| 37 |
if (i <= -32) break; |
| 38 |
in += i; |
| 39 |
out += i; |
| 40 |
} |
| 41 |
|
| 42 |
i = p-w-32; |
| 43 |
for (;;) { |
| 44 |
do { |
| 45 |
__m256i x = _mm256_loadu_si256((__m256i *) in); |
| 46 |
x &= maskvec; |
| 47 |
_mm256_storeu_si256((__m256i *) out,x); |
| 48 |
in += 32; |
| 49 |
out += 32; |
| 50 |
i -= 32; |
| 51 |
} while (i >= 0); |
| 52 |
if (i <= -32) break; |
| 53 |
in += i; |
| 54 |
out += i; |
| 55 |
} |
| 56 |
} |