3 #include <linux/string.h>
4 #include <threefishApi.h>
6 void threefish_set_key(struct threefish_key *key_ctx,
7 enum threefish_size state_size,
8 u64 *key_data, u64 *tweak)
10 int key_words = state_size / 64;
12 u64 parity = KEY_SCHEDULE_CONST;
14 key_ctx->tweak[0] = tweak[0];
15 key_ctx->tweak[1] = tweak[1];
16 key_ctx->tweak[2] = tweak[0] ^ tweak[1];
18 for (i = 0; i < key_words; i++) {
19 key_ctx->key[i] = key_data[i];
20 parity ^= key_data[i];
22 key_ctx->key[i] = parity;
23 key_ctx->state_size = state_size;
26 void threefish_encrypt_block_bytes(struct threefish_key *key_ctx, u8 *in,
29 u64 plain[SKEIN_MAX_STATE_WORDS]; /* max number of words*/
30 u64 cipher[SKEIN_MAX_STATE_WORDS];
32 skein_get64_lsb_first(plain, in, key_ctx->state_size / 64);
33 threefish_encrypt_block_words(key_ctx, plain, cipher);
34 skein_put64_lsb_first(out, cipher, key_ctx->state_size / 8);
37 void threefish_encrypt_block_words(struct threefish_key *key_ctx, u64 *in,
40 switch (key_ctx->state_size) {
42 threefish_encrypt_256(key_ctx, in, out);
45 threefish_encrypt_512(key_ctx, in, out);
48 threefish_encrypt_1024(key_ctx, in, out);
53 void threefish_decrypt_block_bytes(struct threefish_key *key_ctx, u8 *in,
56 u64 plain[SKEIN_MAX_STATE_WORDS]; /* max number of words*/
57 u64 cipher[SKEIN_MAX_STATE_WORDS];
59 skein_get64_lsb_first(cipher, in, key_ctx->state_size / 64);
60 threefish_decrypt_block_words(key_ctx, cipher, plain);
61 skein_put64_lsb_first(out, plain, key_ctx->state_size / 8);
64 void threefish_decrypt_block_words(struct threefish_key *key_ctx, u64 *in,
67 switch (key_ctx->state_size) {
69 threefish_decrypt_256(key_ctx, in, out);
72 threefish_decrypt_512(key_ctx, in, out);
75 threefish_decrypt_1024(key_ctx, in, out);