-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c00c042
commit efc221e
Showing
70 changed files
with
2,118 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
#define crypto_hash_cubehash81_emmintrin_BYTES 64 | ||
#define CRYPTO_BYTES 64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
#define crypto_hash_cubehash81_emmintrin2_BYTES 64 | ||
#define CRYPTO_BYTES 64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
#define crypto_hash_cubehash81_emmintrin3_BYTES 64 | ||
#define CRYPTO_BYTES 64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
#define crypto_hash_cubehash81_simple_BYTES 64 | ||
#define CRYPTO_BYTES 64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
#define crypto_hash_cubehash81_spec_BYTES 64 | ||
#define CRYPTO_BYTES 64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
4bd726b2d467e75d743679abfee036b672941e34dd91af6a29348599bbc94e33108ebd1ff8e2988a71a7339572744aadc5525a2fa169493d6b30123cfce7ce0b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#define CRYPTO_BYTES 64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,239 @@ | ||
/* | ||
20081110 | ||
D. J. Bernstein | ||
Public domain. | ||
Note: This code assumes that CUBEHASH_BLOCKBYTES is 2. | ||
*/ | ||
|
||
#include "parameters.h" | ||
#include "cubehash.h" | ||
#include "crypto_uint32.h" | ||
#include "crypto_uint16.h" | ||
|
||
static void transform(hashState *state,int r) | ||
{ | ||
__m128i x0; | ||
__m128i x1; | ||
__m128i x2; | ||
__m128i x3; | ||
__m128i x4; | ||
__m128i x5; | ||
__m128i x6; | ||
__m128i x7; | ||
__m128i y0; | ||
__m128i y1; | ||
__m128i y2; | ||
__m128i y3; | ||
|
||
x0 = state->x[0]; | ||
x1 = state->x[1]; | ||
x2 = state->x[2]; | ||
x3 = state->x[3]; | ||
x4 = state->x[4]; | ||
x5 = state->x[5]; | ||
x6 = state->x[6]; | ||
x7 = state->x[7]; | ||
|
||
for (;r > 0;--r) { | ||
x4 = _mm_add_epi32(x0,x4); | ||
x5 = _mm_add_epi32(x1,x5); | ||
x6 = _mm_add_epi32(x2,x6); | ||
x7 = _mm_add_epi32(x3,x7); | ||
y0 = x2; | ||
y1 = x3; | ||
y2 = x0; | ||
y3 = x1; | ||
x0 = _mm_xor_si128(_mm_slli_epi32(y0,7),_mm_srli_epi32(y0,25)); | ||
x1 = _mm_xor_si128(_mm_slli_epi32(y1,7),_mm_srli_epi32(y1,25)); | ||
x2 = _mm_xor_si128(_mm_slli_epi32(y2,7),_mm_srli_epi32(y2,25)); | ||
x3 = _mm_xor_si128(_mm_slli_epi32(y3,7),_mm_srli_epi32(y3,25)); | ||
x0 = _mm_xor_si128(x0,x4); | ||
x1 = _mm_xor_si128(x1,x5); | ||
x2 = _mm_xor_si128(x2,x6); | ||
x3 = _mm_xor_si128(x3,x7); | ||
x4 = _mm_shuffle_epi32(x4,0x4e); | ||
x5 = _mm_shuffle_epi32(x5,0x4e); | ||
x6 = _mm_shuffle_epi32(x6,0x4e); | ||
x7 = _mm_shuffle_epi32(x7,0x4e); | ||
x4 = _mm_add_epi32(x0,x4); | ||
x5 = _mm_add_epi32(x1,x5); | ||
x6 = _mm_add_epi32(x2,x6); | ||
x7 = _mm_add_epi32(x3,x7); | ||
y0 = x1; | ||
y1 = x0; | ||
y2 = x3; | ||
y3 = x2; | ||
x0 = _mm_xor_si128(_mm_slli_epi32(y0,11),_mm_srli_epi32(y0,21)); | ||
x1 = _mm_xor_si128(_mm_slli_epi32(y1,11),_mm_srli_epi32(y1,21)); | ||
x2 = _mm_xor_si128(_mm_slli_epi32(y2,11),_mm_srli_epi32(y2,21)); | ||
x3 = _mm_xor_si128(_mm_slli_epi32(y3,11),_mm_srli_epi32(y3,21)); | ||
x0 = _mm_xor_si128(x0,x4); | ||
x1 = _mm_xor_si128(x1,x5); | ||
x2 = _mm_xor_si128(x2,x6); | ||
x3 = _mm_xor_si128(x3,x7); | ||
x4 = _mm_shuffle_epi32(x4,0xb1); | ||
x5 = _mm_shuffle_epi32(x5,0xb1); | ||
x6 = _mm_shuffle_epi32(x6,0xb1); | ||
x7 = _mm_shuffle_epi32(x7,0xb1); | ||
} | ||
|
||
state->x[0] = x0; | ||
state->x[1] = x1; | ||
state->x[2] = x2; | ||
state->x[3] = x3; | ||
state->x[4] = x4; | ||
state->x[5] = x5; | ||
state->x[6] = x6; | ||
state->x[7] = x7; | ||
} | ||
|
||
HashReturn Init(hashState *state, int hashbitlen) | ||
{ | ||
int i; | ||
|
||
if (hashbitlen < 8) return BAD_HASHBITLEN; | ||
if (hashbitlen > 512) return BAD_HASHBITLEN; | ||
if (hashbitlen != 8 * (hashbitlen / 8)) return BAD_HASHBITLEN; | ||
|
||
state->hashbitlen = hashbitlen; | ||
for (i = 0;i < 8;++i) state->x[i] = _mm_set_epi32(0,0,0,0); | ||
state->x[0] = _mm_set_epi32(0,CUBEHASH_ROUNDS,CUBEHASH_BLOCKBYTES,hashbitlen / 8); | ||
transform(state,10 * CUBEHASH_ROUNDS); | ||
state->pos = 0; | ||
return SUCCESS; | ||
} | ||
|
||
HashReturn Update(hashState *state, const BitSequence *data, | ||
DataLength databitlen) | ||
{ | ||
int r; | ||
__m128i x0; | ||
__m128i x1; | ||
__m128i x2; | ||
__m128i x3; | ||
__m128i x4; | ||
__m128i x5; | ||
__m128i x6; | ||
__m128i x7; | ||
__m128i y0; | ||
__m128i y1; | ||
__m128i y2; | ||
__m128i y3; | ||
|
||
while (databitlen >= 8 && state->pos != 0) { | ||
((unsigned char *) state->x)[state->pos / 8] ^= *data; | ||
data += 1; | ||
databitlen -= 8; | ||
state->pos += 8; | ||
if (state->pos == 8 * CUBEHASH_BLOCKBYTES) { | ||
transform(state,CUBEHASH_ROUNDS); | ||
state->pos = 0; | ||
} | ||
} | ||
|
||
x0 = state->x[0]; | ||
x1 = state->x[1]; | ||
x2 = state->x[2]; | ||
x3 = state->x[3]; | ||
x4 = state->x[4]; | ||
x5 = state->x[5]; | ||
x6 = state->x[6]; | ||
x7 = state->x[7]; | ||
|
||
while (databitlen >= 8 * CUBEHASH_BLOCKBYTES) { | ||
x0 = _mm_xor_si128(x0,_mm_set_epi32(0,0,0,(crypto_uint32) *(crypto_uint16 *) data)); | ||
data += CUBEHASH_BLOCKBYTES; | ||
databitlen -= 8 * CUBEHASH_BLOCKBYTES; | ||
|
||
for (r = 0;r < CUBEHASH_ROUNDS;++r) { | ||
x4 = _mm_add_epi32(x0,x4); | ||
x5 = _mm_add_epi32(x1,x5); | ||
x6 = _mm_add_epi32(x2,x6); | ||
x7 = _mm_add_epi32(x3,x7); | ||
y0 = x2; | ||
y1 = x3; | ||
y2 = x0; | ||
y3 = x1; | ||
x0 = _mm_xor_si128(_mm_slli_epi32(y0,7),_mm_srli_epi32(y0,25)); | ||
x1 = _mm_xor_si128(_mm_slli_epi32(y1,7),_mm_srli_epi32(y1,25)); | ||
x2 = _mm_xor_si128(_mm_slli_epi32(y2,7),_mm_srli_epi32(y2,25)); | ||
x3 = _mm_xor_si128(_mm_slli_epi32(y3,7),_mm_srli_epi32(y3,25)); | ||
x0 = _mm_xor_si128(x0,x4); | ||
x1 = _mm_xor_si128(x1,x5); | ||
x2 = _mm_xor_si128(x2,x6); | ||
x3 = _mm_xor_si128(x3,x7); | ||
x4 = _mm_shuffle_epi32(x4,0x4e); | ||
x5 = _mm_shuffle_epi32(x5,0x4e); | ||
x6 = _mm_shuffle_epi32(x6,0x4e); | ||
x7 = _mm_shuffle_epi32(x7,0x4e); | ||
x4 = _mm_add_epi32(x0,x4); | ||
x5 = _mm_add_epi32(x1,x5); | ||
x6 = _mm_add_epi32(x2,x6); | ||
x7 = _mm_add_epi32(x3,x7); | ||
y0 = x1; | ||
y1 = x0; | ||
y2 = x3; | ||
y3 = x2; | ||
x0 = _mm_xor_si128(_mm_slli_epi32(y0,11),_mm_srli_epi32(y0,21)); | ||
x1 = _mm_xor_si128(_mm_slli_epi32(y1,11),_mm_srli_epi32(y1,21)); | ||
x2 = _mm_xor_si128(_mm_slli_epi32(y2,11),_mm_srli_epi32(y2,21)); | ||
x3 = _mm_xor_si128(_mm_slli_epi32(y3,11),_mm_srli_epi32(y3,21)); | ||
x0 = _mm_xor_si128(x0,x4); | ||
x1 = _mm_xor_si128(x1,x5); | ||
x2 = _mm_xor_si128(x2,x6); | ||
x3 = _mm_xor_si128(x3,x7); | ||
x4 = _mm_shuffle_epi32(x4,0xb1); | ||
x5 = _mm_shuffle_epi32(x5,0xb1); | ||
x6 = _mm_shuffle_epi32(x6,0xb1); | ||
x7 = _mm_shuffle_epi32(x7,0xb1); | ||
} | ||
} | ||
|
||
state->x[0] = x0; | ||
state->x[1] = x1; | ||
state->x[2] = x2; | ||
state->x[3] = x3; | ||
state->x[4] = x4; | ||
state->x[5] = x5; | ||
state->x[6] = x6; | ||
state->x[7] = x7; | ||
|
||
while (databitlen >= 8) { | ||
((unsigned char *) state->x)[state->pos / 8] ^= *data; | ||
data += 1; | ||
databitlen -= 8; | ||
state->pos += 8; | ||
if (state->pos == 8 * CUBEHASH_BLOCKBYTES) { | ||
transform(state,CUBEHASH_ROUNDS); | ||
state->pos = 0; | ||
} | ||
} | ||
if (databitlen > 0) { | ||
((unsigned char *) state->x)[state->pos / 8] ^= *data; | ||
state->pos += databitlen; | ||
} | ||
return SUCCESS; | ||
} | ||
|
||
HashReturn Final(hashState *state, BitSequence *hashval) | ||
{ | ||
int i; | ||
|
||
((unsigned char *) state->x)[state->pos / 8] ^= (128 >> (state->pos % 8)); | ||
transform(state,CUBEHASH_ROUNDS); | ||
state->x[7] = _mm_xor_si128(state->x[7],_mm_set_epi32(1,0,0,0)); | ||
transform(state,10 * CUBEHASH_ROUNDS); | ||
for (i = 0;i < state->hashbitlen / 8;++i) | ||
hashval[i] = ((unsigned char *) state->x)[i]; | ||
|
||
return SUCCESS; | ||
} | ||
|
||
HashReturn Hash(int hashbitlen, const BitSequence *data, | ||
DataLength databitlen, BitSequence *hashval) | ||
{ | ||
hashState state; | ||
if (Init(&state,hashbitlen) != SUCCESS) return BAD_HASHBITLEN; | ||
Update(&state,data,databitlen); | ||
return Final(&state,hashval); | ||
} |
Oops, something went wrong.