Changeset View
Changeset View
Standalone View
Standalone View
sys/crypto/skein/skein.c
/*********************************************************************** | /*********************************************************************** | ||||
** | ** | ||||
** Implementation of the Skein hash function. | ** Implementation of the Skein hash function. | ||||
** | ** | ||||
** Source code author: Doug Whiting, 2008. | ** Source code author: Doug Whiting, 2008. | ||||
** | ** | ||||
** This algorithm and source code is released to the public domain. | ** This algorithm and source code is released to the public domain. | ||||
** | ** | ||||
************************************************************************/ | ************************************************************************/ | ||||
#include <sys/cdefs.h> | |||||
__FBSDID("$FreeBSD$"); | |||||
#include <sys/endian.h> | |||||
#include <sys/types.h> | |||||
/* get the memcpy/memset functions */ | |||||
#ifdef _KERNEL | |||||
#include <sys/systm.h> | |||||
#else | |||||
#include <string.h> | |||||
#endif | |||||
#define SKEIN_PORT_CODE /* instantiate any code in skein_port.h */ | #define SKEIN_PORT_CODE /* instantiate any code in skein_port.h */ | ||||
#include <string.h> /* get the memcpy/memset functions */ | |||||
#include "skein.h" /* get the Skein API definitions */ | #include "skein.h" /* get the Skein API definitions */ | ||||
#include "skein_iv.h" /* get precomputed IVs */ | #include "skein_iv.h" /* get precomputed IVs */ | ||||
/*****************************************************************/ | /*****************************************************************/ | ||||
/* External function to process blkCnt (nonzero) full block(s) of data. */ | /* External function to process blkCnt (nonzero) full block(s) of data. */ | ||||
void Skein_256_Process_Block(Skein_256_Ctxt_t *ctx,const u08b_t *blkPtr,size_t blkCnt,size_t byteCntAdd); | void Skein_256_Process_Block(Skein_256_Ctxt_t *ctx,const u08b_t *blkPtr,size_t blkCnt,size_t byteCntAdd); | ||||
void Skein_512_Process_Block(Skein_512_Ctxt_t *ctx,const u08b_t *blkPtr,size_t blkCnt,size_t byteCntAdd); | void Skein_512_Process_Block(Skein_512_Ctxt_t *ctx,const u08b_t *blkPtr,size_t blkCnt,size_t byteCntAdd); | ||||
void Skein1024_Process_Block(Skein1024_Ctxt_t *ctx,const u08b_t *blkPtr,size_t blkCnt,size_t byteCntAdd); | void Skein1024_Process_Block(Skein1024_Ctxt_t *ctx,const u08b_t *blkPtr,size_t blkCnt,size_t byteCntAdd); | ||||
▲ Show 20 Lines • Show All 723 Lines • ▼ Show 20 Lines | for (i=0;i*SKEIN1024_BLOCK_BYTES < byteCnt;i++) | ||||
if (n >= SKEIN1024_BLOCK_BYTES) | if (n >= SKEIN1024_BLOCK_BYTES) | ||||
n = SKEIN1024_BLOCK_BYTES; | n = SKEIN1024_BLOCK_BYTES; | ||||
Skein_Put64_LSB_First(hashVal+i*SKEIN1024_BLOCK_BYTES,ctx->X,n); /* "output" the ctr mode bytes */ | Skein_Put64_LSB_First(hashVal+i*SKEIN1024_BLOCK_BYTES,ctx->X,n); /* "output" the ctr mode bytes */ | ||||
Skein_Show_Final(256,&ctx->h,n,hashVal+i*SKEIN1024_BLOCK_BYTES); | Skein_Show_Final(256,&ctx->h,n,hashVal+i*SKEIN1024_BLOCK_BYTES); | ||||
memcpy(ctx->X,X,sizeof(X)); /* restore the counter mode key for next time */ | memcpy(ctx->X,X,sizeof(X)); /* restore the counter mode key for next time */ | ||||
} | } | ||||
return SKEIN_SUCCESS; | return SKEIN_SUCCESS; | ||||
} | } | ||||
/* Adapt the functions to match the prototype expected by libmd */ | |||||
void | |||||
SKEIN256_Init(SKEIN256_CTX * ctx) | |||||
{ | |||||
Skein_256_Init(ctx, 256); | |||||
} | |||||
void | |||||
SKEIN512_Init(SKEIN512_CTX * ctx) | |||||
{ | |||||
Skein_512_Init(ctx, 512); | |||||
} | |||||
void | |||||
SKEIN1024_Init(SKEIN1024_CTX * ctx) | |||||
{ | |||||
Skein1024_Init(ctx, 1024); | |||||
} | |||||
void | |||||
SKEIN256_Update(SKEIN256_CTX * ctx, const void *in, size_t len) | |||||
{ | |||||
Skein_256_Update(ctx, in, len); | |||||
} | |||||
void | |||||
SKEIN512_Update(SKEIN512_CTX * ctx, const void *in, size_t len) | |||||
{ | |||||
Skein_512_Update(ctx, in, len); | |||||
} | |||||
void | |||||
SKEIN1024_Update(SKEIN1024_CTX * ctx, const void *in, size_t len) | |||||
{ | |||||
Skein1024_Update(ctx, in, len); | |||||
} | |||||
void | |||||
SKEIN256_Final(unsigned char digest[static SKEIN_256_BLOCK_BYTES], SKEIN256_CTX *ctx) | |||||
{ | |||||
Skein_256_Final(ctx, digest); | |||||
} | |||||
void | |||||
SKEIN512_Final(unsigned char digest[static SKEIN_512_BLOCK_BYTES], SKEIN512_CTX *ctx) | |||||
{ | |||||
Skein_512_Final(ctx, digest); | |||||
} | |||||
void | |||||
SKEIN1024_Final(unsigned char digest[static SKEIN1024_BLOCK_BYTES], SKEIN1024_CTX *ctx) | |||||
{ | |||||
Skein1024_Final(ctx, digest); | |||||
} | |||||
#ifdef WEAK_REFS | |||||
/* When building libmd, provide weak references. Note: this is not | |||||
activated in the context of compiling these sources for internal | |||||
use in libcrypt. | |||||
*/ | |||||
#undef SKEIN256_Init | |||||
__weak_reference(_libmd_SKEIN256_Init, SKEIN256_Init); | |||||
#undef SKEIN256_Update | |||||
__weak_reference(_libmd_SKEIN256_Update, SKEIN256_Update); | |||||
#undef SKEIN256_Final | |||||
__weak_reference(_libmd_SKEIN256_Final, SKEIN256_Final); | |||||
#undef SKEIN512_Init | |||||
__weak_reference(_libmd_SKEIN512_Init, SKEIN512_Init); | |||||
#undef SKEIN512_Update | |||||
__weak_reference(_libmd_SKEIN512_Update, SKEIN512_Update); | |||||
#undef SKEIN512_Final | |||||
__weak_reference(_libmd_SKEIN512_Final, SKEIN512_Final); | |||||
#undef SKEIN1024_Init | |||||
__weak_reference(_libmd_SKEIN1024_Init, SKEIN1024_Init); | |||||
#undef SKEIN1024_Update | |||||
__weak_reference(_libmd_SKEIN1024_Update, SKEIN1024_Update); | |||||
#undef SKEIN1024_Final | |||||
__weak_reference(_libmd_SKEIN1024_Final, SKEIN1024_Final); | |||||
#endif | |||||
#endif | #endif |