mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-25 08:37:13 +09:00
Avoid collision with a possibly existing int128 type definition
This commit is contained in:
@@ -9,24 +9,24 @@
|
||||
|
||||
int crypto_stream_aes128ctr_afternm(unsigned char *out, unsigned long long len, const unsigned char *nonce, const unsigned char *c)
|
||||
{
|
||||
int128 xmm0;
|
||||
int128 xmm1;
|
||||
int128 xmm2;
|
||||
int128 xmm3;
|
||||
int128 xmm4;
|
||||
int128 xmm5;
|
||||
int128 xmm6;
|
||||
int128 xmm7;
|
||||
int128 xmm8;
|
||||
int128 xmm9;
|
||||
int128 xmm10;
|
||||
int128 xmm11;
|
||||
int128 xmm12;
|
||||
int128 xmm13;
|
||||
int128 xmm14;
|
||||
int128 xmm15;
|
||||
aes_uint128_t xmm0;
|
||||
aes_uint128_t xmm1;
|
||||
aes_uint128_t xmm2;
|
||||
aes_uint128_t xmm3;
|
||||
aes_uint128_t xmm4;
|
||||
aes_uint128_t xmm5;
|
||||
aes_uint128_t xmm6;
|
||||
aes_uint128_t xmm7;
|
||||
aes_uint128_t xmm8;
|
||||
aes_uint128_t xmm9;
|
||||
aes_uint128_t xmm10;
|
||||
aes_uint128_t xmm11;
|
||||
aes_uint128_t xmm12;
|
||||
aes_uint128_t xmm13;
|
||||
aes_uint128_t xmm14;
|
||||
aes_uint128_t xmm15;
|
||||
|
||||
int128 nonce_stack;
|
||||
aes_uint128_t nonce_stack;
|
||||
unsigned long long lensav;
|
||||
unsigned char bl[128];
|
||||
unsigned char *blp;
|
||||
@@ -36,12 +36,12 @@ int crypto_stream_aes128ctr_afternm(unsigned char *out, unsigned long long len,
|
||||
uint32_t tmp;
|
||||
|
||||
/* Copy nonce on the stack */
|
||||
copy2(&nonce_stack, (const int128 *) (nonce + 0));
|
||||
copy2(&nonce_stack, (const aes_uint128_t *) (nonce + 0));
|
||||
np = (unsigned char *)&nonce_stack;
|
||||
|
||||
enc_block:
|
||||
|
||||
xmm0 = *(int128 *) (np + 0);
|
||||
xmm0 = *(aes_uint128_t *) (np + 0);
|
||||
copy2(&xmm1, &xmm0);
|
||||
shufb(&xmm1, SWAP32);
|
||||
copy2(&xmm2, &xmm1);
|
||||
@@ -90,14 +90,14 @@ enc_block:
|
||||
tmp += 8;
|
||||
STORE32_BE(np + 12, tmp);
|
||||
|
||||
*(int128 *) (out + 0) = xmm8;
|
||||
*(int128 *) (out + 16) = xmm9;
|
||||
*(int128 *) (out + 32) = xmm12;
|
||||
*(int128 *) (out + 48) = xmm14;
|
||||
*(int128 *) (out + 64) = xmm11;
|
||||
*(int128 *) (out + 80) = xmm15;
|
||||
*(int128 *) (out + 96) = xmm10;
|
||||
*(int128 *) (out + 112) = xmm13;
|
||||
*(aes_uint128_t *) (out + 0) = xmm8;
|
||||
*(aes_uint128_t *) (out + 16) = xmm9;
|
||||
*(aes_uint128_t *) (out + 32) = xmm12;
|
||||
*(aes_uint128_t *) (out + 48) = xmm14;
|
||||
*(aes_uint128_t *) (out + 64) = xmm11;
|
||||
*(aes_uint128_t *) (out + 80) = xmm15;
|
||||
*(aes_uint128_t *) (out + 96) = xmm10;
|
||||
*(aes_uint128_t *) (out + 112) = xmm13;
|
||||
|
||||
len -= 128;
|
||||
out += 128;
|
||||
@@ -114,14 +114,14 @@ partial:
|
||||
STORE32_BE(np + 12, tmp);
|
||||
|
||||
blp = bl;
|
||||
*(int128 *)(blp + 0) = xmm8;
|
||||
*(int128 *)(blp + 16) = xmm9;
|
||||
*(int128 *)(blp + 32) = xmm12;
|
||||
*(int128 *)(blp + 48) = xmm14;
|
||||
*(int128 *)(blp + 64) = xmm11;
|
||||
*(int128 *)(blp + 80) = xmm15;
|
||||
*(int128 *)(blp + 96) = xmm10;
|
||||
*(int128 *)(blp + 112) = xmm13;
|
||||
*(aes_uint128_t *)(blp + 0) = xmm8;
|
||||
*(aes_uint128_t *)(blp + 16) = xmm9;
|
||||
*(aes_uint128_t *)(blp + 32) = xmm12;
|
||||
*(aes_uint128_t *)(blp + 48) = xmm14;
|
||||
*(aes_uint128_t *)(blp + 64) = xmm11;
|
||||
*(aes_uint128_t *)(blp + 80) = xmm15;
|
||||
*(aes_uint128_t *)(blp + 96) = xmm10;
|
||||
*(aes_uint128_t *)(blp + 112) = xmm13;
|
||||
|
||||
bytes:
|
||||
|
||||
@@ -142,14 +142,14 @@ full:
|
||||
tmp += 8;
|
||||
STORE32_BE(np + 12, tmp);
|
||||
|
||||
*(int128 *) (out + 0) = xmm8;
|
||||
*(int128 *) (out + 16) = xmm9;
|
||||
*(int128 *) (out + 32) = xmm12;
|
||||
*(int128 *) (out + 48) = xmm14;
|
||||
*(int128 *) (out + 64) = xmm11;
|
||||
*(int128 *) (out + 80) = xmm15;
|
||||
*(int128 *) (out + 96) = xmm10;
|
||||
*(int128 *) (out + 112) = xmm13;
|
||||
*(aes_uint128_t *) (out + 0) = xmm8;
|
||||
*(aes_uint128_t *) (out + 16) = xmm9;
|
||||
*(aes_uint128_t *) (out + 32) = xmm12;
|
||||
*(aes_uint128_t *) (out + 48) = xmm14;
|
||||
*(aes_uint128_t *) (out + 64) = xmm11;
|
||||
*(aes_uint128_t *) (out + 80) = xmm15;
|
||||
*(aes_uint128_t *) (out + 96) = xmm10;
|
||||
*(aes_uint128_t *) (out + 112) = xmm13;
|
||||
|
||||
end:
|
||||
return 0;
|
||||
|
||||
@@ -9,23 +9,23 @@
|
||||
|
||||
int crypto_stream_aes128ctr_beforenm(unsigned char *c, const unsigned char *k)
|
||||
{
|
||||
int128 xmm0;
|
||||
int128 xmm1;
|
||||
int128 xmm2;
|
||||
int128 xmm3;
|
||||
int128 xmm4;
|
||||
int128 xmm5;
|
||||
int128 xmm6;
|
||||
int128 xmm7;
|
||||
int128 xmm8;
|
||||
int128 xmm9;
|
||||
int128 xmm10;
|
||||
int128 xmm11;
|
||||
int128 xmm12;
|
||||
int128 xmm13;
|
||||
int128 xmm14;
|
||||
int128 xmm15;
|
||||
int128 t;
|
||||
aes_uint128_t xmm0;
|
||||
aes_uint128_t xmm1;
|
||||
aes_uint128_t xmm2;
|
||||
aes_uint128_t xmm3;
|
||||
aes_uint128_t xmm4;
|
||||
aes_uint128_t xmm5;
|
||||
aes_uint128_t xmm6;
|
||||
aes_uint128_t xmm7;
|
||||
aes_uint128_t xmm8;
|
||||
aes_uint128_t xmm9;
|
||||
aes_uint128_t xmm10;
|
||||
aes_uint128_t xmm11;
|
||||
aes_uint128_t xmm12;
|
||||
aes_uint128_t xmm13;
|
||||
aes_uint128_t xmm14;
|
||||
aes_uint128_t xmm15;
|
||||
aes_uint128_t t;
|
||||
|
||||
bitslicekey0(k, c)
|
||||
|
||||
|
||||
@@ -32,14 +32,14 @@
|
||||
shufb(&b5, EXPB0);\
|
||||
shufb(&b0, EXPB0);\
|
||||
;\
|
||||
t0 = *(int128 *)(bskey + 0);\
|
||||
t1 = *(int128 *)(bskey + 16);\
|
||||
t2 = *(int128 *)(bskey + 32);\
|
||||
t3 = *(int128 *)(bskey + 48);\
|
||||
t4 = *(int128 *)(bskey + 64);\
|
||||
t5 = *(int128 *)(bskey + 80);\
|
||||
t6 = *(int128 *)(bskey + 96);\
|
||||
t7 = *(int128 *)(bskey + 112);\
|
||||
t0 = *(aes_uint128_t *)(bskey + 0);\
|
||||
t1 = *(aes_uint128_t *)(bskey + 16);\
|
||||
t2 = *(aes_uint128_t *)(bskey + 32);\
|
||||
t3 = *(aes_uint128_t *)(bskey + 48);\
|
||||
t4 = *(aes_uint128_t *)(bskey + 64);\
|
||||
t5 = *(aes_uint128_t *)(bskey + 80);\
|
||||
t6 = *(aes_uint128_t *)(bskey + 96);\
|
||||
t7 = *(aes_uint128_t *)(bskey + 112);\
|
||||
;\
|
||||
xor2(&b0, &t0);\
|
||||
xor2(&b1, &t1);\
|
||||
@@ -104,14 +104,14 @@
|
||||
xor2(&b2, &t6);\
|
||||
xor2(&b5, &t7);\
|
||||
;\
|
||||
*(int128 *)(bskey + 128) = b0;\
|
||||
*(int128 *)(bskey + 144) = b1;\
|
||||
*(int128 *)(bskey + 160) = b4;\
|
||||
*(int128 *)(bskey + 176) = b6;\
|
||||
*(int128 *)(bskey + 192) = b3;\
|
||||
*(int128 *)(bskey + 208) = b7;\
|
||||
*(int128 *)(bskey + 224) = b2;\
|
||||
*(int128 *)(bskey + 240) = b5;\
|
||||
*(aes_uint128_t *)(bskey + 128) = b0;\
|
||||
*(aes_uint128_t *)(bskey + 144) = b1;\
|
||||
*(aes_uint128_t *)(bskey + 160) = b4;\
|
||||
*(aes_uint128_t *)(bskey + 176) = b6;\
|
||||
*(aes_uint128_t *)(bskey + 192) = b3;\
|
||||
*(aes_uint128_t *)(bskey + 208) = b7;\
|
||||
*(aes_uint128_t *)(bskey + 224) = b2;\
|
||||
*(aes_uint128_t *)(bskey + 240) = b5;\
|
||||
|
||||
#define keyexpbs10(b0, b1, b2, b3, b4, b5, b6, b7, t0, t1, t2, t3, t4, t5, t6, t7, bskey) ;\
|
||||
toggle(&b0);\
|
||||
@@ -142,14 +142,14 @@
|
||||
shufb(&b2, EXPB0);\
|
||||
shufb(&b5, EXPB0);\
|
||||
;\
|
||||
t0 = *(int128 *)(bskey + 9 * 128 + 0);\
|
||||
t1 = *(int128 *)(bskey + 9 * 128 + 16);\
|
||||
t2 = *(int128 *)(bskey + 9 * 128 + 32);\
|
||||
t3 = *(int128 *)(bskey + 9 * 128 + 48);\
|
||||
t4 = *(int128 *)(bskey + 9 * 128 + 64);\
|
||||
t5 = *(int128 *)(bskey + 9 * 128 + 80);\
|
||||
t6 = *(int128 *)(bskey + 9 * 128 + 96);\
|
||||
t7 = *(int128 *)(bskey + 9 * 128 + 112);\
|
||||
t0 = *(aes_uint128_t *)(bskey + 9 * 128 + 0);\
|
||||
t1 = *(aes_uint128_t *)(bskey + 9 * 128 + 16);\
|
||||
t2 = *(aes_uint128_t *)(bskey + 9 * 128 + 32);\
|
||||
t3 = *(aes_uint128_t *)(bskey + 9 * 128 + 48);\
|
||||
t4 = *(aes_uint128_t *)(bskey + 9 * 128 + 64);\
|
||||
t5 = *(aes_uint128_t *)(bskey + 9 * 128 + 80);\
|
||||
t6 = *(aes_uint128_t *)(bskey + 9 * 128 + 96);\
|
||||
t7 = *(aes_uint128_t *)(bskey + 9 * 128 + 112);\
|
||||
;\
|
||||
toggle(&t0);\
|
||||
toggle(&t1);\
|
||||
@@ -228,14 +228,14 @@
|
||||
shufb(&b6, M0);\
|
||||
shufb(&b7, M0);\
|
||||
;\
|
||||
*(int128 *)(bskey + 1280) = b0;\
|
||||
*(int128 *)(bskey + 1296) = b1;\
|
||||
*(int128 *)(bskey + 1312) = b4;\
|
||||
*(int128 *)(bskey + 1328) = b6;\
|
||||
*(int128 *)(bskey + 1344) = b3;\
|
||||
*(int128 *)(bskey + 1360) = b7;\
|
||||
*(int128 *)(bskey + 1376) = b2;\
|
||||
*(int128 *)(bskey + 1392) = b5;\
|
||||
*(aes_uint128_t *)(bskey + 1280) = b0;\
|
||||
*(aes_uint128_t *)(bskey + 1296) = b1;\
|
||||
*(aes_uint128_t *)(bskey + 1312) = b4;\
|
||||
*(aes_uint128_t *)(bskey + 1328) = b6;\
|
||||
*(aes_uint128_t *)(bskey + 1344) = b3;\
|
||||
*(aes_uint128_t *)(bskey + 1360) = b7;\
|
||||
*(aes_uint128_t *)(bskey + 1376) = b2;\
|
||||
*(aes_uint128_t *)(bskey + 1392) = b5;\
|
||||
|
||||
|
||||
#define keyexpbs(b0, b1, b2, b3, b4, b5, b6, b7, t0, t1, t2, t3, t4, t5, t6, t7, rcon, i, bskey) \
|
||||
@@ -264,14 +264,14 @@
|
||||
shufb(&b2, EXPB0);\
|
||||
shufb(&b5, EXPB0);\
|
||||
;\
|
||||
t0 = *(int128 *)(bskey + (i-1) * 128 + 0);\
|
||||
t1 = *(int128 *)(bskey + (i-1) * 128 + 16);\
|
||||
t2 = *(int128 *)(bskey + (i-1) * 128 + 32);\
|
||||
t3 = *(int128 *)(bskey + (i-1) * 128 + 48);\
|
||||
t4 = *(int128 *)(bskey + (i-1) * 128 + 64);\
|
||||
t5 = *(int128 *)(bskey + (i-1) * 128 + 80);\
|
||||
t6 = *(int128 *)(bskey + (i-1) * 128 + 96);\
|
||||
t7 = *(int128 *)(bskey + (i-1) * 128 + 112);\
|
||||
t0 = *(aes_uint128_t *)(bskey + (i-1) * 128 + 0);\
|
||||
t1 = *(aes_uint128_t *)(bskey + (i-1) * 128 + 16);\
|
||||
t2 = *(aes_uint128_t *)(bskey + (i-1) * 128 + 32);\
|
||||
t3 = *(aes_uint128_t *)(bskey + (i-1) * 128 + 48);\
|
||||
t4 = *(aes_uint128_t *)(bskey + (i-1) * 128 + 64);\
|
||||
t5 = *(aes_uint128_t *)(bskey + (i-1) * 128 + 80);\
|
||||
t6 = *(aes_uint128_t *)(bskey + (i-1) * 128 + 96);\
|
||||
t7 = *(aes_uint128_t *)(bskey + (i-1) * 128 + 112);\
|
||||
;\
|
||||
toggle(&t0);\
|
||||
toggle(&t1);\
|
||||
@@ -341,19 +341,19 @@
|
||||
xor2(&b2, &t6);\
|
||||
xor2(&b5, &t7);\
|
||||
;\
|
||||
*(int128 *)(bskey + i*128 + 0) = b0;\
|
||||
*(int128 *)(bskey + i*128 + 16) = b1;\
|
||||
*(int128 *)(bskey + i*128 + 32) = b4;\
|
||||
*(int128 *)(bskey + i*128 + 48) = b6;\
|
||||
*(int128 *)(bskey + i*128 + 64) = b3;\
|
||||
*(int128 *)(bskey + i*128 + 80) = b7;\
|
||||
*(int128 *)(bskey + i*128 + 96) = b2;\
|
||||
*(int128 *)(bskey + i*128 + 112) = b5;\
|
||||
*(aes_uint128_t *)(bskey + i*128 + 0) = b0;\
|
||||
*(aes_uint128_t *)(bskey + i*128 + 16) = b1;\
|
||||
*(aes_uint128_t *)(bskey + i*128 + 32) = b4;\
|
||||
*(aes_uint128_t *)(bskey + i*128 + 48) = b6;\
|
||||
*(aes_uint128_t *)(bskey + i*128 + 64) = b3;\
|
||||
*(aes_uint128_t *)(bskey + i*128 + 80) = b7;\
|
||||
*(aes_uint128_t *)(bskey + i*128 + 96) = b2;\
|
||||
*(aes_uint128_t *)(bskey + i*128 + 112) = b5;\
|
||||
|
||||
/* Macros used in multiple contexts */
|
||||
|
||||
#define bitslicekey0(key, bskey) \
|
||||
xmm0 = *(const int128 *) (key + 0);\
|
||||
xmm0 = *(const aes_uint128_t *) (key + 0);\
|
||||
shufb(&xmm0, M0);\
|
||||
copy2(&xmm1, &xmm0);\
|
||||
copy2(&xmm2, &xmm0);\
|
||||
@@ -365,18 +365,18 @@
|
||||
;\
|
||||
bitslice(xmm7, xmm6, xmm5, xmm4, xmm3, xmm2, xmm1, xmm0, t);\
|
||||
;\
|
||||
*(int128 *) (bskey + 0) = xmm0;\
|
||||
*(int128 *) (bskey + 16) = xmm1;\
|
||||
*(int128 *) (bskey + 32) = xmm2;\
|
||||
*(int128 *) (bskey + 48) = xmm3;\
|
||||
*(int128 *) (bskey + 64) = xmm4;\
|
||||
*(int128 *) (bskey + 80) = xmm5;\
|
||||
*(int128 *) (bskey + 96) = xmm6;\
|
||||
*(int128 *) (bskey + 112) = xmm7;\
|
||||
*(aes_uint128_t *) (bskey + 0) = xmm0;\
|
||||
*(aes_uint128_t *) (bskey + 16) = xmm1;\
|
||||
*(aes_uint128_t *) (bskey + 32) = xmm2;\
|
||||
*(aes_uint128_t *) (bskey + 48) = xmm3;\
|
||||
*(aes_uint128_t *) (bskey + 64) = xmm4;\
|
||||
*(aes_uint128_t *) (bskey + 80) = xmm5;\
|
||||
*(aes_uint128_t *) (bskey + 96) = xmm6;\
|
||||
*(aes_uint128_t *) (bskey + 112) = xmm7;\
|
||||
|
||||
|
||||
#define bitslicekey10(key, bskey) \
|
||||
xmm0 = *(int128 *) (key + 0);\
|
||||
xmm0 = *(aes_uint128_t *) (key + 0);\
|
||||
copy2(xmm1, xmm0);\
|
||||
copy2(xmm2, xmm0);\
|
||||
copy2(xmm3, xmm0);\
|
||||
@@ -392,18 +392,18 @@
|
||||
toggle(&xmm1);\
|
||||
toggle(&xmm0);\
|
||||
;\
|
||||
*(int128 *) (bskey + 0 + 1280) = xmm0;\
|
||||
*(int128 *) (bskey + 16 + 1280) = xmm1;\
|
||||
*(int128 *) (bskey + 32 + 1280) = xmm2;\
|
||||
*(int128 *) (bskey + 48 + 1280) = xmm3;\
|
||||
*(int128 *) (bskey + 64 + 1280) = xmm4;\
|
||||
*(int128 *) (bskey + 80 + 1280) = xmm5;\
|
||||
*(int128 *) (bskey + 96 + 1280) = xmm6;\
|
||||
*(int128 *) (bskey + 112 + 1280) = xmm7;\
|
||||
*(aes_uint128_t *) (bskey + 0 + 1280) = xmm0;\
|
||||
*(aes_uint128_t *) (bskey + 16 + 1280) = xmm1;\
|
||||
*(aes_uint128_t *) (bskey + 32 + 1280) = xmm2;\
|
||||
*(aes_uint128_t *) (bskey + 48 + 1280) = xmm3;\
|
||||
*(aes_uint128_t *) (bskey + 64 + 1280) = xmm4;\
|
||||
*(aes_uint128_t *) (bskey + 80 + 1280) = xmm5;\
|
||||
*(aes_uint128_t *) (bskey + 96 + 1280) = xmm6;\
|
||||
*(aes_uint128_t *) (bskey + 112 + 1280) = xmm7;\
|
||||
|
||||
|
||||
#define bitslicekey(i,key,bskey) \
|
||||
xmm0 = *(int128 *) (key + 0);\
|
||||
xmm0 = *(aes_uint128_t *) (key + 0);\
|
||||
shufb(&xmm0, M0);\
|
||||
copy2(&xmm1, &xmm0);\
|
||||
copy2(&xmm2, &xmm0);\
|
||||
@@ -420,14 +420,14 @@
|
||||
toggle(&xmm1);\
|
||||
toggle(&xmm0);\
|
||||
;\
|
||||
*(int128 *) (bskey + 0 + 128*i) = xmm0;\
|
||||
*(int128 *) (bskey + 16 + 128*i) = xmm1;\
|
||||
*(int128 *) (bskey + 32 + 128*i) = xmm2;\
|
||||
*(int128 *) (bskey + 48 + 128*i) = xmm3;\
|
||||
*(int128 *) (bskey + 64 + 128*i) = xmm4;\
|
||||
*(int128 *) (bskey + 80 + 128*i) = xmm5;\
|
||||
*(int128 *) (bskey + 96 + 128*i) = xmm6;\
|
||||
*(int128 *) (bskey + 112 + 128*i) = xmm7;\
|
||||
*(aes_uint128_t *) (bskey + 0 + 128*i) = xmm0;\
|
||||
*(aes_uint128_t *) (bskey + 16 + 128*i) = xmm1;\
|
||||
*(aes_uint128_t *) (bskey + 32 + 128*i) = xmm2;\
|
||||
*(aes_uint128_t *) (bskey + 48 + 128*i) = xmm3;\
|
||||
*(aes_uint128_t *) (bskey + 64 + 128*i) = xmm4;\
|
||||
*(aes_uint128_t *) (bskey + 80 + 128*i) = xmm5;\
|
||||
*(aes_uint128_t *) (bskey + 96 + 128*i) = xmm6;\
|
||||
*(aes_uint128_t *) (bskey + 112 + 128*i) = xmm7;\
|
||||
|
||||
|
||||
#define bitslice(x0, x1, x2, x3, x4, x5, x6, x7, t) \
|
||||
@@ -463,21 +463,21 @@
|
||||
/* Macros used for encryption (and decryption) */
|
||||
|
||||
#define shiftrows(x0, x1, x2, x3, x4, x5, x6, x7, i, M, bskey) \
|
||||
xor2(&x0, (const int128 *)(bskey + 128*(i-1) + 0));\
|
||||
xor2(&x0, (const aes_uint128_t *)(bskey + 128*(i-1) + 0));\
|
||||
shufb(&x0, M);\
|
||||
xor2(&x1, (const int128 *)(bskey + 128*(i-1) + 16));\
|
||||
xor2(&x1, (const aes_uint128_t *)(bskey + 128*(i-1) + 16));\
|
||||
shufb(&x1, M);\
|
||||
xor2(&x2, (const int128 *)(bskey + 128*(i-1) + 32));\
|
||||
xor2(&x2, (const aes_uint128_t *)(bskey + 128*(i-1) + 32));\
|
||||
shufb(&x2, M);\
|
||||
xor2(&x3, (const int128 *)(bskey + 128*(i-1) + 48));\
|
||||
xor2(&x3, (const aes_uint128_t *)(bskey + 128*(i-1) + 48));\
|
||||
shufb(&x3, M);\
|
||||
xor2(&x4, (const int128 *)(bskey + 128*(i-1) + 64));\
|
||||
xor2(&x4, (const aes_uint128_t *)(bskey + 128*(i-1) + 64));\
|
||||
shufb(&x4, M);\
|
||||
xor2(&x5, (const int128 *)(bskey + 128*(i-1) + 80));\
|
||||
xor2(&x5, (const aes_uint128_t *)(bskey + 128*(i-1) + 80));\
|
||||
shufb(&x5, M);\
|
||||
xor2(&x6, (const int128 *)(bskey + 128*(i-1) + 96));\
|
||||
xor2(&x6, (const aes_uint128_t *)(bskey + 128*(i-1) + 96));\
|
||||
shufb(&x6, M);\
|
||||
xor2(&x7, (const int128 *)(bskey + 128*(i-1) + 112));\
|
||||
xor2(&x7, (const aes_uint128_t *)(bskey + 128*(i-1) + 112));\
|
||||
shufb(&x7, M);\
|
||||
|
||||
|
||||
@@ -540,14 +540,14 @@
|
||||
#define lastround(b0, b1, b2, b3, b4, b5, b6, b7, t0, t1, t2, t3, t4, t5, t6, t7, bskey) \
|
||||
shiftrows(b0, b1, b2, b3, b4, b5, b6, b7, 10, SRM0, bskey);\
|
||||
sbox(b0, b1, b2, b3, b4, b5, b6, b7, t0, t1, t2, t3, t4, t5, t6, t7);\
|
||||
xor2(&b0,(const int128 *)(bskey + 128*10));\
|
||||
xor2(&b1,(const int128 *)(bskey + 128*10+16));\
|
||||
xor2(&b4,(const int128 *)(bskey + 128*10+32));\
|
||||
xor2(&b6,(const int128 *)(bskey + 128*10+48));\
|
||||
xor2(&b3,(const int128 *)(bskey + 128*10+64));\
|
||||
xor2(&b7,(const int128 *)(bskey + 128*10+80));\
|
||||
xor2(&b2,(const int128 *)(bskey + 128*10+96));\
|
||||
xor2(&b5,(const int128 *)(bskey + 128*10+112));\
|
||||
xor2(&b0,(const aes_uint128_t *)(bskey + 128*10));\
|
||||
xor2(&b1,(const aes_uint128_t *)(bskey + 128*10+16));\
|
||||
xor2(&b4,(const aes_uint128_t *)(bskey + 128*10+32));\
|
||||
xor2(&b6,(const aes_uint128_t *)(bskey + 128*10+48));\
|
||||
xor2(&b3,(const aes_uint128_t *)(bskey + 128*10+64));\
|
||||
xor2(&b7,(const aes_uint128_t *)(bskey + 128*10+80));\
|
||||
xor2(&b2,(const aes_uint128_t *)(bskey + 128*10+96));\
|
||||
xor2(&b5,(const aes_uint128_t *)(bskey + 128*10+112));\
|
||||
|
||||
|
||||
#define sbox(b0, b1, b2, b3, b4, b5, b6, b7, t0, t1, t2, t3, s0, s1, s2, s3) \
|
||||
|
||||
@@ -21,8 +21,8 @@ extern const unsigned char SWAP32[16];
|
||||
extern const unsigned char M0SWAP[16];
|
||||
extern const unsigned char SR[16];
|
||||
extern const unsigned char SRM0[16];
|
||||
extern const int128 BS0;
|
||||
extern const int128 BS1;
|
||||
extern const int128 BS2;
|
||||
extern const aes_uint128_t BS0;
|
||||
extern const aes_uint128_t BS1;
|
||||
extern const aes_uint128_t BS2;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -9,6 +9,6 @@ const unsigned char M0SWAP[16] = {0x0c, 0x08, 0x04, 0x00, 0x0d, 0x09, 0x05, 0x01
|
||||
const unsigned char SR[16] = {0x01, 0x02, 0x03, 0x00, 0x06, 0x07, 0x04, 0x05, 0x0b, 0x08, 0x09, 0x0a, 0x0c, 0x0d, 0x0e, 0x0f};
|
||||
const unsigned char SRM0[16] = {0x0f, 0x0a, 0x05, 0x00, 0x0e, 0x09, 0x04, 0x03, 0x0d, 0x08, 0x07, 0x02, 0x0c, 0x0b, 0x06, 0x01};
|
||||
|
||||
const int128 BS0 = {{0x5555555555555555ULL, 0x5555555555555555ULL}};
|
||||
const int128 BS1 = {{0x3333333333333333ULL, 0x3333333333333333ULL}};
|
||||
const int128 BS2 = {{0x0f0f0f0f0f0f0f0fULL, 0x0f0f0f0f0f0f0f0fULL}};
|
||||
const aes_uint128_t BS0 = {{0x5555555555555555ULL, 0x5555555555555555ULL}};
|
||||
const aes_uint128_t BS1 = {{0x3333333333333333ULL, 0x3333333333333333ULL}};
|
||||
const aes_uint128_t BS2 = {{0x0f0f0f0f0f0f0f0fULL, 0x0f0f0f0f0f0f0f0fULL}};
|
||||
|
||||
@@ -15,42 +15,42 @@ typedef union {
|
||||
uint64_t u64[2];
|
||||
uint32_t u32[4];
|
||||
uint8_t u8[16];
|
||||
} int128;
|
||||
} aes_uint128_t;
|
||||
|
||||
#define xor2 crypto_stream_aes128ctr_portable_xor2
|
||||
void xor2(int128 *r, const int128 *x);
|
||||
void xor2(aes_uint128_t *r, const aes_uint128_t *x);
|
||||
|
||||
#define and2 crypto_stream_aes128ctr_portable_and2
|
||||
void and2(int128 *r, const int128 *x);
|
||||
void and2(aes_uint128_t *r, const aes_uint128_t *x);
|
||||
|
||||
#define or2 crypto_stream_aes128ctr_portable_or2
|
||||
void or2(int128 *r, const int128 *x);
|
||||
void or2(aes_uint128_t *r, const aes_uint128_t *x);
|
||||
|
||||
#define copy2 crypto_stream_aes128ctr_portable_copy2
|
||||
void copy2(int128 *r, const int128 *x);
|
||||
void copy2(aes_uint128_t *r, const aes_uint128_t *x);
|
||||
|
||||
#define shufb crypto_stream_aes128ctr_portable_shufb
|
||||
void shufb(int128 *r, const unsigned char *l);
|
||||
void shufb(aes_uint128_t *r, const unsigned char *l);
|
||||
|
||||
#define shufd crypto_stream_aes128ctr_portable_shufd
|
||||
void shufd(int128 *r, const int128 *x, const unsigned int c);
|
||||
void shufd(aes_uint128_t *r, const aes_uint128_t *x, const unsigned int c);
|
||||
|
||||
#define rshift32_littleendian crypto_stream_aes128ctr_portable_rshift32_littleendian
|
||||
void rshift32_littleendian(int128 *r, const unsigned int n);
|
||||
void rshift32_littleendian(aes_uint128_t *r, const unsigned int n);
|
||||
|
||||
#define rshift64_littleendian crypto_stream_aes128ctr_portable_rshift64_littleendian
|
||||
void rshift64_littleendian(int128 *r, const unsigned int n);
|
||||
void rshift64_littleendian(aes_uint128_t *r, const unsigned int n);
|
||||
|
||||
#define lshift64_littleendian crypto_stream_aes128ctr_portable_lshift64_littleendian
|
||||
void lshift64_littleendian(int128 *r, const unsigned int n);
|
||||
void lshift64_littleendian(aes_uint128_t *r, const unsigned int n);
|
||||
|
||||
#define toggle crypto_stream_aes128ctr_portable_toggle
|
||||
void toggle(int128 *r);
|
||||
void toggle(aes_uint128_t *r);
|
||||
|
||||
#define xor_rcon crypto_stream_aes128ctr_portable_xor_rcon
|
||||
void xor_rcon(int128 *r);
|
||||
void xor_rcon(aes_uint128_t *r);
|
||||
|
||||
#define add_uint32_big crypto_stream_aes128ctr_portable_add_uint32_big
|
||||
void add_uint32_big(int128 *r, uint32_t x);
|
||||
void add_uint32_big(aes_uint128_t *r, uint32_t x);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,33 +2,33 @@
|
||||
#include "int128.h"
|
||||
#include "common.h"
|
||||
|
||||
void xor2(int128 *r, const int128 *x)
|
||||
void xor2(aes_uint128_t *r, const aes_uint128_t *x)
|
||||
{
|
||||
r->u64[0] ^= x->u64[0];
|
||||
r->u64[1] ^= x->u64[1];
|
||||
}
|
||||
|
||||
void and2(int128 *r, const int128 *x)
|
||||
void and2(aes_uint128_t *r, const aes_uint128_t *x)
|
||||
{
|
||||
r->u64[0] &= x->u64[0];
|
||||
r->u64[1] &= x->u64[1];
|
||||
}
|
||||
|
||||
void or2(int128 *r, const int128 *x)
|
||||
void or2(aes_uint128_t *r, const aes_uint128_t *x)
|
||||
{
|
||||
r->u64[0] |= x->u64[0];
|
||||
r->u64[1] |= x->u64[1];
|
||||
}
|
||||
|
||||
void copy2(int128 *r, const int128 *x)
|
||||
void copy2(aes_uint128_t *r, const aes_uint128_t *x)
|
||||
{
|
||||
r->u64[0] = x->u64[0];
|
||||
r->u64[1] = x->u64[1];
|
||||
}
|
||||
|
||||
void shufb(int128 *r, const unsigned char *l)
|
||||
void shufb(aes_uint128_t *r, const unsigned char *l)
|
||||
{
|
||||
int128 t;
|
||||
aes_uint128_t t;
|
||||
uint8_t *ct;
|
||||
uint8_t *cr;
|
||||
|
||||
@@ -53,9 +53,9 @@ void shufb(int128 *r, const unsigned char *l)
|
||||
cr[15] = ct[l[15]];
|
||||
}
|
||||
|
||||
void shufd(int128 *r, const int128 *x, const unsigned int c)
|
||||
void shufd(aes_uint128_t *r, const aes_uint128_t *x, const unsigned int c)
|
||||
{
|
||||
int128 t;
|
||||
aes_uint128_t t;
|
||||
|
||||
t.u32[0] = x->u32[c >> 0 & 3];
|
||||
t.u32[1] = x->u32[c >> 2 & 3];
|
||||
@@ -64,7 +64,7 @@ void shufd(int128 *r, const int128 *x, const unsigned int c)
|
||||
copy2(r, &t);
|
||||
}
|
||||
|
||||
void rshift32_littleendian(int128 *r, const unsigned int n)
|
||||
void rshift32_littleendian(aes_uint128_t *r, const unsigned int n)
|
||||
{
|
||||
unsigned char *rp = (unsigned char *)r;
|
||||
uint32_t t;
|
||||
@@ -82,7 +82,7 @@ void rshift32_littleendian(int128 *r, const unsigned int n)
|
||||
STORE32_LE(rp+12, t);
|
||||
}
|
||||
|
||||
void rshift64_littleendian(int128 *r, const unsigned int n)
|
||||
void rshift64_littleendian(aes_uint128_t *r, const unsigned int n)
|
||||
{
|
||||
unsigned char *rp = (unsigned char *)r;
|
||||
uint64 t;
|
||||
@@ -94,7 +94,7 @@ void rshift64_littleendian(int128 *r, const unsigned int n)
|
||||
STORE64_LE(rp+8, t);
|
||||
}
|
||||
|
||||
void lshift64_littleendian(int128 *r, const unsigned int n)
|
||||
void lshift64_littleendian(aes_uint128_t *r, const unsigned int n)
|
||||
{
|
||||
unsigned char *rp = (unsigned char *)r;
|
||||
uint64 t;
|
||||
@@ -106,13 +106,13 @@ void lshift64_littleendian(int128 *r, const unsigned int n)
|
||||
STORE64_LE(rp+8, t);
|
||||
}
|
||||
|
||||
void toggle(int128 *r)
|
||||
void toggle(aes_uint128_t *r)
|
||||
{
|
||||
r->u64[0] ^= 0xffffffffffffffffULL;
|
||||
r->u64[1] ^= 0xffffffffffffffffULL;
|
||||
}
|
||||
|
||||
void xor_rcon(int128 *r)
|
||||
void xor_rcon(aes_uint128_t *r)
|
||||
{
|
||||
unsigned char *rp = (unsigned char *)r;
|
||||
uint32_t t;
|
||||
@@ -121,7 +121,7 @@ void xor_rcon(int128 *r)
|
||||
STORE32_LE(rp+12, t);
|
||||
}
|
||||
|
||||
void add_uint32_big(int128 *r, uint32_t x)
|
||||
void add_uint32_big(aes_uint128_t *r, uint32_t x)
|
||||
{
|
||||
unsigned char *rp = (unsigned char *)r;
|
||||
uint32_t t;
|
||||
|
||||
@@ -10,25 +10,25 @@
|
||||
int crypto_stream_aes128ctr_xor_afternm(unsigned char *out, const unsigned char *in, unsigned long long len, const unsigned char *nonce, const unsigned char *c)
|
||||
{
|
||||
|
||||
int128 xmm0;
|
||||
int128 xmm1;
|
||||
int128 xmm2;
|
||||
int128 xmm3;
|
||||
int128 xmm4;
|
||||
int128 xmm5;
|
||||
int128 xmm6;
|
||||
int128 xmm7;
|
||||
aes_uint128_t xmm0;
|
||||
aes_uint128_t xmm1;
|
||||
aes_uint128_t xmm2;
|
||||
aes_uint128_t xmm3;
|
||||
aes_uint128_t xmm4;
|
||||
aes_uint128_t xmm5;
|
||||
aes_uint128_t xmm6;
|
||||
aes_uint128_t xmm7;
|
||||
|
||||
int128 xmm8;
|
||||
int128 xmm9;
|
||||
int128 xmm10;
|
||||
int128 xmm11;
|
||||
int128 xmm12;
|
||||
int128 xmm13;
|
||||
int128 xmm14;
|
||||
int128 xmm15;
|
||||
aes_uint128_t xmm8;
|
||||
aes_uint128_t xmm9;
|
||||
aes_uint128_t xmm10;
|
||||
aes_uint128_t xmm11;
|
||||
aes_uint128_t xmm12;
|
||||
aes_uint128_t xmm13;
|
||||
aes_uint128_t xmm14;
|
||||
aes_uint128_t xmm15;
|
||||
|
||||
int128 nonce_stack;
|
||||
aes_uint128_t nonce_stack;
|
||||
unsigned long long lensav;
|
||||
unsigned char bl[128];
|
||||
unsigned char *blp;
|
||||
@@ -38,12 +38,12 @@ int crypto_stream_aes128ctr_xor_afternm(unsigned char *out, const unsigned char
|
||||
uint32_t tmp;
|
||||
|
||||
/* Copy nonce on the stack */
|
||||
copy2(&nonce_stack, (const int128 *) (nonce + 0));
|
||||
copy2(&nonce_stack, (const aes_uint128_t *) (nonce + 0));
|
||||
np = (unsigned char *)&nonce_stack;
|
||||
|
||||
enc_block:
|
||||
|
||||
xmm0 = *(int128 *) (np + 0);
|
||||
xmm0 = *(aes_uint128_t *) (np + 0);
|
||||
copy2(&xmm1, &xmm0);
|
||||
shufb(&xmm1, SWAP32);
|
||||
copy2(&xmm2, &xmm1);
|
||||
@@ -92,23 +92,23 @@ int crypto_stream_aes128ctr_xor_afternm(unsigned char *out, const unsigned char
|
||||
tmp += 8;
|
||||
STORE32_BE(np + 12, tmp);
|
||||
|
||||
xor2(&xmm8, (const int128 *)(in + 0));
|
||||
xor2(&xmm9, (const int128 *)(in + 16));
|
||||
xor2(&xmm12, (const int128 *)(in + 32));
|
||||
xor2(&xmm14, (const int128 *)(in + 48));
|
||||
xor2(&xmm11, (const int128 *)(in + 64));
|
||||
xor2(&xmm15, (const int128 *)(in + 80));
|
||||
xor2(&xmm10, (const int128 *)(in + 96));
|
||||
xor2(&xmm13, (const int128 *)(in + 112));
|
||||
xor2(&xmm8, (const aes_uint128_t *)(in + 0));
|
||||
xor2(&xmm9, (const aes_uint128_t *)(in + 16));
|
||||
xor2(&xmm12, (const aes_uint128_t *)(in + 32));
|
||||
xor2(&xmm14, (const aes_uint128_t *)(in + 48));
|
||||
xor2(&xmm11, (const aes_uint128_t *)(in + 64));
|
||||
xor2(&xmm15, (const aes_uint128_t *)(in + 80));
|
||||
xor2(&xmm10, (const aes_uint128_t *)(in + 96));
|
||||
xor2(&xmm13, (const aes_uint128_t *)(in + 112));
|
||||
|
||||
*(int128 *) (out + 0) = xmm8;
|
||||
*(int128 *) (out + 16) = xmm9;
|
||||
*(int128 *) (out + 32) = xmm12;
|
||||
*(int128 *) (out + 48) = xmm14;
|
||||
*(int128 *) (out + 64) = xmm11;
|
||||
*(int128 *) (out + 80) = xmm15;
|
||||
*(int128 *) (out + 96) = xmm10;
|
||||
*(int128 *) (out + 112) = xmm13;
|
||||
*(aes_uint128_t *) (out + 0) = xmm8;
|
||||
*(aes_uint128_t *) (out + 16) = xmm9;
|
||||
*(aes_uint128_t *) (out + 32) = xmm12;
|
||||
*(aes_uint128_t *) (out + 48) = xmm14;
|
||||
*(aes_uint128_t *) (out + 64) = xmm11;
|
||||
*(aes_uint128_t *) (out + 80) = xmm15;
|
||||
*(aes_uint128_t *) (out + 96) = xmm10;
|
||||
*(aes_uint128_t *) (out + 112) = xmm13;
|
||||
|
||||
len -= 128;
|
||||
in += 128;
|
||||
@@ -126,14 +126,14 @@ int crypto_stream_aes128ctr_xor_afternm(unsigned char *out, const unsigned char
|
||||
STORE32_BE(np + 12, tmp);
|
||||
|
||||
blp = bl;
|
||||
*(int128 *)(blp + 0) = xmm8;
|
||||
*(int128 *)(blp + 16) = xmm9;
|
||||
*(int128 *)(blp + 32) = xmm12;
|
||||
*(int128 *)(blp + 48) = xmm14;
|
||||
*(int128 *)(blp + 64) = xmm11;
|
||||
*(int128 *)(blp + 80) = xmm15;
|
||||
*(int128 *)(blp + 96) = xmm10;
|
||||
*(int128 *)(blp + 112) = xmm13;
|
||||
*(aes_uint128_t *)(blp + 0) = xmm8;
|
||||
*(aes_uint128_t *)(blp + 16) = xmm9;
|
||||
*(aes_uint128_t *)(blp + 32) = xmm12;
|
||||
*(aes_uint128_t *)(blp + 48) = xmm14;
|
||||
*(aes_uint128_t *)(blp + 64) = xmm11;
|
||||
*(aes_uint128_t *)(blp + 80) = xmm15;
|
||||
*(aes_uint128_t *)(blp + 96) = xmm10;
|
||||
*(aes_uint128_t *)(blp + 112) = xmm13;
|
||||
|
||||
bytes:
|
||||
|
||||
@@ -156,23 +156,23 @@ int crypto_stream_aes128ctr_xor_afternm(unsigned char *out, const unsigned char
|
||||
tmp += 8;
|
||||
STORE32_BE(np + 12, tmp);
|
||||
|
||||
xor2(&xmm8, (const int128 *)(in + 0));
|
||||
xor2(&xmm9, (const int128 *)(in + 16));
|
||||
xor2(&xmm12, (const int128 *)(in + 32));
|
||||
xor2(&xmm14, (const int128 *)(in + 48));
|
||||
xor2(&xmm11, (const int128 *)(in + 64));
|
||||
xor2(&xmm15, (const int128 *)(in + 80));
|
||||
xor2(&xmm10, (const int128 *)(in + 96));
|
||||
xor2(&xmm13, (const int128 *)(in + 112));
|
||||
xor2(&xmm8, (const aes_uint128_t *)(in + 0));
|
||||
xor2(&xmm9, (const aes_uint128_t *)(in + 16));
|
||||
xor2(&xmm12, (const aes_uint128_t *)(in + 32));
|
||||
xor2(&xmm14, (const aes_uint128_t *)(in + 48));
|
||||
xor2(&xmm11, (const aes_uint128_t *)(in + 64));
|
||||
xor2(&xmm15, (const aes_uint128_t *)(in + 80));
|
||||
xor2(&xmm10, (const aes_uint128_t *)(in + 96));
|
||||
xor2(&xmm13, (const aes_uint128_t *)(in + 112));
|
||||
|
||||
*(int128 *) (out + 0) = xmm8;
|
||||
*(int128 *) (out + 16) = xmm9;
|
||||
*(int128 *) (out + 32) = xmm12;
|
||||
*(int128 *) (out + 48) = xmm14;
|
||||
*(int128 *) (out + 64) = xmm11;
|
||||
*(int128 *) (out + 80) = xmm15;
|
||||
*(int128 *) (out + 96) = xmm10;
|
||||
*(int128 *) (out + 112) = xmm13;
|
||||
*(aes_uint128_t *) (out + 0) = xmm8;
|
||||
*(aes_uint128_t *) (out + 16) = xmm9;
|
||||
*(aes_uint128_t *) (out + 32) = xmm12;
|
||||
*(aes_uint128_t *) (out + 48) = xmm14;
|
||||
*(aes_uint128_t *) (out + 64) = xmm11;
|
||||
*(aes_uint128_t *) (out + 80) = xmm15;
|
||||
*(aes_uint128_t *) (out + 96) = xmm10;
|
||||
*(aes_uint128_t *) (out + 112) = xmm13;
|
||||
|
||||
end:
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user