diff options
Diffstat (limited to 'include/crypto')
-rw-r--r-- | include/crypto/aead.h | 4 | ||||
-rw-r--r-- | include/crypto/algapi.h | 6 | ||||
-rw-r--r-- | include/crypto/des.h | 3 | ||||
-rw-r--r-- | include/crypto/drbg.h | 290 | ||||
-rw-r--r-- | include/crypto/hash.h | 4 | ||||
-rw-r--r-- | include/crypto/internal/skcipher.h | 3 | ||||
-rw-r--r-- | include/crypto/scatterwalk.h | 6 | ||||
-rw-r--r-- | include/crypto/skcipher.h | 4 |
8 files changed, 306 insertions, 14 deletions
diff --git a/include/crypto/aead.h b/include/crypto/aead.h index 0edf949f6369..94b19be67574 100644 --- a/include/crypto/aead.h +++ b/include/crypto/aead.h | |||
@@ -75,9 +75,9 @@ static inline void aead_givcrypt_free(struct aead_givcrypt_request *req) | |||
75 | 75 | ||
76 | static inline void aead_givcrypt_set_callback( | 76 | static inline void aead_givcrypt_set_callback( |
77 | struct aead_givcrypt_request *req, u32 flags, | 77 | struct aead_givcrypt_request *req, u32 flags, |
78 | crypto_completion_t complete, void *data) | 78 | crypto_completion_t compl, void *data) |
79 | { | 79 | { |
80 | aead_request_set_callback(&req->areq, flags, complete, data); | 80 | aead_request_set_callback(&req->areq, flags, compl, data); |
81 | } | 81 | } |
82 | 82 | ||
83 | static inline void aead_givcrypt_set_crypt(struct aead_givcrypt_request *req, | 83 | static inline void aead_givcrypt_set_crypt(struct aead_givcrypt_request *req, |
diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index 016c2f110f63..623a59c1ff5a 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h | |||
@@ -410,4 +410,10 @@ static inline int crypto_memneq(const void *a, const void *b, size_t size) | |||
410 | return __crypto_memneq(a, b, size) != 0UL ? 1 : 0; | 410 | return __crypto_memneq(a, b, size) != 0UL ? 1 : 0; |
411 | } | 411 | } |
412 | 412 | ||
413 | static inline void crypto_yield(u32 flags) | ||
414 | { | ||
415 | if (flags & CRYPTO_TFM_REQ_MAY_SLEEP) | ||
416 | cond_resched(); | ||
417 | } | ||
418 | |||
413 | #endif /* _CRYPTO_ALGAPI_H */ | 419 | #endif /* _CRYPTO_ALGAPI_H */ |
diff --git a/include/crypto/des.h b/include/crypto/des.h index 2971c6304ade..fc6274c6bb26 100644 --- a/include/crypto/des.h +++ b/include/crypto/des.h | |||
@@ -16,4 +16,7 @@ | |||
16 | 16 | ||
17 | extern unsigned long des_ekey(u32 *pe, const u8 *k); | 17 | extern unsigned long des_ekey(u32 *pe, const u8 *k); |
18 | 18 | ||
19 | extern int __des3_ede_setkey(u32 *expkey, u32 *flags, const u8 *key, | ||
20 | unsigned int keylen); | ||
21 | |||
19 | #endif /* __CRYPTO_DES_H */ | 22 | #endif /* __CRYPTO_DES_H */ |
diff --git a/include/crypto/drbg.h b/include/crypto/drbg.h new file mode 100644 index 000000000000..831d786976c5 --- /dev/null +++ b/include/crypto/drbg.h | |||
@@ -0,0 +1,290 @@ | |||
1 | /* | ||
2 | * DRBG based on NIST SP800-90A | ||
3 | * | ||
4 | * Copyright Stephan Mueller <smueller@chronox.de>, 2014 | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, and the entire permission notice in its entirety, | ||
11 | * including the disclaimer of warranties. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. The name of the author may not be used to endorse or promote | ||
16 | * products derived from this software without specific prior | ||
17 | * written permission. | ||
18 | * | ||
19 | * ALTERNATIVELY, this product may be distributed under the terms of | ||
20 | * the GNU General Public License, in which case the provisions of the GPL are | ||
21 | * required INSTEAD OF the above restrictions. (This clause is | ||
22 | * necessary due to a potential bad interaction between the GPL and | ||
23 | * the restrictions contained in a BSD-style copyright.) | ||
24 | * | ||
25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED | ||
26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
27 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF | ||
28 | * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE | ||
29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT | ||
31 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | ||
32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
35 | * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH | ||
36 | * DAMAGE. | ||
37 | */ | ||
38 | |||
39 | #ifndef _DRBG_H | ||
40 | #define _DRBG_H | ||
41 | |||
42 | |||
43 | #include <linux/random.h> | ||
44 | #include <linux/scatterlist.h> | ||
45 | #include <crypto/hash.h> | ||
46 | #include <linux/module.h> | ||
47 | #include <linux/crypto.h> | ||
48 | #include <linux/slab.h> | ||
49 | #include <crypto/internal/rng.h> | ||
50 | #include <crypto/rng.h> | ||
51 | #include <linux/fips.h> | ||
52 | #include <linux/spinlock.h> | ||
53 | #include <linux/list.h> | ||
54 | |||
55 | /* | ||
56 | * Concatenation Helper and string operation helper | ||
57 | * | ||
58 | * SP800-90A requires the concatenation of different data. To avoid copying | ||
59 | * buffers around or allocate additional memory, the following data structure | ||
60 | * is used to point to the original memory with its size. In addition, it | ||
61 | * is used to build a linked list. The linked list defines the concatenation | ||
62 | * of individual buffers. The order of memory block referenced in that | ||
63 | * linked list determines the order of concatenation. | ||
64 | */ | ||
65 | struct drbg_string { | ||
66 | const unsigned char *buf; | ||
67 | size_t len; | ||
68 | struct list_head list; | ||
69 | }; | ||
70 | |||
71 | static inline void drbg_string_fill(struct drbg_string *string, | ||
72 | const unsigned char *buf, size_t len) | ||
73 | { | ||
74 | string->buf = buf; | ||
75 | string->len = len; | ||
76 | INIT_LIST_HEAD(&string->list); | ||
77 | } | ||
78 | |||
79 | struct drbg_state; | ||
80 | typedef uint32_t drbg_flag_t; | ||
81 | |||
82 | struct drbg_core { | ||
83 | drbg_flag_t flags; /* flags for the cipher */ | ||
84 | __u8 statelen; /* maximum state length */ | ||
85 | /* | ||
86 | * maximum length of personalization string or additional input | ||
87 | * string -- exponent for base 2 | ||
88 | */ | ||
89 | __u8 max_addtllen; | ||
90 | /* maximum bits per RNG request -- exponent for base 2*/ | ||
91 | __u8 max_bits; | ||
92 | /* maximum number of requests -- exponent for base 2 */ | ||
93 | __u8 max_req; | ||
94 | __u8 blocklen_bytes; /* block size of output in bytes */ | ||
95 | char cra_name[CRYPTO_MAX_ALG_NAME]; /* mapping to kernel crypto API */ | ||
96 | /* kernel crypto API backend cipher name */ | ||
97 | char backend_cra_name[CRYPTO_MAX_ALG_NAME]; | ||
98 | }; | ||
99 | |||
100 | struct drbg_state_ops { | ||
101 | int (*update)(struct drbg_state *drbg, struct list_head *seed, | ||
102 | int reseed); | ||
103 | int (*generate)(struct drbg_state *drbg, | ||
104 | unsigned char *buf, unsigned int buflen, | ||
105 | struct list_head *addtl); | ||
106 | int (*crypto_init)(struct drbg_state *drbg); | ||
107 | int (*crypto_fini)(struct drbg_state *drbg); | ||
108 | |||
109 | }; | ||
110 | |||
111 | struct drbg_test_data { | ||
112 | struct drbg_string *testentropy; /* TEST PARAMETER: test entropy */ | ||
113 | }; | ||
114 | |||
115 | struct drbg_state { | ||
116 | spinlock_t drbg_lock; /* lock around DRBG */ | ||
117 | unsigned char *V; /* internal state 10.1.1.1 1a) */ | ||
118 | /* hash: static value 10.1.1.1 1b) hmac / ctr: key */ | ||
119 | unsigned char *C; | ||
120 | /* Number of RNG requests since last reseed -- 10.1.1.1 1c) */ | ||
121 | size_t reseed_ctr; | ||
122 | /* some memory the DRBG can use for its operation */ | ||
123 | unsigned char *scratchpad; | ||
124 | void *priv_data; /* Cipher handle */ | ||
125 | bool seeded; /* DRBG fully seeded? */ | ||
126 | bool pr; /* Prediction resistance enabled? */ | ||
127 | #ifdef CONFIG_CRYPTO_FIPS | ||
128 | bool fips_primed; /* Continuous test primed? */ | ||
129 | unsigned char *prev; /* FIPS 140-2 continuous test value */ | ||
130 | #endif | ||
131 | const struct drbg_state_ops *d_ops; | ||
132 | const struct drbg_core *core; | ||
133 | struct drbg_test_data *test_data; | ||
134 | }; | ||
135 | |||
136 | static inline __u8 drbg_statelen(struct drbg_state *drbg) | ||
137 | { | ||
138 | if (drbg && drbg->core) | ||
139 | return drbg->core->statelen; | ||
140 | return 0; | ||
141 | } | ||
142 | |||
143 | static inline __u8 drbg_blocklen(struct drbg_state *drbg) | ||
144 | { | ||
145 | if (drbg && drbg->core) | ||
146 | return drbg->core->blocklen_bytes; | ||
147 | return 0; | ||
148 | } | ||
149 | |||
150 | static inline __u8 drbg_keylen(struct drbg_state *drbg) | ||
151 | { | ||
152 | if (drbg && drbg->core) | ||
153 | return (drbg->core->statelen - drbg->core->blocklen_bytes); | ||
154 | return 0; | ||
155 | } | ||
156 | |||
157 | static inline size_t drbg_max_request_bytes(struct drbg_state *drbg) | ||
158 | { | ||
159 | /* max_bits is in bits, but buflen is in bytes */ | ||
160 | return (1 << (drbg->core->max_bits - 3)); | ||
161 | } | ||
162 | |||
163 | static inline size_t drbg_max_addtl(struct drbg_state *drbg) | ||
164 | { | ||
165 | return (1UL<<(drbg->core->max_addtllen)); | ||
166 | } | ||
167 | |||
168 | static inline size_t drbg_max_requests(struct drbg_state *drbg) | ||
169 | { | ||
170 | return (1UL<<(drbg->core->max_req)); | ||
171 | } | ||
172 | |||
173 | /* | ||
174 | * kernel crypto API input data structure for DRBG generate in case dlen | ||
175 | * is set to 0 | ||
176 | */ | ||
177 | struct drbg_gen { | ||
178 | unsigned char *outbuf; /* output buffer for random numbers */ | ||
179 | unsigned int outlen; /* size of output buffer */ | ||
180 | struct drbg_string *addtl; /* additional information string */ | ||
181 | struct drbg_test_data *test_data; /* test data */ | ||
182 | }; | ||
183 | |||
184 | /* | ||
185 | * This is a wrapper to the kernel crypto API function of | ||
186 | * crypto_rng_get_bytes() to allow the caller to provide additional data. | ||
187 | * | ||
188 | * @drng DRBG handle -- see crypto_rng_get_bytes | ||
189 | * @outbuf output buffer -- see crypto_rng_get_bytes | ||
190 | * @outlen length of output buffer -- see crypto_rng_get_bytes | ||
191 | * @addtl_input additional information string input buffer | ||
192 | * @addtllen length of additional information string buffer | ||
193 | * | ||
194 | * return | ||
195 | * see crypto_rng_get_bytes | ||
196 | */ | ||
197 | static inline int crypto_drbg_get_bytes_addtl(struct crypto_rng *drng, | ||
198 | unsigned char *outbuf, unsigned int outlen, | ||
199 | struct drbg_string *addtl) | ||
200 | { | ||
201 | int ret; | ||
202 | struct drbg_gen genbuf; | ||
203 | genbuf.outbuf = outbuf; | ||
204 | genbuf.outlen = outlen; | ||
205 | genbuf.addtl = addtl; | ||
206 | genbuf.test_data = NULL; | ||
207 | ret = crypto_rng_get_bytes(drng, (u8 *)&genbuf, 0); | ||
208 | return ret; | ||
209 | } | ||
210 | |||
211 | /* | ||
212 | * TEST code | ||
213 | * | ||
214 | * This is a wrapper to the kernel crypto API function of | ||
215 | * crypto_rng_get_bytes() to allow the caller to provide additional data and | ||
216 | * allow furnishing of test_data | ||
217 | * | ||
218 | * @drng DRBG handle -- see crypto_rng_get_bytes | ||
219 | * @outbuf output buffer -- see crypto_rng_get_bytes | ||
220 | * @outlen length of output buffer -- see crypto_rng_get_bytes | ||
221 | * @addtl_input additional information string input buffer | ||
222 | * @addtllen length of additional information string buffer | ||
223 | * @test_data filled test data | ||
224 | * | ||
225 | * return | ||
226 | * see crypto_rng_get_bytes | ||
227 | */ | ||
228 | static inline int crypto_drbg_get_bytes_addtl_test(struct crypto_rng *drng, | ||
229 | unsigned char *outbuf, unsigned int outlen, | ||
230 | struct drbg_string *addtl, | ||
231 | struct drbg_test_data *test_data) | ||
232 | { | ||
233 | int ret; | ||
234 | struct drbg_gen genbuf; | ||
235 | genbuf.outbuf = outbuf; | ||
236 | genbuf.outlen = outlen; | ||
237 | genbuf.addtl = addtl; | ||
238 | genbuf.test_data = test_data; | ||
239 | ret = crypto_rng_get_bytes(drng, (u8 *)&genbuf, 0); | ||
240 | return ret; | ||
241 | } | ||
242 | |||
243 | /* | ||
244 | * TEST code | ||
245 | * | ||
246 | * This is a wrapper to the kernel crypto API function of | ||
247 | * crypto_rng_reset() to allow the caller to provide test_data | ||
248 | * | ||
249 | * @drng DRBG handle -- see crypto_rng_reset | ||
250 | * @pers personalization string input buffer | ||
251 | * @perslen length of additional information string buffer | ||
252 | * @test_data filled test data | ||
253 | * | ||
254 | * return | ||
255 | * see crypto_rng_reset | ||
256 | */ | ||
257 | static inline int crypto_drbg_reset_test(struct crypto_rng *drng, | ||
258 | struct drbg_string *pers, | ||
259 | struct drbg_test_data *test_data) | ||
260 | { | ||
261 | int ret; | ||
262 | struct drbg_gen genbuf; | ||
263 | genbuf.outbuf = NULL; | ||
264 | genbuf.outlen = 0; | ||
265 | genbuf.addtl = pers; | ||
266 | genbuf.test_data = test_data; | ||
267 | ret = crypto_rng_reset(drng, (u8 *)&genbuf, 0); | ||
268 | return ret; | ||
269 | } | ||
270 | |||
271 | /* DRBG type flags */ | ||
272 | #define DRBG_CTR ((drbg_flag_t)1<<0) | ||
273 | #define DRBG_HMAC ((drbg_flag_t)1<<1) | ||
274 | #define DRBG_HASH ((drbg_flag_t)1<<2) | ||
275 | #define DRBG_TYPE_MASK (DRBG_CTR | DRBG_HMAC | DRBG_HASH) | ||
276 | /* DRBG strength flags */ | ||
277 | #define DRBG_STRENGTH128 ((drbg_flag_t)1<<3) | ||
278 | #define DRBG_STRENGTH192 ((drbg_flag_t)1<<4) | ||
279 | #define DRBG_STRENGTH256 ((drbg_flag_t)1<<5) | ||
280 | #define DRBG_STRENGTH_MASK (DRBG_STRENGTH128 | DRBG_STRENGTH192 | \ | ||
281 | DRBG_STRENGTH256) | ||
282 | |||
283 | enum drbg_prefixes { | ||
284 | DRBG_PREFIX0 = 0x00, | ||
285 | DRBG_PREFIX1, | ||
286 | DRBG_PREFIX2, | ||
287 | DRBG_PREFIX3 | ||
288 | }; | ||
289 | |||
290 | #endif /* _DRBG_H */ | ||
diff --git a/include/crypto/hash.h b/include/crypto/hash.h index 26cb1eb16f4c..a39195539601 100644 --- a/include/crypto/hash.h +++ b/include/crypto/hash.h | |||
@@ -238,10 +238,10 @@ static inline struct ahash_request *ahash_request_cast( | |||
238 | 238 | ||
239 | static inline void ahash_request_set_callback(struct ahash_request *req, | 239 | static inline void ahash_request_set_callback(struct ahash_request *req, |
240 | u32 flags, | 240 | u32 flags, |
241 | crypto_completion_t complete, | 241 | crypto_completion_t compl, |
242 | void *data) | 242 | void *data) |
243 | { | 243 | { |
244 | req->base.complete = complete; | 244 | req->base.complete = compl; |
245 | req->base.data = data; | 245 | req->base.data = data; |
246 | req->base.flags = flags; | 246 | req->base.flags = flags; |
247 | } | 247 | } |
diff --git a/include/crypto/internal/skcipher.h b/include/crypto/internal/skcipher.h index 06e8b32d541c..b3a46c515d1b 100644 --- a/include/crypto/internal/skcipher.h +++ b/include/crypto/internal/skcipher.h | |||
@@ -81,8 +81,7 @@ static inline int skcipher_enqueue_givcrypt( | |||
81 | static inline struct skcipher_givcrypt_request *skcipher_dequeue_givcrypt( | 81 | static inline struct skcipher_givcrypt_request *skcipher_dequeue_givcrypt( |
82 | struct crypto_queue *queue) | 82 | struct crypto_queue *queue) |
83 | { | 83 | { |
84 | return __crypto_dequeue_request( | 84 | return skcipher_givcrypt_cast(crypto_dequeue_request(queue)); |
85 | queue, offsetof(struct skcipher_givcrypt_request, creq.base)); | ||
86 | } | 85 | } |
87 | 86 | ||
88 | static inline void *skcipher_givcrypt_reqctx( | 87 | static inline void *skcipher_givcrypt_reqctx( |
diff --git a/include/crypto/scatterwalk.h b/include/crypto/scatterwalk.h index 6a626a507b8c..7ef512f8631c 100644 --- a/include/crypto/scatterwalk.h +++ b/include/crypto/scatterwalk.h | |||
@@ -25,12 +25,6 @@ | |||
25 | #include <linux/scatterlist.h> | 25 | #include <linux/scatterlist.h> |
26 | #include <linux/sched.h> | 26 | #include <linux/sched.h> |
27 | 27 | ||
28 | static inline void crypto_yield(u32 flags) | ||
29 | { | ||
30 | if (flags & CRYPTO_TFM_REQ_MAY_SLEEP) | ||
31 | cond_resched(); | ||
32 | } | ||
33 | |||
34 | static inline void scatterwalk_sg_chain(struct scatterlist *sg1, int num, | 28 | static inline void scatterwalk_sg_chain(struct scatterlist *sg1, int num, |
35 | struct scatterlist *sg2) | 29 | struct scatterlist *sg2) |
36 | { | 30 | { |
diff --git a/include/crypto/skcipher.h b/include/crypto/skcipher.h index 25fd6126522d..07d245f073d1 100644 --- a/include/crypto/skcipher.h +++ b/include/crypto/skcipher.h | |||
@@ -86,9 +86,9 @@ static inline void skcipher_givcrypt_free(struct skcipher_givcrypt_request *req) | |||
86 | 86 | ||
87 | static inline void skcipher_givcrypt_set_callback( | 87 | static inline void skcipher_givcrypt_set_callback( |
88 | struct skcipher_givcrypt_request *req, u32 flags, | 88 | struct skcipher_givcrypt_request *req, u32 flags, |
89 | crypto_completion_t complete, void *data) | 89 | crypto_completion_t compl, void *data) |
90 | { | 90 | { |
91 | ablkcipher_request_set_callback(&req->creq, flags, complete, data); | 91 | ablkcipher_request_set_callback(&req->creq, flags, compl, data); |
92 | } | 92 | } |
93 | 93 | ||
94 | static inline void skcipher_givcrypt_set_crypt( | 94 | static inline void skcipher_givcrypt_set_crypt( |