1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/string.h>
3 #include "threefish_api.h"
5 void threefish_set_key(struct threefish_key *key_ctx,
6 enum threefish_size state_size,
7 u64 *key_data, u64 *tweak)
9 int key_words = state_size / 64;
11 u64 parity = KEY_SCHEDULE_CONST;
13 key_ctx->tweak[0] = tweak[0];
14 key_ctx->tweak[1] = tweak[1];
15 key_ctx->tweak[2] = tweak[0] ^ tweak[1];
17 for (i = 0; i < key_words; i++) {
18 key_ctx->key[i] = key_data[i];
19 parity ^= key_data[i];
21 key_ctx->key[i] = parity;
22 key_ctx->state_size = state_size;
25 void threefish_encrypt_block_bytes(struct threefish_key *key_ctx, u8 *in,
28 u64 plain[SKEIN_MAX_STATE_WORDS]; /* max number of words*/
29 u64 cipher[SKEIN_MAX_STATE_WORDS];
31 skein_get64_lsb_first(plain, in, key_ctx->state_size / 64);
32 threefish_encrypt_block_words(key_ctx, plain, cipher);
33 skein_put64_lsb_first(out, cipher, key_ctx->state_size / 8);
36 void threefish_encrypt_block_words(struct threefish_key *key_ctx, u64 *in,
39 switch (key_ctx->state_size) {
41 threefish_encrypt_256(key_ctx, in, out);
44 threefish_encrypt_512(key_ctx, in, out);
47 threefish_encrypt_1024(key_ctx, in, out);
52 void threefish_decrypt_block_bytes(struct threefish_key *key_ctx, u8 *in,
55 u64 plain[SKEIN_MAX_STATE_WORDS]; /* max number of words*/
56 u64 cipher[SKEIN_MAX_STATE_WORDS];
58 skein_get64_lsb_first(cipher, in, key_ctx->state_size / 64);
59 threefish_decrypt_block_words(key_ctx, cipher, plain);
60 skein_put64_lsb_first(out, plain, key_ctx->state_size / 8);
63 void threefish_decrypt_block_words(struct threefish_key *key_ctx, u64 *in,
66 switch (key_ctx->state_size) {
68 threefish_decrypt_256(key_ctx, in, out);
71 threefish_decrypt_512(key_ctx, in, out);
74 threefish_decrypt_1024(key_ctx, in, out);