Changeset View
Changeset View
Standalone View
Standalone View
sys/crypto/aesni/aesni_wrap.c
Show First 20 Lines • Show All 207 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
__m128i tot; | __m128i tot; | ||||
__m128i tmp1, tmp2, tmp3, tmp4; | __m128i tmp1, tmp2, tmp3, tmp4; | ||||
__m128i tmp5, tmp6, tmp7, tmp8; | __m128i tmp5, tmp6, tmp7, tmp8; | ||||
__m128i ctr1, ctr2, ctr3, ctr4; | __m128i ctr1, ctr2, ctr3, ctr4; | ||||
__m128i ctr5, ctr6, ctr7, ctr8; | __m128i ctr5, ctr6, ctr7, ctr8; | ||||
__m128i BSWAP_EPI64; | __m128i BSWAP_EPI64; | ||||
__m128i tout[8]; | __m128i tout[8]; | ||||
__m128i block; | |||||
struct blocks8 *top; | struct blocks8 *top; | ||||
const struct blocks8 *blks; | const struct blocks8 *blks; | ||||
size_t i, cnt; | size_t i, cnt, resid; | ||||
BSWAP_EPI64 = _mm_set_epi8(8,9,10,11,12,13,14,15,0,1,2,3,4,5,6,7); | BSWAP_EPI64 = _mm_set_epi8(8,9,10,11,12,13,14,15,0,1,2,3,4,5,6,7); | ||||
ctr1 = _mm_loadu_si128((const __m128i *)iv); | ctr1 = _mm_loadu_si128((const __m128i *)iv); | ||||
ctr1 = _mm_shuffle_epi8(ctr1, BSWAP_EPI64); | ctr1 = _mm_shuffle_epi8(ctr1, BSWAP_EPI64); | ||||
cnt = len / AES_BLOCK_LEN / 8; | cnt = len / AES_BLOCK_LEN / 8; | ||||
for (i = 0; i < cnt; i++) { | for (i = 0; i < cnt; i++) { | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | for (; i < cnt; i++) { | ||||
tot = tot ^ _mm_loadu_si128((const __m128i *)from); | tot = tot ^ _mm_loadu_si128((const __m128i *)from); | ||||
_mm_storeu_si128((__m128i *)to, tot); | _mm_storeu_si128((__m128i *)to, tot); | ||||
from += AES_BLOCK_LEN; | from += AES_BLOCK_LEN; | ||||
to += AES_BLOCK_LEN; | to += AES_BLOCK_LEN; | ||||
} | } | ||||
/* handle remaining partial round */ | /* | ||||
if (len % AES_BLOCK_LEN != 0) { | * Handle remaining partial round. Copy the remaining payload onto the | ||||
* stack to ensure that the full block can be loaded safely. | |||||
*/ | |||||
resid = len % AES_BLOCK_LEN; | |||||
if (resid != 0) { | |||||
tmp1 = _mm_shuffle_epi8(ctr1, BSWAP_EPI64); | tmp1 = _mm_shuffle_epi8(ctr1, BSWAP_EPI64); | ||||
tot = aesni_enc(rounds - 1, key_schedule, tmp1); | tot = aesni_enc(rounds - 1, key_schedule, tmp1); | ||||
tot = tot ^ _mm_loadu_si128((const __m128i *)from); | block = _mm_setzero_si128(); | ||||
memcpy(to, &tot, len % AES_BLOCK_LEN); | memcpy(&block, from, resid); | ||||
tot = tot ^ _mm_loadu_si128(&block); | |||||
memcpy(to, &tot, resid); | |||||
explicit_bzero(&block, sizeof(block)); | |||||
} | } | ||||
} | } | ||||
#define AES_XTS_BLOCKSIZE 16 | #define AES_XTS_BLOCKSIZE 16 | ||||
#define AES_XTS_IVSIZE 8 | #define AES_XTS_IVSIZE 8 | ||||
#define AES_XTS_ALPHA 0x87 /* GF(2^128) generator polynomial */ | #define AES_XTS_ALPHA 0x87 /* GF(2^128) generator polynomial */ | ||||
static inline __m128i | static inline __m128i | ||||
▲ Show 20 Lines • Show All 190 Lines • Show Last 20 Lines |