Commit 0264b7b7 authored by Anton Saraev's avatar Anton Saraev Committed by Greg Kroah-Hartman

staging: crypto: skein: rename macros

Mixing upper and lower case in names of macros like It_Is_Macro is
not accepted in the Linux Kernel. To prepare skein driver for mainline
inclusion, we rename all macros to uppercase or lowercase names.
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 9435d3ac
......@@ -28,15 +28,15 @@
**
***************************************************************************/
#ifndef RotL_64
#define RotL_64(x, N) (((x) << (N)) | ((x) >> (64-(N))))
#ifndef rotl_64
#define rotl_64(x, N) (((x) << (N)) | ((x) >> (64-(N))))
#endif
/* below two prototype assume we are handed aligned data */
#define Skein_Put64_LSB_First(dst08, src64, b_cnt) memcpy(dst08, src64, b_cnt)
#define Skein_Get64_LSB_First(dst64, src08, w_cnt) \
#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)
#define skein_swap64(w64) (w64)
enum {
SKEIN_SUCCESS = 0, /* return codes from Skein calls */
......@@ -48,20 +48,20 @@ enum {
#define SKEIN_256_STATE_WORDS (4)
#define SKEIN_512_STATE_WORDS (8)
#define SKEIN1024_STATE_WORDS (16)
#define SKEIN_1024_STATE_WORDS (16)
#define SKEIN_MAX_STATE_WORDS (16)
#define SKEIN_256_STATE_BYTES (8*SKEIN_256_STATE_WORDS)
#define SKEIN_512_STATE_BYTES (8*SKEIN_512_STATE_WORDS)
#define SKEIN1024_STATE_BYTES (8*SKEIN1024_STATE_WORDS)
#define SKEIN_1024_STATE_BYTES (8*SKEIN_1024_STATE_WORDS)
#define SKEIN_256_STATE_BITS (64*SKEIN_256_STATE_WORDS)
#define SKEIN_512_STATE_BITS (64*SKEIN_512_STATE_WORDS)
#define SKEIN1024_STATE_BITS (64*SKEIN1024_STATE_WORDS)
#define SKEIN_1024_STATE_BITS (64*SKEIN_1024_STATE_WORDS)
#define SKEIN_256_BLOCK_BYTES (8*SKEIN_256_STATE_WORDS)
#define SKEIN_512_BLOCK_BYTES (8*SKEIN_512_STATE_WORDS)
#define SKEIN1024_BLOCK_BYTES (8*SKEIN1024_STATE_WORDS)
#define SKEIN_1024_BLOCK_BYTES (8*SKEIN_1024_STATE_WORDS)
struct skein_ctx_hdr {
size_t hash_bit_len; /* size of hash result, in bits */
......@@ -83,8 +83,8 @@ struct skein_512_ctx { /* 512-bit Skein hash context structure */
struct skein_1024_ctx { /* 1024-bit Skein hash context structure */
struct skein_ctx_hdr h; /* common header context variables */
u64 X[SKEIN1024_STATE_WORDS]; /* chaining variables */
u8 b[SKEIN1024_BLOCK_BYTES]; /* partial block buf (8-byte aligned) */
u64 X[SKEIN_1024_STATE_WORDS]; /* chaining variables */
u8 b[SKEIN_1024_BLOCK_BYTES]; /* partial block buf (8-byte aligned) */
};
/* Skein APIs for (incremental) "straight hashing" */
......@@ -232,44 +232,44 @@ int skein_1024_output(struct skein_1024_ctx *ctx, u8 *hash_val);
** Skein macros for getting/setting tweak words, etc.
** These are useful for partial input bytes, hash tree init/update, etc.
**/
#define Skein_Get_Tweak(ctx_ptr, TWK_NUM) ((ctx_ptr)->h.T[TWK_NUM])
#define Skein_Set_Tweak(ctx_ptr, TWK_NUM, t_val) { \
#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(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)
#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(ctx_ptr, T0, T1) \
#define skein_set_T0_T1(ctx_ptr, T0, T1) \
{ \
Skein_Set_T0(ctx_ptr, (T0)); \
Skein_Set_T1(ctx_ptr, (T1)); \
skein_set_T0(ctx_ptr, (T0)); \
skein_set_T1(ctx_ptr, (T1)); \
}
#define Skein_Set_Type(ctx_ptr, BLK_TYPE) \
Skein_Set_T1(ctx_ptr, 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.b_cnt=0;
*/
#define Skein_Start_New_Type(ctx_ptr, BLK_TYPE) { \
Skein_Set_T0_T1(ctx_ptr, 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); \
(ctx_ptr)->h.b_cnt = 0; \
}
#define Skein_Clear_First_Flag(hdr) { \
#define skein_clear_first_flag(hdr) { \
(hdr).T[1] &= ~SKEIN_T1_FLAG_FIRST; \
}
#define Skein_Set_Bit_Pad_Flag(hdr) { \
#define skein_set_bit_pad_flag(hdr) { \
(hdr).T[1] |= SKEIN_T1_FLAG_BIT_PAD; \
}
#define Skein_Set_Tree_Level(hdr, height) { \
#define skein_set_tree_level(hdr, height) { \
(hdr).T[1] |= SKEIN_T1_TREE_LEVEL(height); \
}
......@@ -279,15 +279,16 @@ int skein_1024_output(struct skein_1024_ctx *ctx, u8 *hash_val);
#ifdef SKEIN_DEBUG /* examine/display intermediate values? */
#include "skein_debug.h"
#else /* default is no callouts */
#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, out_ptr)
#define Skein_Show_Key(bits, ctx, key, key_bytes)
#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, out_ptr)
#define skein_show_key(bits, ctx, key, key_bytes)
#endif
#define Skein_Assert(x, ret_code)/* ignore all Asserts, for performance */
#define Skein_assert(x)
/* ignore all asserts, for performance */
#define skein_assert_ret(x, ret_code)
#define skein_assert(x)
/*****************************************************************
** Skein block function constants (shared across Ref and Opt code)
......@@ -335,11 +336,11 @@ enum {
#ifndef SKEIN_ROUNDS
#define SKEIN_256_ROUNDS_TOTAL (72) /* # rounds for diff block sizes */
#define SKEIN_512_ROUNDS_TOTAL (72)
#define SKEIN1024_ROUNDS_TOTAL (80)
#define SKEIN_1024_ROUNDS_TOTAL (80)
#else /* allow command-line define in range 8*(5..14) */
#define SKEIN_256_ROUNDS_TOTAL (8*((((SKEIN_ROUNDS/100) + 5) % 10) + 5))
#define SKEIN_512_ROUNDS_TOTAL (8*((((SKEIN_ROUNDS/10) + 5) % 10) + 5))
#define SKEIN1024_ROUNDS_TOTAL (8*((((SKEIN_ROUNDS) + 5) % 10) + 5))
#define SKEIN_1024_ROUNDS_TOTAL (8*((((SKEIN_ROUNDS) + 5) % 10) + 5))
#endif
#endif /* ifndef _SKEIN_H_ */
......@@ -124,7 +124,7 @@ const u64 SKEIN_512_IV_512[] = {
};
/* blkSize = 1024 bits. hashSize = 384 bits */
const u64 SKEIN1024_IV_384[] = {
const u64 SKEIN_1024_IV_384[] = {
MK_64(0x5102B6B8, 0xC1894A35),
MK_64(0xFEEBC9E3, 0xFE8AF11A),
MK_64(0x0C807F06, 0xE32BED71),
......@@ -144,7 +144,7 @@ const u64 SKEIN1024_IV_384[] = {
};
/* blkSize = 1024 bits. hashSize = 512 bits */
const u64 SKEIN1024_IV_512[] = {
const u64 SKEIN_1024_IV_512[] = {
MK_64(0xCAEC0E5D, 0x7C1B1B18),
MK_64(0xA01B0E04, 0x5F03E802),
MK_64(0x33840451, 0xED912885),
......@@ -164,7 +164,7 @@ const u64 SKEIN1024_IV_512[] = {
};
/* blkSize = 1024 bits. hashSize = 1024 bits */
const u64 SKEIN1024_IV_1024[] = {
const u64 SKEIN_1024_IV_1024[] = {
MK_64(0xD593DA07, 0x41E72355),
MK_64(0x15B5E511, 0xAC73E00C),
MK_64(0x5180E5AE, 0xBAF2C4F0),
......
......@@ -31,7 +31,7 @@
#include <linux/types.h>
#include <skein.h>
#define KeyScheduleConst 0x1BD11BDAA9FC1A22L
#define KEY_SCHEDULE_CONST 0x1BD11BDAA9FC1A22L
/**
* Which Threefish size to use
......
This diff is collapsed.
......@@ -29,7 +29,7 @@ OTHER DEALINGS IN THE SOFTWARE.
int skein_ctx_prepare(struct skein_ctx *ctx, enum skein_size size)
{
Skein_Assert(ctx && size, SKEIN_FAIL);
skein_assert_ret(ctx && size, SKEIN_FAIL);
memset(ctx , 0, sizeof(struct skein_ctx));
ctx->skein_size = size;
......@@ -44,7 +44,7 @@ int skein_init(struct skein_ctx *ctx, size_t hash_bit_len)
u64 *X = NULL;
u64 tree_info = SKEIN_CFG_TREE_INFO_SEQUENTIAL;
Skein_Assert(ctx, SKEIN_FAIL);
skein_assert_ret(ctx, SKEIN_FAIL);
/*
* The following two lines rely of the fact that the real Skein
* contexts are a union in out context and thus have tha maximum
......@@ -89,12 +89,12 @@ int skein_mac_init(struct skein_ctx *ctx, const u8 *key, size_t key_len,
size_t X_len = 0;
u64 tree_info = SKEIN_CFG_TREE_INFO_SEQUENTIAL;
Skein_Assert(ctx, SKEIN_FAIL);
skein_assert_ret(ctx, SKEIN_FAIL);
X = ctx->m.s256.X;
X_len = ctx->skein_size/8;
Skein_Assert(hash_bit_len, SKEIN_BAD_HASHLEN);
skein_assert_ret(hash_bit_len, SKEIN_BAD_HASHLEN);
switch (ctx->skein_size) {
case SKEIN_256:
......@@ -141,7 +141,7 @@ void skein_reset(struct skein_ctx *ctx)
memcpy(X, ctx->X_save, X_len);
/* 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,
......@@ -149,7 +149,7 @@ int skein_update(struct skein_ctx *ctx, const u8 *msg,
{
int ret = SKEIN_FAIL;
Skein_Assert(ctx, SKEIN_FAIL);
skein_assert_ret(ctx, SKEIN_FAIL);
switch (ctx->skein_size) {
case SKEIN_256:
......@@ -185,7 +185,7 @@ int skein_update_bits(struct skein_ctx *ctx, const u8 *msg,
* only the final Update() call is allowed do partial bytes, else
* assert an error
*/
Skein_Assert((ctx->m.h.T[1] & SKEIN_T1_FLAG_BIT_PAD) == 0 ||
skein_assert_ret((ctx->m.h.T[1] & SKEIN_T1_FLAG_BIT_PAD) == 0 ||
msg_bit_cnt == 0, SKEIN_FAIL);
/* if number of bits is a multiple of bytes - that's easy */
......@@ -203,13 +203,13 @@ int skein_update_bits(struct skein_ctx *ctx, const u8 *msg,
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);
skein_set_bit_pad_flag(ctx->m.h);
/* now "pad" the final partial byte the way NIST likes */
/* 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);
skein_assert(length != 0);
/* partial byte bit mask */
mask = (u8) (1u << (7 - (msg_bit_cnt & 7)));
/* apply bit padding on final byte (in the buffer) */
......@@ -222,7 +222,7 @@ int skein_final(struct skein_ctx *ctx, u8 *hash)
{
int ret = SKEIN_FAIL;
Skein_Assert(ctx, SKEIN_FAIL);
skein_assert_ret(ctx, SKEIN_FAIL);
switch (ctx->skein_size) {
case SKEIN_256:
......
......@@ -14,7 +14,7 @@ void skein_256_process_block(struct skein_256_ctx *ctx, const u8 *blk_ptr,
u64 w[SKEIN_256_STATE_WORDS]; /* local copy of input block */
u64 words[3];
Skein_assert(blk_cnt != 0); /* never call with blk_cnt == 0! */
skein_assert(blk_cnt != 0); /* never call with blk_cnt == 0! */
tweak[0] = ctx->h.T[0];
tweak[1] = ctx->h.T[1];
......@@ -37,7 +37,7 @@ void skein_256_process_block(struct skein_256_ctx *ctx, const u8 *blk_ptr,
threefish_set_key(&key, THREEFISH_256, ctx->X, tweak);
/* get input block in little-endian format */
Skein_Get64_LSB_First(w, blk_ptr, SKEIN_256_STATE_WORDS);
skein_get64_lsb_first(w, blk_ptr, SKEIN_256_STATE_WORDS);
threefish_encrypt_block_words(&key, w, ctx->X);
......@@ -65,7 +65,7 @@ void skein_512_process_block(struct skein_512_ctx *ctx, const u8 *blk_ptr,
u64 words[3];
u64 w[SKEIN_512_STATE_WORDS]; /* local copy of input block */
Skein_assert(blk_cnt != 0); /* never call with blk_cnt == 0! */
skein_assert(blk_cnt != 0); /* never call with blk_cnt == 0! */
tweak[0] = ctx->h.T[0];
tweak[1] = ctx->h.T[1];
......@@ -88,7 +88,7 @@ void skein_512_process_block(struct skein_512_ctx *ctx, const u8 *blk_ptr,
threefish_set_key(&key, THREEFISH_512, ctx->X, tweak);
/* get input block in little-endian format */
Skein_Get64_LSB_First(w, blk_ptr, SKEIN_512_STATE_WORDS);
skein_get64_lsb_first(w, blk_ptr, SKEIN_512_STATE_WORDS);
threefish_encrypt_block_words(&key, w, ctx->X);
......@@ -118,9 +118,9 @@ void skein_1024_process_block(struct skein_1024_ctx *ctx, const u8 *blk_ptr,
u64 tweak[2];
int i;
u64 words[3];
u64 w[SKEIN1024_STATE_WORDS]; /* local copy of input block */
u64 w[SKEIN_1024_STATE_WORDS]; /* local copy of input block */
Skein_assert(blk_cnt != 0); /* never call with blk_cnt == 0! */
skein_assert(blk_cnt != 0); /* never call with blk_cnt == 0! */
tweak[0] = ctx->h.T[0];
tweak[1] = ctx->h.T[1];
......@@ -143,11 +143,11 @@ void skein_1024_process_block(struct skein_1024_ctx *ctx, const u8 *blk_ptr,
threefish_set_key(&key, THREEFISH_1024, ctx->X, tweak);
/* get input block in little-endian format */
Skein_Get64_LSB_First(w, blk_ptr, SKEIN1024_STATE_WORDS);
skein_get64_lsb_first(w, blk_ptr, SKEIN_1024_STATE_WORDS);
threefish_encrypt_block_words(&key, w, ctx->X);
blk_ptr += SKEIN1024_BLOCK_BYTES;
blk_ptr += SKEIN_1024_BLOCK_BYTES;
/* do the final "feedforward" xor, update ctx chaining vars */
ctx->X[0] = ctx->X[0] ^ w[0];
......
This diff is collapsed.
......@@ -9,7 +9,7 @@ void threefish_set_key(struct threefish_key *key_ctx,
{
int key_words = state_size / 64;
int i;
u64 parity = KeyScheduleConst;
u64 parity = KEY_SCHEDULE_CONST;
key_ctx->tweak[0] = tweak[0];
key_ctx->tweak[1] = tweak[1];
......@@ -29,9 +29,9 @@ void threefish_encrypt_block_bytes(struct threefish_key *key_ctx, u8 *in,
u64 plain[SKEIN_MAX_STATE_WORDS]; /* max number of words*/
u64 cipher[SKEIN_MAX_STATE_WORDS];
Skein_Get64_LSB_First(plain, in, key_ctx->state_size / 64);
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);
skein_put64_lsb_first(out, cipher, key_ctx->state_size / 8);
}
void threefish_encrypt_block_words(struct threefish_key *key_ctx, u64 *in,
......@@ -56,9 +56,9 @@ void threefish_decrypt_block_bytes(struct threefish_key *key_ctx, u8 *in,
u64 plain[SKEIN_MAX_STATE_WORDS]; /* max number of words*/
u64 cipher[SKEIN_MAX_STATE_WORDS];
Skein_Get64_LSB_First(cipher, in, key_ctx->state_size / 64);
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);
skein_put64_lsb_first(out, plain, key_ctx->state_size / 8);
}
void threefish_decrypt_block_words(struct threefish_key *key_ctx, u64 *in,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment