diff options
-rw-r--r-- | crypto/cryptd.c | 1 | ||||
-rw-r--r-- | crypto/digest.c | 1 | ||||
-rw-r--r-- | crypto/hash.c | 1 | ||||
-rw-r--r-- | crypto/tcrypt.c | 1 | ||||
-rw-r--r-- | include/crypto/algapi.h | 36 | ||||
-rw-r--r-- | include/crypto/hash.h | 154 | ||||
-rw-r--r-- | include/crypto/internal/hash.h | 37 | ||||
-rw-r--r-- | include/linux/crypto.h | 136 |
8 files changed, 195 insertions, 172 deletions
diff --git a/crypto/cryptd.c b/crypto/cryptd.c index d3ecd7e73b7e..d29e06b350ff 100644 --- a/crypto/cryptd.c +++ b/crypto/cryptd.c | |||
@@ -11,6 +11,7 @@ | |||
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <crypto/algapi.h> | 13 | #include <crypto/algapi.h> |
14 | #include <crypto/internal/hash.h> | ||
14 | #include <linux/err.h> | 15 | #include <linux/err.h> |
15 | #include <linux/init.h> | 16 | #include <linux/init.h> |
16 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
diff --git a/crypto/digest.c b/crypto/digest.c index bf332982c50d..ac0919460d14 100644 --- a/crypto/digest.c +++ b/crypto/digest.c | |||
@@ -12,6 +12,7 @@ | |||
12 | * | 12 | * |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <crypto/internal/hash.h> | ||
15 | #include <crypto/scatterwalk.h> | 16 | #include <crypto/scatterwalk.h> |
16 | #include <linux/mm.h> | 17 | #include <linux/mm.h> |
17 | #include <linux/errno.h> | 18 | #include <linux/errno.h> |
diff --git a/crypto/hash.c b/crypto/hash.c index 140a75565f15..cb86b19fd105 100644 --- a/crypto/hash.c +++ b/crypto/hash.c | |||
@@ -9,6 +9,7 @@ | |||
9 | * any later version. | 9 | * any later version. |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <crypto/internal/hash.h> | ||
12 | #include <linux/errno.h> | 13 | #include <linux/errno.h> |
13 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
14 | #include <linux/module.h> | 15 | #include <linux/module.h> |
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index 87f08f9b0904..59821a22d752 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c | |||
@@ -15,6 +15,7 @@ | |||
15 | * | 15 | * |
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include <crypto/hash.h> | ||
18 | #include <linux/err.h> | 19 | #include <linux/err.h> |
19 | #include <linux/init.h> | 20 | #include <linux/init.h> |
20 | #include <linux/module.h> | 21 | #include <linux/module.h> |
diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index fef272a8ceeb..60d06e784be3 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h | |||
@@ -98,7 +98,6 @@ extern const struct crypto_type crypto_ablkcipher_type; | |||
98 | extern const struct crypto_type crypto_aead_type; | 98 | extern const struct crypto_type crypto_aead_type; |
99 | extern const struct crypto_type crypto_blkcipher_type; | 99 | extern const struct crypto_type crypto_blkcipher_type; |
100 | extern const struct crypto_type crypto_hash_type; | 100 | extern const struct crypto_type crypto_hash_type; |
101 | extern const struct crypto_type crypto_ahash_type; | ||
102 | 101 | ||
103 | void crypto_mod_put(struct crypto_alg *alg); | 102 | void crypto_mod_put(struct crypto_alg *alg); |
104 | 103 | ||
@@ -315,40 +314,5 @@ static inline int crypto_requires_sync(u32 type, u32 mask) | |||
315 | return (type ^ CRYPTO_ALG_ASYNC) & mask & CRYPTO_ALG_ASYNC; | 314 | return (type ^ CRYPTO_ALG_ASYNC) & mask & CRYPTO_ALG_ASYNC; |
316 | } | 315 | } |
317 | 316 | ||
318 | static inline void *crypto_ahash_ctx(struct crypto_ahash *tfm) | ||
319 | { | ||
320 | return crypto_tfm_ctx(&tfm->base); | ||
321 | } | ||
322 | |||
323 | static inline struct ahash_alg *crypto_ahash_alg( | ||
324 | struct crypto_ahash *tfm) | ||
325 | { | ||
326 | return &crypto_ahash_tfm(tfm)->__crt_alg->cra_ahash; | ||
327 | } | ||
328 | |||
329 | static inline int ahash_enqueue_request(struct crypto_queue *queue, | ||
330 | struct ahash_request *request) | ||
331 | { | ||
332 | return crypto_enqueue_request(queue, &request->base); | ||
333 | } | ||
334 | |||
335 | static inline struct ahash_request *ahash_dequeue_request( | ||
336 | struct crypto_queue *queue) | ||
337 | { | ||
338 | return ahash_request_cast(crypto_dequeue_request(queue)); | ||
339 | } | ||
340 | |||
341 | static inline void *ahash_request_ctx(struct ahash_request *req) | ||
342 | { | ||
343 | return req->__ctx; | ||
344 | } | ||
345 | |||
346 | static inline int ahash_tfm_in_queue(struct crypto_queue *queue, | ||
347 | struct crypto_ahash *tfm) | ||
348 | { | ||
349 | return crypto_tfm_in_queue(queue, crypto_ahash_tfm(tfm)); | ||
350 | } | ||
351 | |||
352 | |||
353 | #endif /* _CRYPTO_ALGAPI_H */ | 317 | #endif /* _CRYPTO_ALGAPI_H */ |
354 | 318 | ||
diff --git a/include/crypto/hash.h b/include/crypto/hash.h new file mode 100644 index 000000000000..d12498ec8a4e --- /dev/null +++ b/include/crypto/hash.h | |||
@@ -0,0 +1,154 @@ | |||
1 | /* | ||
2 | * Hash: Hash algorithms under the crypto API | ||
3 | * | ||
4 | * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the Free | ||
8 | * Software Foundation; either version 2 of the License, or (at your option) | ||
9 | * any later version. | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #ifndef _CRYPTO_HASH_H | ||
14 | #define _CRYPTO_HASH_H | ||
15 | |||
16 | #include <linux/crypto.h> | ||
17 | |||
18 | struct crypto_ahash { | ||
19 | struct crypto_tfm base; | ||
20 | }; | ||
21 | |||
22 | static inline struct crypto_ahash *__crypto_ahash_cast(struct crypto_tfm *tfm) | ||
23 | { | ||
24 | return (struct crypto_ahash *)tfm; | ||
25 | } | ||
26 | |||
27 | static inline struct crypto_ahash *crypto_alloc_ahash(const char *alg_name, | ||
28 | u32 type, u32 mask) | ||
29 | { | ||
30 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
31 | mask &= ~CRYPTO_ALG_TYPE_MASK; | ||
32 | type |= CRYPTO_ALG_TYPE_AHASH; | ||
33 | mask |= CRYPTO_ALG_TYPE_AHASH_MASK; | ||
34 | |||
35 | return __crypto_ahash_cast(crypto_alloc_base(alg_name, type, mask)); | ||
36 | } | ||
37 | |||
38 | static inline struct crypto_tfm *crypto_ahash_tfm(struct crypto_ahash *tfm) | ||
39 | { | ||
40 | return &tfm->base; | ||
41 | } | ||
42 | |||
43 | static inline void crypto_free_ahash(struct crypto_ahash *tfm) | ||
44 | { | ||
45 | crypto_free_tfm(crypto_ahash_tfm(tfm)); | ||
46 | } | ||
47 | |||
48 | static inline unsigned int crypto_ahash_alignmask( | ||
49 | struct crypto_ahash *tfm) | ||
50 | { | ||
51 | return crypto_tfm_alg_alignmask(crypto_ahash_tfm(tfm)); | ||
52 | } | ||
53 | |||
54 | static inline struct ahash_tfm *crypto_ahash_crt(struct crypto_ahash *tfm) | ||
55 | { | ||
56 | return &crypto_ahash_tfm(tfm)->crt_ahash; | ||
57 | } | ||
58 | |||
59 | static inline unsigned int crypto_ahash_digestsize(struct crypto_ahash *tfm) | ||
60 | { | ||
61 | return crypto_ahash_crt(tfm)->digestsize; | ||
62 | } | ||
63 | |||
64 | static inline u32 crypto_ahash_get_flags(struct crypto_ahash *tfm) | ||
65 | { | ||
66 | return crypto_tfm_get_flags(crypto_ahash_tfm(tfm)); | ||
67 | } | ||
68 | |||
69 | static inline void crypto_ahash_set_flags(struct crypto_ahash *tfm, u32 flags) | ||
70 | { | ||
71 | crypto_tfm_set_flags(crypto_ahash_tfm(tfm), flags); | ||
72 | } | ||
73 | |||
74 | static inline void crypto_ahash_clear_flags(struct crypto_ahash *tfm, u32 flags) | ||
75 | { | ||
76 | crypto_tfm_clear_flags(crypto_ahash_tfm(tfm), flags); | ||
77 | } | ||
78 | |||
79 | static inline struct crypto_ahash *crypto_ahash_reqtfm( | ||
80 | struct ahash_request *req) | ||
81 | { | ||
82 | return __crypto_ahash_cast(req->base.tfm); | ||
83 | } | ||
84 | |||
85 | static inline unsigned int crypto_ahash_reqsize(struct crypto_ahash *tfm) | ||
86 | { | ||
87 | return crypto_ahash_crt(tfm)->reqsize; | ||
88 | } | ||
89 | |||
90 | static inline int crypto_ahash_setkey(struct crypto_ahash *tfm, | ||
91 | const u8 *key, unsigned int keylen) | ||
92 | { | ||
93 | struct ahash_tfm *crt = crypto_ahash_crt(tfm); | ||
94 | |||
95 | return crt->setkey(tfm, key, keylen); | ||
96 | } | ||
97 | |||
98 | static inline int crypto_ahash_digest(struct ahash_request *req) | ||
99 | { | ||
100 | struct ahash_tfm *crt = crypto_ahash_crt(crypto_ahash_reqtfm(req)); | ||
101 | return crt->digest(req); | ||
102 | } | ||
103 | |||
104 | static inline void ahash_request_set_tfm(struct ahash_request *req, | ||
105 | struct crypto_ahash *tfm) | ||
106 | { | ||
107 | req->base.tfm = crypto_ahash_tfm(tfm); | ||
108 | } | ||
109 | |||
110 | static inline struct ahash_request *ahash_request_alloc( | ||
111 | struct crypto_ahash *tfm, gfp_t gfp) | ||
112 | { | ||
113 | struct ahash_request *req; | ||
114 | |||
115 | req = kmalloc(sizeof(struct ahash_request) + | ||
116 | crypto_ahash_reqsize(tfm), gfp); | ||
117 | |||
118 | if (likely(req)) | ||
119 | ahash_request_set_tfm(req, tfm); | ||
120 | |||
121 | return req; | ||
122 | } | ||
123 | |||
124 | static inline void ahash_request_free(struct ahash_request *req) | ||
125 | { | ||
126 | kfree(req); | ||
127 | } | ||
128 | |||
129 | static inline struct ahash_request *ahash_request_cast( | ||
130 | struct crypto_async_request *req) | ||
131 | { | ||
132 | return container_of(req, struct ahash_request, base); | ||
133 | } | ||
134 | |||
135 | static inline void ahash_request_set_callback(struct ahash_request *req, | ||
136 | u32 flags, | ||
137 | crypto_completion_t complete, | ||
138 | void *data) | ||
139 | { | ||
140 | req->base.complete = complete; | ||
141 | req->base.data = data; | ||
142 | req->base.flags = flags; | ||
143 | } | ||
144 | |||
145 | static inline void ahash_request_set_crypt(struct ahash_request *req, | ||
146 | struct scatterlist *src, u8 *result, | ||
147 | unsigned int nbytes) | ||
148 | { | ||
149 | req->src = src; | ||
150 | req->nbytes = nbytes; | ||
151 | req->result = result; | ||
152 | } | ||
153 | |||
154 | #endif /* _CRYPTO_HASH_H */ | ||
diff --git a/include/crypto/internal/hash.h b/include/crypto/internal/hash.h index 93ac42280221..917ae57bad4a 100644 --- a/include/crypto/internal/hash.h +++ b/include/crypto/internal/hash.h | |||
@@ -14,6 +14,7 @@ | |||
14 | #define _CRYPTO_INTERNAL_HASH_H | 14 | #define _CRYPTO_INTERNAL_HASH_H |
15 | 15 | ||
16 | #include <crypto/algapi.h> | 16 | #include <crypto/algapi.h> |
17 | #include <crypto/hash.h> | ||
17 | 18 | ||
18 | struct ahash_request; | 19 | struct ahash_request; |
19 | struct scatterlist; | 20 | struct scatterlist; |
@@ -33,9 +34,45 @@ struct crypto_hash_walk { | |||
33 | unsigned int flags; | 34 | unsigned int flags; |
34 | }; | 35 | }; |
35 | 36 | ||
37 | extern const struct crypto_type crypto_ahash_type; | ||
38 | |||
36 | int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err); | 39 | int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err); |
37 | int crypto_hash_walk_first(struct ahash_request *req, | 40 | int crypto_hash_walk_first(struct ahash_request *req, |
38 | struct crypto_hash_walk *walk); | 41 | struct crypto_hash_walk *walk); |
39 | 42 | ||
43 | static inline void *crypto_ahash_ctx(struct crypto_ahash *tfm) | ||
44 | { | ||
45 | return crypto_tfm_ctx(&tfm->base); | ||
46 | } | ||
47 | |||
48 | static inline struct ahash_alg *crypto_ahash_alg( | ||
49 | struct crypto_ahash *tfm) | ||
50 | { | ||
51 | return &crypto_ahash_tfm(tfm)->__crt_alg->cra_ahash; | ||
52 | } | ||
53 | |||
54 | static inline int ahash_enqueue_request(struct crypto_queue *queue, | ||
55 | struct ahash_request *request) | ||
56 | { | ||
57 | return crypto_enqueue_request(queue, &request->base); | ||
58 | } | ||
59 | |||
60 | static inline struct ahash_request *ahash_dequeue_request( | ||
61 | struct crypto_queue *queue) | ||
62 | { | ||
63 | return ahash_request_cast(crypto_dequeue_request(queue)); | ||
64 | } | ||
65 | |||
66 | static inline void *ahash_request_ctx(struct ahash_request *req) | ||
67 | { | ||
68 | return req->__ctx; | ||
69 | } | ||
70 | |||
71 | static inline int ahash_tfm_in_queue(struct crypto_queue *queue, | ||
72 | struct crypto_ahash *tfm) | ||
73 | { | ||
74 | return crypto_tfm_in_queue(queue, crypto_ahash_tfm(tfm)); | ||
75 | } | ||
76 | |||
40 | #endif /* _CRYPTO_INTERNAL_HASH_H */ | 77 | #endif /* _CRYPTO_INTERNAL_HASH_H */ |
41 | 78 | ||
diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 68ef293644d3..c43dc47fdf75 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h | |||
@@ -481,10 +481,6 @@ struct crypto_hash { | |||
481 | struct crypto_tfm base; | 481 | struct crypto_tfm base; |
482 | }; | 482 | }; |
483 | 483 | ||
484 | struct crypto_ahash { | ||
485 | struct crypto_tfm base; | ||
486 | }; | ||
487 | |||
488 | enum { | 484 | enum { |
489 | CRYPTOA_UNSPEC, | 485 | CRYPTOA_UNSPEC, |
490 | CRYPTOA_ALG, | 486 | CRYPTOA_ALG, |
@@ -1308,137 +1304,5 @@ static inline int crypto_comp_decompress(struct crypto_comp *tfm, | |||
1308 | src, slen, dst, dlen); | 1304 | src, slen, dst, dlen); |
1309 | } | 1305 | } |
1310 | 1306 | ||
1311 | static inline struct crypto_ahash *__crypto_ahash_cast(struct crypto_tfm *tfm) | ||
1312 | { | ||
1313 | return (struct crypto_ahash *)tfm; | ||
1314 | } | ||
1315 | |||
1316 | static inline struct crypto_ahash *crypto_alloc_ahash(const char *alg_name, | ||
1317 | u32 type, u32 mask) | ||
1318 | { | ||
1319 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
1320 | mask &= ~CRYPTO_ALG_TYPE_MASK; | ||
1321 | type |= CRYPTO_ALG_TYPE_AHASH; | ||
1322 | mask |= CRYPTO_ALG_TYPE_AHASH_MASK; | ||
1323 | |||
1324 | return __crypto_ahash_cast(crypto_alloc_base(alg_name, type, mask)); | ||
1325 | } | ||
1326 | |||
1327 | static inline struct crypto_tfm *crypto_ahash_tfm(struct crypto_ahash *tfm) | ||
1328 | { | ||
1329 | return &tfm->base; | ||
1330 | } | ||
1331 | |||
1332 | static inline void crypto_free_ahash(struct crypto_ahash *tfm) | ||
1333 | { | ||
1334 | crypto_free_tfm(crypto_ahash_tfm(tfm)); | ||
1335 | } | ||
1336 | |||
1337 | static inline unsigned int crypto_ahash_alignmask( | ||
1338 | struct crypto_ahash *tfm) | ||
1339 | { | ||
1340 | return crypto_tfm_alg_alignmask(crypto_ahash_tfm(tfm)); | ||
1341 | } | ||
1342 | |||
1343 | static inline struct ahash_tfm *crypto_ahash_crt(struct crypto_ahash *tfm) | ||
1344 | { | ||
1345 | return &crypto_ahash_tfm(tfm)->crt_ahash; | ||
1346 | } | ||
1347 | |||
1348 | static inline unsigned int crypto_ahash_digestsize(struct crypto_ahash *tfm) | ||
1349 | { | ||
1350 | return crypto_ahash_crt(tfm)->digestsize; | ||
1351 | } | ||
1352 | |||
1353 | static inline u32 crypto_ahash_get_flags(struct crypto_ahash *tfm) | ||
1354 | { | ||
1355 | return crypto_tfm_get_flags(crypto_ahash_tfm(tfm)); | ||
1356 | } | ||
1357 | |||
1358 | static inline void crypto_ahash_set_flags(struct crypto_ahash *tfm, u32 flags) | ||
1359 | { | ||
1360 | crypto_tfm_set_flags(crypto_ahash_tfm(tfm), flags); | ||
1361 | } | ||
1362 | |||
1363 | static inline void crypto_ahash_clear_flags(struct crypto_ahash *tfm, u32 flags) | ||
1364 | { | ||
1365 | crypto_tfm_clear_flags(crypto_ahash_tfm(tfm), flags); | ||
1366 | } | ||
1367 | |||
1368 | static inline struct crypto_ahash *crypto_ahash_reqtfm( | ||
1369 | struct ahash_request *req) | ||
1370 | { | ||
1371 | return __crypto_ahash_cast(req->base.tfm); | ||
1372 | } | ||
1373 | |||
1374 | static inline unsigned int crypto_ahash_reqsize(struct crypto_ahash *tfm) | ||
1375 | { | ||
1376 | return crypto_ahash_crt(tfm)->reqsize; | ||
1377 | } | ||
1378 | |||
1379 | static inline int crypto_ahash_setkey(struct crypto_ahash *tfm, | ||
1380 | const u8 *key, unsigned int keylen) | ||
1381 | { | ||
1382 | struct ahash_tfm *crt = crypto_ahash_crt(tfm); | ||
1383 | |||
1384 | return crt->setkey(tfm, key, keylen); | ||
1385 | } | ||
1386 | |||
1387 | static inline int crypto_ahash_digest(struct ahash_request *req) | ||
1388 | { | ||
1389 | struct ahash_tfm *crt = crypto_ahash_crt(crypto_ahash_reqtfm(req)); | ||
1390 | return crt->digest(req); | ||
1391 | } | ||
1392 | |||
1393 | static inline void ahash_request_set_tfm(struct ahash_request *req, | ||
1394 | struct crypto_ahash *tfm) | ||
1395 | { | ||
1396 | req->base.tfm = crypto_ahash_tfm(tfm); | ||
1397 | } | ||
1398 | |||
1399 | static inline struct ahash_request *ahash_request_alloc( | ||
1400 | struct crypto_ahash *tfm, gfp_t gfp) | ||
1401 | { | ||
1402 | struct ahash_request *req; | ||
1403 | |||
1404 | req = kmalloc(sizeof(struct ahash_request) + | ||
1405 | crypto_ahash_reqsize(tfm), gfp); | ||
1406 | |||
1407 | if (likely(req)) | ||
1408 | ahash_request_set_tfm(req, tfm); | ||
1409 | |||
1410 | return req; | ||
1411 | } | ||
1412 | |||
1413 | static inline void ahash_request_free(struct ahash_request *req) | ||
1414 | { | ||
1415 | kfree(req); | ||
1416 | } | ||
1417 | |||
1418 | static inline struct ahash_request *ahash_request_cast( | ||
1419 | struct crypto_async_request *req) | ||
1420 | { | ||
1421 | return container_of(req, struct ahash_request, base); | ||
1422 | } | ||
1423 | |||
1424 | static inline void ahash_request_set_callback(struct ahash_request *req, | ||
1425 | u32 flags, | ||
1426 | crypto_completion_t complete, | ||
1427 | void *data) | ||
1428 | { | ||
1429 | req->base.complete = complete; | ||
1430 | req->base.data = data; | ||
1431 | req->base.flags = flags; | ||
1432 | } | ||
1433 | |||
1434 | static inline void ahash_request_set_crypt(struct ahash_request *req, | ||
1435 | struct scatterlist *src, u8 *result, | ||
1436 | unsigned int nbytes) | ||
1437 | { | ||
1438 | req->src = src; | ||
1439 | req->nbytes = nbytes; | ||
1440 | req->result = result; | ||
1441 | } | ||
1442 | |||
1443 | #endif /* _LINUX_CRYPTO_H */ | 1307 | #endif /* _LINUX_CRYPTO_H */ |
1444 | 1308 | ||