int skein_init(struct skein_ctx *ctx, size_t hash_bit_len) { int ret = SKEIN_FAIL; size_t x_len = 0; u64 *x = NULL; u64 tree_info = SKEIN_CFG_TREE_INFO_SEQUENTIAL; 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 * memory available. The beauty of C :-) . */ x = ctx->m.s256.x; x_len = ctx->skein_size / 8; /* * If size is the same and hash bit length is zero then reuse * the save chaining variables. */ switch (ctx->skein_size) { case SKEIN_256: ret = skein_256_init_ext(&ctx->m.s256, hash_bit_len, tree_info, NULL, 0); break; case SKEIN_512: ret = skein_512_init_ext(&ctx->m.s512, hash_bit_len, tree_info, NULL, 0); break; case SKEIN_1024: ret = skein_1024_init_ext(&ctx->m.s1024, hash_bit_len, tree_info, NULL, 0); break; } if (ret == SKEIN_SUCCESS) { /* * Save chaining variables for this combination of size and * hash_bit_len */ memcpy(ctx->x_save, x, x_len); } return ret; }
int skein_mac_init(struct skein_ctx *ctx, const u8 *key, size_t key_len, size_t hash_bit_len) { int ret = SKEIN_FAIL; u64 *x = NULL; size_t x_len = 0; u64 tree_info = SKEIN_CFG_TREE_INFO_SEQUENTIAL; skein_assert_ret(ctx, SKEIN_FAIL); x = ctx->m.s256.x; x_len = ctx->skein_size/8; skein_assert_ret(hash_bit_len, SKEIN_BAD_HASHLEN); switch (ctx->skein_size) { case SKEIN_256: ret = skein_256_init_ext(&ctx->m.s256, hash_bit_len, tree_info, (const u8 *)key, key_len); break; case SKEIN_512: ret = skein_512_init_ext(&ctx->m.s512, hash_bit_len, tree_info, (const u8 *)key, key_len); break; case SKEIN_1024: ret = skein_1024_init_ext(&ctx->m.s1024, hash_bit_len, tree_info, (const u8 *)key, key_len); break; } if (ret == SKEIN_SUCCESS) { /* * Save chaining variables for this combination of key, * key_len, hash_bit_len */ memcpy(ctx->x_save, x, x_len); } return ret; }