Merge 3.15-rc2 into staging-next
[firefly-linux-kernel-4.4.55.git] / drivers / staging / skein / include / threefishApi.h
1
2 #ifndef THREEFISHAPI_H
3 #define THREEFISHAPI_H
4
5 /**
6  * @file threefishApi.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 Threefisch 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 keyCtx;
22
23     // Initialize the context
24     threefishSetKey(&keyCtx, Threefish512, key, tweak);
25
26     // Encrypt
27     threefishEncryptBlockBytes(&keyCtx, input, cipher);
28 @endcode
29  */
30
31 #include <linux/types.h>
32 #include <skein.h>
33
34 #define KeyScheduleConst 0x1BD11BDAA9FC1A22L
35
36 /**
37  * Which Threefish size to use
38  */
39 enum threefish_size {
40         Threefish256 = 256,     /*!< Skein with 256 bit state */
41         Threefish512 = 512,     /*!< Skein with 512 bit state */
42         Threefish1024 = 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  */
53 struct threefish_key {
54         u64 stateSize;
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 keyCtx
67  *     Pointer to a Threefish key structure.
68  * @param size
69  *     Which Skein size to use.
70  * @param keyData
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  */
75 void threefishSetKey(struct threefish_key *keyCtx,
76                         enum threefish_size stateSize,
77                         u64 *keyData, u64 *tweak);
78
79 /**
80  * Encrypt Threefisch block (bytes).
81  *
82  * The buffer must have at least the same length (number of bits) aas the
83  * state size for this key. The function uses the first @c stateSize bits
84  * of the input buffer, encrypts them and stores the result in the output
85  * buffer.
86  *
87  * @param keyCtx
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  */
94 void threefishEncryptBlockBytes(struct threefish_key *keyCtx, u8 *in, u8 *out);
95
96 /**
97  * Encrypt Threefisch block (words).
98  *
99  * The buffer must have at least the same length (number of bits) aas the
100  * state size for this key. The function uses the first @c stateSize bits
101  * of the input buffer, encrypts them and stores the result in the output
102  * buffer.
103  *
104  * The wordsize ist set to 64 bits.
105  *
106  * @param keyCtx
107  *     Pointer to a Threefish key structure.
108  * @param in
109  *     Poionter to plaintext data buffer.
110  * @param out
111  *     Pointer to cipher buffer.
112  */
113 void threefishEncryptBlockWords(struct threefish_key *keyCtx, u64 *in,
114                                 u64 *out);
115
116 /**
117  * Decrypt Threefisch block (bytes).
118  *
119  * The buffer must have at least the same length (number of bits) aas the
120  * state size for this key. The function uses the first @c stateSize bits
121  * of the input buffer, decrypts them and stores the result in the output
122  * buffer
123  *
124  * @param keyCtx
125  *     Pointer to a Threefish key structure.
126  * @param in
127  *     Poionter to cipher data buffer.
128  * @param out
129  *     Pointer to plaintext buffer.
130  */
131 void threefishDecryptBlockBytes(struct threefish_key *keyCtx, u8 *in, u8 *out);
132
133 /**
134  * Decrypt Threefisch block (words).
135  *
136  * The buffer must have at least the same length (number of bits) aas the
137  * state size for this key. The function uses the first @c stateSize bits
138  * of the input buffer, encrypts them and stores the result in the output
139  * buffer.
140  *
141  * The wordsize ist set to 64 bits.
142  *
143  * @param keyCtx
144  *     Pointer to a Threefish key structure.
145  * @param in
146  *     Poionter to cipher data buffer.
147  * @param out
148  *     Pointer to plaintext buffer.
149  */
150 void threefishDecryptBlockWords(struct threefish_key *keyCtx, u64 *in,
151                                 u64 *out);
152
153 void threefishEncrypt256(struct threefish_key *keyCtx, u64 *input, u64 *output);
154 void threefishEncrypt512(struct threefish_key *keyCtx, u64 *input, u64 *output);
155 void threefishEncrypt1024(struct threefish_key *keyCtx, u64 *input,
156                         u64 *output);
157 void threefishDecrypt256(struct threefish_key *keyCtx, u64 *input, u64 *output);
158 void threefishDecrypt512(struct threefish_key *keyCtx, u64 *input, u64 *output);
159 void threefishDecrypt1024(struct threefish_key *keyCtx, u64 *input,
160                         u64 *output);
161 /**
162  * @}
163  */
164 #endif