Permalink
Browse files

supercop-20081111

  • Loading branch information...
1 parent c00c042 commit efc221eb875b56c3a1f5a8ed399617401a4252dc Daniel J. Bernstein committed with Nov 10, 2008
Showing with 2,118 additions and 26 deletions.
  1. +1 −1 cpuid/x86.c
  2. +1 −1 crypto_hash/cubehash81/emmintrin/api.h
  3. +4 −4 crypto_hash/cubehash81/emmintrin/cubehash.c
  4. +2 −2 crypto_hash/cubehash81/emmintrin/cubehash.h
  5. +1 −1 crypto_hash/cubehash81/emmintrin2/api.h
  6. +1 −1 crypto_hash/cubehash81/emmintrin3/api.h
  7. +1 −1 crypto_hash/cubehash81/simple/api.h
  8. +5 −5 crypto_hash/cubehash81/simple/cubehash.c
  9. +3 −3 crypto_hash/cubehash81/simple/cubehash.h
  10. +1 −1 crypto_hash/cubehash81/spec/api.h
  11. +3 −3 crypto_hash/cubehash81/spec/cubehash.c
  12. +1 −0 crypto_hash/cubehash82/checksum
  13. +1 −0 crypto_hash/cubehash82/emmintrin3/api.h
  14. +239 −0 crypto_hash/cubehash82/emmintrin3/cubehash.c
  15. +32 −0 crypto_hash/cubehash82/emmintrin3/cubehash.h
  16. +14 −0 crypto_hash/cubehash82/emmintrin3/nist.c
  17. +1 −0 crypto_hash/cubehash82/emmintrin3/nist.h
  18. +2 −0 crypto_hash/cubehash82/emmintrin3/parameters.h
  19. +1 −0 crypto_hash/cubehash82/simple/api.h
  20. +103 −0 crypto_hash/cubehash82/simple/cubehash.c
  21. +32 −0 crypto_hash/cubehash82/simple/cubehash.h
  22. +14 −0 crypto_hash/cubehash82/simple/nist.c
  23. +1 −0 crypto_hash/cubehash82/simple/nist.h
  24. +2 −0 crypto_hash/cubehash82/simple/parameters.h
  25. +1 −0 crypto_hash/cubehash82/spec/api.h
  26. +206 −0 crypto_hash/cubehash82/spec/cubehash.c
  27. +31 −0 crypto_hash/cubehash82/spec/cubehash.h
  28. +14 −0 crypto_hash/cubehash82/spec/nist.c
  29. +1 −0 crypto_hash/cubehash82/spec/nist.h
  30. +2 −0 crypto_hash/cubehash82/spec/parameters.h
  31. +1 −0 crypto_hash/cubehash84/checksum
  32. +1 −0 crypto_hash/cubehash84/emmintrin3/api.h
  33. +238 −0 crypto_hash/cubehash84/emmintrin3/cubehash.c
  34. +32 −0 crypto_hash/cubehash84/emmintrin3/cubehash.h
  35. +14 −0 crypto_hash/cubehash84/emmintrin3/nist.c
  36. +1 −0 crypto_hash/cubehash84/emmintrin3/nist.h
  37. +2 −0 crypto_hash/cubehash84/emmintrin3/parameters.h
  38. +1 −0 crypto_hash/cubehash84/simple/api.h
  39. +103 −0 crypto_hash/cubehash84/simple/cubehash.c
  40. +32 −0 crypto_hash/cubehash84/simple/cubehash.h
  41. +14 −0 crypto_hash/cubehash84/simple/nist.c
  42. +1 −0 crypto_hash/cubehash84/simple/nist.h
  43. +2 −0 crypto_hash/cubehash84/simple/parameters.h
  44. +1 −0 crypto_hash/cubehash84/spec/api.h
  45. +206 −0 crypto_hash/cubehash84/spec/cubehash.c
  46. +31 −0 crypto_hash/cubehash84/spec/cubehash.h
  47. +14 −0 crypto_hash/cubehash84/spec/nist.c
  48. +1 −0 crypto_hash/cubehash84/spec/nist.h
  49. +2 −0 crypto_hash/cubehash84/spec/parameters.h
  50. +1 −0 crypto_hash/cubehash88/checksum
  51. +1 −0 crypto_hash/cubehash88/emmintrin3/api.h
  52. +238 −0 crypto_hash/cubehash88/emmintrin3/cubehash.c
  53. +32 −0 crypto_hash/cubehash88/emmintrin3/cubehash.h
  54. +14 −0 crypto_hash/cubehash88/emmintrin3/nist.c
  55. +1 −0 crypto_hash/cubehash88/emmintrin3/nist.h
  56. +2 −0 crypto_hash/cubehash88/emmintrin3/parameters.h
  57. +1 −0 crypto_hash/cubehash88/simple/api.h
  58. +103 −0 crypto_hash/cubehash88/simple/cubehash.c
  59. +32 −0 crypto_hash/cubehash88/simple/cubehash.h
  60. +14 −0 crypto_hash/cubehash88/simple/nist.c
  61. +1 −0 crypto_hash/cubehash88/simple/nist.h
  62. +2 −0 crypto_hash/cubehash88/simple/parameters.h
  63. +1 −0 crypto_hash/cubehash88/spec/api.h
  64. +206 −0 crypto_hash/cubehash88/spec/cubehash.c
  65. +31 −0 crypto_hash/cubehash88/spec/cubehash.h
  66. +14 −0 crypto_hash/cubehash88/spec/nist.c
  67. +1 −0 crypto_hash/cubehash88/spec/nist.h
  68. +2 −0 crypto_hash/cubehash88/spec/parameters.h
  69. +1 −1 crypto_stream/dragon/e/submissions/dragon/api.h
  70. +2 −2 do
