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 skein/threefish TODO
- rename camelcase vars
- rename files - rename files
- move macros into appropriate header files - move macros into appropriate header files
- add / pass test vectors - add / pass test vectors
......
...@@ -33,8 +33,9 @@ ...@@ -33,8 +33,9 @@
#endif #endif
/* below two prototype assume we are handed aligned data */ /* below two prototype assume we are handed aligned data */
#define Skein_Put64_LSB_First(dst08, src64, bCnt) memcpy(dst08, src64, bCnt) #define Skein_Put64_LSB_First(dst08, src64, b_cnt) memcpy(dst08, src64, b_cnt)
#define Skein_Get64_LSB_First(dst64, src08, wCnt) memcpy(dst64, src08, 8*(wCnt)) #define Skein_Get64_LSB_First(dst64, src08, w_cnt) \
memcpy(dst64, src08, 8*(w_cnt))
#define Skein_Swap64(w64) (w64) #define Skein_Swap64(w64) (w64)
enum { enum {
...@@ -63,8 +64,8 @@ enum { ...@@ -63,8 +64,8 @@ enum {
#define SKEIN1024_BLOCK_BYTES (8*SKEIN1024_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 hash_bit_len; /* size of hash result, in bits */
size_t bCnt; /* current byte count in buffer b[] */ size_t b_cnt; /* current byte count in buffer b[] */
u64 T[SKEIN_MODIFIER_WORDS]; /* tweak: T[0]=byte cnt, T[1]=flags */ u64 T[SKEIN_MODIFIER_WORDS]; /* tweak: T[0]=byte cnt, T[1]=flags */
}; };
...@@ -87,58 +88,58 @@ struct skein1024_ctx { /* 1024-bit Skein hash context structure */ ...@@ -87,58 +88,58 @@ struct skein1024_ctx { /* 1024-bit Skein hash context structure */
}; };
/* Skein APIs for (incremental) "straight hashing" */ /* Skein APIs for (incremental) "straight hashing" */
int skein_256_init(struct skein_256_ctx *ctx, size_t hashBitLen); int skein_256_init(struct skein_256_ctx *ctx, size_t hash_bit_len);
int skein_512_init(struct skein_512_ctx *ctx, size_t hashBitLen); int skein_512_init(struct skein_512_ctx *ctx, size_t hash_bit_len);
int skein_1024_init(struct skein1024_ctx *ctx, size_t hashBitLen); int skein_1024_init(struct skein1024_ctx *ctx, size_t hash_bit_len);
int skein_256_update(struct skein_256_ctx *ctx, const u8 *msg, int skein_256_update(struct skein_256_ctx *ctx, const u8 *msg,
size_t msgByteCnt); size_t msg_byte_cnt);
int skein_512_update(struct skein_512_ctx *ctx, const u8 *msg, int skein_512_update(struct skein_512_ctx *ctx, const u8 *msg,
size_t msgByteCnt); size_t msg_byte_cnt);
int skein_1024_update(struct skein1024_ctx *ctx, const u8 *msg, int skein_1024_update(struct skein1024_ctx *ctx, const u8 *msg,
size_t msgByteCnt); size_t msg_byte_cnt);
int skein_256_final(struct skein_256_ctx *ctx, u8 *hashVal); int skein_256_final(struct skein_256_ctx *ctx, u8 *hash_val);
int skein_512_final(struct skein_512_ctx *ctx, u8 *hashVal); int skein_512_final(struct skein_512_ctx *ctx, u8 *hash_val);
int skein_1024_final(struct skein1024_ctx *ctx, u8 *hashVal); int skein_1024_final(struct skein1024_ctx *ctx, u8 *hash_val);
/* /*
** Skein APIs for "extended" initialization: MAC keys, tree hashing. ** Skein APIs for "extended" initialization: MAC keys, tree hashing.
** After an init_ext() call, just use update/final calls as with init(). ** After an init_ext() call, just use update/final calls as with init().
** **
** Notes: Same parameters as _init() calls, plus treeInfo/key/keyBytes. ** Notes: Same parameters as _init() calls, plus tree_info/key/key_bytes.
** When keyBytes == 0 and treeInfo == SKEIN_SEQUENTIAL, ** When key_bytes == 0 and tree_info == SKEIN_SEQUENTIAL,
** the results of init_ext() are identical to calling init(). ** the results of init_ext() are identical to calling init().
** The function init() may be called once to "precompute" the IV for ** The function init() may be called once to "precompute" the IV for
** a given hashBitLen value, then by saving a copy of the context ** a given hash_bit_len value, then by saving a copy of the context
** the IV computation may be avoided in later calls. ** the IV computation may be avoided in later calls.
** Similarly, the function init_ext() may be called once per MAC key ** Similarly, the function init_ext() may be called once per MAC key
** to precompute the MAC IV, then a copy of the context saved and ** to precompute the MAC IV, then a copy of the context saved and
** reused for each new MAC computation. ** reused for each new MAC computation.
**/ **/
int skein_256_init_ext(struct skein_256_ctx *ctx, size_t hashBitLen, int skein_256_init_ext(struct skein_256_ctx *ctx, size_t hash_bit_len,
u64 treeInfo, const u8 *key, size_t keyBytes); u64 tree_info, const u8 *key, size_t key_bytes);
int skein_512_init_ext(struct skein_512_ctx *ctx, size_t hashBitLen, int skein_512_init_ext(struct skein_512_ctx *ctx, size_t hash_bit_len,
u64 treeInfo, const u8 *key, size_t keyBytes); u64 tree_info, const u8 *key, size_t key_bytes);
int skein_1024_init_ext(struct skein1024_ctx *ctx, size_t hashBitLen, int skein_1024_init_ext(struct skein1024_ctx *ctx, size_t hash_bit_len,
u64 treeInfo, const u8 *key, size_t keyBytes); u64 tree_info, const u8 *key, size_t key_bytes);
/* /*
** Skein APIs for MAC and tree hash: ** Skein APIs for MAC and tree hash:
** final_pad: pad, do final block, but no OUTPUT type ** final_pad: pad, do final block, but no OUTPUT type
** output: do just the output stage ** output: do just the output stage
*/ */
int skein_256_final_pad(struct skein_256_ctx *ctx, u8 *hashVal); int skein_256_final_pad(struct skein_256_ctx *ctx, u8 *hash_val);
int skein_512_final_pad(struct skein_512_ctx *ctx, u8 *hashVal); int skein_512_final_pad(struct skein_512_ctx *ctx, u8 *hash_val);
int skein_1024_final_pad(struct skein1024_ctx *ctx, u8 *hashVal); int skein_1024_final_pad(struct skein1024_ctx *ctx, u8 *hash_val);
#ifndef SKEIN_TREE_HASH #ifndef SKEIN_TREE_HASH
#define SKEIN_TREE_HASH (1) #define SKEIN_TREE_HASH (1)
#endif #endif
#if SKEIN_TREE_HASH #if SKEIN_TREE_HASH
int skein_256_output(struct skein_256_ctx *ctx, u8 *hashVal); int skein_256_output(struct skein_256_ctx *ctx, u8 *hash_val);
int skein_512_output(struct skein_512_ctx *ctx, u8 *hashVal); int skein_512_output(struct skein_512_ctx *ctx, u8 *hash_val);
int skein_1024_output(struct skein1024_ctx *ctx, u8 *hashVal); int skein_1024_output(struct skein1024_ctx *ctx, u8 *hash_val);
#endif #endif
/***************************************************************** /*****************************************************************
...@@ -207,7 +208,7 @@ int skein_1024_output(struct skein1024_ctx *ctx, u8 *hashVal); ...@@ -207,7 +208,7 @@ int skein_1024_output(struct skein1024_ctx *ctx, u8 *hashVal);
#define SKEIN_CFG_STR_LEN (4*8) #define SKEIN_CFG_STR_LEN (4*8)
/* bit field definitions in config block treeInfo word */ /* bit field definitions in config block tree_info word */
#define SKEIN_CFG_TREE_LEAF_SIZE_POS (0) #define SKEIN_CFG_TREE_LEAF_SIZE_POS (0)
#define SKEIN_CFG_TREE_NODE_SIZE_POS (8) #define SKEIN_CFG_TREE_NODE_SIZE_POS (8)
#define SKEIN_CFG_TREE_MAX_LEVEL_POS (16) #define SKEIN_CFG_TREE_MAX_LEVEL_POS (16)
...@@ -219,46 +220,46 @@ int skein_1024_output(struct skein1024_ctx *ctx, u8 *hashVal); ...@@ -219,46 +220,46 @@ int skein_1024_output(struct skein1024_ctx *ctx, u8 *hashVal);
#define SKEIN_CFG_TREE_MAX_LEVEL_MSK (((u64)0xFF) << \ #define SKEIN_CFG_TREE_MAX_LEVEL_MSK (((u64)0xFF) << \
SKEIN_CFG_TREE_MAX_LEVEL_POS) SKEIN_CFG_TREE_MAX_LEVEL_POS)
#define SKEIN_CFG_TREE_INFO(leaf, node, maxLvl) \ #define SKEIN_CFG_TREE_INFO(leaf, node, max_lvl) \
((((u64)(leaf)) << SKEIN_CFG_TREE_LEAF_SIZE_POS) | \ ((((u64)(leaf)) << SKEIN_CFG_TREE_LEAF_SIZE_POS) | \
(((u64)(node)) << SKEIN_CFG_TREE_NODE_SIZE_POS) | \ (((u64)(node)) << SKEIN_CFG_TREE_NODE_SIZE_POS) | \
(((u64)(maxLvl)) << SKEIN_CFG_TREE_MAX_LEVEL_POS)) (((u64)(max_lvl)) << SKEIN_CFG_TREE_MAX_LEVEL_POS))
/* use as treeInfo in InitExt() call for sequential processing */ /* use as tree_info in InitExt() call for sequential processing */
#define SKEIN_CFG_TREE_INFO_SEQUENTIAL SKEIN_CFG_TREE_INFO(0, 0, 0) #define SKEIN_CFG_TREE_INFO_SEQUENTIAL SKEIN_CFG_TREE_INFO(0, 0, 0)
/* /*
** Skein macros for getting/setting tweak words, etc. ** Skein macros for getting/setting tweak words, etc.
** These are useful for partial input bytes, hash tree init/update, etc. ** These are useful for partial input bytes, hash tree init/update, etc.
**/ **/
#define Skein_Get_Tweak(ctxPtr, TWK_NUM) ((ctxPtr)->h.T[TWK_NUM]) #define Skein_Get_Tweak(ctx_ptr, TWK_NUM) ((ctx_ptr)->h.T[TWK_NUM])
#define Skein_Set_Tweak(ctxPtr, TWK_NUM, tVal) { \ #define Skein_Set_Tweak(ctx_ptr, TWK_NUM, t_val) { \
(ctxPtr)->h.T[TWK_NUM] = (tVal); \ (ctx_ptr)->h.T[TWK_NUM] = (t_val); \
} }
#define Skein_Get_T0(ctxPtr) Skein_Get_Tweak(ctxPtr, 0) #define Skein_Get_T0(ctx_ptr) Skein_Get_Tweak(ctx_ptr, 0)
#define Skein_Get_T1(ctxPtr) Skein_Get_Tweak(ctxPtr, 1) #define Skein_Get_T1(ctx_ptr) Skein_Get_Tweak(ctx_ptr, 1)
#define Skein_Set_T0(ctxPtr, T0) Skein_Set_Tweak(ctxPtr, 0, T0) #define Skein_Set_T0(ctx_ptr, T0) Skein_Set_Tweak(ctx_ptr, 0, T0)
#define Skein_Set_T1(ctxPtr, T1) Skein_Set_Tweak(ctxPtr, 1, T1) #define Skein_Set_T1(ctx_ptr, T1) Skein_Set_Tweak(ctx_ptr, 1, T1)
/* set both tweak words at once */ /* set both tweak words at once */
#define Skein_Set_T0_T1(ctxPtr, T0, T1) \ #define Skein_Set_T0_T1(ctx_ptr, T0, T1) \
{ \ { \
Skein_Set_T0(ctxPtr, (T0)); \ Skein_Set_T0(ctx_ptr, (T0)); \
Skein_Set_T1(ctxPtr, (T1)); \ Skein_Set_T1(ctx_ptr, (T1)); \
} }
#define Skein_Set_Type(ctxPtr, BLK_TYPE) \ #define Skein_Set_Type(ctx_ptr, BLK_TYPE) \
Skein_Set_T1(ctxPtr, SKEIN_T1_BLK_TYPE_##BLK_TYPE) Skein_Set_T1(ctx_ptr, SKEIN_T1_BLK_TYPE_##BLK_TYPE)
/* /*
* setup for starting with a new type: * setup for starting with a new type:
* h.T[0]=0; h.T[1] = NEW_TYPE; h.bCnt=0; * h.T[0]=0; h.T[1] = NEW_TYPE; h.b_cnt=0;
*/ */
#define Skein_Start_New_Type(ctxPtr, BLK_TYPE) { \ #define Skein_Start_New_Type(ctx_ptr, BLK_TYPE) { \
Skein_Set_T0_T1(ctxPtr, 0, SKEIN_T1_FLAG_FIRST | \ Skein_Set_T0_T1(ctx_ptr, 0, SKEIN_T1_FLAG_FIRST | \
SKEIN_T1_BLK_TYPE_##BLK_TYPE); \ SKEIN_T1_BLK_TYPE_##BLK_TYPE); \
(ctxPtr)->h.bCnt = 0; \ (ctx_ptr)->h.b_cnt = 0; \
} }
#define Skein_Clear_First_Flag(hdr) { \ #define Skein_Clear_First_Flag(hdr) { \
...@@ -278,14 +279,14 @@ int skein_1024_output(struct skein1024_ctx *ctx, u8 *hashVal); ...@@ -278,14 +279,14 @@ int skein_1024_output(struct skein1024_ctx *ctx, u8 *hashVal);
#ifdef SKEIN_DEBUG /* examine/display intermediate values? */ #ifdef SKEIN_DEBUG /* examine/display intermediate values? */
#include "skein_debug.h" #include "skein_debug.h"
#else /* default is no callouts */ #else /* default is no callouts */
#define Skein_Show_Block(bits, ctx, X, blkPtr, wPtr, ksEvenPtr, ksOddPtr) #define Skein_Show_Block(bits, ctx, X, blk_ptr, w_ptr, ks_event_ptr, ks_odd_ptr)
#define Skein_Show_Round(bits, ctx, r, X) #define Skein_Show_Round(bits, ctx, r, X)
#define Skein_Show_R_Ptr(bits, ctx, r, X_ptr) #define Skein_Show_R_Ptr(bits, ctx, r, X_ptr)
#define Skein_Show_Final(bits, ctx, cnt, outPtr) #define Skein_Show_Final(bits, ctx, cnt, out_ptr)
#define Skein_Show_Key(bits, ctx, key, keyBytes) #define Skein_Show_Key(bits, ctx, key, key_bytes)
#endif #endif
#define Skein_Assert(x, retCode)/* ignore all Asserts, for performance */ #define Skein_Assert(x, ret_code)/* ignore all Asserts, for performance */
#define Skein_assert(x) #define Skein_assert(x)
/***************************************************************** /*****************************************************************
......
...@@ -59,7 +59,7 @@ OTHER DEALINGS IN THE SOFTWARE. ...@@ -59,7 +59,7 @@ OTHER DEALINGS IN THE SOFTWARE.
* *
* // Now update Skein with any number of message bits. A function that * // Now update Skein with any number of message bits. A function that
* // takes a number of bytes is also available. * // 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 * // 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 * // large enough to hold the request number of output bits. The application
...@@ -99,8 +99,8 @@ enum skein_size { ...@@ -99,8 +99,8 @@ enum skein_size {
* structures as well. * structures as well.
*/ */
struct skein_ctx { struct skein_ctx {
u64 skeinSize; u64 skein_size;
u64 XSave[SKEIN_MAX_STATE_WORDS]; /* save area for state variables */ u64 X_save[SKEIN_MAX_STATE_WORDS]; /* save area for state variables */
union { union {
struct skein_ctx_hdr h; struct skein_ctx_hdr h;
struct skein_256_ctx s256; struct skein_256_ctx s256;
...@@ -133,13 +133,13 @@ int skein_ctx_prepare(struct skein_ctx *ctx, enum skein_size size); ...@@ -133,13 +133,13 @@ int skein_ctx_prepare(struct skein_ctx *ctx, enum skein_size size);
* *
* @param ctx * @param ctx
* Pointer to a Skein context. * Pointer to a Skein context.
* @param hashBitLen * @param hash_bit_len
* Number of MAC hash bits to compute * Number of MAC hash bits to compute
* @return * @return
* SKEIN_SUCESS of SKEIN_FAIL * SKEIN_SUCESS of SKEIN_FAIL
* @see skein_reset * @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. * Resets a Skein context for further use.
...@@ -166,15 +166,15 @@ void skein_reset(struct skein_ctx *ctx); ...@@ -166,15 +166,15 @@ void skein_reset(struct skein_ctx *ctx);
* Pointer to an empty or preinitialized Skein MAC context * Pointer to an empty or preinitialized Skein MAC context
* @param key * @param key
* Pointer to key bytes or NULL * Pointer to key bytes or NULL
* @param keyLen * @param key_len
* Length of the key in bytes or zero * Length of the key in bytes or zero
* @param hashBitLen * @param hash_bit_len
* Number of MAC hash bits to compute * Number of MAC hash bits to compute
* @return * @return
* SKEIN_SUCESS of SKEIN_FAIL * SKEIN_SUCESS of SKEIN_FAIL
*/ */
int skein_mac_init(struct skein_ctx *ctx, const u8 *key, size_t keyLen, int skein_mac_init(struct skein_ctx *ctx, const u8 *key, size_t key_len,
size_t hashBitLen); size_t hash_bit_len);
/** /**
* Update Skein with the next part of the message. * 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, ...@@ -183,13 +183,13 @@ int skein_mac_init(struct skein_ctx *ctx, const u8 *key, size_t keyLen,
* Pointer to initialized Skein context * Pointer to initialized Skein context
* @param msg * @param msg
* Pointer to the message. * Pointer to the message.
* @param msgByteCnt * @param msg_byte_cnt
* Length of the message in @b bytes * Length of the message in @b bytes
* @return * @return
* Success or error code. * Success or error code.
*/ */
int skein_update(struct skein_ctx *ctx, const u8 *msg, 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. * Update the hash with a message bit string.
...@@ -201,11 +201,11 @@ int skein_update(struct skein_ctx *ctx, const u8 *msg, ...@@ -201,11 +201,11 @@ int skein_update(struct skein_ctx *ctx, const u8 *msg,
* Pointer to initialized Skein context * Pointer to initialized Skein context
* @param msg * @param msg
* Pointer to the message. * Pointer to the message.
* @param msgBitCnt * @param msg_bit_cnt
* Length of the message in @b bits. * Length of the message in @b bits.
*/ */
int skein_update_bits(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);
/** /**
* Finalize Skein and return the hash. * Finalize Skein and return the hash.
...@@ -217,7 +217,7 @@ int skein_update_bits(struct skein_ctx *ctx, const u8 *msg, ...@@ -217,7 +217,7 @@ int skein_update_bits(struct skein_ctx *ctx, const u8 *msg,
* Pointer to initialized Skein context * Pointer to initialized Skein context
* @param hash * @param hash
* Pointer to buffer that receives the hash. The buffer must be large * 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 * @return
* Success or error code. * Success or error code.
* @see skein_reset * @see skein_reset
......
...@@ -12,11 +12,11 @@ ...@@ -12,11 +12,11 @@
#include <skein.h> /* get the Skein API definitions */ #include <skein.h> /* get the Skein API definitions */
void skein_256_process_block(struct skein_256_ctx *ctx, const u8 *blkPtr, void skein_256_process_block(struct skein_256_ctx *ctx, const u8 *blk_ptr,
size_t blkCnt, size_t byteCntAdd); size_t blk_cnt, size_t byte_cnt_add);
void skein_512_process_block(struct skein_512_ctx *ctx, const u8 *blkPtr, void skein_512_process_block(struct skein_512_ctx *ctx, const u8 *blk_ptr,
size_t blkCnt, size_t byteCntAdd); size_t blk_cnt, size_t byte_cnt_add);
void skein_1024_process_block(struct skein1024_ctx *ctx, const u8 *blkPtr, void skein_1024_process_block(struct skein1024_ctx *ctx, const u8 *blk_ptr,
size_t blkCnt, size_t byteCntAdd); size_t blk_cnt, size_t byte_cnt_add);
#endif #endif
...@@ -18,13 +18,13 @@ ...@@ -18,13 +18,13 @@
* *
@code @code
// Threefish cipher context data // Threefish cipher context data
struct threefish_key keyCtx; struct threefish_key key_ctx;
// Initialize the context // Initialize the context
threefish_set_key(&keyCtx, Threefish512, key, tweak); threefish_set_key(&key_ctx, Threefish512, key, tweak);
// Encrypt // Encrypt
threefish_encrypt_block_bytes(&keyCtx, input, cipher); threefish_encrypt_block_bytes(&key_ctx, input, cipher);
@endcode @endcode
*/ */
...@@ -51,7 +51,7 @@ enum threefish_size { ...@@ -51,7 +51,7 @@ enum threefish_size {
* structures as well. * structures as well.
*/ */
struct threefish_key { struct threefish_key {
u64 stateSize; u64 state_size;
u64 key[SKEIN_MAX_STATE_WORDS+1]; /* max number of key words*/ u64 key[SKEIN_MAX_STATE_WORDS+1]; /* max number of key words*/
u64 tweak[3]; u64 tweak[3];
}; };
...@@ -63,106 +63,106 @@ struct threefish_key { ...@@ -63,106 +63,106 @@ struct threefish_key {
* the given size. The key data must have the same length (number of bits) * the given size. The key data must have the same length (number of bits)
* as the state size * as the state size
* *
* @param keyCtx * @param key_ctx
* Pointer to a Threefish key structure. * Pointer to a Threefish key structure.
* @param size * @param size
* Which Skein size to use. * Which Skein size to use.
* @param keyData * @param key_data
* Pointer to the key words (word has 64 bits). * Pointer to the key words (word has 64 bits).
* @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 threefish_set_key(struct threefish_key *keyCtx, void threefish_set_key(struct threefish_key *key_ctx,
enum threefish_size stateSize, enum threefish_size state_size,
u64 *keyData, u64 *tweak); u64 *key_data, u64 *tweak);
/** /**
* Encrypt Threefisch block (bytes). * Encrypt Threefisch block (bytes).
* *
* The buffer must have at least the same length (number of bits) aas the * 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 * of the input buffer, encrypts them and stores the result in the output
* buffer. * buffer.
* *
* @param keyCtx * @param key_ctx
* Pointer to a Threefish key structure. * Pointer to a Threefish key structure.
* @param in * @param in
* Poionter to plaintext data buffer. * Poionter to plaintext data buffer.
* @param out * @param out
* Pointer to cipher buffer. * 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); u8 *out);
/** /**
* Encrypt Threefisch block (words). * Encrypt Threefisch block (words).
* *
* The buffer must have at least the same length (number of bits) aas the * 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 * of the input buffer, encrypts them and stores the result in the output
* buffer. * buffer.
* *
* The wordsize ist set to 64 bits. * The wordsize ist set to 64 bits.
* *
* @param keyCtx * @param key_ctx
* Pointer to a Threefish key structure. * Pointer to a Threefish key structure.
* @param in * @param in
* Poionter to plaintext data buffer. * Poionter to plaintext data buffer.
* @param out * @param out
* Pointer to cipher buffer. * 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); u64 *out);
/** /**
* Decrypt Threefisch block (bytes). * Decrypt Threefisch block (bytes).
* *
* The buffer must have at least the same length (number of bits) aas the * 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 * of the input buffer, decrypts them and stores the result in the output
* buffer * buffer
* *
* @param keyCtx * @param key_ctx
* Pointer to a Threefish key structure. * Pointer to a Threefish key structure.
* @param in * @param in
* Poionter to cipher data buffer. * Poionter to cipher data buffer.
* @param out * @param out
* Pointer to plaintext buffer. * 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); u8 *out);
/** /**
* Decrypt Threefisch block (words). * Decrypt Threefisch block (words).
* *
* The buffer must have at least the same length (number of bits) aas the * 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 * of the input buffer, encrypts them and stores the result in the output
* buffer. * buffer.
* *
* The wordsize ist set to 64 bits. * The wordsize ist set to 64 bits.
* *
* @param keyCtx * @param key_ctx
* Pointer to a Threefish key structure. * Pointer to a Threefish key structure.
* @param in * @param in
* Poionter to cipher data buffer. * Poionter to cipher data buffer.
* @param out * @param out
* Pointer to plaintext buffer. * 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); 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); 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); 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); 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); 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); 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); u64 *output);
/** /**
* @} * @}
......
This diff is collapsed.
...@@ -32,17 +32,17 @@ int skein_ctx_prepare(struct skein_ctx *ctx, enum skein_size size) ...@@ -32,17 +32,17 @@ int skein_ctx_prepare(struct skein_ctx *ctx, enum skein_size size)
Skein_Assert(ctx && size, SKEIN_FAIL); Skein_Assert(ctx && size, SKEIN_FAIL);
memset(ctx , 0, sizeof(struct skein_ctx)); memset(ctx , 0, sizeof(struct skein_ctx));
ctx->skeinSize = size; ctx->skein_size = size;
return SKEIN_SUCCESS; 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; int ret = SKEIN_FAIL;
size_t Xlen = 0; size_t X_len = 0;
u64 *X = NULL; u64 *X = NULL;
u64 treeInfo = SKEIN_CFG_TREE_INFO_SEQUENTIAL; u64 tree_info = SKEIN_CFG_TREE_INFO_SEQUENTIAL;
Skein_Assert(ctx, SKEIN_FAIL); Skein_Assert(ctx, SKEIN_FAIL);
/* /*
...@@ -51,83 +51,83 @@ int skein_init(struct skein_ctx *ctx, size_t hashBitLen) ...@@ -51,83 +51,83 @@ int skein_init(struct skein_ctx *ctx, size_t hashBitLen)
* memory available. The beauty of C :-) . * memory available. The beauty of C :-) .
*/ */
X = ctx->m.s256.X; 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 * If size is the same and hash bit length is zero then reuse
* the save chaining variables. * the save chaining variables.
*/ */
switch (ctx->skeinSize) { switch (ctx->skein_size) {
case Skein256: case Skein256:
ret = skein_256_init_ext(&ctx->m.s256, hashBitLen, ret = skein_256_init_ext(&ctx->m.s256, hash_bit_len,
treeInfo, NULL, 0); tree_info, NULL, 0);
break; break;
case Skein512: case Skein512:
ret = skein_512_init_ext(&ctx->m.s512, hashBitLen, ret = skein_512_init_ext(&ctx->m.s512, hash_bit_len,
treeInfo, NULL, 0); tree_info, NULL, 0);
break; break;
case Skein1024: case Skein1024:
ret = skein_1024_init_ext(&ctx->m.s1024, hashBitLen, ret = skein_1024_init_ext(&ctx->m.s1024, hash_bit_len,
treeInfo, NULL, 0); tree_info, NULL, 0);
break; break;
} }
if (ret == SKEIN_SUCCESS) { if (ret == SKEIN_SUCCESS) {
/* /*
* Save chaining variables for this combination of size and * 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; return ret;
} }
int skein_mac_init(struct skein_ctx *ctx, const u8 *key, size_t keyLen, int skein_mac_init(struct skein_ctx *ctx, const u8 *key, size_t key_len,
size_t hashBitLen) size_t hash_bit_len)
{ {
int ret = SKEIN_FAIL; int ret = SKEIN_FAIL;
u64 *X = NULL; u64 *X = NULL;
size_t Xlen = 0; size_t X_len = 0;
u64 treeInfo = SKEIN_CFG_TREE_INFO_SEQUENTIAL; u64 tree_info = SKEIN_CFG_TREE_INFO_SEQUENTIAL;
Skein_Assert(ctx, SKEIN_FAIL); Skein_Assert(ctx, SKEIN_FAIL);
X = ctx->m.s256.X; 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: case Skein256:
ret = skein_256_init_ext(&ctx->m.s256, hashBitLen, ret = skein_256_init_ext(&ctx->m.s256, hash_bit_len,
treeInfo, tree_info,
(const u8 *)key, keyLen); (const u8 *)key, key_len);
break; break;
case Skein512: case Skein512:
ret = skein_512_init_ext(&ctx->m.s512, hashBitLen, ret = skein_512_init_ext(&ctx->m.s512, hash_bit_len,
treeInfo, tree_info,
(const u8 *)key, keyLen); (const u8 *)key, key_len);
break; break;
case Skein1024: case Skein1024:
ret = skein_1024_init_ext(&ctx->m.s1024, hashBitLen, ret = skein_1024_init_ext(&ctx->m.s1024, hash_bit_len,
treeInfo, tree_info,
(const u8 *)key, keyLen); (const u8 *)key, key_len);
break; break;
} }
if (ret == SKEIN_SUCCESS) { if (ret == SKEIN_SUCCESS) {
/* /*
* Save chaining variables for this combination of key, * 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; return ret;
} }
void skein_reset(struct skein_ctx *ctx) void skein_reset(struct skein_ctx *ctx)
{ {
size_t Xlen = 0; size_t X_len = 0;
u64 *X = NULL; u64 *X = NULL;
/* /*
...@@ -136,32 +136,33 @@ void skein_reset(struct skein_ctx *ctx) ...@@ -136,32 +136,33 @@ void skein_reset(struct skein_ctx *ctx)
* memory available. The beautiy of C :-) . * memory available. The beautiy of C :-) .
*/ */
X = ctx->m.s256.X; X = ctx->m.s256.X;
Xlen = ctx->skeinSize/8; X_len = ctx->skein_size/8;
/* Restore the chaing variable, reset byte counter */ /* 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 */ /* Setup context to process the message */
Skein_Start_New_Type(&ctx->m, MSG); Skein_Start_New_Type(&ctx->m, MSG);
} }
int skein_update(struct skein_ctx *ctx, const u8 *msg, int skein_update(struct skein_ctx *ctx, const u8 *msg,
size_t msgByteCnt) size_t msg_byte_cnt)
{ {
int ret = SKEIN_FAIL; int ret = SKEIN_FAIL;
Skein_Assert(ctx, SKEIN_FAIL); Skein_Assert(ctx, SKEIN_FAIL);
switch (ctx->skeinSize) { switch (ctx->skein_size) {
case Skein256: case Skein256:
ret = skein_256_update(&ctx->m.s256, (const u8 *)msg, ret = skein_256_update(&ctx->m.s256, (const u8 *)msg,
msgByteCnt); msg_byte_cnt);
break; break;
case Skein512: case Skein512:
ret = skein_512_update(&ctx->m.s512, (const u8 *)msg, ret = skein_512_update(&ctx->m.s512, (const u8 *)msg,
msgByteCnt); msg_byte_cnt);
break; break;
case Skein1024: case Skein1024:
ret = skein_1024_update(&ctx->m.s1024, (const u8 *)msg, ret = skein_1024_update(&ctx->m.s1024, (const u8 *)msg,
msgByteCnt); msg_byte_cnt);
break; break;
} }
return ret; return ret;
...@@ -169,7 +170,7 @@ int skein_update(struct skein_ctx *ctx, const u8 *msg, ...@@ -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, 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) * 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, ...@@ -185,13 +186,13 @@ int skein_update_bits(struct skein_ctx *ctx, const u8 *msg,
* assert an error * assert an error
*/ */
Skein_Assert((ctx->m.h.T[1] & SKEIN_T1_FLAG_BIT_PAD) == 0 || 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 number of bits is a multiple of bytes - that's easy */
if ((msgBitCnt & 0x7) == 0) if ((msg_bit_cnt & 0x7) == 0)
return skein_update(ctx, msg, msgBitCnt >> 3); 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 * 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, ...@@ -199,18 +200,18 @@ int skein_update_bits(struct skein_ctx *ctx, const u8 *msg,
* Skein's real partial block buffer. * Skein's real partial block buffer.
* If this layout ever changes we have to adapt this as well. * 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 */ /* set tweak flag for the skein_final call */
Skein_Set_Bit_Pad_Flag(ctx->m.h); 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 */
/* get the bCnt value (same location for all block sizes) */ /* get the b_cnt value (same location for all block sizes) */
length = ctx->m.h.bCnt; length = ctx->m.h.b_cnt;
/* internal sanity check: there IS a partial byte in the buffer! */ /* internal sanity check: there IS a partial byte in the buffer! */
Skein_assert(length != 0); Skein_assert(length != 0);
/* partial byte bit mask */ /* 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) */ /* apply bit padding on final byte (in the buffer) */
up[length-1] = (u8)((up[length-1] & (0-mask))|mask); 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, ...@@ -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 skein_final(struct skein_ctx *ctx, u8 *hash)
{ {
int ret = SKEIN_FAIL; int ret = SKEIN_FAIL;
Skein_Assert(ctx, SKEIN_FAIL); Skein_Assert(ctx, SKEIN_FAIL);
switch (ctx->skeinSize) { switch (ctx->skein_size) {
case Skein256: case Skein256:
ret = skein_256_final(&ctx->m.s256, (u8 *)hash); ret = skein_256_final(&ctx->m.s256, (u8 *)hash);
break; break;
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
/***************************** Skein_256 ******************************/ /***************************** Skein_256 ******************************/
void skein_256_process_block(struct skein_256_ctx *ctx, const u8 *blkPtr, void skein_256_process_block(struct skein_256_ctx *ctx, const u8 *blk_ptr,
size_t blkCnt, size_t byteCntAdd) size_t blk_cnt, size_t byte_cnt_add)
{ {
struct threefish_key key; struct threefish_key key;
u64 tweak[2]; u64 tweak[2];
...@@ -14,12 +14,12 @@ void skein_256_process_block(struct skein_256_ctx *ctx, const u8 *blkPtr, ...@@ -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 w[SKEIN_256_STATE_WORDS]; /* local copy of input block */
u64 words[3]; 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[0] = ctx->h.T[0];
tweak[1] = ctx->h.T[1]; tweak[1] = ctx->h.T[1];
do { do {
u64 carry = byteCntAdd; u64 carry = byte_cnt_add;
words[0] = tweak[0] & 0xffffffffL; words[0] = tweak[0] & 0xffffffffL;
words[1] = ((tweak[0] >> 32) & 0xffffffffL); words[1] = ((tweak[0] >> 32) & 0xffffffffL);
...@@ -37,11 +37,11 @@ void skein_256_process_block(struct skein_256_ctx *ctx, const u8 *blkPtr, ...@@ -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); threefish_set_key(&key, Threefish256, ctx->X, tweak);
/* get input block in little-endian format */ /* 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); 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 */ /* 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];
...@@ -50,14 +50,14 @@ void skein_256_process_block(struct skein_256_ctx *ctx, const u8 *blkPtr, ...@@ -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]; ctx->X[3] = ctx->X[3] ^ w[3];
tweak[1] &= ~SKEIN_T1_FLAG_FIRST; tweak[1] &= ~SKEIN_T1_FLAG_FIRST;
} while (--blkCnt); } while (--blk_cnt);
ctx->h.T[0] = tweak[0]; ctx->h.T[0] = tweak[0];
ctx->h.T[1] = tweak[1]; ctx->h.T[1] = tweak[1];
} }
void skein_512_process_block(struct skein_512_ctx *ctx, const u8 *blkPtr, void skein_512_process_block(struct skein_512_ctx *ctx, const u8 *blk_ptr,
size_t blkCnt, size_t byteCntAdd) size_t blk_cnt, size_t byte_cnt_add)
{ {
struct threefish_key key; struct threefish_key key;
u64 tweak[2]; u64 tweak[2];
...@@ -65,12 +65,12 @@ void skein_512_process_block(struct skein_512_ctx *ctx, const u8 *blkPtr, ...@@ -65,12 +65,12 @@ void skein_512_process_block(struct skein_512_ctx *ctx, const u8 *blkPtr,
u64 words[3]; u64 words[3];
u64 w[SKEIN_512_STATE_WORDS]; /* local copy of input block */ 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[0] = ctx->h.T[0];
tweak[1] = ctx->h.T[1]; tweak[1] = ctx->h.T[1];
do { do {
u64 carry = byteCntAdd; u64 carry = byte_cnt_add;
words[0] = tweak[0] & 0xffffffffL; words[0] = tweak[0] & 0xffffffffL;
words[1] = ((tweak[0] >> 32) & 0xffffffffL); words[1] = ((tweak[0] >> 32) & 0xffffffffL);
...@@ -88,11 +88,11 @@ void skein_512_process_block(struct skein_512_ctx *ctx, const u8 *blkPtr, ...@@ -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); threefish_set_key(&key, Threefish512, ctx->X, tweak);
/* get input block in little-endian format */ /* 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); 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 */ /* 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];
...@@ -105,14 +105,14 @@ void skein_512_process_block(struct skein_512_ctx *ctx, const u8 *blkPtr, ...@@ -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]; ctx->X[7] = ctx->X[7] ^ w[7];
tweak[1] &= ~SKEIN_T1_FLAG_FIRST; tweak[1] &= ~SKEIN_T1_FLAG_FIRST;
} while (--blkCnt); } while (--blk_cnt);
ctx->h.T[0] = tweak[0]; ctx->h.T[0] = tweak[0];
ctx->h.T[1] = tweak[1]; ctx->h.T[1] = tweak[1];
} }
void skein_1024_process_block(struct skein1024_ctx *ctx, const u8 *blkPtr, void skein_1024_process_block(struct skein1024_ctx *ctx, const u8 *blk_ptr,
size_t blkCnt, size_t byteCntAdd) size_t blk_cnt, size_t byte_cnt_add)
{ {
struct threefish_key key; struct threefish_key key;
u64 tweak[2]; u64 tweak[2];
...@@ -120,12 +120,12 @@ void skein_1024_process_block(struct skein1024_ctx *ctx, const u8 *blkPtr, ...@@ -120,12 +120,12 @@ void skein_1024_process_block(struct skein1024_ctx *ctx, const u8 *blkPtr,
u64 words[3]; u64 words[3];
u64 w[SKEIN1024_STATE_WORDS]; /* local copy of input block */ 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[0] = ctx->h.T[0];
tweak[1] = ctx->h.T[1]; tweak[1] = ctx->h.T[1];
do { do {
u64 carry = byteCntAdd; u64 carry = byte_cnt_add;
words[0] = tweak[0] & 0xffffffffL; words[0] = tweak[0] & 0xffffffffL;
words[1] = ((tweak[0] >> 32) & 0xffffffffL); words[1] = ((tweak[0] >> 32) & 0xffffffffL);
...@@ -143,11 +143,11 @@ void skein_1024_process_block(struct skein1024_ctx *ctx, const u8 *blkPtr, ...@@ -143,11 +143,11 @@ void skein_1024_process_block(struct skein1024_ctx *ctx, const u8 *blkPtr,
threefish_set_key(&key, Threefish1024, ctx->X, tweak); threefish_set_key(&key, Threefish1024, ctx->X, tweak);
/* get input block in little-endian format */ /* 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); 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 */ /* 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];
...@@ -168,7 +168,7 @@ void skein_1024_process_block(struct skein1024_ctx *ctx, const u8 *blkPtr, ...@@ -168,7 +168,7 @@ void skein_1024_process_block(struct skein1024_ctx *ctx, const u8 *blkPtr,
ctx->X[15] = ctx->X[15] ^ w[15]; ctx->X[15] = ctx->X[15] ^ w[15];
tweak[1] &= ~SKEIN_T1_FLAG_FIRST; tweak[1] &= ~SKEIN_T1_FLAG_FIRST;
} while (--blkCnt); } while (--blk_cnt);
ctx->h.T[0] = tweak[0]; ctx->h.T[0] = tweak[0];
ctx->h.T[1] = tweak[1]; ctx->h.T[1] = tweak[1];
......
This diff is collapsed.
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <threefishApi.h> #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 *output)
{ {
u64 b0 = input[0], b1 = input[1], u64 b0 = input[0], b1 = input[1],
...@@ -13,17 +13,17 @@ void threefish_encrypt_1024(struct threefish_key *keyCtx, u64 *input, ...@@ -13,17 +13,17 @@ void threefish_encrypt_1024(struct threefish_key *keyCtx, u64 *input,
b10 = input[10], b11 = input[11], b10 = input[10], b11 = input[11],
b12 = input[12], b13 = input[13], b12 = input[12], b13 = input[13],
b14 = input[14], b15 = input[15]; b14 = input[14], b15 = input[15];
u64 k0 = keyCtx->key[0], k1 = keyCtx->key[1], u64 k0 = key_ctx->key[0], k1 = key_ctx->key[1],
k2 = keyCtx->key[2], k3 = keyCtx->key[3], k2 = key_ctx->key[2], k3 = key_ctx->key[3],
k4 = keyCtx->key[4], k5 = keyCtx->key[5], k4 = key_ctx->key[4], k5 = key_ctx->key[5],
k6 = keyCtx->key[6], k7 = keyCtx->key[7], k6 = key_ctx->key[6], k7 = key_ctx->key[7],
k8 = keyCtx->key[8], k9 = keyCtx->key[9], k8 = key_ctx->key[8], k9 = key_ctx->key[9],
k10 = keyCtx->key[10], k11 = keyCtx->key[11], k10 = key_ctx->key[10], k11 = key_ctx->key[11],
k12 = keyCtx->key[12], k13 = keyCtx->key[13], k12 = key_ctx->key[12], k13 = key_ctx->key[13],
k14 = keyCtx->key[14], k15 = keyCtx->key[15], k14 = key_ctx->key[14], k15 = key_ctx->key[15],
k16 = keyCtx->key[16]; k16 = key_ctx->key[16];
u64 t0 = keyCtx->tweak[0], t1 = keyCtx->tweak[1], u64 t0 = key_ctx->tweak[0], t1 = key_ctx->tweak[1],
t2 = keyCtx->tweak[2]; t2 = key_ctx->tweak[2];
b1 += k1; b1 += k1;
b0 += b1 + k0; b0 += b1 + k0;
...@@ -2123,7 +2123,7 @@ void threefish_encrypt_1024(struct threefish_key *keyCtx, u64 *input, ...@@ -2123,7 +2123,7 @@ void threefish_encrypt_1024(struct threefish_key *keyCtx, u64 *input,
output[15] = b15 + k1 + 20; 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 *output)
{ {
u64 b0 = input[0], b1 = input[1], u64 b0 = input[0], b1 = input[1],
...@@ -2134,17 +2134,17 @@ void threefish_decrypt_1024(struct threefish_key *keyCtx, u64 *input, ...@@ -2134,17 +2134,17 @@ void threefish_decrypt_1024(struct threefish_key *keyCtx, u64 *input,
b10 = input[10], b11 = input[11], b10 = input[10], b11 = input[11],
b12 = input[12], b13 = input[13], b12 = input[12], b13 = input[13],
b14 = input[14], b15 = input[15]; b14 = input[14], b15 = input[15];
u64 k0 = keyCtx->key[0], k1 = keyCtx->key[1], u64 k0 = key_ctx->key[0], k1 = key_ctx->key[1],
k2 = keyCtx->key[2], k3 = keyCtx->key[3], k2 = key_ctx->key[2], k3 = key_ctx->key[3],
k4 = keyCtx->key[4], k5 = keyCtx->key[5], k4 = key_ctx->key[4], k5 = key_ctx->key[5],
k6 = keyCtx->key[6], k7 = keyCtx->key[7], k6 = key_ctx->key[6], k7 = key_ctx->key[7],
k8 = keyCtx->key[8], k9 = keyCtx->key[9], k8 = key_ctx->key[8], k9 = key_ctx->key[9],
k10 = keyCtx->key[10], k11 = keyCtx->key[11], k10 = key_ctx->key[10], k11 = key_ctx->key[11],
k12 = keyCtx->key[12], k13 = keyCtx->key[13], k12 = key_ctx->key[12], k13 = key_ctx->key[13],
k14 = keyCtx->key[14], k15 = keyCtx->key[15], k14 = key_ctx->key[14], k15 = key_ctx->key[15],
k16 = keyCtx->key[16]; k16 = key_ctx->key[16];
u64 t0 = keyCtx->tweak[0], t1 = keyCtx->tweak[1], u64 t0 = key_ctx->tweak[0], t1 = key_ctx->tweak[1],
t2 = keyCtx->tweak[2]; t2 = key_ctx->tweak[2];
u64 tmp; u64 tmp;
b0 -= k3; b0 -= k3;
......
...@@ -2,16 +2,16 @@ ...@@ -2,16 +2,16 @@
#include <threefishApi.h> #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 *output)
{ {
u64 b0 = input[0], b1 = input[1], u64 b0 = input[0], b1 = input[1],
b2 = input[2], b3 = input[3]; b2 = input[2], b3 = input[3];
u64 k0 = keyCtx->key[0], k1 = keyCtx->key[1], u64 k0 = key_ctx->key[0], k1 = key_ctx->key[1],
k2 = keyCtx->key[2], k3 = keyCtx->key[3], k2 = key_ctx->key[2], k3 = key_ctx->key[3],
k4 = keyCtx->key[4]; k4 = key_ctx->key[4];
u64 t0 = keyCtx->tweak[0], t1 = keyCtx->tweak[1], u64 t0 = key_ctx->tweak[0], t1 = key_ctx->tweak[1],
t2 = keyCtx->tweak[2]; t2 = key_ctx->tweak[2];
b1 += k1 + t0; b1 += k1 + t0;
b0 += b1 + k0; b0 += b1 + k0;
...@@ -495,16 +495,16 @@ void threefish_encrypt_256(struct threefish_key *keyCtx, u64 *input, ...@@ -495,16 +495,16 @@ void threefish_encrypt_256(struct threefish_key *keyCtx, u64 *input,
output[3] = b3 + k1 + 18; 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 *output)
{ {
u64 b0 = input[0], b1 = input[1], u64 b0 = input[0], b1 = input[1],
b2 = input[2], b3 = input[3]; b2 = input[2], b3 = input[3];
u64 k0 = keyCtx->key[0], k1 = keyCtx->key[1], u64 k0 = key_ctx->key[0], k1 = key_ctx->key[1],
k2 = keyCtx->key[2], k3 = keyCtx->key[3], k2 = key_ctx->key[2], k3 = key_ctx->key[3],
k4 = keyCtx->key[4]; k4 = key_ctx->key[4];
u64 t0 = keyCtx->tweak[0], t1 = keyCtx->tweak[1], u64 t0 = key_ctx->tweak[0], t1 = key_ctx->tweak[1],
t2 = keyCtx->tweak[2]; t2 = key_ctx->tweak[2];
u64 tmp; u64 tmp;
......
...@@ -2,20 +2,20 @@ ...@@ -2,20 +2,20 @@
#include <threefishApi.h> #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 *output)
{ {
u64 b0 = input[0], b1 = input[1], u64 b0 = input[0], b1 = input[1],
b2 = input[2], b3 = input[3], b2 = input[2], b3 = input[3],
b4 = input[4], b5 = input[5], b4 = input[4], b5 = input[5],
b6 = input[6], b7 = input[7]; b6 = input[6], b7 = input[7];
u64 k0 = keyCtx->key[0], k1 = keyCtx->key[1], u64 k0 = key_ctx->key[0], k1 = key_ctx->key[1],
k2 = keyCtx->key[2], k3 = keyCtx->key[3], k2 = key_ctx->key[2], k3 = key_ctx->key[3],
k4 = keyCtx->key[4], k5 = keyCtx->key[5], k4 = key_ctx->key[4], k5 = key_ctx->key[5],
k6 = keyCtx->key[6], k7 = keyCtx->key[7], k6 = key_ctx->key[6], k7 = key_ctx->key[7],
k8 = keyCtx->key[8]; k8 = key_ctx->key[8];
u64 t0 = keyCtx->tweak[0], t1 = keyCtx->tweak[1], u64 t0 = key_ctx->tweak[0], t1 = key_ctx->tweak[1],
t2 = keyCtx->tweak[2]; t2 = key_ctx->tweak[2];
b1 += k1; b1 += k1;
b0 += b1 + k0; b0 += b1 + k0;
...@@ -963,20 +963,20 @@ void threefish_encrypt_512(struct threefish_key *keyCtx, u64 *input, ...@@ -963,20 +963,20 @@ void threefish_encrypt_512(struct threefish_key *keyCtx, u64 *input,
output[7] = b7 + k7 + 18; 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 *output)
{ {
u64 b0 = input[0], b1 = input[1], u64 b0 = input[0], b1 = input[1],
b2 = input[2], b3 = input[3], b2 = input[2], b3 = input[3],
b4 = input[4], b5 = input[5], b4 = input[4], b5 = input[5],
b6 = input[6], b7 = input[7]; b6 = input[6], b7 = input[7];
u64 k0 = keyCtx->key[0], k1 = keyCtx->key[1], u64 k0 = key_ctx->key[0], k1 = key_ctx->key[1],
k2 = keyCtx->key[2], k3 = keyCtx->key[3], k2 = key_ctx->key[2], k3 = key_ctx->key[3],
k4 = keyCtx->key[4], k5 = keyCtx->key[5], k4 = key_ctx->key[4], k5 = key_ctx->key[5],
k6 = keyCtx->key[6], k7 = keyCtx->key[7], k6 = key_ctx->key[6], k7 = key_ctx->key[7],
k8 = keyCtx->key[8]; k8 = key_ctx->key[8];
u64 t0 = keyCtx->tweak[0], t1 = keyCtx->tweak[1], u64 t0 = key_ctx->tweak[0], t1 = key_ctx->tweak[1],
t2 = keyCtx->tweak[2]; t2 = key_ctx->tweak[2];
u64 tmp; u64 tmp;
......
...@@ -3,76 +3,76 @@ ...@@ -3,76 +3,76 @@
#include <linux/string.h> #include <linux/string.h>
#include <threefishApi.h> #include <threefishApi.h>
void threefish_set_key(struct threefish_key *keyCtx, void threefish_set_key(struct threefish_key *key_ctx,
enum threefish_size stateSize, enum threefish_size state_size,
u64 *keyData, u64 *tweak) u64 *key_data, u64 *tweak)
{ {
int keyWords = stateSize / 64; int key_words = state_size / 64;
int i; int i;
u64 parity = KeyScheduleConst; u64 parity = KeyScheduleConst;
keyCtx->tweak[0] = tweak[0]; key_ctx->tweak[0] = tweak[0];
keyCtx->tweak[1] = tweak[1]; key_ctx->tweak[1] = tweak[1];
keyCtx->tweak[2] = tweak[0] ^ tweak[1]; key_ctx->tweak[2] = tweak[0] ^ tweak[1];
for (i = 0; i < keyWords; i++) { for (i = 0; i < key_words; i++) {
keyCtx->key[i] = keyData[i]; key_ctx->key[i] = key_data[i];
parity ^= keyData[i]; parity ^= key_data[i];
} }
keyCtx->key[i] = parity; key_ctx->key[i] = parity;
keyCtx->stateSize = stateSize; 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) u8 *out)
{ {
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); Skein_Get64_LSB_First(plain, in, key_ctx->state_size / 64);
threefish_encrypt_block_words(keyCtx, plain, cipher); threefish_encrypt_block_words(key_ctx, plain, cipher);
Skein_Put64_LSB_First(out, cipher, keyCtx->stateSize / 8); 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) u64 *out)
{ {
switch (keyCtx->stateSize) { switch (key_ctx->state_size) {
case Threefish256: case Threefish256:
threefish_encrypt_256(keyCtx, in, out); threefish_encrypt_256(key_ctx, in, out);
break; break;
case Threefish512: case Threefish512:
threefish_encrypt_512(keyCtx, in, out); threefish_encrypt_512(key_ctx, in, out);
break; break;
case Threefish1024: case Threefish1024:
threefish_encrypt_1024(keyCtx, in, out); threefish_encrypt_1024(key_ctx, in, out);
break; 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) u8 *out)
{ {
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); Skein_Get64_LSB_First(cipher, in, key_ctx->state_size / 64);
threefish_decrypt_block_words(keyCtx, cipher, plain); threefish_decrypt_block_words(key_ctx, cipher, plain);
Skein_Put64_LSB_First(out, plain, keyCtx->stateSize / 8); 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) u64 *out)
{ {
switch (keyCtx->stateSize) { switch (key_ctx->state_size) {
case Threefish256: case Threefish256:
threefish_decrypt_256(keyCtx, in, out); threefish_decrypt_256(key_ctx, in, out);
break; break;
case Threefish512: case Threefish512:
threefish_decrypt_512(keyCtx, in, out); threefish_decrypt_512(key_ctx, in, out);
break; break;
case Threefish1024: case Threefish1024:
threefish_decrypt_1024(keyCtx, in, out); threefish_decrypt_1024(key_ctx, in, out);
break; 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