1 #include <linux/string.h>
2 #include "threefish_api.h"
4 void threefish_set_key(struct threefish_key *key_ctx,
5 enum threefish_size state_size,
6 u64 *key_data, u64 *tweak)
8 int key_words = state_size / 64;
10 u64 parity = KEY_SCHEDULE_CONST;
12 key_ctx->tweak[0] = tweak[0];
13 key_ctx->tweak[1] = tweak[1];
14 key_ctx->tweak[2] = tweak[0] ^ tweak[1];
16 for (i = 0; i < key_words; i++) {
17 key_ctx->key[i] = key_data[i];
18 parity ^= key_data[i];
20 key_ctx->key[i] = parity;
21 key_ctx->state_size = state_size;
24 void threefish_encrypt_block_bytes(struct threefish_key *key_ctx, u8 *in,
27 u64 plain[SKEIN_MAX_STATE_WORDS]; /* max number of words*/
28 u64 cipher[SKEIN_MAX_STATE_WORDS];
30 skein_get64_lsb_first(plain, in, key_ctx->state_size / 64);
31 threefish_encrypt_block_words(key_ctx, plain, cipher);
32 skein_put64_lsb_first(out, cipher, key_ctx->state_size / 8);
35 void threefish_encrypt_block_words(struct threefish_key *key_ctx, u64 *in,
38 switch (key_ctx->state_size) {
40 threefish_encrypt_256(key_ctx, in, out);
43 threefish_encrypt_512(key_ctx, in, out);
46 threefish_encrypt_1024(key_ctx, in, out);
51 void threefish_decrypt_block_bytes(struct threefish_key *key_ctx, u8 *in,
54 u64 plain[SKEIN_MAX_STATE_WORDS]; /* max number of words*/
55 u64 cipher[SKEIN_MAX_STATE_WORDS];
57 skein_get64_lsb_first(cipher, in, key_ctx->state_size / 64);
58 threefish_decrypt_block_words(key_ctx, cipher, plain);
59 skein_put64_lsb_first(out, plain, key_ctx->state_size / 8);
62 void threefish_decrypt_block_words(struct threefish_key *key_ctx, u64 *in,
65 switch (key_ctx->state_size) {
67 threefish_decrypt_256(key_ctx, in, out);
70 threefish_decrypt_512(key_ctx, in, out);
73 threefish_decrypt_1024(key_ctx, in, out);