Loading drivers/staging/skein/include/skein.h +12 −18 Original line number Diff line number Diff line Loading @@ -37,8 +37,7 @@ #define Skein_Get64_LSB_First(dst64, src08, wCnt) memcpy(dst64, src08, 8*(wCnt)) #define Skein_Swap64(w64) (w64) enum { enum { SKEIN_SUCCESS = 0, /* return codes from Skein calls */ SKEIN_FAIL = 1, SKEIN_BAD_HASHLEN = 2 Loading @@ -63,29 +62,25 @@ enum #define SKEIN_512_BLOCK_BYTES (8*SKEIN_512_STATE_WORDS) #define SKEIN1024_BLOCK_BYTES (8*SKEIN1024_STATE_WORDS) struct skein_ctx_hdr { struct skein_ctx_hdr { size_t hashBitLen; /* size of hash result, in bits */ size_t bCnt; /* current byte count in buffer b[] */ u64 T[SKEIN_MODIFIER_WORDS]; /* tweak: T[0]=byte cnt, T[1]=flags */ }; struct skein_256_ctx /* 256-bit Skein hash context structure */ { struct skein_256_ctx { /* 256-bit Skein hash context structure */ struct skein_ctx_hdr h; /* common header context variables */ u64 X[SKEIN_256_STATE_WORDS]; /* chaining variables */ u8 b[SKEIN_256_BLOCK_BYTES]; /* partial block buf (8-byte aligned) */ }; struct skein_512_ctx /* 512-bit Skein hash context structure */ { struct skein_512_ctx { /* 512-bit Skein hash context structure */ struct skein_ctx_hdr h; /* common header context variables */ u64 X[SKEIN_512_STATE_WORDS]; /* chaining variables */ u8 b[SKEIN_512_BLOCK_BYTES]; /* partial block buf (8-byte aligned) */ }; struct skein1024_ctx /* 1024-bit Skein hash context structure */ { struct skein1024_ctx { /* 1024-bit Skein hash context structure */ struct skein_ctx_hdr h; /* common header context variables */ u64 X[SKEIN1024_STATE_WORDS]; /* chaining variables */ u8 b[SKEIN1024_BLOCK_BYTES]; /* partial block buf (8-byte aligned) */ Loading Loading @@ -296,8 +291,7 @@ int Skein1024_Output(struct skein1024_ctx *ctx, u8 *hashVal); /***************************************************************** ** Skein block function constants (shared across Ref and Opt code) ******************************************************************/ enum { enum { /* Skein_256 round rotation constants */ R_256_0_0 = 14, R_256_0_1 = 16, R_256_1_0 = 52, R_256_1_1 = 57, Loading drivers/staging/skein/include/skein_iv.h +26 −39 Original line number Diff line number Diff line Loading @@ -20,8 +20,7 @@ #define MK_64 SKEIN_MK_64 /* blkSize = 256 bits. hashSize = 128 bits */ const u64 SKEIN_256_IV_128[] = { const u64 SKEIN_256_IV_128[] = { MK_64(0xE1111906, 0x964D7260), MK_64(0x883DAAA7, 0x7C8D811C), MK_64(0x10080DF4, 0x91960F7A), Loading @@ -29,8 +28,7 @@ const u64 SKEIN_256_IV_128[] = }; /* blkSize = 256 bits. hashSize = 160 bits */ const u64 SKEIN_256_IV_160[] = { const u64 SKEIN_256_IV_160[] = { MK_64(0x14202314, 0x72825E98), MK_64(0x2AC4E9A2, 0x5A77E590), MK_64(0xD47A5856, 0x8838D63E), Loading @@ -38,8 +36,7 @@ const u64 SKEIN_256_IV_160[] = }; /* blkSize = 256 bits. hashSize = 224 bits */ const u64 SKEIN_256_IV_224[] = { const u64 SKEIN_256_IV_224[] = { MK_64(0xC6098A8C, 0x9AE5EA0B), MK_64(0x876D5686, 0x08C5191C), MK_64(0x99CB88D7, 0xD7F53884), Loading @@ -47,8 +44,7 @@ const u64 SKEIN_256_IV_224[] = }; /* blkSize = 256 bits. hashSize = 256 bits */ const u64 SKEIN_256_IV_256[] = { const u64 SKEIN_256_IV_256[] = { MK_64(0xFC9DA860, 0xD048B449), MK_64(0x2FCA6647, 0x9FA7D833), MK_64(0xB33BC389, 0x6656840F), Loading @@ -56,8 +52,7 @@ const u64 SKEIN_256_IV_256[] = }; /* blkSize = 512 bits. hashSize = 128 bits */ const u64 SKEIN_512_IV_128[] = { const u64 SKEIN_512_IV_128[] = { MK_64(0xA8BC7BF3, 0x6FBF9F52), MK_64(0x1E9872CE, 0xBD1AF0AA), MK_64(0x309B1790, 0xB32190D3), Loading @@ -69,8 +64,7 @@ const u64 SKEIN_512_IV_128[] = }; /* blkSize = 512 bits. hashSize = 160 bits */ const u64 SKEIN_512_IV_160[] = { const u64 SKEIN_512_IV_160[] = { MK_64(0x28B81A2A, 0xE013BD91), MK_64(0xC2F11668, 0xB5BDF78F), MK_64(0x1760D8F3, 0xF6A56F12), Loading @@ -82,8 +76,7 @@ const u64 SKEIN_512_IV_160[] = }; /* blkSize = 512 bits. hashSize = 224 bits */ const u64 SKEIN_512_IV_224[] = { const u64 SKEIN_512_IV_224[] = { MK_64(0xCCD06162, 0x48677224), MK_64(0xCBA65CF3, 0xA92339EF), MK_64(0x8CCD69D6, 0x52FF4B64), Loading @@ -95,8 +88,7 @@ const u64 SKEIN_512_IV_224[] = }; /* blkSize = 512 bits. hashSize = 256 bits */ const u64 SKEIN_512_IV_256[] = { const u64 SKEIN_512_IV_256[] = { MK_64(0xCCD044A1, 0x2FDB3E13), MK_64(0xE8359030, 0x1A79A9EB), MK_64(0x55AEA061, 0x4F816E6F), Loading @@ -108,8 +100,7 @@ const u64 SKEIN_512_IV_256[] = }; /* blkSize = 512 bits. hashSize = 384 bits */ const u64 SKEIN_512_IV_384[] = { const u64 SKEIN_512_IV_384[] = { MK_64(0xA3F6C6BF, 0x3A75EF5F), MK_64(0xB0FEF9CC, 0xFD84FAA4), MK_64(0x9D77DD66, 0x3D770CFE), Loading @@ -121,8 +112,7 @@ const u64 SKEIN_512_IV_384[] = }; /* blkSize = 512 bits. hashSize = 512 bits */ const u64 SKEIN_512_IV_512[] = { const u64 SKEIN_512_IV_512[] = { MK_64(0x4903ADFF, 0x749C51CE), MK_64(0x0D95DE39, 0x9746DF03), MK_64(0x8FD19341, 0x27C79BCE), Loading @@ -134,8 +124,7 @@ const u64 SKEIN_512_IV_512[] = }; /* blkSize = 1024 bits. hashSize = 384 bits */ const u64 SKEIN1024_IV_384[] = { const u64 SKEIN1024_IV_384[] = { MK_64(0x5102B6B8, 0xC1894A35), MK_64(0xFEEBC9E3, 0xFE8AF11A), MK_64(0x0C807F06, 0xE32BED71), Loading @@ -155,8 +144,7 @@ const u64 SKEIN1024_IV_384[] = }; /* blkSize = 1024 bits. hashSize = 512 bits */ const u64 SKEIN1024_IV_512[] = { const u64 SKEIN1024_IV_512[] = { MK_64(0xCAEC0E5D, 0x7C1B1B18), MK_64(0xA01B0E04, 0x5F03E802), MK_64(0x33840451, 0xED912885), Loading @@ -176,8 +164,7 @@ const u64 SKEIN1024_IV_512[] = }; /* blkSize = 1024 bits. hashSize = 1024 bits */ const u64 SKEIN1024_IV_1024[] = { const u64 SKEIN1024_IV_1024[] = { MK_64(0xD593DA07, 0x41E72355), MK_64(0x15B5E511, 0xAC73E00C), MK_64(0x5180E5AE, 0xBAF2C4F0), Loading drivers/staging/skein/skein.c +36 −75 Original line number Diff line number Diff line Loading @@ -31,8 +31,7 @@ void Skein1024_Process_Block(struct skein1024_ctx *ctx, const u8 *blkPtr, /* init the context for a straight hashing operation */ int Skein_256_Init(struct skein_256_ctx *ctx, size_t hashBitLen) { union { union { u8 b[SKEIN_256_STATE_BYTES]; u64 w[SKEIN_256_STATE_WORDS]; } cfg; /* config block */ Loading @@ -40,8 +39,7 @@ int Skein_256_Init(struct skein_256_ctx *ctx, size_t hashBitLen) Skein_Assert(hashBitLen > 0, SKEIN_BAD_HASHLEN); ctx->h.hashBitLen = hashBitLen; /* output hash bit count */ switch (hashBitLen) { /* use pre-computed values, where available */ switch (hashBitLen) { /* use pre-computed values, where available */ case 256: memcpy(ctx->X, SKEIN_256_IV_256, sizeof(ctx->X)); break; Loading Loading @@ -91,8 +89,7 @@ int Skein_256_Init(struct skein_256_ctx *ctx, size_t hashBitLen) int Skein_256_InitExt(struct skein_256_ctx *ctx, size_t hashBitLen, u64 treeInfo, const u8 *key, size_t keyBytes) { union { union { u8 b[SKEIN_256_STATE_BYTES]; u64 w[SKEIN_256_STATE_WORDS]; } cfg; /* config block */ Loading @@ -101,13 +98,10 @@ int Skein_256_InitExt(struct skein_256_ctx *ctx, size_t hashBitLen, Skein_Assert(keyBytes == 0 || key != NULL, SKEIN_FAIL); /* compute the initial chaining values ctx->X[], based on key */ if (keyBytes == 0) /* is there a key? */ { if (keyBytes == 0) { /* is there a key? */ /* no key: use all zeroes as key for config block */ memset(ctx->X, 0, sizeof(ctx->X)); } else /* here to pre-process a key */ { } else { /* here to pre-process a key */ Skein_assert(sizeof(cfg.b) >= sizeof(ctx->X)); /* do a mini-Init right here */ /* set output hash bit count = state size */ Loading Loading @@ -162,15 +156,12 @@ int Skein_256_Update(struct skein_256_ctx *ctx, const u8 *msg, Skein_Assert(ctx->h.bCnt <= SKEIN_256_BLOCK_BYTES, SKEIN_FAIL); /* process full blocks, if any */ if (msgByteCnt + ctx->h.bCnt > SKEIN_256_BLOCK_BYTES) { if (msgByteCnt + ctx->h.bCnt > SKEIN_256_BLOCK_BYTES) { /* finish up any buffered message data */ if (ctx->h.bCnt) { if (ctx->h.bCnt) { /* # bytes free in buffer b[] */ n = SKEIN_256_BLOCK_BYTES - ctx->h.bCnt; if (n) { if (n) { /* check on our logic here */ Skein_assert(n < msgByteCnt); memcpy(&ctx->b[ctx->h.bCnt], msg, n); Loading @@ -187,8 +178,7 @@ int Skein_256_Update(struct skein_256_ctx *ctx, const u8 *msg, * now process any remaining full blocks, directly from input * message data */ if (msgByteCnt > SKEIN_256_BLOCK_BYTES) { if (msgByteCnt > SKEIN_256_BLOCK_BYTES) { /* number of full blocks to process */ n = (msgByteCnt-1) / SKEIN_256_BLOCK_BYTES; Skein_256_Process_Block(ctx, msg, n, Loading @@ -200,8 +190,7 @@ int Skein_256_Update(struct skein_256_ctx *ctx, const u8 *msg, } /* copy any remaining source message data bytes into b[] */ if (msgByteCnt) { if (msgByteCnt) { Skein_assert(msgByteCnt + ctx->h.bCnt <= SKEIN_256_BLOCK_BYTES); memcpy(&ctx->b[ctx->h.bCnt], msg, msgByteCnt); ctx->h.bCnt += msgByteCnt; Loading Loading @@ -238,8 +227,7 @@ int Skein_256_Final(struct skein_256_ctx *ctx, u8 *hashVal) memset(ctx->b, 0, sizeof(ctx->b)); /* keep a local copy of counter mode "key" */ memcpy(X, ctx->X, sizeof(X)); for (i = 0; i*SKEIN_256_BLOCK_BYTES < byteCnt; i++) { for (i = 0; i*SKEIN_256_BLOCK_BYTES < byteCnt; i++) { /* build the counter block */ ((u64 *)ctx->b)[0] = Skein_Swap64((u64) i); Skein_Start_New_Type(ctx, OUT_FINAL); Loading Loading @@ -268,8 +256,7 @@ int Skein_256_Final(struct skein_256_ctx *ctx, u8 *hashVal) /* init the context for a straight hashing operation */ int Skein_512_Init(struct skein_512_ctx *ctx, size_t hashBitLen) { union { union { u8 b[SKEIN_512_STATE_BYTES]; u64 w[SKEIN_512_STATE_WORDS]; } cfg; /* config block */ Loading @@ -277,8 +264,7 @@ int Skein_512_Init(struct skein_512_ctx *ctx, size_t hashBitLen) Skein_Assert(hashBitLen > 0, SKEIN_BAD_HASHLEN); ctx->h.hashBitLen = hashBitLen; /* output hash bit count */ switch (hashBitLen) { /* use pre-computed values, where available */ switch (hashBitLen) { /* use pre-computed values, where available */ case 512: memcpy(ctx->X, SKEIN_512_IV_512, sizeof(ctx->X)); break; Loading Loading @@ -332,8 +318,7 @@ int Skein_512_Init(struct skein_512_ctx *ctx, size_t hashBitLen) int Skein_512_InitExt(struct skein_512_ctx *ctx, size_t hashBitLen, u64 treeInfo, const u8 *key, size_t keyBytes) { union { union { u8 b[SKEIN_512_STATE_BYTES]; u64 w[SKEIN_512_STATE_WORDS]; } cfg; /* config block */ Loading @@ -342,13 +327,10 @@ int Skein_512_InitExt(struct skein_512_ctx *ctx, size_t hashBitLen, Skein_Assert(keyBytes == 0 || key != NULL, SKEIN_FAIL); /* compute the initial chaining values ctx->X[], based on key */ if (keyBytes == 0) /* is there a key? */ { if (keyBytes == 0) { /* is there a key? */ /* no key: use all zeroes as key for config block */ memset(ctx->X, 0, sizeof(ctx->X)); } else /* here to pre-process a key */ { } else { /* here to pre-process a key */ Skein_assert(sizeof(cfg.b) >= sizeof(ctx->X)); /* do a mini-Init right here */ /* set output hash bit count = state size */ Loading Loading @@ -402,15 +384,12 @@ int Skein_512_Update(struct skein_512_ctx *ctx, const u8 *msg, Skein_Assert(ctx->h.bCnt <= SKEIN_512_BLOCK_BYTES, SKEIN_FAIL); /* process full blocks, if any */ if (msgByteCnt + ctx->h.bCnt > SKEIN_512_BLOCK_BYTES) { if (msgByteCnt + ctx->h.bCnt > SKEIN_512_BLOCK_BYTES) { /* finish up any buffered message data */ if (ctx->h.bCnt) { if (ctx->h.bCnt) { /* # bytes free in buffer b[] */ n = SKEIN_512_BLOCK_BYTES - ctx->h.bCnt; if (n) { if (n) { /* check on our logic here */ Skein_assert(n < msgByteCnt); memcpy(&ctx->b[ctx->h.bCnt], msg, n); Loading @@ -427,8 +406,7 @@ int Skein_512_Update(struct skein_512_ctx *ctx, const u8 *msg, * now process any remaining full blocks, directly from input * message data */ if (msgByteCnt > SKEIN_512_BLOCK_BYTES) { if (msgByteCnt > SKEIN_512_BLOCK_BYTES) { /* number of full blocks to process */ n = (msgByteCnt-1) / SKEIN_512_BLOCK_BYTES; Skein_512_Process_Block(ctx, msg, n, Loading @@ -440,8 +418,7 @@ int Skein_512_Update(struct skein_512_ctx *ctx, const u8 *msg, } /* copy any remaining source message data bytes into b[] */ if (msgByteCnt) { if (msgByteCnt) { Skein_assert(msgByteCnt + ctx->h.bCnt <= SKEIN_512_BLOCK_BYTES); memcpy(&ctx->b[ctx->h.bCnt], msg, msgByteCnt); ctx->h.bCnt += msgByteCnt; Loading Loading @@ -478,8 +455,7 @@ int Skein_512_Final(struct skein_512_ctx *ctx, u8 *hashVal) memset(ctx->b, 0, sizeof(ctx->b)); /* keep a local copy of counter mode "key" */ memcpy(X, ctx->X, sizeof(X)); for (i = 0; i*SKEIN_512_BLOCK_BYTES < byteCnt; i++) { for (i = 0; i*SKEIN_512_BLOCK_BYTES < byteCnt; i++) { /* build the counter block */ ((u64 *)ctx->b)[0] = Skein_Swap64((u64) i); Skein_Start_New_Type(ctx, OUT_FINAL); Loading Loading @@ -508,8 +484,7 @@ int Skein_512_Final(struct skein_512_ctx *ctx, u8 *hashVal) /* init the context for a straight hashing operation */ int Skein1024_Init(struct skein1024_ctx *ctx, size_t hashBitLen) { union { union { u8 b[SKEIN1024_STATE_BYTES]; u64 w[SKEIN1024_STATE_WORDS]; } cfg; /* config block */ Loading @@ -517,8 +492,7 @@ int Skein1024_Init(struct skein1024_ctx *ctx, size_t hashBitLen) Skein_Assert(hashBitLen > 0, SKEIN_BAD_HASHLEN); ctx->h.hashBitLen = hashBitLen; /* output hash bit count */ switch (hashBitLen) { /* use pre-computed values, where available */ switch (hashBitLen) { /* use pre-computed values, where available */ case 512: memcpy(ctx->X, SKEIN1024_IV_512, sizeof(ctx->X)); break; Loading Loading @@ -566,8 +540,7 @@ int Skein1024_Init(struct skein1024_ctx *ctx, size_t hashBitLen) int Skein1024_InitExt(struct skein1024_ctx *ctx, size_t hashBitLen, u64 treeInfo, const u8 *key, size_t keyBytes) { union { union { u8 b[SKEIN1024_STATE_BYTES]; u64 w[SKEIN1024_STATE_WORDS]; } cfg; /* config block */ Loading @@ -576,13 +549,10 @@ int Skein1024_InitExt(struct skein1024_ctx *ctx, size_t hashBitLen, Skein_Assert(keyBytes == 0 || key != NULL, SKEIN_FAIL); /* compute the initial chaining values ctx->X[], based on key */ if (keyBytes == 0) /* is there a key? */ { if (keyBytes == 0) { /* is there a key? */ /* no key: use all zeroes as key for config block */ memset(ctx->X, 0, sizeof(ctx->X)); } else /* here to pre-process a key */ { } else { /* here to pre-process a key */ Skein_assert(sizeof(cfg.b) >= sizeof(ctx->X)); /* do a mini-Init right here */ /* set output hash bit count = state size */ Loading Loading @@ -637,15 +607,12 @@ int Skein1024_Update(struct skein1024_ctx *ctx, const u8 *msg, Skein_Assert(ctx->h.bCnt <= SKEIN1024_BLOCK_BYTES, SKEIN_FAIL); /* process full blocks, if any */ if (msgByteCnt + ctx->h.bCnt > SKEIN1024_BLOCK_BYTES) { if (msgByteCnt + ctx->h.bCnt > SKEIN1024_BLOCK_BYTES) { /* finish up any buffered message data */ if (ctx->h.bCnt) { if (ctx->h.bCnt) { /* # bytes free in buffer b[] */ n = SKEIN1024_BLOCK_BYTES - ctx->h.bCnt; if (n) { if (n) { /* check on our logic here */ Skein_assert(n < msgByteCnt); memcpy(&ctx->b[ctx->h.bCnt], msg, n); Loading @@ -662,8 +629,7 @@ int Skein1024_Update(struct skein1024_ctx *ctx, const u8 *msg, * now process any remaining full blocks, directly from input * message data */ if (msgByteCnt > SKEIN1024_BLOCK_BYTES) { if (msgByteCnt > SKEIN1024_BLOCK_BYTES) { /* number of full blocks to process */ n = (msgByteCnt-1) / SKEIN1024_BLOCK_BYTES; Skein1024_Process_Block(ctx, msg, n, Loading @@ -675,8 +641,7 @@ int Skein1024_Update(struct skein1024_ctx *ctx, const u8 *msg, } /* copy any remaining source message data bytes into b[] */ if (msgByteCnt) { if (msgByteCnt) { Skein_assert(msgByteCnt + ctx->h.bCnt <= SKEIN1024_BLOCK_BYTES); memcpy(&ctx->b[ctx->h.bCnt], msg, msgByteCnt); ctx->h.bCnt += msgByteCnt; Loading Loading @@ -713,8 +678,7 @@ int Skein1024_Final(struct skein1024_ctx *ctx, u8 *hashVal) memset(ctx->b, 0, sizeof(ctx->b)); /* keep a local copy of counter mode "key" */ memcpy(X, ctx->X, sizeof(X)); for (i = 0; i*SKEIN1024_BLOCK_BYTES < byteCnt; i++) { for (i = 0; i*SKEIN1024_BLOCK_BYTES < byteCnt; i++) { /* build the counter block */ ((u64 *)ctx->b)[0] = Skein_Swap64((u64) i); Skein_Start_New_Type(ctx, OUT_FINAL); Loading Loading @@ -823,8 +787,7 @@ int Skein_256_Output(struct skein_256_ctx *ctx, u8 *hashVal) memset(ctx->b, 0, sizeof(ctx->b)); /* keep a local copy of counter mode "key" */ memcpy(X, ctx->X, sizeof(X)); for (i = 0; i*SKEIN_256_BLOCK_BYTES < byteCnt; i++) { for (i = 0; i*SKEIN_256_BLOCK_BYTES < byteCnt; i++) { /* build the counter block */ ((u64 *)ctx->b)[0] = Skein_Swap64((u64) i); Skein_Start_New_Type(ctx, OUT_FINAL); Loading Loading @@ -863,8 +826,7 @@ int Skein_512_Output(struct skein_512_ctx *ctx, u8 *hashVal) memset(ctx->b, 0, sizeof(ctx->b)); /* keep a local copy of counter mode "key" */ memcpy(X, ctx->X, sizeof(X)); for (i = 0; i*SKEIN_512_BLOCK_BYTES < byteCnt; i++) { for (i = 0; i*SKEIN_512_BLOCK_BYTES < byteCnt; i++) { /* build the counter block */ ((u64 *)ctx->b)[0] = Skein_Swap64((u64) i); Skein_Start_New_Type(ctx, OUT_FINAL); Loading Loading @@ -903,8 +865,7 @@ int Skein1024_Output(struct skein1024_ctx *ctx, u8 *hashVal) memset(ctx->b, 0, sizeof(ctx->b)); /* keep a local copy of counter mode "key" */ memcpy(X, ctx->X, sizeof(X)); for (i = 0; i*SKEIN1024_BLOCK_BYTES < byteCnt; i++) { for (i = 0; i*SKEIN1024_BLOCK_BYTES < byteCnt; i++) { /* build the counter block */ ((u64 *)ctx->b)[0] = Skein_Swap64((u64) i); Skein_Start_New_Type(ctx, OUT_FINAL); Loading Loading
drivers/staging/skein/include/skein.h +12 −18 Original line number Diff line number Diff line Loading @@ -37,8 +37,7 @@ #define Skein_Get64_LSB_First(dst64, src08, wCnt) memcpy(dst64, src08, 8*(wCnt)) #define Skein_Swap64(w64) (w64) enum { enum { SKEIN_SUCCESS = 0, /* return codes from Skein calls */ SKEIN_FAIL = 1, SKEIN_BAD_HASHLEN = 2 Loading @@ -63,29 +62,25 @@ enum #define SKEIN_512_BLOCK_BYTES (8*SKEIN_512_STATE_WORDS) #define SKEIN1024_BLOCK_BYTES (8*SKEIN1024_STATE_WORDS) struct skein_ctx_hdr { struct skein_ctx_hdr { size_t hashBitLen; /* size of hash result, in bits */ size_t bCnt; /* current byte count in buffer b[] */ u64 T[SKEIN_MODIFIER_WORDS]; /* tweak: T[0]=byte cnt, T[1]=flags */ }; struct skein_256_ctx /* 256-bit Skein hash context structure */ { struct skein_256_ctx { /* 256-bit Skein hash context structure */ struct skein_ctx_hdr h; /* common header context variables */ u64 X[SKEIN_256_STATE_WORDS]; /* chaining variables */ u8 b[SKEIN_256_BLOCK_BYTES]; /* partial block buf (8-byte aligned) */ }; struct skein_512_ctx /* 512-bit Skein hash context structure */ { struct skein_512_ctx { /* 512-bit Skein hash context structure */ struct skein_ctx_hdr h; /* common header context variables */ u64 X[SKEIN_512_STATE_WORDS]; /* chaining variables */ u8 b[SKEIN_512_BLOCK_BYTES]; /* partial block buf (8-byte aligned) */ }; struct skein1024_ctx /* 1024-bit Skein hash context structure */ { struct skein1024_ctx { /* 1024-bit Skein hash context structure */ struct skein_ctx_hdr h; /* common header context variables */ u64 X[SKEIN1024_STATE_WORDS]; /* chaining variables */ u8 b[SKEIN1024_BLOCK_BYTES]; /* partial block buf (8-byte aligned) */ Loading Loading @@ -296,8 +291,7 @@ int Skein1024_Output(struct skein1024_ctx *ctx, u8 *hashVal); /***************************************************************** ** Skein block function constants (shared across Ref and Opt code) ******************************************************************/ enum { enum { /* Skein_256 round rotation constants */ R_256_0_0 = 14, R_256_0_1 = 16, R_256_1_0 = 52, R_256_1_1 = 57, Loading
drivers/staging/skein/include/skein_iv.h +26 −39 Original line number Diff line number Diff line Loading @@ -20,8 +20,7 @@ #define MK_64 SKEIN_MK_64 /* blkSize = 256 bits. hashSize = 128 bits */ const u64 SKEIN_256_IV_128[] = { const u64 SKEIN_256_IV_128[] = { MK_64(0xE1111906, 0x964D7260), MK_64(0x883DAAA7, 0x7C8D811C), MK_64(0x10080DF4, 0x91960F7A), Loading @@ -29,8 +28,7 @@ const u64 SKEIN_256_IV_128[] = }; /* blkSize = 256 bits. hashSize = 160 bits */ const u64 SKEIN_256_IV_160[] = { const u64 SKEIN_256_IV_160[] = { MK_64(0x14202314, 0x72825E98), MK_64(0x2AC4E9A2, 0x5A77E590), MK_64(0xD47A5856, 0x8838D63E), Loading @@ -38,8 +36,7 @@ const u64 SKEIN_256_IV_160[] = }; /* blkSize = 256 bits. hashSize = 224 bits */ const u64 SKEIN_256_IV_224[] = { const u64 SKEIN_256_IV_224[] = { MK_64(0xC6098A8C, 0x9AE5EA0B), MK_64(0x876D5686, 0x08C5191C), MK_64(0x99CB88D7, 0xD7F53884), Loading @@ -47,8 +44,7 @@ const u64 SKEIN_256_IV_224[] = }; /* blkSize = 256 bits. hashSize = 256 bits */ const u64 SKEIN_256_IV_256[] = { const u64 SKEIN_256_IV_256[] = { MK_64(0xFC9DA860, 0xD048B449), MK_64(0x2FCA6647, 0x9FA7D833), MK_64(0xB33BC389, 0x6656840F), Loading @@ -56,8 +52,7 @@ const u64 SKEIN_256_IV_256[] = }; /* blkSize = 512 bits. hashSize = 128 bits */ const u64 SKEIN_512_IV_128[] = { const u64 SKEIN_512_IV_128[] = { MK_64(0xA8BC7BF3, 0x6FBF9F52), MK_64(0x1E9872CE, 0xBD1AF0AA), MK_64(0x309B1790, 0xB32190D3), Loading @@ -69,8 +64,7 @@ const u64 SKEIN_512_IV_128[] = }; /* blkSize = 512 bits. hashSize = 160 bits */ const u64 SKEIN_512_IV_160[] = { const u64 SKEIN_512_IV_160[] = { MK_64(0x28B81A2A, 0xE013BD91), MK_64(0xC2F11668, 0xB5BDF78F), MK_64(0x1760D8F3, 0xF6A56F12), Loading @@ -82,8 +76,7 @@ const u64 SKEIN_512_IV_160[] = }; /* blkSize = 512 bits. hashSize = 224 bits */ const u64 SKEIN_512_IV_224[] = { const u64 SKEIN_512_IV_224[] = { MK_64(0xCCD06162, 0x48677224), MK_64(0xCBA65CF3, 0xA92339EF), MK_64(0x8CCD69D6, 0x52FF4B64), Loading @@ -95,8 +88,7 @@ const u64 SKEIN_512_IV_224[] = }; /* blkSize = 512 bits. hashSize = 256 bits */ const u64 SKEIN_512_IV_256[] = { const u64 SKEIN_512_IV_256[] = { MK_64(0xCCD044A1, 0x2FDB3E13), MK_64(0xE8359030, 0x1A79A9EB), MK_64(0x55AEA061, 0x4F816E6F), Loading @@ -108,8 +100,7 @@ const u64 SKEIN_512_IV_256[] = }; /* blkSize = 512 bits. hashSize = 384 bits */ const u64 SKEIN_512_IV_384[] = { const u64 SKEIN_512_IV_384[] = { MK_64(0xA3F6C6BF, 0x3A75EF5F), MK_64(0xB0FEF9CC, 0xFD84FAA4), MK_64(0x9D77DD66, 0x3D770CFE), Loading @@ -121,8 +112,7 @@ const u64 SKEIN_512_IV_384[] = }; /* blkSize = 512 bits. hashSize = 512 bits */ const u64 SKEIN_512_IV_512[] = { const u64 SKEIN_512_IV_512[] = { MK_64(0x4903ADFF, 0x749C51CE), MK_64(0x0D95DE39, 0x9746DF03), MK_64(0x8FD19341, 0x27C79BCE), Loading @@ -134,8 +124,7 @@ const u64 SKEIN_512_IV_512[] = }; /* blkSize = 1024 bits. hashSize = 384 bits */ const u64 SKEIN1024_IV_384[] = { const u64 SKEIN1024_IV_384[] = { MK_64(0x5102B6B8, 0xC1894A35), MK_64(0xFEEBC9E3, 0xFE8AF11A), MK_64(0x0C807F06, 0xE32BED71), Loading @@ -155,8 +144,7 @@ const u64 SKEIN1024_IV_384[] = }; /* blkSize = 1024 bits. hashSize = 512 bits */ const u64 SKEIN1024_IV_512[] = { const u64 SKEIN1024_IV_512[] = { MK_64(0xCAEC0E5D, 0x7C1B1B18), MK_64(0xA01B0E04, 0x5F03E802), MK_64(0x33840451, 0xED912885), Loading @@ -176,8 +164,7 @@ const u64 SKEIN1024_IV_512[] = }; /* blkSize = 1024 bits. hashSize = 1024 bits */ const u64 SKEIN1024_IV_1024[] = { const u64 SKEIN1024_IV_1024[] = { MK_64(0xD593DA07, 0x41E72355), MK_64(0x15B5E511, 0xAC73E00C), MK_64(0x5180E5AE, 0xBAF2C4F0), Loading
drivers/staging/skein/skein.c +36 −75 Original line number Diff line number Diff line Loading @@ -31,8 +31,7 @@ void Skein1024_Process_Block(struct skein1024_ctx *ctx, const u8 *blkPtr, /* init the context for a straight hashing operation */ int Skein_256_Init(struct skein_256_ctx *ctx, size_t hashBitLen) { union { union { u8 b[SKEIN_256_STATE_BYTES]; u64 w[SKEIN_256_STATE_WORDS]; } cfg; /* config block */ Loading @@ -40,8 +39,7 @@ int Skein_256_Init(struct skein_256_ctx *ctx, size_t hashBitLen) Skein_Assert(hashBitLen > 0, SKEIN_BAD_HASHLEN); ctx->h.hashBitLen = hashBitLen; /* output hash bit count */ switch (hashBitLen) { /* use pre-computed values, where available */ switch (hashBitLen) { /* use pre-computed values, where available */ case 256: memcpy(ctx->X, SKEIN_256_IV_256, sizeof(ctx->X)); break; Loading Loading @@ -91,8 +89,7 @@ int Skein_256_Init(struct skein_256_ctx *ctx, size_t hashBitLen) int Skein_256_InitExt(struct skein_256_ctx *ctx, size_t hashBitLen, u64 treeInfo, const u8 *key, size_t keyBytes) { union { union { u8 b[SKEIN_256_STATE_BYTES]; u64 w[SKEIN_256_STATE_WORDS]; } cfg; /* config block */ Loading @@ -101,13 +98,10 @@ int Skein_256_InitExt(struct skein_256_ctx *ctx, size_t hashBitLen, Skein_Assert(keyBytes == 0 || key != NULL, SKEIN_FAIL); /* compute the initial chaining values ctx->X[], based on key */ if (keyBytes == 0) /* is there a key? */ { if (keyBytes == 0) { /* is there a key? */ /* no key: use all zeroes as key for config block */ memset(ctx->X, 0, sizeof(ctx->X)); } else /* here to pre-process a key */ { } else { /* here to pre-process a key */ Skein_assert(sizeof(cfg.b) >= sizeof(ctx->X)); /* do a mini-Init right here */ /* set output hash bit count = state size */ Loading Loading @@ -162,15 +156,12 @@ int Skein_256_Update(struct skein_256_ctx *ctx, const u8 *msg, Skein_Assert(ctx->h.bCnt <= SKEIN_256_BLOCK_BYTES, SKEIN_FAIL); /* process full blocks, if any */ if (msgByteCnt + ctx->h.bCnt > SKEIN_256_BLOCK_BYTES) { if (msgByteCnt + ctx->h.bCnt > SKEIN_256_BLOCK_BYTES) { /* finish up any buffered message data */ if (ctx->h.bCnt) { if (ctx->h.bCnt) { /* # bytes free in buffer b[] */ n = SKEIN_256_BLOCK_BYTES - ctx->h.bCnt; if (n) { if (n) { /* check on our logic here */ Skein_assert(n < msgByteCnt); memcpy(&ctx->b[ctx->h.bCnt], msg, n); Loading @@ -187,8 +178,7 @@ int Skein_256_Update(struct skein_256_ctx *ctx, const u8 *msg, * now process any remaining full blocks, directly from input * message data */ if (msgByteCnt > SKEIN_256_BLOCK_BYTES) { if (msgByteCnt > SKEIN_256_BLOCK_BYTES) { /* number of full blocks to process */ n = (msgByteCnt-1) / SKEIN_256_BLOCK_BYTES; Skein_256_Process_Block(ctx, msg, n, Loading @@ -200,8 +190,7 @@ int Skein_256_Update(struct skein_256_ctx *ctx, const u8 *msg, } /* copy any remaining source message data bytes into b[] */ if (msgByteCnt) { if (msgByteCnt) { Skein_assert(msgByteCnt + ctx->h.bCnt <= SKEIN_256_BLOCK_BYTES); memcpy(&ctx->b[ctx->h.bCnt], msg, msgByteCnt); ctx->h.bCnt += msgByteCnt; Loading Loading @@ -238,8 +227,7 @@ int Skein_256_Final(struct skein_256_ctx *ctx, u8 *hashVal) memset(ctx->b, 0, sizeof(ctx->b)); /* keep a local copy of counter mode "key" */ memcpy(X, ctx->X, sizeof(X)); for (i = 0; i*SKEIN_256_BLOCK_BYTES < byteCnt; i++) { for (i = 0; i*SKEIN_256_BLOCK_BYTES < byteCnt; i++) { /* build the counter block */ ((u64 *)ctx->b)[0] = Skein_Swap64((u64) i); Skein_Start_New_Type(ctx, OUT_FINAL); Loading Loading @@ -268,8 +256,7 @@ int Skein_256_Final(struct skein_256_ctx *ctx, u8 *hashVal) /* init the context for a straight hashing operation */ int Skein_512_Init(struct skein_512_ctx *ctx, size_t hashBitLen) { union { union { u8 b[SKEIN_512_STATE_BYTES]; u64 w[SKEIN_512_STATE_WORDS]; } cfg; /* config block */ Loading @@ -277,8 +264,7 @@ int Skein_512_Init(struct skein_512_ctx *ctx, size_t hashBitLen) Skein_Assert(hashBitLen > 0, SKEIN_BAD_HASHLEN); ctx->h.hashBitLen = hashBitLen; /* output hash bit count */ switch (hashBitLen) { /* use pre-computed values, where available */ switch (hashBitLen) { /* use pre-computed values, where available */ case 512: memcpy(ctx->X, SKEIN_512_IV_512, sizeof(ctx->X)); break; Loading Loading @@ -332,8 +318,7 @@ int Skein_512_Init(struct skein_512_ctx *ctx, size_t hashBitLen) int Skein_512_InitExt(struct skein_512_ctx *ctx, size_t hashBitLen, u64 treeInfo, const u8 *key, size_t keyBytes) { union { union { u8 b[SKEIN_512_STATE_BYTES]; u64 w[SKEIN_512_STATE_WORDS]; } cfg; /* config block */ Loading @@ -342,13 +327,10 @@ int Skein_512_InitExt(struct skein_512_ctx *ctx, size_t hashBitLen, Skein_Assert(keyBytes == 0 || key != NULL, SKEIN_FAIL); /* compute the initial chaining values ctx->X[], based on key */ if (keyBytes == 0) /* is there a key? */ { if (keyBytes == 0) { /* is there a key? */ /* no key: use all zeroes as key for config block */ memset(ctx->X, 0, sizeof(ctx->X)); } else /* here to pre-process a key */ { } else { /* here to pre-process a key */ Skein_assert(sizeof(cfg.b) >= sizeof(ctx->X)); /* do a mini-Init right here */ /* set output hash bit count = state size */ Loading Loading @@ -402,15 +384,12 @@ int Skein_512_Update(struct skein_512_ctx *ctx, const u8 *msg, Skein_Assert(ctx->h.bCnt <= SKEIN_512_BLOCK_BYTES, SKEIN_FAIL); /* process full blocks, if any */ if (msgByteCnt + ctx->h.bCnt > SKEIN_512_BLOCK_BYTES) { if (msgByteCnt + ctx->h.bCnt > SKEIN_512_BLOCK_BYTES) { /* finish up any buffered message data */ if (ctx->h.bCnt) { if (ctx->h.bCnt) { /* # bytes free in buffer b[] */ n = SKEIN_512_BLOCK_BYTES - ctx->h.bCnt; if (n) { if (n) { /* check on our logic here */ Skein_assert(n < msgByteCnt); memcpy(&ctx->b[ctx->h.bCnt], msg, n); Loading @@ -427,8 +406,7 @@ int Skein_512_Update(struct skein_512_ctx *ctx, const u8 *msg, * now process any remaining full blocks, directly from input * message data */ if (msgByteCnt > SKEIN_512_BLOCK_BYTES) { if (msgByteCnt > SKEIN_512_BLOCK_BYTES) { /* number of full blocks to process */ n = (msgByteCnt-1) / SKEIN_512_BLOCK_BYTES; Skein_512_Process_Block(ctx, msg, n, Loading @@ -440,8 +418,7 @@ int Skein_512_Update(struct skein_512_ctx *ctx, const u8 *msg, } /* copy any remaining source message data bytes into b[] */ if (msgByteCnt) { if (msgByteCnt) { Skein_assert(msgByteCnt + ctx->h.bCnt <= SKEIN_512_BLOCK_BYTES); memcpy(&ctx->b[ctx->h.bCnt], msg, msgByteCnt); ctx->h.bCnt += msgByteCnt; Loading Loading @@ -478,8 +455,7 @@ int Skein_512_Final(struct skein_512_ctx *ctx, u8 *hashVal) memset(ctx->b, 0, sizeof(ctx->b)); /* keep a local copy of counter mode "key" */ memcpy(X, ctx->X, sizeof(X)); for (i = 0; i*SKEIN_512_BLOCK_BYTES < byteCnt; i++) { for (i = 0; i*SKEIN_512_BLOCK_BYTES < byteCnt; i++) { /* build the counter block */ ((u64 *)ctx->b)[0] = Skein_Swap64((u64) i); Skein_Start_New_Type(ctx, OUT_FINAL); Loading Loading @@ -508,8 +484,7 @@ int Skein_512_Final(struct skein_512_ctx *ctx, u8 *hashVal) /* init the context for a straight hashing operation */ int Skein1024_Init(struct skein1024_ctx *ctx, size_t hashBitLen) { union { union { u8 b[SKEIN1024_STATE_BYTES]; u64 w[SKEIN1024_STATE_WORDS]; } cfg; /* config block */ Loading @@ -517,8 +492,7 @@ int Skein1024_Init(struct skein1024_ctx *ctx, size_t hashBitLen) Skein_Assert(hashBitLen > 0, SKEIN_BAD_HASHLEN); ctx->h.hashBitLen = hashBitLen; /* output hash bit count */ switch (hashBitLen) { /* use pre-computed values, where available */ switch (hashBitLen) { /* use pre-computed values, where available */ case 512: memcpy(ctx->X, SKEIN1024_IV_512, sizeof(ctx->X)); break; Loading Loading @@ -566,8 +540,7 @@ int Skein1024_Init(struct skein1024_ctx *ctx, size_t hashBitLen) int Skein1024_InitExt(struct skein1024_ctx *ctx, size_t hashBitLen, u64 treeInfo, const u8 *key, size_t keyBytes) { union { union { u8 b[SKEIN1024_STATE_BYTES]; u64 w[SKEIN1024_STATE_WORDS]; } cfg; /* config block */ Loading @@ -576,13 +549,10 @@ int Skein1024_InitExt(struct skein1024_ctx *ctx, size_t hashBitLen, Skein_Assert(keyBytes == 0 || key != NULL, SKEIN_FAIL); /* compute the initial chaining values ctx->X[], based on key */ if (keyBytes == 0) /* is there a key? */ { if (keyBytes == 0) { /* is there a key? */ /* no key: use all zeroes as key for config block */ memset(ctx->X, 0, sizeof(ctx->X)); } else /* here to pre-process a key */ { } else { /* here to pre-process a key */ Skein_assert(sizeof(cfg.b) >= sizeof(ctx->X)); /* do a mini-Init right here */ /* set output hash bit count = state size */ Loading Loading @@ -637,15 +607,12 @@ int Skein1024_Update(struct skein1024_ctx *ctx, const u8 *msg, Skein_Assert(ctx->h.bCnt <= SKEIN1024_BLOCK_BYTES, SKEIN_FAIL); /* process full blocks, if any */ if (msgByteCnt + ctx->h.bCnt > SKEIN1024_BLOCK_BYTES) { if (msgByteCnt + ctx->h.bCnt > SKEIN1024_BLOCK_BYTES) { /* finish up any buffered message data */ if (ctx->h.bCnt) { if (ctx->h.bCnt) { /* # bytes free in buffer b[] */ n = SKEIN1024_BLOCK_BYTES - ctx->h.bCnt; if (n) { if (n) { /* check on our logic here */ Skein_assert(n < msgByteCnt); memcpy(&ctx->b[ctx->h.bCnt], msg, n); Loading @@ -662,8 +629,7 @@ int Skein1024_Update(struct skein1024_ctx *ctx, const u8 *msg, * now process any remaining full blocks, directly from input * message data */ if (msgByteCnt > SKEIN1024_BLOCK_BYTES) { if (msgByteCnt > SKEIN1024_BLOCK_BYTES) { /* number of full blocks to process */ n = (msgByteCnt-1) / SKEIN1024_BLOCK_BYTES; Skein1024_Process_Block(ctx, msg, n, Loading @@ -675,8 +641,7 @@ int Skein1024_Update(struct skein1024_ctx *ctx, const u8 *msg, } /* copy any remaining source message data bytes into b[] */ if (msgByteCnt) { if (msgByteCnt) { Skein_assert(msgByteCnt + ctx->h.bCnt <= SKEIN1024_BLOCK_BYTES); memcpy(&ctx->b[ctx->h.bCnt], msg, msgByteCnt); ctx->h.bCnt += msgByteCnt; Loading Loading @@ -713,8 +678,7 @@ int Skein1024_Final(struct skein1024_ctx *ctx, u8 *hashVal) memset(ctx->b, 0, sizeof(ctx->b)); /* keep a local copy of counter mode "key" */ memcpy(X, ctx->X, sizeof(X)); for (i = 0; i*SKEIN1024_BLOCK_BYTES < byteCnt; i++) { for (i = 0; i*SKEIN1024_BLOCK_BYTES < byteCnt; i++) { /* build the counter block */ ((u64 *)ctx->b)[0] = Skein_Swap64((u64) i); Skein_Start_New_Type(ctx, OUT_FINAL); Loading Loading @@ -823,8 +787,7 @@ int Skein_256_Output(struct skein_256_ctx *ctx, u8 *hashVal) memset(ctx->b, 0, sizeof(ctx->b)); /* keep a local copy of counter mode "key" */ memcpy(X, ctx->X, sizeof(X)); for (i = 0; i*SKEIN_256_BLOCK_BYTES < byteCnt; i++) { for (i = 0; i*SKEIN_256_BLOCK_BYTES < byteCnt; i++) { /* build the counter block */ ((u64 *)ctx->b)[0] = Skein_Swap64((u64) i); Skein_Start_New_Type(ctx, OUT_FINAL); Loading Loading @@ -863,8 +826,7 @@ int Skein_512_Output(struct skein_512_ctx *ctx, u8 *hashVal) memset(ctx->b, 0, sizeof(ctx->b)); /* keep a local copy of counter mode "key" */ memcpy(X, ctx->X, sizeof(X)); for (i = 0; i*SKEIN_512_BLOCK_BYTES < byteCnt; i++) { for (i = 0; i*SKEIN_512_BLOCK_BYTES < byteCnt; i++) { /* build the counter block */ ((u64 *)ctx->b)[0] = Skein_Swap64((u64) i); Skein_Start_New_Type(ctx, OUT_FINAL); Loading Loading @@ -903,8 +865,7 @@ int Skein1024_Output(struct skein1024_ctx *ctx, u8 *hashVal) memset(ctx->b, 0, sizeof(ctx->b)); /* keep a local copy of counter mode "key" */ memcpy(X, ctx->X, sizeof(X)); for (i = 0; i*SKEIN1024_BLOCK_BYTES < byteCnt; i++) { for (i = 0; i*SKEIN1024_BLOCK_BYTES < byteCnt; i++) { /* build the counter block */ ((u64 *)ctx->b)[0] = Skein_Swap64((u64) i); Skein_Start_New_Type(ctx, OUT_FINAL); Loading