Skip to content
Browse files

supercop-20081106

  • Loading branch information...
1 parent e5a603a commit 757faff6ae1da9ec4ebf1ce90fd7ebdd5a9f8e29 Daniel J. Bernstein committed with Nov 6, 2008
View
1 crypto_hash/blake32/checksum
@@ -0,0 +1 @@
+39b2b2e9fa90250381967ef3282463918857f0c110fa46565c7320a0240486dc
View
1 crypto_hash/blake64/checksum
@@ -0,0 +1 @@
+550d4cfd94548a19da2344b764ee8691e4816b782871d0d9d06a9614e229ad1ce2176620e3d46e2aff4b7eafabfe391ca3d84d7b441bce51121a9b20b391d1d4
View
1 crypto_hash/cubehash81/checksum
@@ -0,0 +1 @@
+ed2a5331a49c037d1ff6455e7c1d5e88da60ea6b2dc776ed9fe1b9f7c2b2f5eed6dce4cc0df35335f24c6074ac40ab6288459a6a2c27d3369efe02f6f5f4c8b0
View
1 crypto_hash/cubehash81/emmintrin/api.h
@@ -0,0 +1 @@
+#define crypto_hash_cubehash81_emmintrin_BYTES 64
View
162 crypto_hash/cubehash81/emmintrin/cubehash.c
@@ -0,0 +1,162 @@
+/*
+20081106
+D. J. Bernstein
+Public domain.
+*/
+
+#include "parameters.h"
+#include "cubehash.h"
+#include <emmintrin.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;
+ __m128i y4;
+ __m128i y5;
+ __m128i y6;
+ __m128i y7;
+
+ x0 = _mm_loadu_si128(0 + (__m128i *) state->x);
+ x1 = _mm_loadu_si128(1 + (__m128i *) state->x);
+ x2 = _mm_loadu_si128(2 + (__m128i *) state->x);
+ x3 = _mm_loadu_si128(3 + (__m128i *) state->x);
+ x4 = _mm_loadu_si128(4 + (__m128i *) state->x);
+ x5 = _mm_loadu_si128(5 + (__m128i *) state->x);
+ x6 = _mm_loadu_si128(6 + (__m128i *) state->x);
+ x7 = _mm_loadu_si128(7 + (__m128i *) state->x);
+
+ 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);
+ }
+
+ _mm_storeu_si128(0 + (__m128i *) state->x,x0);
+ _mm_storeu_si128(1 + (__m128i *) state->x,x1);
+ _mm_storeu_si128(2 + (__m128i *) state->x,x2);
+ _mm_storeu_si128(3 + (__m128i *) state->x,x3);
+ _mm_storeu_si128(4 + (__m128i *) state->x,x4);
+ _mm_storeu_si128(5 + (__m128i *) state->x,x5);
+ _mm_storeu_si128(6 + (__m128i *) state->x,x6);
+ _mm_storeu_si128(7 + (__m128i *) state->x,x7);
+}
+
+HashReturn Init(hashState *state, int hashbitlen)
+{
+ int i;
+ int j;
+
+ 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 < 32;++i) state->x[i] = 0;
+ state->x[0] = hashbitlen / 8;
+ state->x[1] = CUBEHASH_BLOCKBYTES;
+ state->x[2] = CUBEHASH_ROUNDS;
+ for (i = 0;i < 10;++i) transform(state);
+ state->pos = 0;
+ return SUCCESS;
+}
+
+HashReturn Update(hashState *state, const BitSequence *data,
+ DataLength databitlen)
+{
+ /* caller promises us that previous data had integral number of bytes */
+ /* so state->pos is a multiple of 8 */
+
+ while (databitlen >= 8) {
+ myuint32 u = *data;
+ u <<= 8 * ((state->pos / 8) % 4);
+ state->x[state->pos / 32] ^= u;
+ data += 1;
+ databitlen -= 8;
+ state->pos += 8;
+ if (state->pos == 8 * CUBEHASH_BLOCKBYTES) {
+ transform(state);
+ state->pos = 0;
+ }
+ }
+ if (databitlen > 0) {
+ myuint32 u = *data;
+ u <<= 8 * ((state->pos / 8) % 4);
+ state->x[state->pos / 32] ^= u;
+ state->pos += databitlen;
+ }
+ return SUCCESS;
+}
+
+HashReturn Final(hashState *state, BitSequence *hashval)
+{
+ int i;
+ myuint32 u;
+
+ u = (128 >> (state->pos % 8));
+ u <<= 8 * ((state->pos / 8) % 4);
+ state->x[state->pos / 32] ^= u;
+ transform(state);
+ state->x[31] ^= 1;
+ for (i = 0;i < 10;++i) transform(state);
+ for (i = 0;i < state->hashbitlen / 8;++i) hashval[i] = state->x[i / 4] >> (8 * (i % 4));
+
+ 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);
+}
View
32 crypto_hash/cubehash81/emmintrin/cubehash.h
@@ -0,0 +1,32 @@
+/*
+20081106
+D. J. Bernstein
+Public domain.
+*/
+
+#ifndef cubehash_h
+#define cubehash_h
+
+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 */
+
+typedef struct {
+ int hashbitlen;
+ int pos; /* number of bits read into x from current block */
+ myuint32 x[32];
+} hashState;
+
+HashReturn Init(hashState *state, int hashbitlen);
+
+HashReturn Update(hashState *state, const BitSequence *data,
+ DataLength databitlen);
+
+HashReturn Final(hashState *state, BitSequence *hashval);
+
+HashReturn Hash(int hashbitlen, const BitSequence *data,
+ DataLength databitlen, BitSequence *hashval);
+
+#endif
View
14 crypto_hash/cubehash81/emmintrin/nist.c
@@ -0,0 +1,14 @@
+/*
+20081106
+D. J. Bernstein
+Public domain.
+*/
+
+#include "crypto_hash.h"
+#include "nist.h"
+
+int crypto_hash(unsigned char *out,const unsigned char *in,unsigned long long inlen)
+{
+ if (Hash(crypto_hash_BYTES * 8,in,inlen * 8,out) == SUCCESS) return 0;
+ return -1;
+}
View
1 crypto_hash/cubehash81/emmintrin/nist.h
@@ -0,0 +1 @@
+#include "cubehash.h"
View
2 crypto_hash/cubehash81/emmintrin/parameters.h
@@ -0,0 +1,2 @@
+#define CUBEHASH_ROUNDS 8
+#define CUBEHASH_BLOCKBYTES 1
View
1 crypto_hash/cubehash81/emmintrin2/api.h
@@ -0,0 +1 @@
+#define crypto_hash_cubehash81_emmintrin2_BYTES 64
View
153 crypto_hash/cubehash81/emmintrin2/cubehash.c
@@ -0,0 +1,153 @@
+/*
+20081106
+D. J. Bernstein
+Public domain.
+*/
+
+#include "parameters.h"
+#include "cubehash.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;
+ __m128i y4;
+ __m128i y5;
+ __m128i y6;
+ __m128i y7;
+
+ x0 = _mm_load_si128(0 + state->x);
+ x1 = _mm_load_si128(1 + state->x);
+ x2 = _mm_load_si128(2 + state->x);
+ x3 = _mm_load_si128(3 + state->x);
+ x4 = _mm_load_si128(4 + state->x);
+ x5 = _mm_load_si128(5 + state->x);
+ x6 = _mm_load_si128(6 + state->x);
+ x7 = _mm_load_si128(7 + state->x);
+
+ 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);
+ }
+
+ _mm_store_si128(0 + state->x,x0);
+ _mm_store_si128(1 + state->x,x1);
+ _mm_store_si128(2 + state->x,x2);
+ _mm_store_si128(3 + state->x,x3);
+ _mm_store_si128(4 + state->x,x4);
+ _mm_store_si128(5 + state->x,x5);
+ _mm_store_si128(6 + state->x,x6);
+ _mm_store_si128(7 + state->x,x7);
+}
+
+HashReturn Init(hashState *state, int hashbitlen)
+{
+ int i;
+ int j;
+
+ 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);
+ for (i = 0;i < 10;++i) transform(state);
+ state->pos = 0;
+ return SUCCESS;
+}
+
+HashReturn Update(hashState *state, const BitSequence *data,
+ DataLength databitlen)
+{
+ /* caller promises us that previous data had integral number of bytes */
+ /* so state->pos is a multiple of 8 */
+
+ 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);
+ 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);
+ state->x[7] = _mm_xor_si128(state->x[7],_mm_set_epi32(1,0,0,0));
+ for (i = 0;i < 10;++i) transform(state);
+ 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);
+}
View
32 crypto_hash/cubehash81/emmintrin2/cubehash.h
@@ -0,0 +1,32 @@
+/*
+20081106
+D. J. Bernstein
+Public domain.
+*/
+
+#ifndef cubehash_h
+#define cubehash_h
+
+typedef unsigned char BitSequence;
+typedef unsigned long long DataLength;
+typedef enum { SUCCESS = 0, FAIL = 1, BAD_HASHBITLEN = 2 } HashReturn;
+
+#include <emmintrin.h>
+
+typedef struct {
+ int hashbitlen;
+ int pos; /* number of bits read into x from current block */
+ __m128i x[8];
+} hashState;
+
+HashReturn Init(hashState *state, int hashbitlen);
+
+HashReturn Update(hashState *state, const BitSequence *data,
+ DataLength databitlen);
+
+HashReturn Final(hashState *state, BitSequence *hashval);
+
+HashReturn Hash(int hashbitlen, const BitSequence *data,
+ DataLength databitlen, BitSequence *hashval);
+
+#endif
View
14 crypto_hash/cubehash81/emmintrin2/nist.c
@@ -0,0 +1,14 @@
+/*
+20081106
+D. J. Bernstein
+Public domain.
+*/
+
+#include "crypto_hash.h"
+#include "nist.h"
+
+int crypto_hash(unsigned char *out,const unsigned char *in,unsigned long long inlen)
+{
+ if (Hash(crypto_hash_BYTES * 8,in,inlen * 8,out) == SUCCESS) return 0;
+ return -1;
+}
View
1 crypto_hash/cubehash81/emmintrin2/nist.h
@@ -0,0 +1 @@
+#include "cubehash.h"
View
2 crypto_hash/cubehash81/emmintrin2/parameters.h
@@ -0,0 +1,2 @@
+#define CUBEHASH_ROUNDS 8
+#define CUBEHASH_BLOCKBYTES 1
View
1 crypto_hash/cubehash81/simple/api.h
@@ -0,0 +1 @@
+#define crypto_hash_cubehash81_simple_BYTES 64
View
103 crypto_hash/cubehash81/simple/cubehash.c
@@ -0,0 +1,103 @@
+/*
+20081106
+D. J. Bernstein
+Public domain.
+*/
+
+#include "parameters.h"
+#include "cubehash.h"
+
+#define ROTATE(a,b) (((a) << (b)) | ((a) >> (32 - b)))
+
+static void transform(hashState *state)
+{
+ int i;
+ int r;
+ myuint32 y[16];
+
+ for (r = 0;r < CUBEHASH_ROUNDS;++r) {
+ for (i = 0;i < 16;++i) state->x[i + 16] += state->x[i];
+ for (i = 0;i < 16;++i) y[i ^ 8] = state->x[i];
+ for (i = 0;i < 16;++i) state->x[i] = ROTATE(y[i],7);
+ for (i = 0;i < 16;++i) state->x[i] ^= state->x[i + 16];
+ for (i = 0;i < 16;++i) y[i ^ 2] = state->x[i + 16];
+ for (i = 0;i < 16;++i) state->x[i + 16] = y[i];
+ for (i = 0;i < 16;++i) state->x[i + 16] += state->x[i];
+ for (i = 0;i < 16;++i) y[i ^ 4] = state->x[i];
+ for (i = 0;i < 16;++i) state->x[i] = ROTATE(y[i],11);
+ for (i = 0;i < 16;++i) state->x[i] ^= state->x[i + 16];
+ for (i = 0;i < 16;++i) y[i ^ 1] = state->x[i + 16];
+ for (i = 0;i < 16;++i) state->x[i + 16] = y[i];
+ }
+}
+
+HashReturn Init(hashState *state, int hashbitlen)
+{
+ int i;
+ int j;
+
+ 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 < 32;++i) state->x[i] = 0;
+ state->x[0] = hashbitlen / 8;
+ state->x[1] = CUBEHASH_BLOCKBYTES;
+ state->x[2] = CUBEHASH_ROUNDS;
+ for (i = 0;i < 10;++i) transform(state);
+ state->pos = 0;
+ return SUCCESS;
+}
+
+HashReturn Update(hashState *state, const BitSequence *data,
+ DataLength databitlen)
+{
+ /* caller promises us that previous data had integral number of bytes */
+ /* so state->pos is a multiple of 8 */
+
+ while (databitlen >= 8) {
+ myuint32 u = *data;
+ u <<= 8 * ((state->pos / 8) % 4);
+ state->x[state->pos / 32] ^= u;
+ data += 1;
+ databitlen -= 8;
+ state->pos += 8;
+ if (state->pos == 8 * CUBEHASH_BLOCKBYTES) {
+ transform(state);
+ state->pos = 0;
+ }
+ }
+ if (databitlen > 0) {
+ myuint32 u = *data;
+ u <<= 8 * ((state->pos / 8) % 4);
+ state->x[state->pos / 32] ^= u;
+ state->pos += databitlen;
+ }
+ return SUCCESS;
+}
+
+HashReturn Final(hashState *state, BitSequence *hashval)
+{
+ int i;
+ myuint32 u;
+
+ u = (128 >> (state->pos % 8));
+ u <<= 8 * ((state->pos / 8) % 4);
+ state->x[state->pos / 32] ^= u;
+ transform(state);
+ state->x[31] ^= 1;
+ for (i = 0;i < 10;++i) transform(state);
+ for (i = 0;i < state->hashbitlen / 8;++i) hashval[i] = state->x[i / 4] >> (8 * (i % 4));
+
+ 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);
+}
View
32 crypto_hash/cubehash81/simple/cubehash.h
@@ -0,0 +1,32 @@
+/*
+20081106
+D. J. Bernstein
+Public domain.
+*/
+
+#ifndef cubehash_h
+#define cubehash_h
+
+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 */
+
+typedef struct {
+ int hashbitlen;
+ int pos; /* number of bits read into x from current block */
+ myuint32 x[32];
+} hashState;
+
+HashReturn Init(hashState *state, int hashbitlen);
+
+HashReturn Update(hashState *state, const BitSequence *data,
+ DataLength databitlen);
+
+HashReturn Final(hashState *state, BitSequence *hashval);
+
+HashReturn Hash(int hashbitlen, const BitSequence *data,
+ DataLength databitlen, BitSequence *hashval);
+
+#endif
View
14 crypto_hash/cubehash81/simple/nist.c
@@ -0,0 +1,14 @@
+/*
+20081106
+D. J. Bernstein
+Public domain.
+*/
+
+#include "crypto_hash.h"
+#include "nist.h"
+
+int crypto_hash(unsigned char *out,const unsigned char *in,unsigned long long inlen)
+{
+ if (Hash(crypto_hash_BYTES * 8,in,inlen * 8,out) == SUCCESS) return 0;
+ return -1;
+}
View
1 crypto_hash/cubehash81/simple/nist.h
@@ -0,0 +1 @@
+#include "cubehash.h"
View
2 crypto_hash/cubehash81/simple/parameters.h
@@ -0,0 +1,2 @@
+#define CUBEHASH_ROUNDS 8
+#define CUBEHASH_BLOCKBYTES 1
View
1 crypto_hash/cubehash81/spec/api.h
@@ -0,0 +1 @@
+#define crypto_hash_cubehash81_spec_BYTES 64
View
206 crypto_hash/cubehash81/spec/cubehash.c
@@ -0,0 +1,206 @@
+/*
+20081106
+D. J. Bernstein
+Public domain.
+*/
+
+#include "parameters.h"
+#include "cubehash.h"
+
+typedef unsigned int myuint32; /* must be exactly 32 bits */
+
+#define ROTATEUPWARDS7(a) (((a) << 7) | ((a) >> 25))
+#define ROTATEUPWARDS11(a) (((a) << 11) | ((a) >> 21))
+#define SWAP(a,b) { myuint32 u = a; a = b; b = u; }
+
+static void rrounds(myuint32 x[2][2][2][2][2])
+{
+ int r;
+ int j;
+ int k;
+ int l;
+ int m;
+
+ for (r = 0;r < CUBEHASH_ROUNDS;++r) {
+ /* "add x_0jklm into x_1jklmn modulo 2^32" */
+ for (j = 0;j < 2;++j) for (k = 0;k < 2;++k) for (l = 0;l < 2;++l) for (m = 0;m < 2;++m)
+ x[1][j][k][l][m] += x[0][j][k][l][m];
+ /* "rotate x_0jklm upwards by 7 bits" */
+ for (j = 0;j < 2;++j) for (k = 0;k < 2;++k) for (l = 0;l < 2;++l) for (m = 0;m < 2;++m)
+ x[0][j][k][l][m] = ROTATEUPWARDS7(x[0][j][k][l][m]);
+ /* "swap x_00klm with x_01klm" */
+ for (k = 0;k < 2;++k) for (l = 0;l < 2;++l) for (m = 0;m < 2;++m)
+ SWAP(x[0][0][k][l][m],x[0][1][k][l][m])
+ /* "xor x_1jklm into x_0jklm" */
+ for (j = 0;j < 2;++j) for (k = 0;k < 2;++k) for (l = 0;l < 2;++l) for (m = 0;m < 2;++m)
+ x[0][j][k][l][m] ^= x[1][j][k][l][m];
+ /* "swap x_1jk0m with x_1jk1m" */
+ for (j = 0;j < 2;++j) for (k = 0;k < 2;++k) for (m = 0;m < 2;++m)
+ SWAP(x[1][j][k][0][m],x[1][j][k][1][m])
+ /* "add x_0jklm into x_1jklm modulo 2^32" */
+ for (j = 0;j < 2;++j) for (k = 0;k < 2;++k) for (l = 0;l < 2;++l) for (m = 0;m < 2;++m)
+ x[1][j][k][l][m] += x[0][j][k][l][m];
+ /* "rotate x_0jklm upwards by 11 bits" */
+ for (j = 0;j < 2;++j) for (k = 0;k < 2;++k) for (l = 0;l < 2;++l) for (m = 0;m < 2;++m)
+ x[0][j][k][l][m] = ROTATEUPWARDS11(x[0][j][k][l][m]);
+ /* "swap x_0j0lm with x_0j1lm" */
+ for (j = 0;j < 2;++j) for (l = 0;l < 2;++l) for (m = 0;m < 2;++m)
+ SWAP(x[0][j][0][l][m],x[0][j][1][l][m])
+ /* "xor x_1jklm into x_0jklm" */
+ for (j = 0;j < 2;++j) for (k = 0;k < 2;++k) for (l = 0;l < 2;++l) for (m = 0;m < 2;++m)
+ x[0][j][k][l][m] ^= x[1][j][k][l][m];
+ /* "swap x_1jkl0 with x_1jkl1" */
+ for (j = 0;j < 2;++j) for (k = 0;k < 2;++k) for (l = 0;l < 2;++l)
+ SWAP(x[1][j][k][l][0],x[1][j][k][l][1])
+ }
+}
+
+static void state_fromx(unsigned char state[128],myuint32 x[2][2][2][2][2])
+{
+ int i;
+ int j;
+ int k;
+ int l;
+ int m;
+ myuint32 u;
+
+ for (i = 0;i < 2;++i)
+ for (j = 0;j < 2;++j)
+ for (k = 0;k < 2;++k)
+ for (l = 0;l < 2;++l)
+ for (m = 0;m < 2;++m) {
+ u = x[i][j][k][l][m];
+ *state++ = u; u >>= 8;
+ *state++ = u; u >>= 8;
+ *state++ = u; u >>= 8;
+ *state++ = u; u >>= 8;
+ }
+}
+
+static void state_tox(unsigned char state[128],myuint32 x[2][2][2][2][2])
+{
+ int i;
+ int j;
+ int k;
+ int l;
+ int m;
+ myuint32 u;
+
+ for (i = 0;i < 2;++i)
+ for (j = 0;j < 2;++j)
+ for (k = 0;k < 2;++k)
+ for (l = 0;l < 2;++l)
+ for (m = 0;m < 2;++m) {
+ u = ((myuint32) *state++) << 0;
+ u |= ((myuint32) *state++) << 8;
+ u |= ((myuint32) *state++) << 16;
+ u |= ((myuint32) *state++) << 24;
+ x[i][j][k][l][m] = u;
+ }
+}
+
+HashReturn Init(hashState *state, int hashbitlen)
+{
+ myuint32 x[2][2][2][2][2];
+ int i;
+ int j;
+ int k;
+ int l;
+ int m;
+
+ if (hashbitlen < 8) return BAD_HASHBITLEN;
+ if (hashbitlen > 512) return BAD_HASHBITLEN;
+ if (hashbitlen != 8 * (hashbitlen / 8)) return BAD_HASHBITLEN;
+
+ /* "the first three state words x_00000, x_00001, x_00010" */
+ /* "are set to the integers h/8, b, r respectively." */
+ /* "the remaining state words are set to 0." */
+ for (i = 0;i < 2;++i)
+ for (j = 0;j < 2;++j)
+ for (k = 0;k < 2;++k)
+ for (l = 0;l < 2;++l)
+ for (m = 0;m < 2;++m)
+ x[i][j][k][l][m] = 0;
+ x[0][0][0][0][0] = hashbitlen/8;
+ x[0][0][0][0][1] = CUBEHASH_BLOCKBYTES;
+ x[0][0][0][1][0] = CUBEHASH_ROUNDS;
+
+ /* "the state is then transformed invertibly through 10r identical rounds" */
+ for (i = 0;i < 10;++i) rrounds(x);
+ state_fromx(state->state,x);
+ state->hashbitlen = hashbitlen;
+ state->blockbits = 0;
+
+ return SUCCESS;
+}
+
+static const BitSequence mybit[8] = { 128, 64, 32, 16, 8, 4, 2, 1 } ;
+
+static void updatebit(hashState *state,BitSequence nextbit)
+{
+ myuint32 x[2][2][2][2][2];
+ int j;
+
+ state->block[state->blockbits / 8] &= ~mybit[state->blockbits % 8];
+ state->block[state->blockbits / 8] |= nextbit * mybit[state->blockbits % 8];
+ ++state->blockbits;
+
+ /* "for each b-byte block of the padded message:" */
+ if (state->blockbits < 8 * CUBEHASH_BLOCKBYTES) return;
+
+ /* "xor the block into the first b bytes of the state" */
+ for (j = 0;j < CUBEHASH_BLOCKBYTES;++j) state->state[j] ^= state->block[j];
+ state->blockbits = 0;
+
+ /* "and then transform the state invertibly through r identical rounds" */
+ state_tox(state->state,x);
+ rrounds(x);
+ state_fromx(state->state,x);
+}
+
+HashReturn Update(hashState *state, const BitSequence *data,
+ DataLength databitlen)
+{
+ DataLength i;
+ BitSequence nextbit;
+
+ for (i = 0;i < databitlen;++i) {
+ nextbit = (data[i / 8] & mybit[i % 8]) / mybit[i % 8];
+ updatebit(state,nextbit);
+ }
+ return SUCCESS;
+}
+
+HashReturn Final(hashState *state, BitSequence *hashval)
+{
+ myuint32 x[2][2][2][2][2];
+ int i;
+
+ /* "append a 1 bit to the input message;" */
+ updatebit(state,1);
+
+ /* "then append the minimum possible number of 0 bits" */
+ /* "to reach a multiple of 8b bits" */
+ while (state->blockbits != 0) updatebit(state,0);
+
+ /* "the integer 1 is xored into the last state word x_11111" */
+ state_tox(state->state,x);
+ x[1][1][1][1][1] ^= 1;
+
+ /* "the state is then transformed invertibly through 10r identical rounds" */
+ for (i = 0;i < 10;++i) rrounds(x);
+ state_fromx(state->state,x);
+
+ /* "output the first h/8 bytes of the state" */
+ for (i = 0;i < state->hashbitlen / 8;++i) hashval[i] = state->state[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);
+}
View
31 crypto_hash/cubehash81/spec/cubehash.h
@@ -0,0 +1,31 @@
+/*
+20081106
+D. J. Bernstein
+Public domain.
+*/
+
+#ifndef cubehash_h
+#define cubehash_h
+
+typedef unsigned char BitSequence;
+typedef unsigned long long DataLength;
+typedef enum { SUCCESS = 0, FAIL = 1, BAD_HASHBITLEN = 2 } HashReturn;
+
+typedef struct {
+ int hashbitlen;
+ unsigned char state[128];
+ unsigned char block[128];
+ int blockbits;
+} hashState;
+
+HashReturn Init(hashState *state, int hashbitlen);
+
+HashReturn Update(hashState *state, const BitSequence *data,
+ DataLength databitlen);
+
+HashReturn Final(hashState *state, BitSequence *hashval);
+
+HashReturn Hash(int hashbitlen, const BitSequence *data,
+ DataLength databitlen, BitSequence *hashval);
+
+#endif
View
14 crypto_hash/cubehash81/spec/nist.c
@@ -0,0 +1,14 @@
+/*
+20081106
+D. J. Bernstein
+Public domain.
+*/
+
+#include "crypto_hash.h"
+#include "nist.h"
+
+int crypto_hash(unsigned char *out,const unsigned char *in,unsigned long long inlen)
+{
+ if (Hash(crypto_hash_BYTES * 8,in,inlen * 8,out) == SUCCESS) return 0;
+ return -1;
+}
View
1 crypto_hash/cubehash81/spec/nist.h
@@ -0,0 +1 @@
+#include "cubehash.h"
View
2 crypto_hash/cubehash81/spec/parameters.h
@@ -0,0 +1,2 @@
+#define CUBEHASH_ROUNDS 8 /* this is r for CubeHashr/b */
+#define CUBEHASH_BLOCKBYTES 1 /* this is b for CubeHashr/b */
View
2 do
@@ -1,7 +1,7 @@
#!/bin/sh -e
# supercop/do
-version=20081105
+version=20081106
# D. J. Bernstein
# Public domain.
View
4 inttypes/do
@@ -6,15 +6,15 @@ okabi | (
(
echo 'int8 signed char'
echo 'int16 short'
- echo 'int32 long'
echo 'int32 int'
+ echo 'int32 long'
echo 'int64 long long'
echo 'int64 long'
echo 'int64 int __attribute__((__mode__(__DI__)))'
echo 'uint8 unsigned char'
echo 'uint16 unsigned short'
- echo 'uint32 unsigned long'
echo 'uint32 unsigned int'
+ echo 'uint32 unsigned long'
echo 'uint64 unsigned long long'
echo 'uint64 unsigned long'
echo 'uint64 unsigned int __attribute__((__mode__(__DI__)))'
View
2 okcompilers/do
@@ -88,7 +88,7 @@ do
done
abi=`awk '{print length($0),$0}' < c-compatible \
- | sort -n | head -1 | sed 's/ *$//' | sed 's/^[^ ]* //' | tr ' ' '_'`
+ | sort -n | head -1 | sed 's/ *$//' | sed 's/^[^ ]* //' | tr ' /' '__'`
echo "echo '"$abi"'" >&7

0 comments on commit 757faff

Please sign in to comment.
Something went wrong with that request. Please try again.