Commit 60eb8175 authored by Jason Cooper's avatar Jason Cooper Committed by Greg Kroah-Hartman

staging: crypto: skein: cleanup >80 character lines

Signed-off-by: default avatarJason Cooper <jason@lakedaemon.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 06a620f0
This diff is collapsed.
...@@ -72,7 +72,9 @@ struct threefish_key { ...@@ -72,7 +72,9 @@ struct threefish_key {
* @param tweak * @param tweak
* Pointer to the two tweak words (word has 64 bits). * Pointer to the two tweak words (word has 64 bits).
*/ */
void threefishSetKey(struct threefish_key *keyCtx, enum threefish_size stateSize, u64 *keyData, u64 *tweak); void threefishSetKey(struct threefish_key *keyCtx,
enum threefish_size stateSize,
u64 *keyData, u64 *tweak);
/** /**
* Encrypt Threefisch block (bytes). * Encrypt Threefisch block (bytes).
...@@ -108,7 +110,8 @@ void threefishEncryptBlockBytes(struct threefish_key *keyCtx, u8 *in, u8 *out); ...@@ -108,7 +110,8 @@ void threefishEncryptBlockBytes(struct threefish_key *keyCtx, u8 *in, u8 *out);
* @param out * @param out
* Pointer to cipher buffer. * Pointer to cipher buffer.
*/ */
void threefishEncryptBlockWords(struct threefish_key *keyCtx, u64 *in, u64 *out); void threefishEncryptBlockWords(struct threefish_key *keyCtx, u64 *in,
u64 *out);
/** /**
* Decrypt Threefisch block (bytes). * Decrypt Threefisch block (bytes).
...@@ -144,14 +147,17 @@ void threefishDecryptBlockBytes(struct threefish_key *keyCtx, u8 *in, u8 *out); ...@@ -144,14 +147,17 @@ void threefishDecryptBlockBytes(struct threefish_key *keyCtx, u8 *in, u8 *out);
* @param out * @param out
* Pointer to plaintext buffer. * Pointer to plaintext buffer.
*/ */
void threefishDecryptBlockWords(struct threefish_key *keyCtx, u64 *in, u64 *out); void threefishDecryptBlockWords(struct threefish_key *keyCtx, u64 *in,
u64 *out);
void threefishEncrypt256(struct threefish_key *keyCtx, u64 *input, u64 *output); void threefishEncrypt256(struct threefish_key *keyCtx, u64 *input, u64 *output);
void threefishEncrypt512(struct threefish_key *keyCtx, u64 *input, u64 *output); void threefishEncrypt512(struct threefish_key *keyCtx, u64 *input, u64 *output);
void threefishEncrypt1024(struct threefish_key *keyCtx, u64 *input, u64 *output); void threefishEncrypt1024(struct threefish_key *keyCtx, u64 *input,
u64 *output);
void threefishDecrypt256(struct threefish_key *keyCtx, u64 *input, u64 *output); void threefishDecrypt256(struct threefish_key *keyCtx, u64 *input, u64 *output);
void threefishDecrypt512(struct threefish_key *keyCtx, u64 *input, u64 *output); void threefishDecrypt512(struct threefish_key *keyCtx, u64 *input, u64 *output);
void threefishDecrypt1024(struct threefish_key *keyCtx, u64 *input, u64 *output); void threefishDecrypt1024(struct threefish_key *keyCtx, u64 *input,
u64 *output);
/** /**
* @} * @}
*/ */
......
This diff is collapsed.
...@@ -46,9 +46,9 @@ int skeinInit(struct skein_ctx *ctx, size_t hashBitLen) ...@@ -46,9 +46,9 @@ int skeinInit(struct skein_ctx *ctx, size_t hashBitLen)
Skein_Assert(ctx, SKEIN_FAIL); Skein_Assert(ctx, SKEIN_FAIL);
/* /*
* The following two lines rely of the fact that the real Skein contexts are * The following two lines rely of the fact that the real Skein
* a union in out context and thus have tha maximum memory available. * contexts are a union in out context and thus have tha maximum
* The beauty of C :-) . * memory available. The beauty of C :-) .
*/ */
X = ctx->m.s256.X; X = ctx->m.s256.X;
Xlen = ctx->skeinSize/8; Xlen = ctx->skeinSize/8;
...@@ -72,7 +72,10 @@ int skeinInit(struct skein_ctx *ctx, size_t hashBitLen) ...@@ -72,7 +72,10 @@ int skeinInit(struct skein_ctx *ctx, size_t hashBitLen)
} }
if (ret == SKEIN_SUCCESS) { if (ret == SKEIN_SUCCESS) {
/* Save chaining variables for this combination of size and hashBitLen */ /*
* Save chaining variables for this combination of size and
* hashBitLen
*/
memcpy(ctx->XSave, X, Xlen); memcpy(ctx->XSave, X, Xlen);
} }
return ret; return ret;
...@@ -113,7 +116,10 @@ int skeinMacInit(struct skein_ctx *ctx, const u8 *key, size_t keyLen, ...@@ -113,7 +116,10 @@ int skeinMacInit(struct skein_ctx *ctx, const u8 *key, size_t keyLen,
break; break;
} }
if (ret == SKEIN_SUCCESS) { if (ret == SKEIN_SUCCESS) {
/* Save chaining variables for this combination of key, keyLen, hashBitLen */ /*
* Save chaining variables for this combination of key,
* keyLen, hashBitLen
*/
memcpy(ctx->XSave, X, Xlen); memcpy(ctx->XSave, X, Xlen);
} }
return ret; return ret;
...@@ -125,9 +131,9 @@ void skeinReset(struct skein_ctx *ctx) ...@@ -125,9 +131,9 @@ void skeinReset(struct skein_ctx *ctx)
u64 *X = NULL; u64 *X = NULL;
/* /*
* The following two lines rely of the fact that the real Skein contexts are * The following two lines rely of the fact that the real Skein
* a union in out context and thus have tha maximum memory available. * contexts are a union in out context and thus have tha maximum
* The beautiy of C :-) . * memory available. The beautiy of C :-) .
*/ */
X = ctx->m.s256.X; X = ctx->m.s256.X;
Xlen = ctx->skeinSize/8; Xlen = ctx->skeinSize/8;
...@@ -146,13 +152,16 @@ int skeinUpdate(struct skein_ctx *ctx, const u8 *msg, ...@@ -146,13 +152,16 @@ int skeinUpdate(struct skein_ctx *ctx, const u8 *msg,
switch (ctx->skeinSize) { switch (ctx->skeinSize) {
case Skein256: case Skein256:
ret = Skein_256_Update(&ctx->m.s256, (const u8 *)msg, msgByteCnt); ret = Skein_256_Update(&ctx->m.s256, (const u8 *)msg,
msgByteCnt);
break; break;
case Skein512: case Skein512:
ret = Skein_512_Update(&ctx->m.s512, (const u8 *)msg, msgByteCnt); ret = Skein_512_Update(&ctx->m.s512, (const u8 *)msg,
msgByteCnt);
break; break;
case Skein1024: case Skein1024:
ret = Skein1024_Update(&ctx->m.s1024, (const u8 *)msg, msgByteCnt); ret = Skein1024_Update(&ctx->m.s1024, (const u8 *)msg,
msgByteCnt);
break; break;
} }
return ret; return ret;
...@@ -164,15 +173,19 @@ int skeinUpdateBits(struct skein_ctx *ctx, const u8 *msg, ...@@ -164,15 +173,19 @@ int skeinUpdateBits(struct skein_ctx *ctx, const u8 *msg,
{ {
/* /*
* I've used the bit pad implementation from skein_test.c (see NIST CD) * I've used the bit pad implementation from skein_test.c (see NIST CD)
* and modified it to use the convenience functions and added some pointer * and modified it to use the convenience functions and added some
* arithmetic. * pointer arithmetic.
*/ */
size_t length; size_t length;
u8 mask; u8 mask;
u8 *up; u8 *up;
/* only the final Update() call is allowed do partial bytes, else assert an error */ /*
Skein_Assert((ctx->m.h.T[1] & SKEIN_T1_FLAG_BIT_PAD) == 0 || msgBitCnt == 0, SKEIN_FAIL); * only the final Update() call is allowed do partial bytes, else
* assert an error
*/
Skein_Assert((ctx->m.h.T[1] & SKEIN_T1_FLAG_BIT_PAD) == 0 ||
msgBitCnt == 0, SKEIN_FAIL);
/* if number of bits is a multiple of bytes - that's easy */ /* if number of bits is a multiple of bytes - that's easy */
if ((msgBitCnt & 0x7) == 0) { if ((msgBitCnt & 0x7) == 0) {
...@@ -188,13 +201,18 @@ int skeinUpdateBits(struct skein_ctx *ctx, const u8 *msg, ...@@ -188,13 +201,18 @@ int skeinUpdateBits(struct skein_ctx *ctx, const u8 *msg,
*/ */
up = (u8 *)ctx->m.s256.X + ctx->skeinSize / 8; up = (u8 *)ctx->m.s256.X + ctx->skeinSize / 8;
Skein_Set_Bit_Pad_Flag(ctx->m.h); /* set tweak flag for the skeinFinal call */ /* set tweak flag for the skeinFinal call */
Skein_Set_Bit_Pad_Flag(ctx->m.h);
/* now "pad" the final partial byte the way NIST likes */ /* now "pad" the final partial byte the way NIST likes */
length = ctx->m.h.bCnt; /* get the bCnt value (same location for all block sizes) */ /* get the bCnt value (same location for all block sizes) */
Skein_assert(length != 0); /* internal sanity check: there IS a partial byte in the buffer! */ length = ctx->m.h.bCnt;
mask = (u8) (1u << (7 - (msgBitCnt & 7))); /* partial byte bit mask */ /* internal sanity check: there IS a partial byte in the buffer! */
up[length-1] = (u8)((up[length-1] & (0-mask))|mask); /* apply bit padding on final byte (in the buffer) */ Skein_assert(length != 0);
/* partial byte bit mask */
mask = (u8) (1u << (7 - (msgBitCnt & 7)));
/* apply bit padding on final byte (in the buffer) */
up[length-1] = (u8)((up[length-1] & (0-mask))|mask);
return SKEIN_SUCCESS; return SKEIN_SUCCESS;
} }
......
...@@ -36,13 +36,14 @@ void Skein_256_Process_Block(struct skein_256_ctx *ctx, const u8 *blkPtr, ...@@ -36,13 +36,14 @@ void Skein_256_Process_Block(struct skein_256_ctx *ctx, const u8 *blkPtr,
threefishSetKey(&key, Threefish256, ctx->X, tweak); threefishSetKey(&key, Threefish256, ctx->X, tweak);
Skein_Get64_LSB_First(w, blkPtr, SKEIN_256_STATE_WORDS); /* get input block in little-endian format */ /* get input block in little-endian format */
Skein_Get64_LSB_First(w, blkPtr, SKEIN_256_STATE_WORDS);
threefishEncryptBlockWords(&key, w, ctx->X); threefishEncryptBlockWords(&key, w, ctx->X);
blkPtr += SKEIN_256_BLOCK_BYTES; blkPtr += SKEIN_256_BLOCK_BYTES;
/* do the final "feedforward" xor, update context chaining vars */ /* do the final "feedforward" xor, update ctx chaining vars */
ctx->X[0] = ctx->X[0] ^ w[0]; ctx->X[0] = ctx->X[0] ^ w[0];
ctx->X[1] = ctx->X[1] ^ w[1]; ctx->X[1] = ctx->X[1] ^ w[1];
ctx->X[2] = ctx->X[2] ^ w[2]; ctx->X[2] = ctx->X[2] ^ w[2];
...@@ -86,13 +87,14 @@ void Skein_512_Process_Block(struct skein_512_ctx *ctx, const u8 *blkPtr, ...@@ -86,13 +87,14 @@ void Skein_512_Process_Block(struct skein_512_ctx *ctx, const u8 *blkPtr,
threefishSetKey(&key, Threefish512, ctx->X, tweak); threefishSetKey(&key, Threefish512, ctx->X, tweak);
Skein_Get64_LSB_First(w, blkPtr, SKEIN_512_STATE_WORDS); /* get input block in little-endian format */ /* get input block in little-endian format */
Skein_Get64_LSB_First(w, blkPtr, SKEIN_512_STATE_WORDS);
threefishEncryptBlockWords(&key, w, ctx->X); threefishEncryptBlockWords(&key, w, ctx->X);
blkPtr += SKEIN_512_BLOCK_BYTES; blkPtr += SKEIN_512_BLOCK_BYTES;
/* do the final "feedforward" xor, update context chaining vars */ /* do the final "feedforward" xor, update ctx chaining vars */
ctx->X[0] = ctx->X[0] ^ w[0]; ctx->X[0] = ctx->X[0] ^ w[0];
ctx->X[1] = ctx->X[1] ^ w[1]; ctx->X[1] = ctx->X[1] ^ w[1];
ctx->X[2] = ctx->X[2] ^ w[2]; ctx->X[2] = ctx->X[2] ^ w[2];
...@@ -140,13 +142,14 @@ void Skein1024_Process_Block(struct skein1024_ctx *ctx, const u8 *blkPtr, ...@@ -140,13 +142,14 @@ void Skein1024_Process_Block(struct skein1024_ctx *ctx, const u8 *blkPtr,
threefishSetKey(&key, Threefish1024, ctx->X, tweak); threefishSetKey(&key, Threefish1024, ctx->X, tweak);
Skein_Get64_LSB_First(w, blkPtr, SKEIN1024_STATE_WORDS); /* get input block in little-endian format */ /* get input block in little-endian format */
Skein_Get64_LSB_First(w, blkPtr, SKEIN1024_STATE_WORDS);
threefishEncryptBlockWords(&key, w, ctx->X); threefishEncryptBlockWords(&key, w, ctx->X);
blkPtr += SKEIN1024_BLOCK_BYTES; blkPtr += SKEIN1024_BLOCK_BYTES;
/* do the final "feedforward" xor, update context chaining vars */ /* do the final "feedforward" xor, update ctx chaining vars */
ctx->X[0] = ctx->X[0] ^ w[0]; ctx->X[0] = ctx->X[0] ^ w[0];
ctx->X[1] = ctx->X[1] ^ w[1]; ctx->X[1] = ctx->X[1] ^ w[1];
ctx->X[2] = ctx->X[2] ^ w[2]; ctx->X[2] = ctx->X[2] ^ w[2];
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
#include <linux/string.h> #include <linux/string.h>
#include <threefishApi.h> #include <threefishApi.h>
void threefishSetKey(struct threefish_key *keyCtx, enum threefish_size stateSize, void threefishSetKey(struct threefish_key *keyCtx,
enum threefish_size stateSize,
u64 *keyData, u64 *tweak) u64 *keyData, u64 *tweak)
{ {
int keyWords = stateSize / 64; int keyWords = stateSize / 64;
...@@ -28,9 +29,9 @@ void threefishEncryptBlockBytes(struct threefish_key *keyCtx, u8 *in, ...@@ -28,9 +29,9 @@ void threefishEncryptBlockBytes(struct threefish_key *keyCtx, u8 *in,
u64 plain[SKEIN_MAX_STATE_WORDS]; /* max number of words*/ u64 plain[SKEIN_MAX_STATE_WORDS]; /* max number of words*/
u64 cipher[SKEIN_MAX_STATE_WORDS]; u64 cipher[SKEIN_MAX_STATE_WORDS];
Skein_Get64_LSB_First(plain, in, keyCtx->stateSize / 64); /* bytes to words */ Skein_Get64_LSB_First(plain, in, keyCtx->stateSize / 64);
threefishEncryptBlockWords(keyCtx, plain, cipher); threefishEncryptBlockWords(keyCtx, plain, cipher);
Skein_Put64_LSB_First(out, cipher, keyCtx->stateSize / 8); /* words to bytes */ Skein_Put64_LSB_First(out, cipher, keyCtx->stateSize / 8);
} }
void threefishEncryptBlockWords(struct threefish_key *keyCtx, u64 *in, void threefishEncryptBlockWords(struct threefish_key *keyCtx, u64 *in,
...@@ -55,9 +56,9 @@ void threefishDecryptBlockBytes(struct threefish_key *keyCtx, u8 *in, ...@@ -55,9 +56,9 @@ void threefishDecryptBlockBytes(struct threefish_key *keyCtx, u8 *in,
u64 plain[SKEIN_MAX_STATE_WORDS]; /* max number of words*/ u64 plain[SKEIN_MAX_STATE_WORDS]; /* max number of words*/
u64 cipher[SKEIN_MAX_STATE_WORDS]; u64 cipher[SKEIN_MAX_STATE_WORDS];
Skein_Get64_LSB_First(cipher, in, keyCtx->stateSize / 64); /* bytes to words */ Skein_Get64_LSB_First(cipher, in, keyCtx->stateSize / 64);
threefishDecryptBlockWords(keyCtx, cipher, plain); threefishDecryptBlockWords(keyCtx, cipher, plain);
Skein_Put64_LSB_First(out, plain, keyCtx->stateSize / 8); /* words to bytes */ Skein_Put64_LSB_First(out, plain, keyCtx->stateSize / 8);
} }
void threefishDecryptBlockWords(struct threefish_key *keyCtx, u64 *in, void threefishDecryptBlockWords(struct threefish_key *keyCtx, u64 *in,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment