1 2#ifndef THREEFISHAPI_H 3#define THREEFISHAPI_H 4 5/** 6 * @file threefish_api.h 7 * @brief A Threefish cipher API and its functions. 8 * @{ 9 * 10 * This API and the functions that implement this API simplify the usage 11 * of the Threefish cipher. The design and the way to use the functions 12 * follow the openSSL design but at the same time take care of some Threefish 13 * specific behaviour and possibilities. 14 * 15 * These are the low level functions that deal with Threefish blocks only. 16 * Implementations for cipher modes such as ECB, CFB, or CBC may use these 17 * functions. 18 * 19@code 20 // Threefish cipher context data 21 struct threefish_key key_ctx; 22 23 // Initialize the context 24 threefish_set_key(&key_ctx, THREEFISH_512, key, tweak); 25 26 // Encrypt 27 threefish_encrypt_block_bytes(&key_ctx, input, cipher); 28@endcode 29 */ 30 31#include <linux/types.h> 32#include "skein_base.h" 33 34#define KEY_SCHEDULE_CONST 0x1BD11BDAA9FC1A22L 35 36/** 37 * Which Threefish size to use 38 */ 39enum threefish_size { 40 THREEFISH_256 = 256, /*!< Skein with 256 bit state */ 41 THREEFISH_512 = 512, /*!< Skein with 512 bit state */ 42 THREEFISH_1024 = 1024 /*!< Skein with 1024 bit state */ 43}; 44 45/** 46 * Context for Threefish key and tweak words. 47 * 48 * This structure was setup with some know-how of the internal 49 * Skein structures, in particular ordering of header and size dependent 50 * variables. If Skein implementation changes this, the adapt these 51 * structures as well. 52 */ 53struct threefish_key { 54 u64 state_size; 55 u64 key[SKEIN_MAX_STATE_WORDS+1]; /* max number of key words*/ 56 u64 tweak[3]; 57}; 58 59/** 60 * Set Threefish key and tweak data. 61 * 62 * This function sets the key and tweak data for the Threefish cipher of 63 * the given size. The key data must have the same length (number of bits) 64 * as the state size 65 * 66 * @param key_ctx 67 * Pointer to a Threefish key structure. 68 * @param size 69 * Which Skein size to use. 70 * @param key_data 71 * Pointer to the key words (word has 64 bits). 72 * @param tweak 73 * Pointer to the two tweak words (word has 64 bits). 74 */ 75void threefish_set_key(struct threefish_key *key_ctx, 76 enum threefish_size state_size, 77 u64 *key_data, u64 *tweak); 78 79/** 80 * Encrypt Threefish block (bytes). 81 * 82 * The buffer must have at least the same length (number of bits) as the 83 * state size for this key. The function uses the first @c state_size bits 84 * of the input buffer, encrypts them and stores the result in the output 85 * buffer. 86 * 87 * @param key_ctx 88 * Pointer to a Threefish key structure. 89 * @param in 90 * Poionter to plaintext data buffer. 91 * @param out 92 * Pointer to cipher buffer. 93 */ 94void threefish_encrypt_block_bytes(struct threefish_key *key_ctx, u8 *in, 95 u8 *out); 96 97/** 98 * Encrypt Threefish block (words). 99 * 100 * The buffer must have at least the same length (number of bits) as the 101 * state size for this key. The function uses the first @c state_size bits 102 * of the input buffer, encrypts them and stores the result in the output 103 * buffer. 104 * 105 * The wordsize ist set to 64 bits. 106 * 107 * @param key_ctx 108 * Pointer to a Threefish key structure. 109 * @param in 110 * Poionter to plaintext data buffer. 111 * @param out 112 * Pointer to cipher buffer. 113 */ 114void threefish_encrypt_block_words(struct threefish_key *key_ctx, u64 *in, 115 u64 *out); 116 117/** 118 * Decrypt Threefish block (bytes). 119 * 120 * The buffer must have at least the same length (number of bits) as the 121 * state size for this key. The function uses the first @c state_size bits 122 * of the input buffer, decrypts them and stores the result in the output 123 * buffer 124 * 125 * @param key_ctx 126 * Pointer to a Threefish key structure. 127 * @param in 128 * Poionter to cipher data buffer. 129 * @param out 130 * Pointer to plaintext buffer. 131 */ 132void threefish_decrypt_block_bytes(struct threefish_key *key_ctx, u8 *in, 133 u8 *out); 134 135/** 136 * Decrypt Threefish block (words). 137 * 138 * The buffer must have at least the same length (number of bits) as the 139 * state size for this key. The function uses the first @c state_size bits 140 * of the input buffer, encrypts them and stores the result in the output 141 * buffer. 142 * 143 * The wordsize ist set to 64 bits. 144 * 145 * @param key_ctx 146 * Pointer to a Threefish key structure. 147 * @param in 148 * Poionter to cipher data buffer. 149 * @param out 150 * Pointer to plaintext buffer. 151 */ 152void threefish_decrypt_block_words(struct threefish_key *key_ctx, u64 *in, 153 u64 *out); 154 155void threefish_encrypt_256(struct threefish_key *key_ctx, u64 *input, 156 u64 *output); 157void threefish_encrypt_512(struct threefish_key *key_ctx, u64 *input, 158 u64 *output); 159void threefish_encrypt_1024(struct threefish_key *key_ctx, u64 *input, 160 u64 *output); 161void threefish_decrypt_256(struct threefish_key *key_ctx, u64 *input, 162 u64 *output); 163void threefish_decrypt_512(struct threefish_key *key_ctx, u64 *input, 164 u64 *output); 165void threefish_decrypt_1024(struct threefish_key *key_ctx, u64 *input, 166 u64 *output); 167/** 168 * @} 169 */ 170#endif 171