+++ /dev/null
-/***********************************************************************\r
-**\r
-** Implementation of the AHS API using the Skein hash function.\r
-**\r
-** Source code author: Doug Whiting, 2008.\r
-**\r
-** This algorithm and source code is released to the public domain.\r
-** \r
-************************************************************************/\r
-\r
-#include <string.h> /* get the memcpy/memset functions */\r
-#include "skein.h" /* get the Skein API definitions */\r
-#include "SHA3api_ref.h"/* get the AHS API definitions */\r
-
-//#define SKEIN_DEBUG 1
-#ifdef SKEIN_DEBUG
-# include <stdio.h>
-# include <stdlib.h>
-# include <string.h>
-#endif
-
-\r
-/******************************************************************/\r
-/* AHS API code */\r
-/******************************************************************/\r
-\r
-/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/\r
-/* select the context size and init the context */\r
-HashReturn Init(hashState *state, int hashbitlen)\r
- {\r
-#if SKEIN_256_NIST_MAX_HASH_BITS\r
- if (hashbitlen <= SKEIN_256_NIST_MAX_HASHBITS)\r
- {\r
- Skein_Assert(hashbitlen > 0,BAD_HASHLEN);\r
- state->statebits = 64*SKEIN_256_STATE_WORDS;\r
- return Skein_256_Init(&state->u.ctx_256,(size_t) hashbitlen);\r
- }\r
-#endif\r
- if (hashbitlen <= SKEIN_512_NIST_MAX_HASHBITS)\r
- {\r
- state->statebits = 64*SKEIN_512_STATE_WORDS;\r
- return Skein_512_Init(&state->u.ctx_512,(size_t) hashbitlen);\r
- }\r
- else\r
- {\r
- state->statebits = 64*SKEIN1024_STATE_WORDS;\r
- return Skein1024_Init(&state->u.ctx1024,(size_t) hashbitlen);\r
- }\r
- }\r
-\r
-/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/\r
-/* process data to be hashed */\r
-HashReturn Update(hashState *state, const BitSequence *data, DataLength databitlen)\r
- {\r
- /* only the final Update() call is allowed do partial bytes, else assert an error */\r
- Skein_Assert((state->u.h.T[1] & SKEIN_T1_FLAG_BIT_PAD) == 0 || databitlen == 0, FAIL);\r
-\r
- Skein_Assert(state->statebits % 256 == 0 && (state->statebits-256) < 1024,FAIL);\r
- if ((databitlen & 7) == 0) /* partial bytes? */\r
- {\r
- switch ((state->statebits >> 8) & 3)\r
- {\r
- case 2: return Skein_512_Update(&state->u.ctx_512,data,databitlen >> 3);\r
- case 1: return Skein_256_Update(&state->u.ctx_256,data,databitlen >> 3);\r
- case 0: return Skein1024_Update(&state->u.ctx1024,data,databitlen >> 3);\r
- default: return FAIL;\r
- }\r
- }\r
- else\r
- { /* handle partial final byte */\r
- size_t bCnt = (databitlen >> 3) + 1; /* number of bytes to handle (nonzero here!) */\r
- u08b_t b,mask;\r
-\r
- mask = (u08b_t) (1u << (7 - (databitlen & 7))); /* partial byte bit mask */\r
- b = (u08b_t) ((data[bCnt-1] & (0-mask)) | mask); /* apply bit padding on final byte */\r
-\r
- switch ((state->statebits >> 8) & 3)\r
- {\r
- case 2: Skein_512_Update(&state->u.ctx_512,data,bCnt-1); /* process all but the final byte */\r
- Skein_512_Update(&state->u.ctx_512,&b , 1 ); /* process the (masked) partial byte */\r
- break;\r
- case 1: Skein_256_Update(&state->u.ctx_256,data,bCnt-1); /* process all but the final byte */\r
- Skein_256_Update(&state->u.ctx_256,&b , 1 ); /* process the (masked) partial byte */\r
- break;\r
- case 0: Skein1024_Update(&state->u.ctx1024,data,bCnt-1); /* process all but the final byte */\r
- Skein1024_Update(&state->u.ctx1024,&b , 1 ); /* process the (masked) partial byte */\r
- break;\r
- default: return FAIL;\r
- }\r
- Skein_Set_Bit_Pad_Flag(state->u.h); /* set tweak flag for the final call */\r
- \r
- return SUCCESS;\r
- }\r
- }\r
-\r
-/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/\r
-/* finalize hash computation and output the result (hashbitlen bits) */\r
-HashReturn Final(hashState *state, BitSequence *hashval)\r
- {\r
- Skein_Assert(state->statebits % 256 == 0 && (state->statebits-256) < 1024,FAIL);\r
- switch ((state->statebits >> 8) & 3)\r
- {\r
- case 2: return Skein_512_Final(&state->u.ctx_512,hashval);\r
- case 1: return Skein_256_Final(&state->u.ctx_256,hashval);\r
- case 0: return Skein1024_Final(&state->u.ctx1024,hashval);\r
- default: return FAIL;\r
- }\r
- }\r
-\r
-/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/\r
-/* all-in-one hash function */\r
-HashReturn Hash(int hashbitlen, const BitSequence *data, /* all-in-one call */\r
- DataLength databitlen,BitSequence *hashval)\r
- {\r
- hashState state;\r
- HashReturn r = Init(&state,hashbitlen);\r
- if (r == SUCCESS)\r
- { /* these calls do not fail when called properly */\r
- r = Update(&state,data,databitlen);\r
- Final(&state,hashval);\r
-#ifdef SKEIN_DEBUG
- if (r == SUCCESS && getenv("SKEIN_DEEP_DUMP"))
- {
- int i;
- printf("==== Hashbitlen = %d, DataBitLen = %llu, Data:\n%s\n==== Hash:\n",
- hashbitlen, (long long unsigned)databitlen, (const char*)data);
- for (i = 0; i < hashbitlen / 8; i++)
- printf("%02X", hashval[i]);
- printf("\n");
- }
-#endif
- }\r
- return r;\r
- }\r
+++ /dev/null
-#ifndef _AHS_API_H_\r
-#define _AHS_API_H_\r
-\r
-/***********************************************************************\r
-**\r
-** Interface declarations of the AHS API using the Skein hash function.\r
-**\r
-** Source code author: Doug Whiting, 2008.\r
-**\r
-** This algorithm and source code is released to the public domain.\r
-** \r
-************************************************************************/\r
-\r
-#include "skein.h"\r
-\r
-typedef enum\r
- {\r
- SUCCESS = SKEIN_SUCCESS,\r
- FAIL = SKEIN_FAIL,\r
- BAD_HASHLEN = SKEIN_BAD_HASHLEN\r
- }\r
- HashReturn;\r
-\r
-typedef size_t DataLength; /* bit count type */\r
-typedef u08b_t BitSequence; /* bit stream type */\r
-\r
-typedef struct\r
- {\r
- uint_t statebits; /* 256, 512, or 1024 */\r
- union\r
- {\r
- Skein_Ctxt_Hdr_t h; /* common header "overlay" */\r
- Skein_256_Ctxt_t ctx_256;\r
- Skein_512_Ctxt_t ctx_512;\r
- Skein1024_Ctxt_t ctx1024;\r
- } u;\r
- }\r
- hashState;\r
-\r
-/* "incremental" hashing API */\r
-HashReturn Init (hashState *state, int hashbitlen);\r
-HashReturn Update(hashState *state, const BitSequence *data, DataLength databitlen);\r
-HashReturn Final (hashState *state, BitSequence *hashval);\r
-\r
-/* "all-in-one" call */\r
-HashReturn Hash (int hashbitlen, const BitSequence *data, \r
- DataLength databitlen, BitSequence *hashval);\r
-\r
-\r
-/*\r
-** Re-define the compile-time constants below to change the selection\r
-** of the Skein state size in the Init() function in SHA3api_ref.c.\r
-**\r
-** That is, the NIST API does not allow for explicit selection of the\r
-** Skein block size, so it must be done implicitly in the Init() function.\r
-** The selection is controlled by these constants.\r
-*/\r
-#ifndef SKEIN_256_NIST_MAX_HASHBITS\r
-#define SKEIN_256_NIST_MAX_HASHBITS (0)\r
-#endif\r
-\r
-#ifndef SKEIN_512_NIST_MAX_HASHBITS\r
-#define SKEIN_512_NIST_MAX_HASHBITS (512)\r
-#endif\r
-\r
-#endif /* ifdef _AHS_API_H_ */\r
bin_PROGRAMS = skein256sum skein512sum skein1024sum
-skein256sum_SOURCES = SHA3api_ref.c skein.c skein256.c skein_block.c skein_debug.c skein_cli.c
-skein512sum_SOURCES = SHA3api_ref.c skein.c skein512.c skein_block.c skein_debug.c skein_cli.c
-skein1024sum_SOURCES = SHA3api_ref.c skein.c skein1024.c skein_block.c skein_debug.c skein_cli.c
-include_HEADERS = brg_endian.h brg_types.h SHA3api_ref.h skein.h skein_debug.h skein_port.h
+skein256sum_SOURCES = skeinapi_ref.c skein.c skein256.c skein_block.c skein_debug.c skein_cli.c
+skein512sum_SOURCES = skeinapi_ref.c skein.c skein512.c skein_block.c skein_debug.c skein_cli.c
+skein1024sum_SOURCES = skeinapi_ref.c skein.c skein1024.c skein_block.c skein_debug.c skein_cli.c
+include_HEADERS = brg_endian.h brg_types.h skeinapi_ref.h skein.h skein_debug.h skein_port.h
#define SKEIN_VERSION (1)\r
\r
#ifndef SKEIN_ID_STRING_LE /* allow compile-time personalization */\r
-#define SKEIN_ID_STRING_LE (0x33414853) /* "SHA3" (little-endian)*/\r
+#define SKEIN_ID_STRING_LE (0x33414853) /* "skein" (little-endian)*/\r
#endif\r
\r
#define SKEIN_MK_64(hi32,lo32) ((lo32) + (((u64b_t) (hi32)) << 32))\r
#include <glob.h>
#include <sys/stat.h>
#include <errno.h>
-#include "SHA3api_ref.h"
+#include "skeinapi_ref.h"
#define WARN(msg, ...) fprintf(stderr, "skein%dsum: " msg, hashbitlen, ##__VA_ARGS__)
--- /dev/null
+/***********************************************************************\r
+**\r
+** Implementation of the AHS API using the Skein hash function.\r
+**\r
+** Source code author: Doug Whiting, 2008.\r
+**\r
+** This algorithm and source code is released to the public domain.\r
+** \r
+************************************************************************/\r
+\r
+#include <string.h> /* get the memcpy/memset functions */\r
+#include "skein.h" /* get the Skein API definitions */\r
+#include "skeinapi_ref.h"/* get the AHS API definitions */\r
+
+//#define SKEIN_DEBUG 1
+#ifdef SKEIN_DEBUG
+# include <stdio.h>
+# include <stdlib.h>
+# include <string.h>
+#endif
+
+\r
+/******************************************************************/\r
+/* AHS API code */\r
+/******************************************************************/\r
+\r
+/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/\r
+/* select the context size and init the context */\r
+HashReturn Init(hashState *state, int hashbitlen)\r
+ {\r
+#if SKEIN_256_NIST_MAX_HASH_BITS\r
+ if (hashbitlen <= SKEIN_256_NIST_MAX_HASHBITS)\r
+ {\r
+ Skein_Assert(hashbitlen > 0,BAD_HASHLEN);\r
+ state->statebits = 64*SKEIN_256_STATE_WORDS;\r
+ return Skein_256_Init(&state->u.ctx_256,(size_t) hashbitlen);\r
+ }\r
+#endif\r
+ if (hashbitlen <= SKEIN_512_NIST_MAX_HASHBITS)\r
+ {\r
+ state->statebits = 64*SKEIN_512_STATE_WORDS;\r
+ return Skein_512_Init(&state->u.ctx_512,(size_t) hashbitlen);\r
+ }\r
+ else\r
+ {\r
+ state->statebits = 64*SKEIN1024_STATE_WORDS;\r
+ return Skein1024_Init(&state->u.ctx1024,(size_t) hashbitlen);\r
+ }\r
+ }\r
+\r
+/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/\r
+/* process data to be hashed */\r
+HashReturn Update(hashState *state, const BitSequence *data, DataLength databitlen)\r
+ {\r
+ /* only the final Update() call is allowed do partial bytes, else assert an error */\r
+ Skein_Assert((state->u.h.T[1] & SKEIN_T1_FLAG_BIT_PAD) == 0 || databitlen == 0, FAIL);\r
+\r
+ Skein_Assert(state->statebits % 256 == 0 && (state->statebits-256) < 1024,FAIL);\r
+ if ((databitlen & 7) == 0) /* partial bytes? */\r
+ {\r
+ switch ((state->statebits >> 8) & 3)\r
+ {\r
+ case 2: return Skein_512_Update(&state->u.ctx_512,data,databitlen >> 3);\r
+ case 1: return Skein_256_Update(&state->u.ctx_256,data,databitlen >> 3);\r
+ case 0: return Skein1024_Update(&state->u.ctx1024,data,databitlen >> 3);\r
+ default: return FAIL;\r
+ }\r
+ }\r
+ else\r
+ { /* handle partial final byte */\r
+ size_t bCnt = (databitlen >> 3) + 1; /* number of bytes to handle (nonzero here!) */\r
+ u08b_t b,mask;\r
+\r
+ mask = (u08b_t) (1u << (7 - (databitlen & 7))); /* partial byte bit mask */\r
+ b = (u08b_t) ((data[bCnt-1] & (0-mask)) | mask); /* apply bit padding on final byte */\r
+\r
+ switch ((state->statebits >> 8) & 3)\r
+ {\r
+ case 2: Skein_512_Update(&state->u.ctx_512,data,bCnt-1); /* process all but the final byte */\r
+ Skein_512_Update(&state->u.ctx_512,&b , 1 ); /* process the (masked) partial byte */\r
+ break;\r
+ case 1: Skein_256_Update(&state->u.ctx_256,data,bCnt-1); /* process all but the final byte */\r
+ Skein_256_Update(&state->u.ctx_256,&b , 1 ); /* process the (masked) partial byte */\r
+ break;\r
+ case 0: Skein1024_Update(&state->u.ctx1024,data,bCnt-1); /* process all but the final byte */\r
+ Skein1024_Update(&state->u.ctx1024,&b , 1 ); /* process the (masked) partial byte */\r
+ break;\r
+ default: return FAIL;\r
+ }\r
+ Skein_Set_Bit_Pad_Flag(state->u.h); /* set tweak flag for the final call */\r
+ \r
+ return SUCCESS;\r
+ }\r
+ }\r
+\r
+/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/\r
+/* finalize hash computation and output the result (hashbitlen bits) */\r
+HashReturn Final(hashState *state, BitSequence *hashval)\r
+ {\r
+ Skein_Assert(state->statebits % 256 == 0 && (state->statebits-256) < 1024,FAIL);\r
+ switch ((state->statebits >> 8) & 3)\r
+ {\r
+ case 2: return Skein_512_Final(&state->u.ctx_512,hashval);\r
+ case 1: return Skein_256_Final(&state->u.ctx_256,hashval);\r
+ case 0: return Skein1024_Final(&state->u.ctx1024,hashval);\r
+ default: return FAIL;\r
+ }\r
+ }\r
+\r
+/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/\r
+/* all-in-one hash function */\r
+HashReturn Hash(int hashbitlen, const BitSequence *data, /* all-in-one call */\r
+ DataLength databitlen,BitSequence *hashval)\r
+ {\r
+ hashState state;\r
+ HashReturn r = Init(&state,hashbitlen);\r
+ if (r == SUCCESS)\r
+ { /* these calls do not fail when called properly */\r
+ r = Update(&state,data,databitlen);\r
+ Final(&state,hashval);\r
+#ifdef SKEIN_DEBUG
+ if (r == SUCCESS && getenv("SKEIN_DEEP_DUMP"))
+ {
+ int i;
+ printf("==== Hashbitlen = %d, DataBitLen = %llu, Data:\n%s\n==== Hash:\n",
+ hashbitlen, (long long unsigned)databitlen, (const char*)data);
+ for (i = 0; i < hashbitlen / 8; i++)
+ printf("%02X", hashval[i]);
+ printf("\n");
+ }
+#endif
+ }\r
+ return r;\r
+ }\r
--- /dev/null
+#ifndef _AHS_API_H_\r
+#define _AHS_API_H_\r
+\r
+/***********************************************************************\r
+**\r
+** Interface declarations of the AHS API using the Skein hash function.\r
+**\r
+** Source code author: Doug Whiting, 2008.\r
+**\r
+** This algorithm and source code is released to the public domain.\r
+** \r
+************************************************************************/\r
+\r
+#include "skein.h"\r
+\r
+typedef enum\r
+ {\r
+ SUCCESS = SKEIN_SUCCESS,\r
+ FAIL = SKEIN_FAIL,\r
+ BAD_HASHLEN = SKEIN_BAD_HASHLEN\r
+ }\r
+ HashReturn;\r
+\r
+typedef size_t DataLength; /* bit count type */\r
+typedef u08b_t BitSequence; /* bit stream type */\r
+\r
+typedef struct\r
+ {\r
+ uint_t statebits; /* 256, 512, or 1024 */\r
+ union\r
+ {\r
+ Skein_Ctxt_Hdr_t h; /* common header "overlay" */\r
+ Skein_256_Ctxt_t ctx_256;\r
+ Skein_512_Ctxt_t ctx_512;\r
+ Skein1024_Ctxt_t ctx1024;\r
+ } u;\r
+ }\r
+ hashState;\r
+\r
+/* "incremental" hashing API */\r
+HashReturn Init (hashState *state, int hashbitlen);\r
+HashReturn Update(hashState *state, const BitSequence *data, DataLength databitlen);\r
+HashReturn Final (hashState *state, BitSequence *hashval);\r
+\r
+/* "all-in-one" call */\r
+HashReturn Hash (int hashbitlen, const BitSequence *data, \r
+ DataLength databitlen, BitSequence *hashval);\r
+\r
+\r
+/*\r
+** Re-define the compile-time constants below to change the selection\r
+** of the Skein state size in the Init() function in skeinapi_ref.c.\r
+**\r
+** That is, the NIST API does not allow for explicit selection of the\r
+** Skein block size, so it must be done implicitly in the Init() function.\r
+** The selection is controlled by these constants.\r
+*/\r
+#ifndef SKEIN_256_NIST_MAX_HASHBITS\r
+#define SKEIN_256_NIST_MAX_HASHBITS (0)\r
+#endif\r
+\r
+#ifndef SKEIN_512_NIST_MAX_HASHBITS\r
+#define SKEIN_512_NIST_MAX_HASHBITS (512)\r
+#endif\r
+\r
+#endif /* ifdef _AHS_API_H_ */\r