1 /* SPDX-License-Identifier: GPL-2.0 */
7 * @file threefish_api.h
8 * @brief A Threefish cipher API and its functions.
11 * This API and the functions that implement this API simplify the usage
12 * of the Threefish cipher. The design and the way to use the functions
13 * follow the openSSL design but at the same time take care of some Threefish
14 * specific behaviour and possibilities.
16 * These are the low level functions that deal with Threefish blocks only.
17 * Implementations for cipher modes such as ECB, CFB, or CBC may use these
21 // Threefish cipher context data
22 struct threefish_key key_ctx;
24 // Initialize the context
25 threefish_set_key(&key_ctx, THREEFISH_512, key, tweak);
28 threefish_encrypt_block_bytes(&key_ctx, input, cipher);
32 #include <linux/types.h>
33 #include "skein_base.h"
35 #define KEY_SCHEDULE_CONST 0x1BD11BDAA9FC1A22L
38 * Which Threefish size to use
41 THREEFISH_256 = 256, /*!< Skein with 256 bit state */
42 THREEFISH_512 = 512, /*!< Skein with 512 bit state */
43 THREEFISH_1024 = 1024 /*!< Skein with 1024 bit state */
47 * Context for Threefish key and tweak words.
49 * This structure was setup with some know-how of the internal
50 * Skein structures, in particular ordering of header and size dependent
51 * variables. If Skein implementation changes this, the adapt these
54 struct threefish_key {
56 u64 key[SKEIN_MAX_STATE_WORDS + 1]; /* max number of key words*/
61 * Set Threefish key and tweak data.
63 * This function sets the key and tweak data for the Threefish cipher of
64 * the given size. The key data must have the same length (number of bits)
68 * Pointer to a Threefish key structure.
70 * Which Skein size to use.
72 * Pointer to the key words (word has 64 bits).
74 * Pointer to the two tweak words (word has 64 bits).
76 void threefish_set_key(struct threefish_key *key_ctx,
77 enum threefish_size state_size,
78 u64 *key_data, u64 *tweak);
81 * Encrypt Threefish block (bytes).
83 * The buffer must have at least the same length (number of bits) as the
84 * state size for this key. The function uses the first @c state_size bits
85 * of the input buffer, encrypts them and stores the result in the output
89 * Pointer to a Threefish key structure.
91 * Poionter to plaintext data buffer.
93 * Pointer to cipher buffer.
95 void threefish_encrypt_block_bytes(struct threefish_key *key_ctx, u8 *in,
99 * Encrypt Threefish block (words).
101 * The buffer must have at least the same length (number of bits) as the
102 * state size for this key. The function uses the first @c state_size bits
103 * of the input buffer, encrypts them and stores the result in the output
106 * The wordsize ist set to 64 bits.
109 * Pointer to a Threefish key structure.
111 * Poionter to plaintext data buffer.
113 * Pointer to cipher buffer.
115 void threefish_encrypt_block_words(struct threefish_key *key_ctx, u64 *in,
119 * Decrypt Threefish block (bytes).
121 * The buffer must have at least the same length (number of bits) as the
122 * state size for this key. The function uses the first @c state_size bits
123 * of the input buffer, decrypts them and stores the result in the output
127 * Pointer to a Threefish key structure.
129 * Poionter to cipher data buffer.
131 * Pointer to plaintext buffer.
133 void threefish_decrypt_block_bytes(struct threefish_key *key_ctx, u8 *in,
137 * Decrypt Threefish block (words).
139 * The buffer must have at least the same length (number of bits) as the
140 * state size for this key. The function uses the first @c state_size bits
141 * of the input buffer, encrypts them and stores the result in the output
144 * The wordsize ist set to 64 bits.
147 * Pointer to a Threefish key structure.
149 * Poionter to cipher data buffer.
151 * Pointer to plaintext buffer.
153 void threefish_decrypt_block_words(struct threefish_key *key_ctx, u64 *in,
156 void threefish_encrypt_256(struct threefish_key *key_ctx, u64 *input,
158 void threefish_encrypt_512(struct threefish_key *key_ctx, u64 *input,
160 void threefish_encrypt_1024(struct threefish_key *key_ctx, u64 *input,
162 void threefish_decrypt_256(struct threefish_key *key_ctx, u64 *input,
164 void threefish_decrypt_512(struct threefish_key *key_ctx, u64 *input,
166 void threefish_decrypt_1024(struct threefish_key *key_ctx, u64 *input,