Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

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

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
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
skein/threefish TODO

 - rename camelcase vars
 - rename files
 - move macros into appropriate header files
 - add / pass test vectors
+60 −59
Original line number Diff line number Diff line
@@ -33,8 +33,9 @@
#endif

/* below two prototype assume we are handed aligned data */
#define Skein_Put64_LSB_First(dst08, src64, bCnt) memcpy(dst08, src64, bCnt)
#define Skein_Get64_LSB_First(dst64, src08, wCnt) memcpy(dst64, src08, 8*(wCnt))
#define Skein_Put64_LSB_First(dst08, src64, b_cnt) memcpy(dst08, src64, b_cnt)
#define Skein_Get64_LSB_First(dst64, src08, w_cnt) \
		memcpy(dst64, src08, 8*(w_cnt))
#define Skein_Swap64(w64)  (w64)

enum {
@@ -63,8 +64,8 @@ enum {
#define  SKEIN1024_BLOCK_BYTES  (8*SKEIN1024_STATE_WORDS)

struct skein_ctx_hdr {
	size_t  hashBitLen;		/* size of hash result, in bits */
	size_t  bCnt;			/* current byte count in buffer b[] */
	size_t hash_bit_len;		/* size of hash result, in bits */
	size_t b_cnt;			/* current byte count in buffer b[] */
	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 */
};

/* Skein APIs for (incremental) "straight hashing" */
int skein_256_init(struct skein_256_ctx *ctx, size_t hashBitLen);
int skein_512_init(struct skein_512_ctx *ctx, size_t hashBitLen);
int skein_1024_init(struct skein1024_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 hash_bit_len);
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,
		     size_t msgByteCnt);
		     size_t msg_byte_cnt);
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,
		      size_t msgByteCnt);
		      size_t msg_byte_cnt);

int skein_256_final(struct skein_256_ctx *ctx, u8 *hashVal);
int skein_512_final(struct skein_512_ctx *ctx, u8 *hashVal);
int skein_1024_final(struct skein1024_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 *hash_val);
int skein_1024_final(struct skein1024_ctx *ctx, u8 *hash_val);

/*
**   Skein APIs for "extended" initialization: MAC keys, tree hashing.
**   After an init_ext() call, just use update/final calls as with init().
**
**   Notes: Same parameters as _init() calls, plus treeInfo/key/keyBytes.
**          When keyBytes == 0 and treeInfo == SKEIN_SEQUENTIAL,
**   Notes: Same parameters as _init() calls, plus tree_info/key/key_bytes.
**          When key_bytes == 0 and tree_info == SKEIN_SEQUENTIAL,
**              the results of init_ext() are identical to calling init().
**          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.
**          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
**              reused for each new MAC computation.
**/
int skein_256_init_ext(struct skein_256_ctx *ctx, size_t hashBitLen,
		       u64 treeInfo, const u8 *key, size_t keyBytes);
int skein_512_init_ext(struct skein_512_ctx *ctx, size_t hashBitLen,
		       u64 treeInfo, const u8 *key, size_t keyBytes);
int skein_1024_init_ext(struct skein1024_ctx *ctx, size_t hashBitLen,
			u64 treeInfo, const u8 *key, size_t keyBytes);
int skein_256_init_ext(struct skein_256_ctx *ctx, size_t hash_bit_len,
		       u64 tree_info, const u8 *key, size_t key_bytes);
int skein_512_init_ext(struct skein_512_ctx *ctx, size_t hash_bit_len,
		       u64 tree_info, const u8 *key, size_t key_bytes);
int skein_1024_init_ext(struct skein1024_ctx *ctx, size_t hash_bit_len,
			u64 tree_info, const u8 *key, size_t key_bytes);

/*
**   Skein APIs for MAC and tree hash:
**      final_pad:  pad, do final block, but no OUTPUT type
**      output:     do just the output stage
*/
int skein_256_final_pad(struct skein_256_ctx *ctx, u8 *hashVal);
int skein_512_final_pad(struct skein_512_ctx *ctx, u8 *hashVal);
int skein_1024_final_pad(struct skein1024_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 *hash_val);
int skein_1024_final_pad(struct skein1024_ctx *ctx, u8 *hash_val);

