Commit 95f1840a authored by Anton Saraev's avatar Anton Saraev Committed by Greg Kroah-Hartman

staging: crypto: skein: rename camelcase vars

camelCase is not accepted in the Linux Kernel. To prepare skein
driver for mainline inclusion, we rename all vars to
non-camelCase equivalents.
Signed-off-by: default avatarAnton Saraev <antonysaraev@gmail.com>
Reviewed-by: default avatarJake Edge <jake@lwn.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 68ace624
skein/threefish TODO
- rename camelcase vars
- rename files
- move macros into appropriate header files
- add / pass test vectors
......
This diff is collapsed.
......@@ -59,7 +59,7 @@ OTHER DEALINGS IN THE SOFTWARE.
*
* // Now update Skein with any number of message bits. A function that
* // takes a number of bytes is also available.
* skein_update_bits(&ctx, message, msgLength);
* skein_update_bits(&ctx, message, msg_length);
*
* // Now get the result of the Skein hash. The output buffer must be
* // large enough to hold the request number of output bits. The application
......@@ -99,8 +99,8 @@ enum skein_size {
* structures as well.
*/
struct skein_ctx {
u64 skeinSize;
u64 XSave[SKEIN_MAX_STATE_WORDS]; /* save area for state variables */
u64 skein_size;
u64 X_save[SKEIN_MAX_STATE_WORDS]; /* save area for state variables */
union {
struct skein_ctx_hdr h;
struct skein_256_ctx s256;
......@@ -133,13 +133,13 @@ int skein_ctx_prepare(struct skein_ctx *ctx, enum skein_size size);
*
* @param ctx
* Pointer to a Skein context.
* @param hashBitLen
* @param hash_bit_len
* Number of MAC hash bits to compute
* @return
* SKEIN_SUCESS of SKEIN_FAIL
* @see skein_reset
*/
int skein_init(struct skein_ctx *ctx, size_t hashBitLen);
int skein_init(struct skein_ctx *ctx, size_t hash_bit_len);
/**
* Resets a Skein context for further use.
......@@ -166,15 +166,15 @@ void skein_reset(struct skein_ctx *ctx);
* Pointer to an empty or preinitialized Skein MAC context
* @param key
* Pointer to key bytes or NULL
* @param keyLen
* @param key_len
* Length of the key in bytes or zero
* @param hashBitLen
* @param hash_bit_len
* Number of MAC hash bits to compute
* @return
* SKEIN_SUCESS of SKEIN_FAIL
*/
int skein_mac_init(struct skein_ctx *ctx, const u8 *key, size_t keyLen,
size_t hashBitLen);
int skein_mac_init(struct skein_ctx *ctx, const u8 *key, size_t key_len,
size_t hash_bit_len);
/**
* Update Skein with the next part of the message.
......@@ -183,13 +183,13 @@ int skein_mac_init(struct skein_ctx *ctx, const u8 *key, size_t keyLen,
* Pointer to initialized Skein context
* @param msg
* Pointer to the message.
* @param msgByteCnt
* @param msg_byte_cnt
* Length of the message in @b bytes
* @return
* Success or error code.
*/
int skein_update(struct skein_ctx *ctx, const u8 *msg,
size_t msgByteCnt);
size_t msg_byte_cnt);
/**
* Update the hash with a message bit string.
......@@ -201,11 +201,11 @@ int skein_update(struct skein_ctx *ctx, const u8 *msg,
* Pointer to initialized Skein context
* @param msg
* Pointer to the message.
* @param msgBitCnt
* @param msg_bit_cnt
* Length of the message in @b bits.
*/
int skein_update_bits(struct skein_ctx *ctx, const u8 *msg,
size_t msgBitCnt);
size_t msg_bit_cnt);
/**
* Finalize Skein and return the hash.
......@@ -217,7 +217,7 @@ int skein_update_bits(struct skein_ctx *ctx, const u8 *msg,
* Pointer to initialized Skein context
* @param hash
* Pointer to buffer that receives the hash. The buffer must be large
* enough to store @c hashBitLen bits.
* enough to store @c hash_bit_len bits.
* @return
* Success or error code.
* @see skein_reset
......
......@@ -12,11 +12,11 @@
#include <skein.h> /* get the Skein API definitions */
void skein_256_process_block(struct skein_256_ctx *ctx, const u8 *blkPtr,
size_t blkCnt, size_t byteCntAdd);
void skein_512_process_block(struct skein_512_ctx *ctx, const u8 *blkPtr,
size_t blkCnt, size_t byteCntAdd);
void skein_1024_process_block(struct skein1024_ctx *ctx, const u8 *blkPtr,
size_t blkCnt, size_t byteCntAdd);
void skein_256_process_block(struct skein_256_ctx *ctx, const u8 *blk_ptr,
size_t blk_cnt, size_t byte_cnt_add);
void skein_512_process_block(struct skein_512_ctx *ctx, const u8 *blk_ptr,
size_t blk_cnt, size_t byte_cnt_add);
void skein_1024_process_block(struct skein1024_ctx *ctx, const u8 *blk_ptr,
size_t blk_cnt, size_t byte_cnt_add);
#endif
......@@ -18,13 +18,13 @@
*
@code
// Threefish cipher context data
struct threefish_key keyCtx;
struct threefish_key key_ctx;
// Initialize the context
threefish_set_key(&keyCtx, Threefish512, key, tweak);
threefish_set_key(&key_ctx, Threefish512, key, tweak);
// Encrypt
threefish_encrypt_block_bytes(&keyCtx, input, cipher);
threefish_encrypt_block_bytes(&key_ctx, input, cipher);
@endcode
*/
......@@ -51,7 +51,7 @@ enum threefish_size {
* structures as well.
*/
struct threefish_key {
u64 stateSize;
u64 state_size;
u64 key[SKEIN_MAX_STATE_WORDS+1]; /* max number of key words*/
u64 tweak[3];
};
......@@ -63,106 +63,106 @@ struct threefish_key {
* the given size. The key data must have the same length (number of bits)
* as the state size
*
* @param keyCtx
* @param key_ctx
* Pointer to a Threefish key structure.
* @param size
* Which Skein size to use.
* @param keyData
* @param key_data
* Pointer to the key words (word has 64 bits).
* @param tweak
* Pointer to the two tweak words (word has 64 bits).
*/
void threefish_set_key(struct threefish_key *keyCtx,
enum threefish_size stateSize,
u64 *keyData, u64 *tweak);
void threefish_set_key(struct threefish_key *key_ctx,
enum threefish_size state_size,
u64 *key_data, u64 *tweak);
/**
* Encrypt Threefisch block (bytes).
*
* The buffer must have at least the same length (number of bits) aas the
* state size for this key. The function uses the first @c stateSize bits
* state size for this key. The function uses the first @c state_size bits
* of the input buffer, encrypts them and stores the result in the output
* buffer.
*
* @param keyCtx
* @param key_ctx
* Pointer to a Threefish key structure.
* @param in
* Poionter to plaintext data buffer.
* @param out
* Pointer to cipher buffer.
*/
void threefish_encrypt_block_bytes(struct threefish_key *keyCtx, u8 *in,
void threefish_encrypt_block_bytes(struct threefish_key *key_ctx, u8 *in,
u8 *out);
/**
* Encrypt Threefisch block (words).
*
* The buffer must have at least the same length (number of bits) aas the
* state size for this key. The function uses the first @c stateSize bits
* state size for this key. The function uses the first @c state_size bits
* of the input buffer, encrypts them and stores the result in the output
* buffer.
*
* The wordsize ist set to 64 bits.
*
* @param keyCtx
* @param key_ctx
* Pointer to a Threefish key structure.
* @param in
* Poionter to plaintext data buffer.
* @param out
* Pointer to cipher buffer.
*/
void threefish_encrypt_block_words(struct threefish_key *keyCtx, u64 *in,
void threefish_encrypt_block_words(struct threefish_key *key_ctx, u64 *in,
u64 *out);
/**
* Decrypt Threefisch block (bytes).
*
* The buffer must have at least the same length (number of bits) aas the
* state size for this key. The function uses the first @c stateSize bits
* state size for this key. The function uses the first @c state_size bits
* of the input buffer, decrypts them and stores the result in the output
* buffer
*
* @param keyCtx
* @param key_ctx
* Pointer to a Threefish key structure.
* @param in
* Poionter to cipher data buffer.
* @param out
* Pointer to plaintext buffer.
*/
void threefish_decrypt_block_bytes(struct threefish_key *keyCtx, u8 *in,
void threefish_decrypt_block_bytes(struct threefish_key *key_ctx, u8 *in,
u8 *out);
/**
* Decrypt Threefisch block (words).
*
* The buffer must have at least the same length (number of bits) aas the
* state size for this key. The function uses the first @c stateSize bits
* state size for this key. The function uses the first @c state_size bits
* of the input buffer, encrypts them and stores the result in the output
* buffer.
*
* The wordsize ist set to 64 bits.
*
* @param keyCtx
* @param key_ctx
* Pointer to a Threefish key structure.
* @param in
* Poionter to cipher data buffer.
* @param out
* Pointer to plaintext buffer.
*/
void threefish_decrypt_block_words(struct threefish_key *keyCtx, u64 *in,
void threefish_decrypt_block_words(struct threefish_key *key_ctx, u64 *in,
u64 *out);
void threefish_encrypt_256(struct threefish_key *keyCtx, u64 *input,
void threefish_encrypt_256(struct threefish_key *key_ctx, u64 *input,
u64 *output);
void threefish_encrypt_512(struct threefish_key *keyCtx, u64 *input,
void threefish_encrypt_512(struct threefish_key *key_ctx, u64 *input,
u64 *output);
void threefish_encrypt_1024(struct threefish_key *keyCtx, u64 *input,
void threefish_encrypt_1024(struct threefish_key *key_ctx, u64 *input,
u64 *output);
void threefish_decrypt_256(struct threefish_key *keyCtx, u64 *input,
void threefish_decrypt_256(struct threefish_key *key_ctx, u64 *input,
u64 *output);
void threefish_decrypt_512(struct threefish_key *keyCtx, u64 *input,
void threefish_decrypt_512(struct threefish_key *key_ctx, u64 *input,
u64 *output);
void threefish_decrypt_1024(struct threefish_key *keyCtx, u64 *input,
void threefish_decrypt_1024(struct threefish_key *key_ctx, u64 *input,
u64 *output);
/**
* @}
......
This diff is collapsed.
......@@ -32,17 +32,17 @@ int skein_ctx_prepare(struct skein_ctx *ctx, enum skein_size size)
Skein_Assert(ctx && size, SKEIN_FAIL);
memset(ctx , 0, sizeof(struct skein_ctx));
ctx->skeinSize = size;
ctx->skein_size = size;
return SKEIN_SUCCESS;
}
int skein_init(struct skein_ctx *ctx, size_t hashBitLen)
int skein_init(struct skein_ctx *ctx, size_t hash_bit_len)
{
int ret = SKEIN_FAIL;
size_t Xlen = 0;
size_t X_len = 0;
u64 *X = NULL;
u64 treeInfo = SKEIN_CFG_TREE_INFO_SEQUENTIAL;
u64 tree_info = SKEIN_CFG_TREE_INFO_SEQUENTIAL;
Skein_Assert(ctx, SKEIN_FAIL);
/*
......@@ -51,83 +51,83 @@ int skein_init(struct skein_ctx *ctx, size_t hashBitLen)
* memory available. The beauty of C :-) .
*/
X = ctx->m.s256.X;
Xlen = ctx->skeinSize/8;
X_len = ctx->skein_size/8;
/*
* If size is the same and hash bit length is zero then reuse
* the save chaining variables.
*/
switch (ctx->skeinSize) {
switch (ctx->skein_size) {
case Skein256:
ret = skein_256_init_ext(&ctx->m.s256, hashBitLen,
treeInfo, NULL, 0);
ret = skein_256_init_ext(&ctx->m.s256, hash_bit_len,
tree_info, NULL, 0);
break;
case Skein512:
ret = skein_512_init_ext(&ctx->m.s512, hashBitLen,
treeInfo, NULL, 0);
ret = skein_512_init_ext(&ctx->m.s512, hash_bit_len,
tree_info, NULL, 0);
break;
case Skein1024:
ret = skein_1024_init_ext(&ctx->m.s1024, hashBitLen,
treeInfo, NULL, 0);
ret = skein_1024_init_ext(&ctx->m.s1024, hash_bit_len,
tree_info, NULL, 0);
break;
}
if (ret == SKEIN_SUCCESS) {
/*
* Save chaining variables for this combination of size and
* hashBitLen
* hash_bit_len
*/
memcpy(ctx->XSave, X, Xlen);
memcpy(ctx->X_save, X, X_len);
}
return ret;
}
int skein_mac_init(struct skein_ctx *ctx, const u8 *key, size_t keyLen,
size_t hashBitLen)
int skein_mac_init(struct skein_ctx *ctx, const u8 *key, size_t key_len,
size_t hash_bit_len)
{
int ret = SKEIN_FAIL;
u64 *X = NULL;
size_t Xlen = 0;
u64 treeInfo = SKEIN_CFG_TREE_INFO_SEQUENTIAL;
size_t X_len = 0;
u64 tree_info = SKEIN_CFG_TREE_INFO_SEQUENTIAL;
Skein_Assert(ctx, SKEIN_FAIL);
X = ctx->m.s256.X;
Xlen = ctx->skeinSize/8;
X_len = ctx->skein_size/8;
Skein_Assert(hashBitLen, SKEIN_BAD_HASHLEN);
Skein_Assert(hash_bit_len, SKEIN_BAD_HASHLEN);
switch (ctx->skeinSize) {
switch (ctx->skein_size) {
case Skein256:
ret = skein_256_init_ext(&ctx->m.s256, hashBitLen,
treeInfo,
(const u8 *)key, keyLen);
ret = skein_256_init_ext(&ctx->m.s256, hash_bit_len,
tree_info,
(const u8 *)key, key_len);
break;
case Skein512:
ret = skein_512_init_ext(&ctx->m.s512, hashBitLen,
treeInfo,
(const u8 *)key, keyLen);
ret = skein_512_init_ext(&ctx->m.s512, hash_bit_len,
tree_info,
(const u8 *)key, key_len);
break;
case Skein1024:
ret = skein_1024_init_ext(&ctx->m.s1024, hashBitLen,
treeInfo,
(const u8 *)key, keyLen);
ret = skein_1024_init_ext(&ctx->m.s1024, hash_bit_len,
tree_info,
(const u8 *)key, key_len);
break;
}
if (ret == SKEIN_SUCCESS) {
/*
* Save chaining variables for this combination of key,
* keyLen, hashBitLen
* key_len, hash_bit_len
*/
memcpy(ctx->XSave, X, Xlen);
memcpy(ctx->X_save, X, X_len);
}
return ret;
}
void skein_reset(struct skein_ctx *ctx)
{
size_t Xlen = 0;
size_t X_len = 0;
u64 *X = NULL;
/*
......@@ -136,32 +136,33 @@ void skein_reset(struct skein_ctx *ctx)
* memory available. The beautiy of C :-) .
*/
X = ctx->m.s256.X;
Xlen = ctx->skeinSize/8;
X_len = ctx->skein_size/8;
/* Restore the chaing variable, reset byte counter */
memcpy(X, ctx->XSave, Xlen);
memcpy(X, ctx->X_save, X_len);
/* Setup context to process the message */
Skein_Start_New_Type(&ctx->m, MSG);
}
int skein_update(struct skein_ctx *ctx, const u8 *msg,
size_t msgByteCnt)
size_t msg_byte_cnt)
{
int ret = SKEIN_FAIL;
Skein_Assert(ctx, SKEIN_FAIL);
switch (ctx->skeinSize) {
switch (ctx->skein_size) {
case Skein256:
ret = skein_256_update(&ctx->m.s256, (const u8 *)msg,
msgByteCnt);
msg_byte_cnt);
break;
case Skein512:
ret = skein_512_update(&ctx->m.s512, (const u8 *)msg,
msgByteCnt);
msg_byte_cnt);
break;
case Skein1024:
ret = skein_1024_update(&ctx->m.s1024, (const u8 *)msg,
msgByteCnt);
msg_byte_cnt);
break;
}
return ret;
......@@ -169,7 +170,7 @@ int skein_update(struct skein_ctx *ctx, const u8 *msg,
}
int skein_update_bits(struct skein_ctx *ctx, const u8 *msg,
size_t msgBitCnt)
size_t msg_bit_cnt)
{
/*
* I've used the bit pad implementation from skein_test.c (see NIST CD)
......@@ -185,13 +186,13 @@ int skein_update_bits(struct skein_ctx *ctx, const u8 *msg,
* assert an error
*/
Skein_Assert((ctx->m.h.T[1] & SKEIN_T1_FLAG_BIT_PAD) == 0 ||
msgBitCnt == 0, SKEIN_FAIL);
msg_bit_cnt == 0, SKEIN_FAIL);
/* if number of bits is a multiple of bytes - that's easy */
if ((msgBitCnt & 0x7) == 0)
return skein_update(ctx, msg, msgBitCnt >> 3);
if ((msg_bit_cnt & 0x7) == 0)
return skein_update(ctx, msg, msg_bit_cnt >> 3);
skein_update(ctx, msg, (msgBitCnt >> 3) + 1);
skein_update(ctx, msg, (msg_bit_cnt >> 3) + 1);
/*
* The next line rely on the fact that the real Skein contexts
......@@ -199,18 +200,18 @@ int skein_update_bits(struct skein_ctx *ctx, const u8 *msg,
* Skein's real partial block buffer.
* If this layout ever changes we have to adapt this as well.
*/
up = (u8 *)ctx->m.s256.X + ctx->skeinSize / 8;
up = (u8 *)ctx->m.s256.X + ctx->skein_size / 8;
/* set tweak flag for the skein_final call */
Skein_Set_Bit_Pad_Flag(ctx->m.h);
/* now "pad" the final partial byte the way NIST likes */
/* get the bCnt value (same location for all block sizes) */
length = ctx->m.h.bCnt;
/* get the b_cnt value (same location for all block sizes) */
length = ctx->m.h.b_cnt;
/* internal sanity check: there IS a partial byte in the buffer! */
Skein_assert(length != 0);
/* partial byte bit mask */
mask = (u8) (1u << (7 - (msgBitCnt & 7)));
mask = (u8) (1u << (7 - (msg_bit_cnt & 7)));
/* apply bit padding on final byte (in the buffer) */
up[length-1] = (u8)((up[length-1] & (0-mask))|mask);
......@@ -220,9 +221,10 @@ int skein_update_bits(struct skein_ctx *ctx, const u8 *msg,
int skein_final(struct skein_ctx *ctx, u8 *hash)
{
int ret = SKEIN_FAIL;
Skein_Assert(ctx, SKEIN_FAIL);
switch (ctx->skeinSize) {
switch (ctx->skein_size) {
case Skein256:
ret = skein_256_final(&ctx->m.s256, (u8 *)hash);
break;
......
......@@ -5,8 +5,8 @@
/***************************** Skein_256 ******************************/
void skein_256_process_block(struct skein_256_ctx *ctx, const u8 *blkPtr,
size_t blkCnt, size_t byteCntAdd)
void skein_256_process_block(struct skein_256_ctx *ctx, const u8 *blk_ptr,
size_t blk_cnt, size_t byte_cnt_add)
{
struct threefish_key key;
u64 tweak[2];
......@@ -14,12 +14,12 @@ void skein_256_process_block(struct skein_256_ctx *ctx, const u8 *blkPtr,
u64 w[SKEIN_256_STATE_WORDS]; /* local copy of input block */
u64 words[3];
Skein_assert(blkCnt != 0); /* never call with blkCnt == 0! */
Skein_assert(blk_cnt != 0); /* never call with blk_cnt == 0! */
tweak[0] = ctx->h.T[0];
tweak[1] = ctx->h.T[1];
do {
u64 carry = byteCntAdd;
u64 carry = byte_cnt_add;
words[0] = tweak[0] & 0xffffffffL;
words[1] = ((tweak[0] >> 32) & 0xffffffffL);
......@@ -37,11 +37,11 @@ void skein_256_process_block(struct skein_256_ctx *ctx, const u8 *blkPtr,
threefish_set_key(&key, Threefish256, ctx->X, tweak);
/* get input block in little-endian format */
Skein_Get64_LSB_First(w, blkPtr, SKEIN_256_STATE_WORDS);
Skein_Get64_LSB_First(w, blk_ptr, SKEIN_256_STATE_WORDS);
threefish_encrypt_block_words(&key, w, ctx->X);
blkPtr += SKEIN_256_BLOCK_BYTES;
blk_ptr += SKEIN_256_BLOCK_BYTES;
/* do the final "feedforward" xor, update ctx chaining vars */
ctx->X[0] = ctx->X[0] ^ w[0];
......@@ -50,14 +50,14 @@ void skein_256_process_block(struct skein_256_ctx *ctx, const u8 *blkPtr,
ctx->X[3] = ctx->X[3] ^ w[3];
tweak[1] &= ~SKEIN_T1_FLAG_FIRST;
} while (--blkCnt);
} while (--blk_cnt);
ctx->h.T[0] = tweak[0];
ctx->h.T[1] = tweak[1];
}
void skein_512_process_block(struct skein_512_ctx *ctx, const u8 *blkPtr,
size_t blkCnt, size_t byteCntAdd)
void skein_512_process_block(struct skein_512_ctx *ctx, const u8 *blk_ptr,
size_t blk_cnt, size_t byte_cnt_add)
{
struct threefish_key key;
u64 tweak[2];
......@@ -65,12 +65,12 @@ void skein_512_process_block(struct skein_512_ctx *ctx, const u8 *blkPtr,
u64 words[3];
u64 w[SKEIN_512_STATE_WORDS]; /* local copy of input block */
Skein_assert(blkCnt != 0); /* never call with blkCnt == 0! */
Skein_assert(blk_cnt != 0); /* never call with blk_cnt == 0! */
tweak[0] = ctx->h.T[0];
tweak[1] = ctx->h.T[1];
do {
u64 carry = byteCntAdd;
u64 carry = byte_cnt_add;
words[0] = tweak[0] & 0xffffffffL;
words[1] = ((tweak[0] >> 32) & 0xffffffffL);
......@@ -88,11 +88,11 @@ void skein_512_process_block(struct skein_512_ctx *ctx, const u8 *blkPtr,
threefish_set_key(&key, Threefish512, ctx->X, tweak);
/* get input block in little-endian format */
Skein_Get64_LSB_First(w, blkPtr, SKEIN_512_STATE_WORDS);
Skein_Get64_LSB_First(w, blk_ptr, SKEIN_512_STATE_WORDS);
threefish_encrypt_block_words(&key, w, ctx->X);
blkPtr += SKEIN_512_BLOCK_BYTES;
blk_ptr += SKEIN_512_BLOCK_BYTES;
/* do the final "feedforward" xor, update ctx chaining vars */
ctx->X[0] = ctx->X[0] ^ w[0];
......@@ -105,14 +105,14 @@ void skein_512_process_block(struct skein_512_ctx *ctx, const u8 *blkPtr,
ctx->X[7] = ctx->X[7] ^ w[7];
tweak[1] &= ~SKEIN_T1_FLAG_FIRST;
} while (--blkCnt);
} while (--blk_cnt);
ctx->h.T[0] = tweak[0];
ctx->h.T[1] = tweak[1];
}
void skein_1024_process_block(struct skein1024_ctx *ctx, const u8 *blkPtr,
size_t blkCnt, size_t byteCntAdd)
void skein_1024_process_block(struct skein1024_ctx *ctx, const u8 *blk_ptr,
size_t blk_cnt, size_t byte_cnt_add)
{
struct threefish_key key;
u64 tweak[2];
......@@ -120,12 +120,12 @@ void skein_1024_process_block(struct skein1024_ctx *ctx, const u8 *blkPtr,
u64 words[3];
u64 w[SKEIN1024_STATE_WORDS]; /* local copy of input block */
Skein_assert(blkCnt != 0); /* never call with blkCnt == 0! */
Skein_assert(blk_cnt != 0); /* never call with blk_cnt == 0! */
tweak[0] = ctx->h.T[0];
tweak[1] = ctx->h.T[1];
do {
u64 carry = byteCntAdd;
u64 carry = byte_cnt_add;
words[0] = tweak[0] & 0xffffffffL;
words[1] = ((tweak[0] >> 32) & 0xffffffffL);
......@@ -143,11 +143,11 @@ void skein_1024_process_block(struct skein1024_ctx *ctx, const u8 *blkPtr,
threefish_set_key(&key, Threefish1024, ctx->X, tweak);
/* get input block in little-endian format */
Skein_Get64_LSB_First(w, blkPtr, SKEIN1024_STATE_WORDS);
Skein_Get64_LSB_First(w, blk_ptr, SKEIN1024_STATE_WORDS);
threefish_encrypt_block_words(&key, w, ctx->X);
blkPtr += SKEIN1024_BLOCK_BYTES;
blk_ptr += SKEIN1024_BLOCK_BYTES;
/* do the final "feedforward" xor, update ctx chaining vars */
ctx->X[0] = ctx->X[0] ^ w[0];
......@@ -168,7 +168,7 @@ void skein_1024_process_block(struct skein1024_ctx *ctx, const u8 *blkPtr,
ctx->X[15] = ctx->X[15] ^ w[15];
tweak[1] &= ~SKEIN_T1_FLAG_FIRST;
} while (--blkCnt);
} while (--blk_cnt);
ctx->h.T[0] = tweak[0];
ctx->h.T[1] = tweak[1];
......
This diff is collapsed.
......@@ -2,28 +2,28 @@
#include <threefishApi.h>
void threefish_encrypt_1024(struct threefish_key *keyCtx, u64 *input,
void threefish_encrypt_1024(struct threefish_key *key_ctx, u64 *input,
u64 *output)
{
u64 b0 = input[0], b1 = input[1],
b2 = input[2], b3 = input[3],
b4 = input[4], b5 = input[5],
b6 = input[6], b7 = input[7],
b8 = input[8], b9 = input[9],
b10 = input[10], b11 = input[11],
b12 = input[12], b13 = input[13],
b14 = input[14], b15 = input[15];
u64 k0 = keyCtx->key[0], k1 = keyCtx->key[1],
k2 = keyCtx->key[2], k3 = keyCtx->key[3],
k4 = keyCtx->key[4], k5 = keyCtx->key[5],
k6 = keyCtx->key[6], k7 = keyCtx->key[7],
k8 = keyCtx->key[8], k9 = keyCtx->key[9],
k10 = keyCtx->key[10], k11 = keyCtx->key[11],
k12 = keyCtx->key[12], k13 = keyCtx->key[13],
k14 = keyCtx->key[14], k15 = keyCtx->key[15],
k16 = keyCtx->key[16];
u64 t0 = keyCtx->tweak[0], t1 = keyCtx->tweak[1],
t2 = keyCtx->tweak[2];
b2 = input[2], b3 = input[3],
b4 = input[4], b5 = input[5],
b6 = input[6], b7 = input[7],
b8 = input[8], b9 = input[9],
b10 = input[10], b11 = input[11],
b12 = input[12], b13 = input[13],
b14 = input[14], b15 = input[15];
u64 k0 = key_ctx->key[0], k1 = key_ctx->key[1],
k2 = key_ctx->key[2], k3 = key_ctx->key[3],
k4 = key_ctx->key[4], k5 = key_ctx->key[5],
k6 = key_ctx->key[6], k7 = key_ctx->key[7],
k8 = key_ctx->key[8], k9 = key_ctx->key[9],
k10 = key_ctx->key[10], k11 = key_ctx->key[11],
k12 = key_ctx->key[12], k13 = key_ctx->key[13],
k14 = key_ctx->key[14], k15 = key_ctx->key[15],
k16 = key_ctx->key[16];
u64 t0 = key_ctx->tweak[0], t1 = key_ctx->tweak[1],
t2 = key_ctx->tweak[2];
b1 += k1;
b0 += b1 + k0;
......@@ -2123,28 +2123,28 @@ void threefish_encrypt_1024(struct threefish_key *keyCtx, u64 *input,
output[15] = b15 + k1 + 20;
}
void threefish_decrypt_1024(struct threefish_key *keyCtx, u64 *input,
void threefish_decrypt_1024(struct threefish_key *key_ctx, u64 *input,
u64 *output)
{
u64 b0 = input[0], b1 = input[1],
b2 = input[2], b3 = input[3],
b4 = input[4], b5 = input[5],
b6 = input[6], b7 = input[7],
b8 = input[8], b9 = input[9],
b10 = input[10], b11 = input[11],
b12 = input[12], b13 = input[13],
b14 = input[14], b15 = input[15];
u64 k0 = keyCtx->key[0], k1 = keyCtx->key[1],
k2 = keyCtx->key[2], k3 = keyCtx->key[3],
k4 = keyCtx->key[4], k5 = keyCtx->key[5],
k6 = keyCtx->key[6], k7 = keyCtx->key[7],
k8 = keyCtx->key[8], k9 = keyCtx->key[9],
k10 = keyCtx->key[10], k11 = keyCtx->key[11],
k12 = keyCtx->key[12], k13 = keyCtx->key[13],
k14 = keyCtx->key[14], k15 = keyCtx->key[15],
k16 = keyCtx->key[16];
u64 t0 = keyCtx->tweak[0], t1 = keyCtx->tweak[1],
t2 = keyCtx->tweak[2];
b2 = input[2], b3 = input[3],
b4 = input[4], b5 = input[5],
b6 = input[6], b7 = input[7],
b8 = input[8], b9 = input[9],
b10 = input[10], b11 = input[11],
b12 = input[12], b13 = input[13],
b14 = input[14], b15 = input[15];
u64 k0 = key_ctx->key[0], k1 = key_ctx->key[1],
k2 = key_ctx->key[2], k3 = key_ctx->key[3],
k4 = key_ctx->key[4], k5 = key_ctx->key[5],
k6 = key_ctx->key[6], k7 = key_ctx->key[7],
k8 = key_ctx->key[8], k9 = key_ctx->key[9],
k10 = key_ctx->key[10], k11 = key_ctx->key[11],
k12 = key_ctx->key[12], k13 = key_ctx->key[13],
k14 = key_ctx->key[14], k15 = key_ctx->key[15],
k16 = key_ctx->key[16];
u64 t0 = key_ctx->tweak[0], t1 = key_ctx->tweak[1],
t2 = key_ctx->tweak[2];
u64 tmp;
b0 -= k3;
......
......@@ -2,16 +2,16 @@
#include <threefishApi.h>
void threefish_encrypt_256(struct threefish_key *keyCtx, u64 *input,
void threefish_encrypt_256(struct threefish_key *key_ctx, u64 *input,
u64 *output)
{
u64 b0 = input[0], b1 = input[1],
b2 = input[2], b3 = input[3];
u64 k0 = keyCtx->key[0], k1 = keyCtx->key[1],
k2 = keyCtx->key[2], k3 = keyCtx->key[3],
k4 = keyCtx->key[4];
u64 t0 = keyCtx->tweak[0], t1 = keyCtx->tweak[1],
t2 = keyCtx->tweak[2];
b2 = input[2], b3 = input[3];
u64 k0 = key_ctx->key[0], k1 = key_ctx->key[1],
k2 = key_ctx->key[2], k3 = key_ctx->key[3],
k4 = key_ctx->key[4];
u64 t0 = key_ctx->tweak[0], t1 = key_ctx->tweak[1],
t2 = key_ctx->tweak[2];
b1 += k1 + t0;
b0 += b1 + k0;
......@@ -495,16 +495,16 @@ void threefish_encrypt_256(struct threefish_key *keyCtx, u64 *input,
output[3] = b3 + k1 + 18;
}
void threefish_decrypt_256(struct threefish_key *keyCtx, u64 *input,
void threefish_decrypt_256(struct threefish_key *key_ctx, u64 *input,
u64 *output)
{
u64 b0 = input[0], b1 = input[1],
b2 = input[2], b3 = input[3];
u64 k0 = keyCtx->key[0], k1 = keyCtx->key[1],
k2 = keyCtx->key[2], k3 = keyCtx->key[3],
k4 = keyCtx->key[4];
u64 t0 = keyCtx->tweak[0], t1 = keyCtx->tweak[1],
t2 = keyCtx->tweak[2];
b2 = input[2], b3 = input[3];
u64 k0 = key_ctx->key[0], k1 = key_ctx->key[1],
k2 = key_ctx->key[2], k3 = key_ctx->key[3],
k4 = key_ctx->key[4];
u64 t0 = key_ctx->tweak[0], t1 = key_ctx->tweak[1],
t2 = key_ctx->tweak[2];
u64 tmp;
......
......@@ -2,20 +2,20 @@
#include <threefishApi.h>
void threefish_encrypt_512(struct threefish_key *keyCtx, u64 *input,
void threefish_encrypt_512(struct threefish_key *key_ctx, u64 *input,
u64 *output)
{
u64 b0 = input[0], b1 = input[1],
b2 = input[2], b3 = input[3],
b4 = input[4], b5 = input[5],
b6 = input[6], b7 = input[7];
u64 k0 = keyCtx->key[0], k1 = keyCtx->key[1],
k2 = keyCtx->key[2], k3 = keyCtx->key[3],
k4 = keyCtx->key[4], k5 = keyCtx->key[5],
k6 = keyCtx->key[6], k7 = keyCtx->key[7],
k8 = keyCtx->key[8];
u64 t0 = keyCtx->tweak[0], t1 = keyCtx->tweak[1],
t2 = keyCtx->tweak[2];
b2 = input[2], b3 = input[3],
b4 = input[4], b5 = input[5],
b6 = input[6], b7 = input[7];
u64 k0 = key_ctx->key[0], k1 = key_ctx->key[1],
k2 = key_ctx->key[2], k3 = key_ctx->key[3],
k4 = key_ctx->key[4], k5 = key_ctx->key[5],
k6 = key_ctx->key[6], k7 = key_ctx->key[7],
k8 = key_ctx->key[8];
u64 t0 = key_ctx->tweak[0], t1 = key_ctx->tweak[1],
t2 = key_ctx->tweak[2];
b1 += k1;
b0 += b1 + k0;
......@@ -963,20 +963,20 @@ void threefish_encrypt_512(struct threefish_key *keyCtx, u64 *input,
output[7] = b7 + k7 + 18;
}
void threefish_decrypt_512(struct threefish_key *keyCtx, u64 *input,
void threefish_decrypt_512(struct threefish_key *key_ctx, u64 *input,
u64 *output)
{
u64 b0 = input[0], b1 = input[1],
b2 = input[2], b3 = input[3],
b4 = input[4], b5 = input[5],
b6 = input[6], b7 = input[7];
u64 k0 = keyCtx->key[0], k1 = keyCtx->key[1],
k2 = keyCtx->key[2], k3 = keyCtx->key[3],
k4 = keyCtx->key[4], k5 = keyCtx->key[5],
k6 = keyCtx->key[6], k7 = keyCtx->key[7],
k8 = keyCtx->key[8];
u64 t0 = keyCtx->tweak[0], t1 = keyCtx->tweak[1],
t2 = keyCtx->tweak[2];
b2 = input[2], b3 = input[3],
b4 = input[4], b5 = input[5],
b6 = input[6], b7 = input[7];
u64 k0 = key_ctx->key[0], k1 = key_ctx->key[1],
k2 = key_ctx->key[2], k3 = key_ctx->key[3],
k4 = key_ctx->key[4], k5 = key_ctx->key[5],
k6 = key_ctx->key[6], k7 = key_ctx->key[7],
k8 = key_ctx->key[8];
u64 t0 = key_ctx->tweak[0], t1 = key_ctx->tweak[1],
t2 = key_ctx->tweak[2];
u64 tmp;
......
......@@ -3,76 +3,76 @@
#include <linux/string.h>
#include <threefishApi.h>
void threefish_set_key(struct threefish_key *keyCtx,
enum threefish_size stateSize,
u64 *keyData, u64 *tweak)
void threefish_set_key(struct threefish_key *key_ctx,
enum threefish_size state_size,
u64 *key_data, u64 *tweak)
{
int keyWords = stateSize / 64;
int key_words = state_size / 64;
int i;
u64 parity = KeyScheduleConst;
keyCtx->tweak[0] = tweak[0];
keyCtx->tweak[1] = tweak[1];
keyCtx->tweak[2] = tweak[0] ^ tweak[1];
key_ctx->tweak[0] = tweak[0];
key_ctx->tweak[1] = tweak[1];
key_ctx->tweak[2] = tweak[0] ^ tweak[1];
for (i = 0; i < keyWords; i++) {
keyCtx->key[i] = keyData[i];
parity ^= keyData[i];
for (i = 0; i < key_words; i++) {
key_ctx->key[i] = key_data[i];
parity ^= key_data[i];
}
keyCtx->key[i] = parity;
keyCtx->stateSize = stateSize;
key_ctx->key[i] = parity;
key_ctx->state_size = state_size;
}
void threefish_encrypt_block_bytes(struct threefish_key *keyCtx, u8 *in,
void threefish_encrypt_block_bytes(struct threefish_key *key_ctx, u8 *in,
u8 *out)
{
u64 plain[SKEIN_MAX_STATE_WORDS]; /* max number of words*/
u64 cipher[SKEIN_MAX_STATE_WORDS];
Skein_Get64_LSB_First(plain, in, keyCtx->stateSize / 64);
threefish_encrypt_block_words(keyCtx, plain, cipher);
Skein_Put64_LSB_First(out, cipher, keyCtx->stateSize / 8);
Skein_Get64_LSB_First(plain, in, key_ctx->state_size / 64);
threefish_encrypt_block_words(key_ctx, plain, cipher);
Skein_Put64_LSB_First(out, cipher, key_ctx->state_size / 8);
}
void threefish_encrypt_block_words(struct threefish_key *keyCtx, u64 *in,
void threefish_encrypt_block_words(struct threefish_key *key_ctx, u64 *in,
u64 *out)
{
switch (keyCtx->stateSize) {
switch (key_ctx->state_size) {
case Threefish256:
threefish_encrypt_256(keyCtx, in, out);
threefish_encrypt_256(key_ctx, in, out);
break;
case Threefish512:
threefish_encrypt_512(keyCtx, in, out);
threefish_encrypt_512(key_ctx, in, out);
break;
case Threefish1024:
threefish_encrypt_1024(keyCtx, in, out);
threefish_encrypt_1024(key_ctx, in, out);
break;
}
}
void threefish_decrypt_block_bytes(struct threefish_key *keyCtx, u8 *in,
void threefish_decrypt_block_bytes(struct threefish_key *key_ctx, u8 *in,
u8 *out)
{
u64 plain[SKEIN_MAX_STATE_WORDS]; /* max number of words*/
u64 cipher[SKEIN_MAX_STATE_WORDS];
Skein_Get64_LSB_First(cipher, in, keyCtx->stateSize / 64);
threefish_decrypt_block_words(keyCtx, cipher, plain);
Skein_Put64_LSB_First(out, plain, keyCtx->stateSize / 8);
Skein_Get64_LSB_First(cipher, in, key_ctx->state_size / 64);
threefish_decrypt_block_words(key_ctx, cipher, plain);
Skein_Put64_LSB_First(out, plain, key_ctx->state_size / 8);
}
void threefish_decrypt_block_words(struct threefish_key *keyCtx, u64 *in,
void threefish_decrypt_block_words(struct threefish_key *key_ctx, u64 *in,
u64 *out)
{
switch (keyCtx->stateSize) {
switch (key_ctx->state_size) {
case Threefish256:
threefish_decrypt_256(keyCtx, in, out);
threefish_decrypt_256(key_ctx, in, out);
break;
case Threefish512:
threefish_decrypt_512(keyCtx, in, out);
threefish_decrypt_512(key_ctx, in, out);
break;
case Threefish1024:
threefish_decrypt_1024(keyCtx, in, out);
threefish_decrypt_1024(key_ctx, in, out);
break;
}
}
......
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