View
@@ -35,7 +35,7 @@ int main()
putchar(c);
}
- printf("-%08x-%08x\n",y[0],y[3]);
+ printf("-%08x-%08x\n",(unsigned int) y[0],(unsigned int) y[3]);
return 0;
}
@@ -1 +1 @@
-#define crypto_hash_cubehash81_emmintrin_BYTES 64
+#define CRYPTO_BYTES 64
@@ -1,5 +1,5 @@
/*
-20081106
+20081110
D. J. Bernstein
Public domain.
*/
@@ -116,7 +116,7 @@ HashReturn Update(hashState *state, const BitSequence *data,
/* so state->pos is a multiple of 8 */
while (databitlen >= 8) {
- myuint32 u = *data;
+ crypto_uint32 u = *data;
u <<= 8 * ((state->pos / 8) % 4);
state->x[state->pos / 32] ^= u;
data += 1;
@@ -128,7 +128,7 @@ HashReturn Update(hashState *state, const BitSequence *data,
}
}
if (databitlen > 0) {
- myuint32 u = *data;
+ crypto_uint32 u = *data;
u <<= 8 * ((state->pos / 8) % 4);
state->x[state->pos / 32] ^= u;
state->pos += databitlen;
@@ -139,7 +139,7 @@ HashReturn Update(hashState *state, const BitSequence *data,
HashReturn Final(hashState *state, BitSequence *hashval)
{
int i;
- myuint32 u;
+ crypto_uint32 u;
u = (128 >> (state->pos % 8));
u <<= 8 * ((state->pos / 8) % 4);
@@ -11,12 +11,12 @@ typedef unsigned char BitSequence;
typedef unsigned long long DataLength;
typedef enum { SUCCESS = 0, FAIL = 1, BAD_HASHBITLEN = 2 } HashReturn;
-typedef unsigned int myuint32; /* must be exactly 32 bits */
+#include "crypto_uint32.h"
typedef struct {
int hashbitlen;
int pos; /* number of bits read into x from current block */
- myuint32 x[32];
+ crypto_uint32 x[32];
} hashState;
HashReturn Init(hashState *state, int hashbitlen);
@@ -1 +1 @@
-#define crypto_hash_cubehash81_emmintrin2_BYTES 64
+#define CRYPTO_BYTES 64
@@ -1 +1 @@
-#define crypto_hash_cubehash81_emmintrin3_BYTES 64
+#define CRYPTO_BYTES 64
@@ -1 +1 @@
-#define crypto_hash_cubehash81_simple_BYTES 64
+#define CRYPTO_BYTES 64
@@ -1,5 +1,5 @@
/*
-20081106
+20081110
D. J. Bernstein
Public domain.
*/
@@ -13,7 +13,7 @@ static void transform(hashState *state)
{
int i;
int r;
- myuint32 y[16];
+ crypto_uint32 y[16];
for (r = 0;r < CUBEHASH_ROUNDS;++r) {
for (i = 0;i < 16;++i) state->x[i + 16] += state->x[i];
@@ -57,7 +57,7 @@ HashReturn Update(hashState *state, const BitSequence *data,
/* so state->pos is a multiple of 8 */
while (databitlen >= 8) {
- myuint32 u = *data;
+ crypto_uint32 u = *data;
u <<= 8 * ((state->pos / 8) % 4);
state->x[state->pos / 32] ^= u;
data += 1;
@@ -69,7 +69,7 @@ HashReturn Update(hashState *state, const BitSequence *data,
}
}
if (databitlen > 0) {
- myuint32 u = *data;
+ crypto_uint32 u = *data;
u <<= 8 * ((state->pos / 8) % 4);
state->x[state->pos / 32] ^= u;
state->pos += databitlen;
@@ -80,7 +80,7 @@ HashReturn Update(hashState *state, const BitSequence *data,
HashReturn Final(hashState *state, BitSequence *hashval)
{
int i;
- myuint32 u;
+ crypto_uint32 u;
u = (128 >> (state->pos % 8));
u <<= 8 * ((state->pos / 8) % 4);
@@ -1,5 +1,5 @@
/*
-20081106
+20081110
D. J. Bernstein
Public domain.
*/
@@ -11,12 +11,12 @@ typedef unsigned char BitSequence;
typedef unsigned long long DataLength;
typedef enum { SUCCESS = 0, FAIL = 1, BAD_HASHBITLEN = 2 } HashReturn;
-typedef unsigned int myuint32; /* must be exactly 32 bits */
+#include "crypto_uint32.h"
typedef struct {
int hashbitlen;
int pos; /* number of bits read into x from current block */
- myuint32 x[32];
+ crypto_uint32 x[32];
} hashState;
HashReturn Init(hashState *state, int hashbitlen);
@@ -1 +1 @@
-#define crypto_hash_cubehash81_spec_BYTES 64
+#define CRYPTO_BYTES 64
@@ -1,13 +1,13 @@
/*
-20081106
+20081110
D. J. Bernstein
Public domain.
*/
#include "parameters.h"
#include "cubehash.h"
-
-typedef unsigned int myuint32; /* must be exactly 32 bits */
+#include "crypto_uint32.h"
+#define myuint32 crypto_uint32
#define ROTATEUPWARDS7(a) (((a) << 7) | ((a) >> 25))
#define ROTATEUPWARDS11(a) (((a) << 11) | ((a) >> 21))
@@ -0,0 +1 @@
+4bd726b2d467e75d743679abfee036b672941e34dd91af6a29348599bbc94e33108ebd1ff8e2988a71a7339572744aadc5525a2fa169493d6b30123cfce7ce0b
@@ -0,0 +1 @@
+#define CRYPTO_BYTES 64
@@ -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.

0 comments on commit efc221e

Please sign in to comment.