#ifndef SKEIN_TREE_HASH
#define SKEIN_TREE_HASH (1)
#endif
#if  SKEIN_TREE_HASH
int skein_256_output(struct skein_256_ctx *ctx, u8 *hashVal);
int skein_512_output(struct skein_512_ctx *ctx, u8 *hashVal);
int skein_1024_output(struct skein1024_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 *hash_val);
int skein_1024_output(struct skein1024_ctx *ctx, u8 *hash_val);
#endif

/*****************************************************************
@@ -207,7 +208,7 @@ int skein_1024_output(struct skein1024_ctx *ctx, u8 *hashVal);

#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_NODE_SIZE_POS  (8)
#define SKEIN_CFG_TREE_MAX_LEVEL_POS  (16)
@@ -219,46 +220,46 @@ int skein_1024_output(struct skein1024_ctx *ctx, u8 *hashVal);
#define SKEIN_CFG_TREE_MAX_LEVEL_MSK (((u64)0xFF) << \
					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)(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)

/*
**   Skein macros for getting/setting tweak words, 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_Set_Tweak(ctxPtr, TWK_NUM, tVal) { \
		(ctxPtr)->h.T[TWK_NUM] = (tVal); \
#define Skein_Get_Tweak(ctx_ptr, TWK_NUM)          ((ctx_ptr)->h.T[TWK_NUM])
#define Skein_Set_Tweak(ctx_ptr, TWK_NUM, t_val) { \
		(ctx_ptr)->h.T[TWK_NUM] = (t_val); \
	}

#define Skein_Get_T0(ctxPtr)     Skein_Get_Tweak(ctxPtr, 0)
#define Skein_Get_T1(ctxPtr)     Skein_Get_Tweak(ctxPtr, 1)
#define Skein_Set_T0(ctxPtr, T0) Skein_Set_Tweak(ctxPtr, 0, T0)
#define Skein_Set_T1(ctxPtr, T1) Skein_Set_Tweak(ctxPtr, 1, T1)
#define Skein_Get_T0(ctx_ptr)     Skein_Get_Tweak(ctx_ptr, 0)
#define Skein_Get_T1(ctx_ptr)     Skein_Get_Tweak(ctx_ptr, 1)
#define Skein_Set_T0(ctx_ptr, T0) Skein_Set_Tweak(ctx_ptr, 0, T0)
#define Skein_Set_T1(ctx_ptr, T1) Skein_Set_Tweak(ctx_ptr, 1, T1)

/* 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_T1(ctxPtr, (T1));                  \
	Skein_Set_T0(ctx_ptr, (T0));                  \
	Skein_Set_T1(ctx_ptr, (T1));                  \
	}

#define Skein_Set_Type(ctxPtr, BLK_TYPE)         \
	Skein_Set_T1(ctxPtr, SKEIN_T1_BLK_TYPE_##BLK_TYPE)
#define Skein_Set_Type(ctx_ptr, BLK_TYPE)         \
	Skein_Set_T1(ctx_ptr, SKEIN_T1_BLK_TYPE_##BLK_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) { \
		Skein_Set_T0_T1(ctxPtr, 0, SKEIN_T1_FLAG_FIRST | \
#define Skein_Start_New_Type(ctx_ptr, BLK_TYPE) { \
		Skein_Set_T0_T1(ctx_ptr, 0, SKEIN_T1_FLAG_FIRST | \
				SKEIN_T1_BLK_TYPE_##BLK_TYPE); \
		(ctxPtr)->h.bCnt = 0; \
		(ctx_ptr)->h.b_cnt = 0; \
	}

#define Skein_Clear_First_Flag(hdr) { \
@@ -278,14 +279,14 @@ int skein_1024_output(struct skein1024_ctx *ctx, u8 *hashVal);
#ifdef SKEIN_DEBUG             /* examine/display intermediate values? */
#include "skein_debug.h"
#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_R_Ptr(bits, ctx, r, X_ptr)
#define Skein_Show_Final(bits, ctx, cnt, outPtr)
#define Skein_Show_Key(bits, ctx, key, keyBytes)
#define Skein_Show_Final(bits, ctx, cnt, out_ptr)
#define Skein_Show_Key(bits, ctx, key, key_bytes)
#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)

/*****************************************************************
+14 −14
Original line number Diff line number Diff line
@@ -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
+6 −6
Original line number Diff line number Diff line
@@ -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
+27 −27
Original line number Diff line number Diff line
@@ -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);
/**
 * @}
Loading