From: Jason Self Date: Sun, 24 Feb 2019 21:04:03 +0000 (-0800) Subject: Remove SHA3 references X-Git-Url: https://jxself.org/git/?p=skeinsum.git;a=commitdiff_plain;h=c8a25186e510d8f15e54a5b4763e30e0ee9981f4 Remove SHA3 references Skein was one of the finalists in the NIST competition to develop a new hash function called SHA-3. Skein made it all the way through to the end but was ultimately not selected. Since skeinsum uses the reference implementation that was submitted to NIST for the SHA-3 competition it contained references to SHA3. This commit removes them, since Skein wasn't selected and isn't SHA-3. --- diff --git a/SHA3api_ref.c b/SHA3api_ref.c deleted file mode 100644 index cab5c69..0000000 --- a/SHA3api_ref.c +++ /dev/null @@ -1,134 +0,0 @@ -/*********************************************************************** -** -** Implementation of the AHS API using the Skein hash function. -** -** Source code author: Doug Whiting, 2008. -** -** This algorithm and source code is released to the public domain. -** -************************************************************************/ - -#include /* get the memcpy/memset functions */ -#include "skein.h" /* get the Skein API definitions */ -#include "SHA3api_ref.h"/* get the AHS API definitions */ - -//#define SKEIN_DEBUG 1 -#ifdef SKEIN_DEBUG -# include -# include -# include -#endif - - -/******************************************************************/ -/* AHS API code */ -/******************************************************************/ - -/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ -/* select the context size and init the context */ -HashReturn Init(hashState *state, int hashbitlen) - { -#if SKEIN_256_NIST_MAX_HASH_BITS - if (hashbitlen <= SKEIN_256_NIST_MAX_HASHBITS) - { - Skein_Assert(hashbitlen > 0,BAD_HASHLEN); - state->statebits = 64*SKEIN_256_STATE_WORDS; - return Skein_256_Init(&state->u.ctx_256,(size_t) hashbitlen); - } -#endif - if (hashbitlen <= SKEIN_512_NIST_MAX_HASHBITS) - { - state->statebits = 64*SKEIN_512_STATE_WORDS; - return Skein_512_Init(&state->u.ctx_512,(size_t) hashbitlen); - } - else - { - state->statebits = 64*SKEIN1024_STATE_WORDS; - return Skein1024_Init(&state->u.ctx1024,(size_t) hashbitlen); - } - } - -/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ -/* process data to be hashed */ -HashReturn Update(hashState *state, const BitSequence *data, DataLength databitlen) - { - /* only the final Update() call is allowed do partial bytes, else assert an error */ - Skein_Assert((state->u.h.T[1] & SKEIN_T1_FLAG_BIT_PAD) == 0 || databitlen == 0, FAIL); - - Skein_Assert(state->statebits % 256 == 0 && (state->statebits-256) < 1024,FAIL); - if ((databitlen & 7) == 0) /* partial bytes? */ - { - switch ((state->statebits >> 8) & 3) - { - case 2: return Skein_512_Update(&state->u.ctx_512,data,databitlen >> 3); - case 1: return Skein_256_Update(&state->u.ctx_256,data,databitlen >> 3); - case 0: return Skein1024_Update(&state->u.ctx1024,data,databitlen >> 3); - default: return FAIL; - } - } - else - { /* handle partial final byte */ - size_t bCnt = (databitlen >> 3) + 1; /* number of bytes to handle (nonzero here!) */ - u08b_t b,mask; - - mask = (u08b_t) (1u << (7 - (databitlen & 7))); /* partial byte bit mask */ - b = (u08b_t) ((data[bCnt-1] & (0-mask)) | mask); /* apply bit padding on final byte */ - - switch ((state->statebits >> 8) & 3) - { - case 2: Skein_512_Update(&state->u.ctx_512,data,bCnt-1); /* process all but the final byte */ - Skein_512_Update(&state->u.ctx_512,&b , 1 ); /* process the (masked) partial byte */ - break; - case 1: Skein_256_Update(&state->u.ctx_256,data,bCnt-1); /* process all but the final byte */ - Skein_256_Update(&state->u.ctx_256,&b , 1 ); /* process the (masked) partial byte */ - break; - case 0: Skein1024_Update(&state->u.ctx1024,data,bCnt-1); /* process all but the final byte */ - Skein1024_Update(&state->u.ctx1024,&b , 1 ); /* process the (masked) partial byte */ - break; - default: return FAIL; - } - Skein_Set_Bit_Pad_Flag(state->u.h); /* set tweak flag for the final call */ - - return SUCCESS; - } - } - -/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ -/* finalize hash computation and output the result (hashbitlen bits) */ -HashReturn Final(hashState *state, BitSequence *hashval) - { - Skein_Assert(state->statebits % 256 == 0 && (state->statebits-256) < 1024,FAIL); - switch ((state->statebits >> 8) & 3) - { - case 2: return Skein_512_Final(&state->u.ctx_512,hashval); - case 1: return Skein_256_Final(&state->u.ctx_256,hashval); - case 0: return Skein1024_Final(&state->u.ctx1024,hashval); - default: return FAIL; - } - } - -/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ -/* all-in-one hash function */ -HashReturn Hash(int hashbitlen, const BitSequence *data, /* all-in-one call */ - DataLength databitlen,BitSequence *hashval) - { - hashState state; - HashReturn r = Init(&state,hashbitlen); - if (r == SUCCESS) - { /* these calls do not fail when called properly */ - r = Update(&state,data,databitlen); - Final(&state,hashval); -#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 - } - return r; - } diff --git a/SHA3api_ref.h b/SHA3api_ref.h deleted file mode 100644 index 93e81f6..0000000 --- a/SHA3api_ref.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef _AHS_API_H_ -#define _AHS_API_H_ - -/*********************************************************************** -** -** Interface declarations of the AHS API using the Skein hash function. -** -** Source code author: Doug Whiting, 2008. -** -** This algorithm and source code is released to the public domain. -** -************************************************************************/ - -#include "skein.h" - -typedef enum - { - SUCCESS = SKEIN_SUCCESS, - FAIL = SKEIN_FAIL, - BAD_HASHLEN = SKEIN_BAD_HASHLEN - } - HashReturn; - -typedef size_t DataLength; /* bit count type */ -typedef u08b_t BitSequence; /* bit stream type */ - -typedef struct - { - uint_t statebits; /* 256, 512, or 1024 */ - union - { - Skein_Ctxt_Hdr_t h; /* common header "overlay" */ - Skein_256_Ctxt_t ctx_256; - Skein_512_Ctxt_t ctx_512; - Skein1024_Ctxt_t ctx1024; - } u; - } - hashState; - -/* "incremental" hashing API */ -HashReturn Init (hashState *state, int hashbitlen); -HashReturn Update(hashState *state, const BitSequence *data, DataLength databitlen); -HashReturn Final (hashState *state, BitSequence *hashval); - -/* "all-in-one" call */ -HashReturn Hash (int hashbitlen, const BitSequence *data, - DataLength databitlen, BitSequence *hashval); - - -/* -** Re-define the compile-time constants below to change the selection -** of the Skein state size in the Init() function in SHA3api_ref.c. -** -** That is, the NIST API does not allow for explicit selection of the -** Skein block size, so it must be done implicitly in the Init() function. -** The selection is controlled by these constants. -*/ -#ifndef SKEIN_256_NIST_MAX_HASHBITS -#define SKEIN_256_NIST_MAX_HASHBITS (0) -#endif - -#ifndef SKEIN_512_NIST_MAX_HASHBITS -#define SKEIN_512_NIST_MAX_HASHBITS (512) -#endif - -#endif /* ifdef _AHS_API_H_ */ diff --git a/makefile.am b/makefile.am index 741052d..567b923 100644 --- a/makefile.am +++ b/makefile.am @@ -1,5 +1,5 @@ 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 diff --git a/skein.h b/skein.h index b4717ff..7160fc6 100644 --- a/skein.h +++ b/skein.h @@ -192,7 +192,7 @@ int Skein1024_Output (Skein1024_Ctxt_t *ctx, u08b_t * hashVal); #define SKEIN_VERSION (1) #ifndef SKEIN_ID_STRING_LE /* allow compile-time personalization */ -#define SKEIN_ID_STRING_LE (0x33414853) /* "SHA3" (little-endian)*/ +#define SKEIN_ID_STRING_LE (0x33414853) /* "skein" (little-endian)*/ #endif #define SKEIN_MK_64(hi32,lo32) ((lo32) + (((u64b_t) (hi32)) << 32)) diff --git a/skein_cli.c b/skein_cli.c index 34c2a6a..bb82354 100644 --- a/skein_cli.c +++ b/skein_cli.c @@ -29,7 +29,7 @@ along with skeinsum. If not, see . #include #include #include -#include "SHA3api_ref.h" +#include "skeinapi_ref.h" #define WARN(msg, ...) fprintf(stderr, "skein%dsum: " msg, hashbitlen, ##__VA_ARGS__) diff --git a/skeinapi_ref.c b/skeinapi_ref.c new file mode 100644 index 0000000..cedcceb --- /dev/null +++ b/skeinapi_ref.c @@ -0,0 +1,134 @@ +/*********************************************************************** +** +** Implementation of the AHS API using the Skein hash function. +** +** Source code author: Doug Whiting, 2008. +** +** This algorithm and source code is released to the public domain. +** +************************************************************************/ + +#include /* get the memcpy/memset functions */ +#include "skein.h" /* get the Skein API definitions */ +#include "skeinapi_ref.h"/* get the AHS API definitions */ + +//#define SKEIN_DEBUG 1 +#ifdef SKEIN_DEBUG +# include +# include +# include +#endif + + +/******************************************************************/ +/* AHS API code */ +/******************************************************************/ + +/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +/* select the context size and init the context */ +HashReturn Init(hashState *state, int hashbitlen) + { +#if SKEIN_256_NIST_MAX_HASH_BITS + if (hashbitlen <= SKEIN_256_NIST_MAX_HASHBITS) + { + Skein_Assert(hashbitlen > 0,BAD_HASHLEN); + state->statebits = 64*SKEIN_256_STATE_WORDS; + return Skein_256_Init(&state->u.ctx_256,(size_t) hashbitlen); + } +#endif + if (hashbitlen <= SKEIN_512_NIST_MAX_HASHBITS) + { + state->statebits = 64*SKEIN_512_STATE_WORDS; + return Skein_512_Init(&state->u.ctx_512,(size_t) hashbitlen); + } + else + { + state->statebits = 64*SKEIN1024_STATE_WORDS; + return Skein1024_Init(&state->u.ctx1024,(size_t) hashbitlen); + } + } + +/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +/* process data to be hashed */ +HashReturn Update(hashState *state, const BitSequence *data, DataLength databitlen) + { + /* only the final Update() call is allowed do partial bytes, else assert an error */ + Skein_Assert((state->u.h.T[1] & SKEIN_T1_FLAG_BIT_PAD) == 0 || databitlen == 0, FAIL); + + Skein_Assert(state->statebits % 256 == 0 && (state->statebits-256) < 1024,FAIL); + if ((databitlen & 7) == 0) /* partial bytes? */ + { + switch ((state->statebits >> 8) & 3) + { + case 2: return Skein_512_Update(&state->u.ctx_512,data,databitlen >> 3); + case 1: return Skein_256_Update(&state->u.ctx_256,data,databitlen >> 3); + case 0: return Skein1024_Update(&state->u.ctx1024,data,databitlen >> 3); + default: return FAIL; + } + } + else + { /* handle partial final byte */ + size_t bCnt = (databitlen >> 3) + 1; /* number of bytes to handle (nonzero here!) */ + u08b_t b,mask; + + mask = (u08b_t) (1u << (7 - (databitlen & 7))); /* partial byte bit mask */ + b = (u08b_t) ((data[bCnt-1] & (0-mask)) | mask); /* apply bit padding on final byte */ + + switch ((state->statebits >> 8) & 3) + { + case 2: Skein_512_Update(&state->u.ctx_512,data,bCnt-1); /* process all but the final byte */ + Skein_512_Update(&state->u.ctx_512,&b , 1 ); /* process the (masked) partial byte */ + break; + case 1: Skein_256_Update(&state->u.ctx_256,data,bCnt-1); /* process all but the final byte */ + Skein_256_Update(&state->u.ctx_256,&b , 1 ); /* process the (masked) partial byte */ + break; + case 0: Skein1024_Update(&state->u.ctx1024,data,bCnt-1); /* process all but the final byte */ + Skein1024_Update(&state->u.ctx1024,&b , 1 ); /* process the (masked) partial byte */ + break; + default: return FAIL; + } + Skein_Set_Bit_Pad_Flag(state->u.h); /* set tweak flag for the final call */ + + return SUCCESS; + } + } + +/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +/* finalize hash computation and output the result (hashbitlen bits) */ +HashReturn Final(hashState *state, BitSequence *hashval) + { + Skein_Assert(state->statebits % 256 == 0 && (state->statebits-256) < 1024,FAIL); + switch ((state->statebits >> 8) & 3) + { + case 2: return Skein_512_Final(&state->u.ctx_512,hashval); + case 1: return Skein_256_Final(&state->u.ctx_256,hashval); + case 0: return Skein1024_Final(&state->u.ctx1024,hashval); + default: return FAIL; + } + } + +/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +/* all-in-one hash function */ +HashReturn Hash(int hashbitlen, const BitSequence *data, /* all-in-one call */ + DataLength databitlen,BitSequence *hashval) + { + hashState state; + HashReturn r = Init(&state,hashbitlen); + if (r == SUCCESS) + { /* these calls do not fail when called properly */ + r = Update(&state,data,databitlen); + Final(&state,hashval); +#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 + } + return r; + } diff --git a/skeinapi_ref.h b/skeinapi_ref.h new file mode 100644 index 0000000..9aa4fdb --- /dev/null +++ b/skeinapi_ref.h @@ -0,0 +1,66 @@ +#ifndef _AHS_API_H_ +#define _AHS_API_H_ + +/*********************************************************************** +** +** Interface declarations of the AHS API using the Skein hash function. +** +** Source code author: Doug Whiting, 2008. +** +** This algorithm and source code is released to the public domain. +** +************************************************************************/ + +#include "skein.h" + +typedef enum + { + SUCCESS = SKEIN_SUCCESS, + FAIL = SKEIN_FAIL, + BAD_HASHLEN = SKEIN_BAD_HASHLEN + } + HashReturn; + +typedef size_t DataLength; /* bit count type */ +typedef u08b_t BitSequence; /* bit stream type */ + +typedef struct + { + uint_t statebits; /* 256, 512, or 1024 */ + union + { + Skein_Ctxt_Hdr_t h; /* common header "overlay" */ + Skein_256_Ctxt_t ctx_256; + Skein_512_Ctxt_t ctx_512; + Skein1024_Ctxt_t ctx1024; + } u; + } + hashState; + +/* "incremental" hashing API */ +HashReturn Init (hashState *state, int hashbitlen); +HashReturn Update(hashState *state, const BitSequence *data, DataLength databitlen); +HashReturn Final (hashState *state, BitSequence *hashval); + +/* "all-in-one" call */ +HashReturn Hash (int hashbitlen, const BitSequence *data, + DataLength databitlen, BitSequence *hashval); + + +/* +** Re-define the compile-time constants below to change the selection +** of the Skein state size in the Init() function in skeinapi_ref.c. +** +** That is, the NIST API does not allow for explicit selection of the +** Skein block size, so it must be done implicitly in the Init() function. +** The selection is controlled by these constants. +*/ +#ifndef SKEIN_256_NIST_MAX_HASHBITS +#define SKEIN_256_NIST_MAX_HASHBITS (0) +#endif + +#ifndef SKEIN_512_NIST_MAX_HASHBITS +#define SKEIN_512_NIST_MAX_HASHBITS (512) +#endif + +#endif /* ifdef _AHS_API_H_ */