diff options
author | Anton Saraev <antonysaraev@gmail.com> | 2014-05-19 12:09:58 +0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-05-19 14:18:14 -0700 |
commit | 0264b7b7fb44e78414d16fa5142cea4b9799609a (patch) | |
tree | 176e7ac607ce894eb4f3e85aba267a8b5899fbf7 /drivers/staging/skein | |
parent | 9435d3ace68afea0533954e69cf0f8569fb7dc42 (diff) |
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: Anton Saraev <antonysaraev@gmail.com>
Reviewed-by: Jake Edge <jake@lwn.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/skein')
-rw-r--r-- | drivers/staging/skein/include/skein.h | 75 | ||||
-rw-r--r-- | drivers/staging/skein/include/skein_iv.h | 6 | ||||
-rw-r--r-- | drivers/staging/skein/include/threefishApi.h | 2 | ||||
-rw-r--r-- | drivers/staging/skein/skein.c | 262 | ||||
-rw-r--r-- | drivers/staging/skein/skeinApi.c | 22 | ||||
-rw-r--r-- | drivers/staging/skein/skeinBlockNo3F.c | 20 | ||||
-rw-r--r-- | drivers/staging/skein/skein_block.c | 308 | ||||
-rw-r--r-- | drivers/staging/skein/threefishApi.c | 10 |
8 files changed, 353 insertions, 352 deletions
diff --git a/drivers/staging/skein/include/skein.h b/drivers/staging/skein/include/skein.h index 8ecd720f981c..2c87ff74aaea 100644 --- a/drivers/staging/skein/include/skein.h +++ b/drivers/staging/skein/include/skein.h @@ -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) \ - { \ - Skein_Set_T0(ctx_ptr, (T0)); \ - Skein_Set_T1(ctx_ptr, (T1)); \ +#define skein_set_T0_T1(ctx_ptr, T0, 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_ */ diff --git a/drivers/staging/skein/include/skein_iv.h b/drivers/staging/skein/include/skein_iv.h index 8dd5e4d88a1d..7ff93dfd912f 100644 --- a/drivers/staging/skein/include/skein_iv.h +++ b/drivers/staging/skein/include/skein_iv.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), diff --git a/drivers/staging/skein/include/threefishApi.h b/drivers/staging/skein/include/threefishApi.h index 63030e52b9a0..96cc0e868f43 100644 --- a/drivers/staging/skein/include/threefishApi.h +++ b/drivers/staging/skein/include/threefishApi.h @@ -31,7 +31,7 @@ #include <linux/types.h> #include <skein.h> -#define KeyScheduleConst 0x1BD11BDAA9FC1A22L +#define KEY_SCHEDULE_CONST 0x1BD11BDAA9FC1A22L /** * Which Threefish size to use diff --git a/drivers/staging/skein/skein.c b/drivers/staging/skein/skein.c index 43e7757872fa..2a2da983a1cc 100644 --- a/drivers/staging/skein/skein.c +++ b/drivers/staging/skein/skein.c @@ -28,7 +28,7 @@ int skein_256_init(struct skein_256_ctx *ctx, size_t hash_bit_len) u64 w[SKEIN_256_STATE_WORDS]; } cfg; /* config block */ - Skein_Assert(hash_bit_len > 0, SKEIN_BAD_HASHLEN); + skein_assert_ret(hash_bit_len > 0, SKEIN_BAD_HASHLEN); ctx->h.hash_bit_len = hash_bit_len; /* output hash bit count */ switch (hash_bit_len) { /* use pre-computed values, where available */ @@ -51,13 +51,13 @@ int skein_256_init(struct skein_256_ctx *ctx, size_t hash_bit_len) * precomputed) */ /* set tweaks: T0=0; T1=CFG | FINAL */ - Skein_Start_New_Type(ctx, CFG_FINAL); + skein_start_new_type(ctx, CFG_FINAL); /* set the schema, version */ - cfg.w[0] = Skein_Swap64(SKEIN_SCHEMA_VER); + cfg.w[0] = skein_swap64(SKEIN_SCHEMA_VER); /* hash result length in bits */ - cfg.w[1] = Skein_Swap64(hash_bit_len); - cfg.w[2] = Skein_Swap64(SKEIN_CFG_TREE_INFO_SEQUENTIAL); + cfg.w[1] = skein_swap64(hash_bit_len); + cfg.w[2] = skein_swap64(SKEIN_CFG_TREE_INFO_SEQUENTIAL); /* zero pad config block */ memset(&cfg.w[3], 0, sizeof(cfg) - 3*sizeof(cfg.w[0])); @@ -69,7 +69,7 @@ int skein_256_init(struct skein_256_ctx *ctx, size_t hash_bit_len) } /* The chaining vars ctx->X are now initialized for hash_bit_len. */ /* Set up to process the data message portion of the hash (default) */ - Skein_Start_New_Type(ctx, MSG); /* T0=0, T1= MSG type */ + skein_start_new_type(ctx, MSG); /* T0=0, T1= MSG type */ return SKEIN_SUCCESS; } @@ -86,20 +86,20 @@ int skein_256_init_ext(struct skein_256_ctx *ctx, size_t hash_bit_len, u64 w[SKEIN_256_STATE_WORDS]; } cfg; /* config block */ - Skein_Assert(hash_bit_len > 0, SKEIN_BAD_HASHLEN); - Skein_Assert(key_bytes == 0 || key != NULL, SKEIN_FAIL); + skein_assert_ret(hash_bit_len > 0, SKEIN_BAD_HASHLEN); + skein_assert_ret(key_bytes == 0 || key != NULL, SKEIN_FAIL); /* compute the initial chaining values ctx->X[], based on key */ if (key_bytes == 0) { /* is there a key? */ /* no key: use all zeroes as key for config block */ memset(ctx->X, 0, sizeof(ctx->X)); } else { /* here to pre-process a key */ - Skein_assert(sizeof(cfg.b) >= sizeof(ctx->X)); + skein_assert(sizeof(cfg.b) >= sizeof(ctx->X)); /* do a mini-Init right here */ /* set output hash bit count = state size */ ctx->h.hash_bit_len = 8*sizeof(ctx->X); /* set tweaks: T0 = 0; T1 = KEY type */ - Skein_Start_New_Type(ctx, KEY); + skein_start_new_type(ctx, KEY); /* zero the initial chaining variables */ memset(ctx->X, 0, sizeof(ctx->X)); /* hash the key */ @@ -115,24 +115,24 @@ int skein_256_init_ext(struct skein_256_ctx *ctx, size_t hash_bit_len, */ /* output hash bit count */ ctx->h.hash_bit_len = hash_bit_len; - Skein_Start_New_Type(ctx, CFG_FINAL); + skein_start_new_type(ctx, CFG_FINAL); /* pre-pad cfg.w[] with zeroes */ memset(&cfg.w, 0, sizeof(cfg.w)); - cfg.w[0] = Skein_Swap64(SKEIN_SCHEMA_VER); + cfg.w[0] = skein_swap64(SKEIN_SCHEMA_VER); /* hash result length in bits */ - cfg.w[1] = Skein_Swap64(hash_bit_len); + cfg.w[1] = skein_swap64(hash_bit_len); /* tree hash config info (or SKEIN_CFG_TREE_INFO_SEQUENTIAL) */ - cfg.w[2] = Skein_Swap64(tree_info); + cfg.w[2] = skein_swap64(tree_info); - Skein_Show_Key(256, &ctx->h, key, key_bytes); + skein_show_key(256, &ctx->h, key, key_bytes); /* compute the initial chaining values from config block */ skein_256_process_block(ctx, cfg.b, 1, SKEIN_CFG_STR_LEN); /* The chaining vars ctx->X are now initialized */ /* Set up to process the data message portion of the hash (default) */ - Skein_Start_New_Type(ctx, MSG); + skein_start_new_type(ctx, MSG); return SKEIN_SUCCESS; } @@ -145,7 +145,7 @@ int skein_256_update(struct skein_256_ctx *ctx, const u8 *msg, size_t n; /* catch uninitialized context */ - Skein_Assert(ctx->h.b_cnt <= SKEIN_256_BLOCK_BYTES, SKEIN_FAIL); + skein_assert_ret(ctx->h.b_cnt <= SKEIN_256_BLOCK_BYTES, SKEIN_FAIL); /* process full blocks, if any */ if (msg_byte_cnt + ctx->h.b_cnt > SKEIN_256_BLOCK_BYTES) { @@ -155,13 +155,13 @@ int skein_256_update(struct skein_256_ctx *ctx, const u8 *msg, n = SKEIN_256_BLOCK_BYTES - ctx->h.b_cnt; if (n) { /* check on our logic here */ - Skein_assert(n < msg_byte_cnt); + skein_assert(n < msg_byte_cnt); memcpy(&ctx->b[ctx->h.b_cnt], msg, n); msg_byte_cnt -= n; msg += n; ctx->h.b_cnt += n; } - Skein_assert(ctx->h.b_cnt == SKEIN_256_BLOCK_BYTES); + skein_assert(ctx->h.b_cnt == SKEIN_256_BLOCK_BYTES); skein_256_process_block(ctx, ctx->b, 1, SKEIN_256_BLOCK_BYTES); ctx->h.b_cnt = 0; @@ -178,12 +178,12 @@ int skein_256_update(struct skein_256_ctx *ctx, const u8 *msg, msg_byte_cnt -= n * SKEIN_256_BLOCK_BYTES; msg += n * SKEIN_256_BLOCK_BYTES; } - Skein_assert(ctx->h.b_cnt == 0); + skein_assert(ctx->h.b_cnt == 0); } /* copy any remaining source message data bytes into b[] */ if (msg_byte_cnt) { - Skein_assert(msg_byte_cnt + ctx->h.b_cnt <= + skein_assert(msg_byte_cnt + ctx->h.b_cnt <= SKEIN_256_BLOCK_BYTES); memcpy(&ctx->b[ctx->h.b_cnt], msg, msg_byte_cnt); ctx->h.b_cnt += msg_byte_cnt; @@ -199,7 +199,7 @@ int skein_256_final(struct skein_256_ctx *ctx, u8 *hash_val) size_t i, n, byte_cnt; u64 X[SKEIN_256_STATE_WORDS]; /* catch uninitialized context */ - Skein_Assert(ctx->h.b_cnt <= SKEIN_256_BLOCK_BYTES, SKEIN_FAIL); + skein_assert_ret(ctx->h.b_cnt <= SKEIN_256_BLOCK_BYTES, SKEIN_FAIL); /* tag as the final block */ ctx->h.T[1] |= SKEIN_T1_FLAG_FINAL; @@ -222,8 +222,8 @@ int skein_256_final(struct skein_256_ctx *ctx, u8 *hash_val) memcpy(X, ctx->X, sizeof(X)); for (i = 0; i*SKEIN_256_BLOCK_BYTES < byte_cnt; i++) { /* build the counter block */ - ((u64 *)ctx->b)[0] = Skein_Swap64((u64) i); - Skein_Start_New_Type(ctx, OUT_FINAL); + ((u64 *)ctx->b)[0] = skein_swap64((u64) i); + skein_start_new_type(ctx, OUT_FINAL); /* run "counter mode" */ skein_256_process_block(ctx, ctx->b, 1, sizeof(u64)); /* number of output bytes left to go */ @@ -231,9 +231,9 @@ int skein_256_final(struct skein_256_ctx *ctx, u8 *hash_val) if (n >= SKEIN_256_BLOCK_BYTES) n = SKEIN_256_BLOCK_BYTES; /* "output" the ctr mode bytes */ - Skein_Put64_LSB_First(hash_val+i*SKEIN_256_BLOCK_BYTES, ctx->X, + skein_put64_lsb_first(hash_val+i*SKEIN_256_BLOCK_BYTES, ctx->X, n); - Skein_Show_Final(256, &ctx->h, n, + skein_show_final(256, &ctx->h, n, hash_val+i*SKEIN_256_BLOCK_BYTES); /* restore the counter mode key for next time */ memcpy(ctx->X, X, sizeof(X)); @@ -254,7 +254,7 @@ int skein_512_init(struct skein_512_ctx *ctx, size_t hash_bit_len) u64 w[SKEIN_512_STATE_WORDS]; } cfg; /* config block */ - Skein_Assert(hash_bit_len > 0, SKEIN_BAD_HASHLEN); + skein_assert_ret(hash_bit_len > 0, SKEIN_BAD_HASHLEN); ctx->h.hash_bit_len = hash_bit_len; /* output hash bit count */ switch (hash_bit_len) { /* use pre-computed values, where available */ @@ -277,13 +277,13 @@ int skein_512_init(struct skein_512_ctx *ctx, size_t hash_bit_len) * precomputed) */ /* set tweaks: T0=0; T1=CFG | FINAL */ - Skein_Start_New_Type(ctx, CFG_FINAL); + skein_start_new_type(ctx, CFG_FINAL); /* set the schema, version */ - cfg.w[0] = Skein_Swap64(SKEIN_SCHEMA_VER); + cfg.w[0] = skein_swap64(SKEIN_SCHEMA_VER); /* hash result length in bits */ - cfg.w[1] = Skein_Swap64(hash_bit_len); - cfg.w[2] = Skein_Swap64(SKEIN_CFG_TREE_INFO_SEQUENTIAL); + cfg.w[1] = skein_swap64(hash_bit_len); + cfg.w[2] = skein_swap64(SKEIN_CFG_TREE_INFO_SEQUENTIAL); /* zero pad config block */ memset(&cfg.w[3], 0, sizeof(cfg) - 3*sizeof(cfg.w[0])); @@ -299,7 +299,7 @@ int skein_512_init(struct skein_512_ctx *ctx, size_t hash_bit_len) * hash_bit_len. */ /* Set up to process the data message portion of the hash (default) */ - Skein_Start_New_Type(ctx, MSG); /* T0=0, T1= MSG type */ + skein_start_new_type(ctx, MSG); /* T0=0, T1= MSG type */ return SKEIN_SUCCESS; } @@ -316,20 +316,20 @@ int skein_512_init_ext(struct skein_512_ctx *ctx, size_t hash_bit_len, u64 w[SKEIN_512_STATE_WORDS]; } cfg; /* config block */ - Skein_Assert(hash_bit_len > 0, SKEIN_BAD_HASHLEN); - Skein_Assert(key_bytes == 0 || key != NULL, SKEIN_FAIL); + skein_assert_ret(hash_bit_len > 0, SKEIN_BAD_HASHLEN); + skein_assert_ret(key_bytes == 0 || key != NULL, SKEIN_FAIL); /* compute the initial chaining values ctx->X[], based on key */ if (key_bytes == 0) { /* is there a key? */ /* no key: use all zeroes as key for config block */ memset(ctx->X, 0, sizeof(ctx->X)); } else { /* here to pre-process a key */ - Skein_assert(sizeof(cfg.b) >= sizeof(ctx->X)); + skein_assert(sizeof(cfg.b) >= sizeof(ctx->X)); /* do a mini-Init right here */ /* set output hash bit count = state size */ ctx->h.hash_bit_len = 8*sizeof(ctx->X); /* set tweaks: T0 = 0; T1 = KEY type */ - Skein_Start_New_Type(ctx, KEY); + skein_start_new_type(ctx, KEY); /* zero the initial chaining variables */ memset(ctx->X, 0, sizeof(ctx->X)); /* hash the key */ @@ -344,24 +344,24 @@ int skein_512_init_ext(struct skein_512_ctx *ctx, size_t hash_bit_len, * precomputed for each key) */ ctx->h.hash_bit_len = hash_bit_len; /* output hash bit count */ - Skein_Start_New_Type(ctx, CFG_FINAL); + skein_start_new_type(ctx, CFG_FINAL); /* pre-pad cfg.w[] with zeroes */ memset(&cfg.w, 0, sizeof(cfg.w)); - cfg.w[0] = Skein_Swap64(SKEIN_SCHEMA_VER); + cfg.w[0] = skein_swap64(SKEIN_SCHEMA_VER); /* hash result length in bits */ - cfg.w[1] = Skein_Swap64(hash_bit_len); + cfg.w[1] = skein_swap64(hash_bit_len); /* tree hash config info (or SKEIN_CFG_TREE_INFO_SEQUENTIAL) */ - cfg.w[2] = Skein_Swap64(tree_info); + cfg.w[2] = skein_swap64(tree_info); - Skein_Show_Key(512, &ctx->h, key, key_bytes); + skein_show_key(512, &ctx->h, key, key_bytes); /* compute the initial chaining values from config block */ skein_512_process_block(ctx, cfg.b, 1, SKEIN_CFG_STR_LEN); /* The chaining vars ctx->X are now initialized */ /* Set up to process the data message portion of the hash (default) */ - Skein_Start_New_Type(ctx, MSG); + skein_start_new_type(ctx, MSG); return SKEIN_SUCCESS; } @@ -374,7 +374,7 @@ int skein_512_update(struct skein_512_ctx *ctx, const u8 *msg, size_t n; /* catch uninitialized context */ - Skein_Assert(ctx->h.b_cnt <= SKEIN_512_BLOCK_BYTES, SKEIN_FAIL); + skein_assert_ret(ctx->h.b_cnt <= SKEIN_512_BLOCK_BYTES, SKEIN_FAIL); /* process full blocks, if any */ if (msg_byte_cnt + ctx->h.b_cnt > SKEIN_512_BLOCK_BYTES) { @@ -384,13 +384,13 @@ int skein_512_update(struct skein_512_ctx *ctx, const u8 *msg, n = SKEIN_512_BLOCK_BYTES - ctx->h.b_cnt; if (n) { /* check on our logic here */ - Skein_assert(n < msg_byte_cnt); + skein_assert(n < msg_byte_cnt); memcpy(&ctx->b[ctx->h.b_cnt], msg, n); msg_byte_cnt -= n; msg += n; ctx->h.b_cnt += n; } - Skein_assert(ctx->h.b_cnt == SKEIN_512_BLOCK_BYTES); + skein_assert(ctx->h.b_cnt == SKEIN_512_BLOCK_BYTES); skein_512_process_block(ctx, ctx->b, 1, SKEIN_512_BLOCK_BYTES); ctx->h.b_cnt = 0; @@ -407,12 +407,12 @@ int skein_512_update(struct skein_512_ctx *ctx, const u8 *msg, msg_byte_cnt -= n * SKEIN_512_BLOCK_BYTES; msg += n * SKEIN_512_BLOCK_BYTES; } - Skein_assert(ctx->h.b_cnt == 0); + skein_assert(ctx->h.b_cnt == 0); } /* copy any remaining source message data bytes into b[] */ if (msg_byte_cnt) { - Skein_assert(msg_byte_cnt + ctx->h.b_cnt <= + skein_assert(msg_byte_cnt + ctx->h.b_cnt <= SKEIN_512_BLOCK_BYTES); memcpy(&ctx->b[ctx->h.b_cnt], msg, msg_byte_cnt); ctx->h.b_cnt += msg_byte_cnt; @@ -428,7 +428,7 @@ int skein_512_final(struct skein_512_ctx *ctx, u8 *hash_val) size_t i, n, byte_cnt; u64 X[SKEIN_512_STATE_WORDS]; /* catch uninitialized context */ - Skein_Assert(ctx->h.b_cnt <= SKEIN_512_BLOCK_BYTES, SKEIN_FAIL); + skein_assert_ret(ctx->h.b_cnt <= SKEIN_512_BLOCK_BYTES, SKEIN_FAIL); /* tag as the final block */ ctx->h.T[1] |= SKEIN_T1_FLAG_FINAL; @@ -451,8 +451,8 @@ int skein_512_final(struct skein_512_ctx *ctx, u8 *hash_val) memcpy(X, ctx->X, sizeof(X)); for (i = 0; i*SKEIN_512_BLOCK_BYTES < byte_cnt; i++) { /* build the counter block */ - ((u64 *)ctx->b)[0] = Skein_Swap64((u64) i); - Skein_Start_New_Type(ctx, OUT_FINAL); + ((u64 *)ctx->b)[0] = skein_swap64((u64) i); + skein_start_new_type(ctx, OUT_FINAL); /* run "counter mode" */ skein_512_process_block(ctx, ctx->b, 1, sizeof(u64)); /* number of output bytes left to go */ @@ -460,9 +460,9 @@ int skein_512_final(struct skein_512_ctx *ctx, u8 *hash_val) if (n >= SKEIN_512_BLOCK_BYTES) n = SKEIN_512_BLOCK_BYTES; /* "output" the ctr mode bytes */ - Skein_Put64_LSB_First(hash_val+i*SKEIN_512_BLOCK_BYTES, ctx->X, + skein_put64_lsb_first(hash_val+i*SKEIN_512_BLOCK_BYTES, ctx->X, n); - Skein_Show_Final(512, &ctx->h, n, + skein_show_final(512, &ctx->h, n, hash_val+i*SKEIN_512_BLOCK_BYTES); /* restore the counter mode key for next time */ memcpy(ctx->X, X, sizeof(X)); @@ -479,22 +479,22 @@ int skein_512_final(struct skein_512_ctx *ctx, u8 *hash_val) int skein_1024_init(struct skein_1024_ctx *ctx, size_t hash_bit_len) { union { - u8 b[SKEIN1024_STATE_BYTES]; - u64 w[SKEIN1024_STATE_WORDS]; + u8 b[SKEIN_1024_STATE_BYTES]; + u64 w[SKEIN_1024_STATE_WORDS]; } cfg; /* config block */ - Skein_Assert(hash_bit_len > 0, SKEIN_BAD_HASHLEN); + skein_assert_ret(hash_bit_len > 0, SKEIN_BAD_HASHLEN); ctx->h.hash_bit_len = hash_bit_len; /* output hash bit count */ switch (hash_bit_len) { /* use pre-computed values, where available */ case 512: - memcpy(ctx->X, SKEIN1024_IV_512, sizeof(ctx->X)); + memcpy(ctx->X, SKEIN_1024_IV_512, sizeof(ctx->X)); break; case 384: - memcpy(ctx->X, SKEIN1024_IV_384, sizeof(ctx->X)); + memcpy(ctx->X, SKEIN_1024_IV_384, sizeof(ctx->X)); break; case 1024: - memcpy(ctx->X, SKEIN1024_IV_1024, sizeof(ctx->X)); + memcpy(ctx->X, SKEIN_1024_IV_1024, sizeof(ctx->X)); break; default: /* here if there is no precomputed IV value available */ @@ -503,13 +503,13 @@ int skein_1024_init(struct skein_1024_ctx *ctx, size_t hash_bit_len) * (could be precomputed) */ /* set tweaks: T0=0; T1=CFG | FINAL */ - Skein_Start_New_Type(ctx, CFG_FINAL); + skein_start_new_type(ctx, CFG_FINAL); /* set the schema, version */ - cfg.w[0] = Skein_Swap64(SKEIN_SCHEMA_VER); + cfg.w[0] = skein_swap64(SKEIN_SCHEMA_VER); /* hash result length in bits */ - cfg.w[1] = Skein_Swap64(hash_bit_len); - cfg.w[2] = Skein_Swap64(SKEIN_CFG_TREE_INFO_SEQUENTIAL); + cfg.w[1] = skein_swap64(hash_bit_len); + cfg.w[2] = skein_swap64(SKEIN_CFG_TREE_INFO_SEQUENTIAL); /* zero pad config block */ memset(&cfg.w[3], 0, sizeof(cfg) - 3*sizeof(cfg.w[0])); @@ -522,7 +522,7 @@ int skein_1024_init(struct skein_1024_ctx *ctx, size_t hash_bit_len) /* The chaining vars ctx->X are now initialized for the hash_bit_len. */ /* Set up to process the data message portion of the hash (default) */ - Skein_Start_New_Type(ctx, MSG); /* T0=0, T1= MSG type */ + skein_start_new_type(ctx, MSG); /* T0=0, T1= MSG type */ return SKEIN_SUCCESS; } @@ -535,24 +535,24 @@ int skein_1024_init_ext(struct skein_1024_ctx *ctx, size_t hash_bit_len, u64 tree_info, const u8 *key, size_t key_bytes) { union { - u8 b[SKEIN1024_STATE_BYTES]; - u64 w[SKEIN1024_STATE_WORDS]; + u8 b[SKEIN_1024_STATE_BYTES]; + u64 w[SKEIN_1024_STATE_WORDS]; } cfg; /* config block */ - Skein_Assert(hash_bit_len > 0, SKEIN_BAD_HASHLEN); - Skein_Assert(key_bytes == 0 || key != NULL, SKEIN_FAIL); + skein_assert_ret(hash_bit_len > 0, SKEIN_BAD_HASHLEN); + skein_assert_ret(key_bytes == 0 || key != NULL, SKEIN_FAIL); /* compute the initial chaining values ctx->X[], based on key */ if (key_bytes == 0) { /* is there a key? */ /* no key: use all zeroes as key for config block */ memset(ctx->X, 0, sizeof(ctx->X)); } else { /* here to pre-process a key */ - Skein_assert(sizeof(cfg.b) >= sizeof(ctx->X)); + skein_assert(sizeof(cfg.b) >= sizeof(ctx->X)); /* do a mini-Init right here */ /* set output hash bit count = state size */ ctx->h.hash_bit_len = 8*sizeof(ctx->X); /* set tweaks: T0 = 0; T1 = KEY type */ - Skein_Start_New_Type(ctx, KEY); + skein_start_new_type(ctx, KEY); /* zero the initial chaining variables */ memset(ctx->X, 0, sizeof(ctx->X)); /* hash the key */ @@ -568,24 +568,24 @@ int skein_1024_init_ext(struct skein_1024_ctx *ctx, size_t hash_bit_len, */ /* output hash bit count */ ctx->h.hash_bit_len = hash_bit_len; - Skein_Start_New_Type(ctx, CFG_FINAL); + skein_start_new_type(ctx, CFG_FINAL); /* pre-pad cfg.w[] with zeroes */ memset(&cfg.w, 0, sizeof(cfg.w)); - cfg.w[0] = Skein_Swap64(SKEIN_SCHEMA_VER); + cfg.w[0] = skein_swap64(SKEIN_SCHEMA_VER); /* hash result length in bits */ - cfg.w[1] = Skein_Swap64(hash_bit_len); + cfg.w[1] = skein_swap64(hash_bit_len); /* tree hash config info (or SKEIN_CFG_TREE_INFO_SEQUENTIAL) */ - cfg.w[2] = Skein_Swap64(tree_info); + cfg.w[2] = skein_swap64(tree_info); - Skein_Show_Key(1024, &ctx->h, key, key_bytes); + skein_show_key(1024, &ctx->h, key, key_bytes); /* compute the initial chaining values from config block */ skein_1024_process_block(ctx, cfg.b, 1, SKEIN_CFG_STR_LEN); /* The chaining vars ctx->X are now initialized */ /* Set up to process the data message portion of the hash (default) */ - Skein_Start_New_Type(ctx, MSG); + skein_start_new_type(ctx, MSG); return SKEIN_SUCCESS; } @@ -598,46 +598,46 @@ int skein_1024_update(struct skein_1024_ctx *ctx, const u8 *msg, size_t n; /* catch uninitialized context */ - Skein_Assert(ctx->h.b_cnt <= SKEIN1024_BLOCK_BYTES, SKEIN_FAIL); + skein_assert_ret(ctx->h.b_cnt <= SKEIN_1024_BLOCK_BYTES, SKEIN_FAIL); /* process full blocks, if any */ - if (msg_byte_cnt + ctx->h.b_cnt > SKEIN1024_BLOCK_BYTES) { + if (msg_byte_cnt + ctx->h.b_cnt > SKEIN_1024_BLOCK_BYTES) { /* finish up any buffered message data */ if (ctx->h.b_cnt) { /* # bytes free in buffer b[] */ - n = SKEIN1024_BLOCK_BYTES - ctx->h.b_cnt; + n = SKEIN_1024_BLOCK_BYTES - ctx->h.b_cnt; if (n) { /* check on our logic here */ - Skein_assert(n < msg_byte_cnt); + skein_assert(n < msg_byte_cnt); memcpy(&ctx->b[ctx->h.b_cnt], msg, n); msg_byte_cnt -= n; msg += n; ctx->h.b_cnt += n; } - Skein_assert(ctx->h.b_cnt == SKEIN1024_BLOCK_BYTES); + skein_assert(ctx->h.b_cnt == SKEIN_1024_BLOCK_BYTES); skein_1024_process_block(ctx, ctx->b, 1, - SKEIN1024_BLOCK_BYTES); + SKEIN_1024_BLOCK_BYTES); ctx->h.b_cnt = 0; } /* * now process any remaining full blocks, directly from input * message data */ - if (msg_byte_cnt > SKEIN1024_BLOCK_BYTES) { + if (msg_byte_cnt > SKEIN_1024_BLOCK_BYTES) { /* number of full blocks to process */ - n = (msg_byte_cnt-1) / SKEIN1024_BLOCK_BYTES; + n = (msg_byte_cnt-1) / SKEIN_1024_BLOCK_BYTES; skein_1024_process_block(ctx, msg, n, - SKEIN1024_BLOCK_BYTES); - msg_byte_cnt -= n * SKEIN1024_BLOCK_BYTES; - msg += n * SKEIN1024_BLOCK_BYTES; + SKEIN_1024_BLOCK_BYTES); + msg_byte_cnt -= n * SKEIN_1024_BLOCK_BYTES; + msg += n * SKEIN_1024_BLOCK_BYTES; } - Skein_assert(ctx->h.b_cnt == 0); + skein_assert(ctx->h.b_cnt == 0); } /* copy any remaining source message data bytes into b[] */ if (msg_byte_cnt) { - Skein_assert(msg_byte_cnt + ctx->h.b_cnt <= - SKEIN1024_BLOCK_BYTES); + skein_assert(msg_byte_cnt + ctx->h.b_cnt <= + SKEIN_1024_BLOCK_BYTES); memcpy(&ctx->b[ctx->h.b_cnt], msg, msg_byte_cnt); ctx->h.b_cnt += msg_byte_cnt; } @@ -650,16 +650,16 @@ int skein_1024_update(struct skein_1024_ctx *ctx, const u8 *msg, int skein_1024_final(struct skein_1024_ctx *ctx, u8 *hash_val) { size_t i, n, byte_cnt; - u64 X[SKEIN1024_STATE_WORDS]; + u64 X[SKEIN_1024_STATE_WORDS]; /* catch uninitialized context */ - Skein_Assert(ctx->h.b_cnt <= SKEIN1024_BLOCK_BYTES, SKEIN_FAIL); + skein_assert_ret(ctx->h.b_cnt <= SKEIN_1024_BLOCK_BYTES, SKEIN_FAIL); /* tag as the final block */ ctx->h.T[1] |= SKEIN_T1_FLAG_FINAL; /* zero pad b[] if necessary */ - if (ctx->h.b_cnt < SKEIN1024_BLOCK_BYTES) + if (ctx->h.b_cnt < SKEIN_1024_BLOCK_BYTES) memset(&ctx->b[ctx->h.b_cnt], 0, - SKEIN1024_BLOCK_BYTES - ctx->h.b_cnt); + SKEIN_1024_BLOCK_BYTES - ctx->h.b_cnt); /* process the final block */ skein_1024_process_block(ctx, ctx->b, 1, ctx->h.b_cnt); @@ -673,21 +673,21 @@ int skein_1024_final(struct skein_1024_ctx *ctx, u8 *hash_val) memset(ctx->b, 0, sizeof(ctx->b)); /* keep a local copy of counter mode "key" */ memcpy(X, ctx->X, sizeof(X)); - for (i = 0; i*SKEIN1024_BLOCK_BYTES < byte_cnt; i++) { + for (i = 0; i*SKEIN_1024_BLOCK_BYTES < byte_cnt; i++) { /* build the counter block */ - ((u64 *)ctx->b)[0] = Skein_Swap64((u64) i); - Skein_Start_New_Type(ctx, OUT_FINAL); + ((u64 *)ctx->b)[0] = skein_swap64((u64) i); + skein_start_new_type(ctx, OUT_FINAL); /* run "counter mode" */ skein_1024_process_block(ctx, ctx->b, 1, sizeof(u64)); /* number of output bytes left to go */ - n = byte_cnt - i*SKEIN1024_BLOCK_BYTES; - if (n >= SKEIN1024_BLOCK_BYTES) - n = SKEIN1024_BLOCK_BYTES; + n = byte_cnt - i*SKEIN_1024_BLOCK_BYTES; + if (n >= SKEIN_1024_BLOCK_BYTES) + n = SKEIN_1024_BLOCK_BYTES; /* "output" the ctr mode bytes */ - Skein_Put64_LSB_First(hash_val+i*SKEIN1024_BLOCK_BYTES, ctx->X, + skein_put64_lsb_first(hash_val+i*SKEIN_1024_BLOCK_BYTES, ctx->X, n); - Skein_Show_Final(1024, &ctx->h, n, - hash_val+i*SKEIN1024_BLOCK_BYTES); + skein_show_final(1024, &ctx->h, n, + hash_val+i*SKEIN_1024_BLOCK_BYTES); /* restore the counter mode key for next time */ memcpy(ctx->X, X, sizeof(X)); } @@ -702,7 +702,7 @@ int skein_1024_final(struct skein_1024_ctx *ctx, u8 *hash_val) int skein_256_final_pad(struct skein_256_ctx *ctx, u8 *hash_val) { /* catch uninitialized context */ - Skein_Assert(ctx->h.b_cnt <= SKEIN_256_BLOCK_BYTES, SKEIN_FAIL); + skein_assert_ret(ctx->h.b_cnt <= SKEIN_256_BLOCK_BYTES, SKEIN_FAIL); /* tag as the final block */ ctx->h.T[1] |= SKEIN_T1_FLAG_FINAL; @@ -714,7 +714,7 @@ int skein_256_final_pad(struct skein_256_ctx *ctx, u8 *hash_val) skein_256_process_block(ctx, ctx->b, 1, ctx->h.b_cnt); /* "output" the state bytes */ - Skein_Put64_LSB_First(hash_val, ctx->X, SKEIN_256_BLOCK_BYTES); + skein_put64_lsb_first(hash_val, ctx->X, SKEIN_256_BLOCK_BYTES); return SKEIN_SUCCESS; } @@ -724,7 +724,7 @@ 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) { /* catch uninitialized context */ - Skein_Assert(ctx->h.b_cnt <= SKEIN_512_BLOCK_BYTES, SKEIN_FAIL); + skein_assert_ret(ctx->h.b_cnt <= SKEIN_512_BLOCK_BYTES, SKEIN_FAIL); /* tag as the final block */ ctx->h.T[1] |= SKEIN_T1_FLAG_FINAL; @@ -736,7 +736,7 @@ int skein_512_final_pad(struct skein_512_ctx *ctx, u8 *hash_val) skein_512_process_block(ctx, ctx->b, 1, ctx->h.b_cnt); /* "output" the state bytes */ - Skein_Put64_LSB_First(hash_val, ctx->X, SKEIN_512_BLOCK_BYTES); + skein_put64_lsb_first(hash_val, ctx->X, SKEIN_512_BLOCK_BYTES); return SKEIN_SUCCESS; } @@ -746,19 +746,19 @@ int skein_512_final_pad(struct skein_512_ctx *ctx, u8 *hash_val) int skein_1024_final_pad(struct skein_1024_ctx *ctx, u8 *hash_val) { /* catch uninitialized context */ - Skein_Assert(ctx->h.b_cnt <= SKEIN1024_BLOCK_BYTES, SKEIN_FAIL); + skein_assert_ret(ctx->h.b_cnt <= SKEIN_1024_BLOCK_BYTES, SKEIN_FAIL); /* tag as the final block */ ctx->h.T[1] |= SKEIN_T1_FLAG_FINAL; /* zero pad b[] if necessary */ - if (ctx->h.b_cnt < SKEIN1024_BLOCK_BYTES) + if (ctx->h.b_cnt < SKEIN_1024_BLOCK_BYTES) memset(&ctx->b[ctx->h.b_cnt], 0, - SKEIN1024_BLOCK_BYTES - ctx->h.b_cnt); + SKEIN_1024_BLOCK_BYTES - ctx->h.b_cnt); /* process the final block */ skein_1024_process_block(ctx, ctx->b, 1, ctx->h.b_cnt); /* "output" the state bytes */ - Skein_Put64_LSB_First(hash_val, ctx->X, SKEIN1024_BLOCK_BYTES); + skein_put64_lsb_first(hash_val, ctx->X, SKEIN_1024_BLOCK_BYTES); return SKEIN_SUCCESS; } @@ -771,7 +771,7 @@ int skein_256_output(struct skein_256_ctx *ctx, u8 *hash_val) size_t i, n, byte_cnt; u64 X[SKEIN_256_STATE_WORDS]; /* catch uninitialized context */ - Skein_Assert(ctx->h.b_cnt <= SKEIN_256_BLOCK_BYTES, SKEIN_FAIL); + skein_assert_ret(ctx->h.b_cnt <= SKEIN_256_BLOCK_BYTES, SKEIN_FAIL); /* now output the result */ /* total number of output bytes */ @@ -784,8 +784,8 @@ int skein_256_output(struct skein_256_ctx *ctx, u8 *hash_val) memcpy(X, ctx->X, sizeof(X)); for (i = 0; i*SKEIN_256_BLOCK_BYTES < byte_cnt; i++) { /* build the counter block */ - ((u64 *)ctx->b)[0] = Skein_Swap64((u64) i); - Skein_Start_New_Type(ctx, OUT_FINAL); + ((u64 *)ctx->b)[0] = skein_swap64((u64) i); + skein_start_new_type(ctx, OUT_FINAL); /* run "counter mode" */ skein_256_process_block(ctx, ctx->b, 1, sizeof(u64)); /* number of output bytes left to go */ @@ -793,9 +793,9 @@ int skein_256_output(struct skein_256_ctx *ctx, u8 *hash_val) if (n >= SKEIN_256_BLOCK_BYTES) n = SKEIN_256_BLOCK_BYTES; /* "output" the ctr mode bytes */ - Skein_Put64_LSB_First(hash_val+i*SKEIN_256_BLOCK_BYTES, ctx->X, + skein_put64_lsb_first(hash_val+i*SKEIN_256_BLOCK_BYTES, ctx->X, n); - Skein_Show_Final(256, &ctx->h, n, + skein_show_final(256, &ctx->h, n, hash_val+i*SKEIN_256_BLOCK_BYTES); /* restore the counter mode key for next time */ memcpy(ctx->X, X, sizeof(X)); @@ -810,7 +810,7 @@ int skein_512_output(struct skein_512_ctx *ctx, u8 *hash_val) size_t i, n, byte_cnt; u64 X[SKEIN_512_STATE_WORDS]; /* catch uninitialized context */ - Skein_Assert(ctx-&g |