u512 rc0[10] = {0};\r
u512 MIX_4;\r
void load_constants() {\r
- MIX_4 = _mm512_set_epi32(3,11,7,15,8,0,12,4,9,1,13,5,2,10,6,14);\r
-\r
- rc[0] = _mm512_set_epi32(0x0684704c,0xe620c00a,0xb2c5fef0,0x75817b9d,0x8b66b4e1,0x88f3a06b,0x640f6ba4,0x2f08f717,0x3402de2d,0x53f28498,0xcf029d60,0x9f029114,0x0ed6eae6,0x2e7b4f08,0xbbf3bcaf,0xfd5b4f79);\r
- rc[1] = _mm512_set_epi32(0xcbcfb0cb,0x4872448b,0x79eecd1c,0xbe397044,0x7eeacdee,0x6e9032b7,0x8d5335ed,0x2b8a057b,0x67c28f43,0x5e2e7cd0,0xe2412761,0xda4fef1b,0x2924d9b0,0xafcacc07,0x675ffde2,0x1fc70b3b);\r
- rc[2] = _mm512_set_epi32(0xab4d63f1,0xe6867fe9,0xecdb8fca,0xb9d465ee,0x1c30bf84,0xd4b7cd64,0x5b2a404f,0xad037e33,0xb2cc0bb9,0x941723bf,0x69028b2e,0x8df69800,0xfa0478a6,0xde6f5572,0x4aaa9ec8,0x5c9d2d8a);\r
- rc[3] = _mm512_set_epi32(0xdfb49f2b,0x6b772a12,0x0efa4f2e,0x29129fd4,0x1ea10344,0xf449a236,0x32d611ae,0xbb6a12ee,0xaf044988,0x4b050084,0x5f9600c9,0x9ca8eca6,0x21025ed8,0x9d199c4f,0x78a2c7e3,0x27e593ec);\r
- rc[4] = _mm512_set_epi32(0xbf3aaaf8,0xa759c9b7,0xb9282ecd,0x82d40173,0x6260700d,0x6186b017,0x37f2efd9,0x10307d6b,0x5aca45c2,0x21300443,0x81c29153,0xf6fc9ac6,0x9223973c,0x226b68bb,0x2caf92e8,0x36d1943a);\r
- rc[5] = _mm512_set_epi32(0xd3bf9238,0x225886eb,0x6cbab958,0xe51071b4,0xdb863ce5,0xaef0c677,0x933dfddd,0x24e1128d,0xbb606268,0xffeba09c,0x83e48de3,0xcb2212b1,0x734bd3dc,0xe2e4d19c,0x2db91a4e,0xc72bf77d);\r
- rc[6] = _mm512_set_epi32(0x43bb47c3,0x61301b43,0x4b1415c4,0x2cb3924e,0xdba775a8,0xe707eff6,0x03b231dd,0x16eb6899,0x6df3614b,0x3c755977,0x8e5e2302,0x7eca472c,0xcda75a17,0xd6de7d77,0x6d1be5b9,0xb88617f9);\r
- rc[7] = _mm512_set_epi32(0xec6b43f0,0x6ba8e9aa,0x9d6c069d,0xa946ee5d,0xcb1e6950,0xf957332b,0xa2531159,0x3bf327c1,0x2cee0c75,0x00da619c,0xe4ed0353,0x600ed0d9,0xf0b1a5a1,0x96e90cab,0x80bbbabc,0x63a4a350);\r
- rc[8] = _mm512_set_epi32(0xae3db102,0x5e962988,0xab0dde30,0x938dca39,0x17bb8f38,0xd554a40b,0x8814f3a8,0x2e75b442,0x34bb8a5b,0x5f427fd7,0xaeb6b779,0x360a16f6,0x26f65241,0xcbe55438,0x43ce5918,0xffbaafde);\r
- rc[9] = _mm512_set_epi32(0x4ce99a54,0xb9f3026a,0xa2ca9cf7,0x839ec978,0xae51a51a,0x1bdff7be,0x40c06e28,0x22901235,0xa0c1613c,0xba7ed22b,0xc173bc0f,0x48a659cf,0x756acc03,0x02288288,0x4ad6bdfd,0xe9c59da1);\r
-}\r
-\r
-void test_implementations() {\r
- unsigned char *in = (unsigned char *)calloc(64*8, sizeof(unsigned char));\r
- unsigned char *out256 = (unsigned char *)calloc(32*8, sizeof(unsigned char));\r
- unsigned char *out512 = (unsigned char *)calloc(32*8, sizeof(unsigned char));\r
- unsigned char testvector256[32] = {0x80, 0x27, 0xcc, 0xb8, 0x79, 0x49, 0x77, 0x4b,\r
+ //MIX_4 = _mm512_set_epi32(3,11,7,15,8,0,12,4,9,1,13,5,2,10,6,14); stupid thing goes the wrong way\r
+ MIX_4 = _mm512_set_epi32(14,6,10,2,5,13,1,9,4,12,0,8,15,7,11,3);\r
+\r
+ rc[0] = _mm512_set_epi32(0x0ed6eae6,0x2e7b4f08,0xbbf3bcaf,0xfd5b4f79,0x3402de2d,0x53f28498,0xcf029d60,0x9f029114,0x8b66b4e1,0x88f3a06b,0x640f6ba4,0x2f08f717,0x0684704c,0xe620c00a,0xb2c5fef0,0x75817b9d);\r
+ rc[1] = _mm512_set_epi32(0x2924d9b0,0xafcacc07,0x675ffde2,0x1fc70b3b,0x67c28f43,0x5e2e7cd0,0xe2412761,0xda4fef1b,0x7eeacdee,0x6e9032b7,0x8d5335ed,0x2b8a057b,0xcbcfb0cb,0x4872448b,0x79eecd1c,0xbe397044);\r
+ rc[2] = _mm512_set_epi32(0xfa0478a6,0xde6f5572,0x4aaa9ec8,0x5c9d2d8a,0xb2cc0bb9,0x941723bf,0x69028b2e,0x8df69800,0x1c30bf84,0xd4b7cd64,0x5b2a404f,0xad037e33,0xab4d63f1,0xe6867fe9,0xecdb8fca,0xb9d465ee);\r
+ rc[3] = _mm512_set_epi32(0x21025ed8,0x9d199c4f,0x78a2c7e3,0x27e593ec,0xaf044988,0x4b050084,0x5f9600c9,0x9ca8eca6,0x1ea10344,0xf449a236,0x32d611ae,0xbb6a12ee,0xdfb49f2b,0x6b772a12,0x0efa4f2e,0x29129fd4);\r
+ rc[4] = _mm512_set_epi32(0x9223973c,0x226b68bb,0x2caf92e8,0x36d1943a,0x5aca45c2,0x21300443,0x81c29153,0xf6fc9ac6,0x6260700d,0x6186b017,0x37f2efd9,0x10307d6b,0xbf3aaaf8,0xa759c9b7,0xb9282ecd,0x82d40173);\r
+ rc[5] = _mm512_set_epi32(0x734bd3dc,0xe2e4d19c,0x2db91a4e,0xc72bf77d,0xbb606268,0xffeba09c,0x83e48de3,0xcb2212b1,0xdb863ce5,0xaef0c677,0x933dfddd,0x24e1128d,0xd3bf9238,0x225886eb,0x6cbab958,0xe51071b4);\r
+ rc[6] = _mm512_set_epi32(0xcda75a17,0xd6de7d77,0x6d1be5b9,0xb88617f9,0x6df3614b,0x3c755977,0x8e5e2302,0x7eca472c,0xdba775a8,0xe707eff6,0x03b231dd,0x16eb6899,0x43bb47c3,0x61301b43,0x4b1415c4,0x2cb3924e);\r
+ rc[7] = _mm512_set_epi32(0xf0b1a5a1,0x96e90cab,0x80bbbabc,0x63a4a350,0x2cee0c75,0x00da619c,0xe4ed0353,0x600ed0d9,0xcb1e6950,0xf957332b,0xa2531159,0x3bf327c1,0xec6b43f0,0x6ba8e9aa,0x9d6c069d,0xa946ee5d);\r
+ rc[8] = _mm512_set_epi32(0x26f65241,0xcbe55438,0x43ce5918,0xffbaafde,0x34bb8a5b,0x5f427fd7,0xaeb6b779,0x360a16f6,0x17bb8f38,0xd554a40b,0x8814f3a8,0x2e75b442,0xae3db102,0x5e962988,0xab0dde30,0x938dca39);\r
+ rc[9] = _mm512_set_epi32(0x756acc03,0x02288288,0x4ad6bdfd,0xe9c59da1,0xa0c1613c,0xba7ed22b,0xc173bc0f,0x48a659cf,0xae51a51a,0x1bdff7be,0x40c06e28,0x22901235,0x4ce99a54,0xb9f3026a,0xa2ca9cf7,0x839ec978);\r
+}//duck its endien ness // good programers make programs to make their programs i fixed it\r
+\r
+\r
+int test_implementations() {\r
+ alignas(64) unsigned char in[64*8];\r
+ alignas(64) unsigned char out256[32*8];\r
+ alignas(64) unsigned char out512[32*8];\r
+ alignas(64) unsigned char testvector256[32] = {0x80, 0x27, 0xcc, 0xb8, 0x79, 0x49, 0x77, 0x4b,\r
0x78, 0xd0, 0x54, 0x5f, 0xb7, 0x2b, 0xf7, 0x0c,\r
0x69, 0x5c, 0x2a, 0x09, 0x23, 0xcb, 0xd4, 0x7b,\r
0xba, 0x11, 0x59, 0xef, 0xbf, 0x2b, 0x2c, 0x1c};\r
\r
- unsigned char testvector512[32] = {0xbe, 0x7f, 0x72, 0x3b, 0x4e, 0x80, 0xa9, 0x98,\r
+ alignas(64) unsigned char testvector512[32] = {0xbe, 0x7f, 0x72, 0x3b, 0x4e, 0x80, 0xa9, 0x98,\r
0x13, 0xb2, 0x92, 0x28, 0x7f, 0x30, 0x6f, 0x62,\r
0x5a, 0x6d, 0x57, 0x33, 0x1c, 0xae, 0x5f, 0x34,\r
0xdd, 0x92, 0x77, 0xb0, 0x94, 0x5b, 0xe2, 0xaa};\r
}\r
\r
load_constants();\r
- // haraka512_8x(out512, in);\r
+ haraka512_8x(out512, in);\r
\r
// Verify output\r
for(i = 0; i < 32; i++) {\r
if (out512[i % 32] != testvector512[i]) {\r
printf("Error: testvector incorrect.\n");\r
- return;\r
+ return -1;\r
}\r
}\r
-\r
- free(in);\r
- free(out256);\r
- free(out512);\r
+ return 0;\r
}\r
/*\r
void haraka256(unsigned char *out, const unsigned char *in) {\r
\r
unsigned char i;\r
for (i = 0; i < len; ++i)\r
- printf("%lx, ", str[i]);\r
+ printf("%hx, ", str[i]);\r
printf("\n");\r
}\r
void haraka512(unsigned char *out, const unsigned char *in) {\r
MIX4(s);\r
\r
s = _mm512_xor_si512(s, i);\r
- STORE(out,s);\r
\r
TRUNCSTORE(out, s);\r
}\r
void haraka512_zero(unsigned char *out, const unsigned char *in) {\r
u512 s,i;\r
s = LOAD (in);\r
- STORE(out,s);\r
- phex(out);\r
i = s;\r
AES4_zero(s, 0);\r
MIX4(s);\r
MIX4(s);\r
\r
s = _mm512_xor_si512(s, i);\r
- STORE(out,s);\r
-\r
-\r
\r
TRUNCSTORE(out, s);\r
}\r
-/*\r
-void haraka512_keyed(unsigned char *out, const unsigned char *in, const u128 *rc) {\r
- u128 s[4], tmp;\r
-\r
- s[0] = LOAD(in);\r
- s[1] = LOAD(in + 16);\r
- s[2] = LOAD(in + 32);\r
- s[3] = LOAD(in + 48);\r
-\r
- AES4(s[0], s[1], s[2], s[3], 0);\r
- MIX4(s[0], s[1], s[2], s[3]);\r
-\r
- AES4(s[0], s[1], s[2], s[3], 8);\r
- MIX4(s[0], s[1], s[2], s[3]);\r
-\r
- AES4(s[0], s[1], s[2], s[3], 16);\r
- MIX4(s[0], s[1], s[2], s[3]);\r
-\r
- AES4(s[0], s[1], s[2], s[3], 24);\r
- MIX4_LAST(s[0], s[1], s[2], s[3]);\r
-\r
- AES4_LAST(s[0], s[1], s[2], s[3], 32);\r
-\r
-\r
- // s[0] = _mm_xor_si128(s[0], LOAD(in));\r
- // s[1] = _mm_xor_si128(s[1], LOAD(in + 16));\r
- // s[2] = _mm_xor_si128(s[2], LOAD(in + 32));\r
- // s[3] = _mm_xor_si128(s[0], LOAD(in + 48));\r
- ((uint32_t*)&out[0])[7] = ((uint32_t*)&s[0])[10] ^ ((uint32_t*)&in[52])[0];\r
-\r
- //TRUNCSTORE(out, s[0],s[1], s[2], s[3]);\r
-}\r
\r
void haraka512_4x(unsigned char *out, const unsigned char *in) {\r
- u128 s[4][4], tmp;\r
+ u512 s[4],i[4];\r
\r
- s[0][0] = LOAD(in);\r
- s[0][1] = LOAD(in + 16);\r
- s[0][2] = LOAD(in + 32);\r
- s[0][3] = LOAD(in + 48);\r
- s[1][0] = LOAD(in + 64);\r
- s[1][1] = LOAD(in + 80);\r
- s[1][2] = LOAD(in + 96);\r
- s[1][3] = LOAD(in + 112);\r
- s[2][0] = LOAD(in + 128);\r
- s[2][1] = LOAD(in + 144);\r
- s[2][2] = LOAD(in + 160);\r
- s[2][3] = LOAD(in + 176);\r
- s[3][0] = LOAD(in + 192);\r
- s[3][1] = LOAD(in + 208);\r
- s[3][2] = LOAD(in + 224);\r
- s[3][3] = LOAD(in + 240);\r
-\r
- AES4_4x(s[0], s[1], s[2], s[3], 0);\r
- MIX4(s[0][0], s[0][1], s[0][2], s[0][3]);\r
- MIX4(s[1][0], s[1][1], s[1][2], s[1][3]);\r
- MIX4(s[2][0], s[2][1], s[2][2], s[2][3]);\r
- MIX4(s[3][0], s[3][1], s[3][2], s[3][3]);\r
-\r
- AES4_4x(s[0], s[1], s[2], s[3], 8);\r
- MIX4(s[0][0], s[0][1], s[0][2], s[0][3]);\r
- MIX4(s[1][0], s[1][1], s[1][2], s[1][3]);\r
- MIX4(s[2][0], s[2][1], s[2][2], s[2][3]);\r
- MIX4(s[3][0], s[3][1], s[3][2], s[3][3]);\r
-\r
- AES4_4x(s[0], s[1], s[2], s[3], 16);\r
- MIX4(s[0][0], s[0][1], s[0][2], s[0][3]);\r
- MIX4(s[1][0], s[1][1], s[1][2], s[1][3]);\r
- MIX4(s[2][0], s[2][1], s[2][2], s[2][3]);\r
- MIX4(s[3][0], s[3][1], s[3][2], s[3][3]);\r
-\r
- AES4_4x(s[0], s[1], s[2], s[3], 24);\r
- MIX4(s[0][0], s[0][1], s[0][2], s[0][3]);\r
- MIX4(s[1][0], s[1][1], s[1][2], s[1][3]);\r
- MIX4(s[2][0], s[2][1], s[2][2], s[2][3]);\r
- MIX4(s[3][0], s[3][1], s[3][2], s[3][3]);\r
-\r
- AES4_4x(s[0], s[1], s[2], s[3], 32);\r
- MIX4(s[0][0], s[0][1], s[0][2], s[0][3]);\r
- MIX4(s[1][0], s[1][1], s[1][2], s[1][3]);\r
- MIX4(s[2][0], s[2][1], s[2][2], s[2][3]);\r
- MIX4(s[3][0], s[3][1], s[3][2], s[3][3]);\r
-\r
-\r
- s[0][0] = _mm_xor_si128(s[0][0], LOAD(in));\r
- s[0][1] = _mm_xor_si128(s[0][1], LOAD(in + 16));\r
- s[0][2] = _mm_xor_si128(s[0][2], LOAD(in + 32));\r
- s[0][3] = _mm_xor_si128(s[0][3], LOAD(in + 48));\r
- s[1][0] = _mm_xor_si128(s[1][0], LOAD(in + 64));\r
- s[1][1] = _mm_xor_si128(s[1][1], LOAD(in + 80));\r
- s[1][2] = _mm_xor_si128(s[1][2], LOAD(in + 96));\r
- s[1][3] = _mm_xor_si128(s[1][3], LOAD(in + 112));\r
- s[2][0] = _mm_xor_si128(s[2][0], LOAD(in + 128));\r
- s[2][1] = _mm_xor_si128(s[2][1], LOAD(in + 144));\r
- s[2][2] = _mm_xor_si128(s[2][2], LOAD(in + 160));\r
- s[2][3] = _mm_xor_si128(s[2][3], LOAD(in + 176));\r
- s[3][0] = _mm_xor_si128(s[3][0], LOAD(in + 192));\r
- s[3][1] = _mm_xor_si128(s[3][1], LOAD(in + 208));\r
- s[3][2] = _mm_xor_si128(s[3][2], LOAD(in + 224));\r
- s[3][3] = _mm_xor_si128(s[3][3], LOAD(in + 240));\r
-\r
- TRUNCSTORE(out, s[0][0], s[0][1], s[0][2], s[0][3]);\r
- TRUNCSTORE(out + 32, s[1][0], s[1][1], s[1][2], s[1][3]);\r
- TRUNCSTORE(out + 64, s[2][0], s[2][1], s[2][2], s[2][3]);\r
- TRUNCSTORE(out + 96, s[3][0], s[3][1], s[3][2], s[3][3]);\r
+ s[0] = LOAD(in);\r
+ s[1] = LOAD(in + 64);\r
+ s[2] = LOAD(in + 128);\r
+ s[3] = LOAD(in + 192);\r
+ i[0] = s[0];\r
+ i[1] = s[1];\r
+ i[2] = s[2];\r
+ i[3] = s[3];\r
+\r
+\r
+\r
+ AES4_4x(s, 0);\r
+ MIX4(s[0]);\r
+ MIX4(s[1]);\r
+ MIX4(s[2]);\r
+ MIX4(s[3]);\r
+\r
+ AES4_4x(s, 8);\r
+ MIX4(s[0]);\r
+ MIX4(s[1]);\r
+ MIX4(s[2]);\r
+ MIX4(s[3]);\r
+\r
+ AES4_4x(s, 16);\r
+ MIX4(s[0]);\r
+ MIX4(s[1]);\r
+ MIX4(s[2]);\r
+ MIX4(s[3]);\r
+\r
+ AES4_4x(s, 24);\r
+ MIX4(s[0]);\r
+ MIX4(s[1]);\r
+ MIX4(s[2]);\r
+ MIX4(s[3]);\r
+\r
+ AES4_4x(s, 32);\r
+ MIX4(s[0]);\r
+ MIX4(s[1]);\r
+ MIX4(s[2]);\r
+ MIX4(s[3]);\r
+\r
+\r
+ s[0] = _mm512_xor_si512(s[0], i[0]);\r
+ s[1] = _mm512_xor_si512(s[1], i[1]);\r
+ s[2] = _mm512_xor_si512(s[2], i[2]);\r
+ s[3] = _mm512_xor_si512(s[3], i[3]);\r
+\r
+\r
+ TRUNCSTORE(out, s[0]);\r
+ TRUNCSTORE(out + 32, s[1]);\r
+ TRUNCSTORE(out + 64, s[2]);\r
+ TRUNCSTORE(out + 96, s[3]);\r
}\r
\r
void haraka512_8x(unsigned char *out, const unsigned char *in) {\r
// TRUNCSTORE(out + 160, s[5][0], s[5][1], s[5][2], s[5][3]);\r
// TRUNCSTORE(out + 192, s[6][0], s[6][1], s[6][2], s[6][3]);\r
// TRUNCSTORE(out + 224, s[7][0], s[7][1], s[7][2], s[7][3]);\r
-}*/\r
+}\r