diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/crypto/aes.h | 8 | ||||
-rw-r--r-- | include/crypto/algapi.h | 16 | ||||
-rw-r--r-- | include/crypto/hash.h | 125 | ||||
-rw-r--r-- | include/crypto/internal/hash.h | 16 | ||||
-rw-r--r-- | include/linux/crc32c.h | 6 | ||||
-rw-r--r-- | include/linux/crypto.h | 10 |
6 files changed, 166 insertions, 15 deletions
diff --git a/include/crypto/aes.h b/include/crypto/aes.h index 40008d67ee3d..656a4c66a568 100644 --- a/include/crypto/aes.h +++ b/include/crypto/aes.h | |||
@@ -23,10 +23,10 @@ struct crypto_aes_ctx { | |||
23 | u32 key_dec[AES_MAX_KEYLENGTH_U32]; | 23 | u32 key_dec[AES_MAX_KEYLENGTH_U32]; |
24 | }; | 24 | }; |
25 | 25 | ||
26 | extern u32 crypto_ft_tab[4][256]; | 26 | extern const u32 crypto_ft_tab[4][256]; |
27 | extern u32 crypto_fl_tab[4][256]; | 27 | extern const u32 crypto_fl_tab[4][256]; |
28 | extern u32 crypto_it_tab[4][256]; | 28 | extern const u32 crypto_it_tab[4][256]; |
29 | extern u32 crypto_il_tab[4][256]; | 29 | extern const u32 crypto_il_tab[4][256]; |
30 | 30 | ||
31 | int crypto_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, | 31 | int crypto_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, |
32 | unsigned int key_len); | 32 | unsigned int key_len); |
diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index 60d06e784be3..010545436efa 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h | |||
@@ -22,9 +22,18 @@ struct seq_file; | |||
22 | 22 | ||
23 | struct crypto_type { | 23 | struct crypto_type { |
24 | unsigned int (*ctxsize)(struct crypto_alg *alg, u32 type, u32 mask); | 24 | unsigned int (*ctxsize)(struct crypto_alg *alg, u32 type, u32 mask); |
25 | unsigned int (*extsize)(struct crypto_alg *alg, | ||
26 | const struct crypto_type *frontend); | ||
25 | int (*init)(struct crypto_tfm *tfm, u32 type, u32 mask); | 27 | int (*init)(struct crypto_tfm *tfm, u32 type, u32 mask); |
26 | void (*exit)(struct crypto_tfm *tfm); | 28 | int (*init_tfm)(struct crypto_tfm *tfm, |
29 | const struct crypto_type *frontend); | ||
27 | void (*show)(struct seq_file *m, struct crypto_alg *alg); | 30 | void (*show)(struct seq_file *m, struct crypto_alg *alg); |
31 | struct crypto_alg *(*lookup)(const char *name, u32 type, u32 mask); | ||
32 | |||
33 | unsigned int type; | ||
34 | unsigned int maskclear; | ||
35 | unsigned int maskset; | ||
36 | unsigned int tfmsize; | ||
28 | }; | 37 | }; |
29 | 38 | ||
30 | struct crypto_instance { | 39 | struct crypto_instance { |
@@ -239,6 +248,11 @@ static inline struct crypto_hash *crypto_spawn_hash(struct crypto_spawn *spawn) | |||
239 | return __crypto_hash_cast(crypto_spawn_tfm(spawn, type, mask)); | 248 | return __crypto_hash_cast(crypto_spawn_tfm(spawn, type, mask)); |
240 | } | 249 | } |
241 | 250 | ||
251 | static inline void *crypto_hash_ctx(struct crypto_hash *tfm) | ||
252 | { | ||
253 | return crypto_tfm_ctx(&tfm->base); | ||
254 | } | ||
255 | |||
242 | static inline void *crypto_hash_ctx_aligned(struct crypto_hash *tfm) | 256 | static inline void *crypto_hash_ctx_aligned(struct crypto_hash *tfm) |
243 | { | 257 | { |
244 | return crypto_tfm_ctx_aligned(&tfm->base); | 258 | return crypto_tfm_ctx_aligned(&tfm->base); |
diff --git a/include/crypto/hash.h b/include/crypto/hash.h index ee48ef8fb2ea..cd16d6e668ce 100644 --- a/include/crypto/hash.h +++ b/include/crypto/hash.h | |||
@@ -15,10 +15,40 @@ | |||
15 | 15 | ||
16 | #include <linux/crypto.h> | 16 | #include <linux/crypto.h> |
17 | 17 | ||
18 | struct shash_desc { | ||
19 | struct crypto_shash *tfm; | ||
20 | u32 flags; | ||
21 | |||
22 | void *__ctx[] CRYPTO_MINALIGN_ATTR; | ||
23 | }; | ||
24 | |||
25 | struct shash_alg { | ||
26 | int (*init)(struct shash_desc *desc); | ||
27 | int (*reinit)(struct shash_desc *desc); | ||
28 | int (*update)(struct shash_desc *desc, const u8 *data, | ||
29 | unsigned int len); | ||
30 | int (*final)(struct shash_desc *desc, u8 *out); | ||
31 | int (*finup)(struct shash_desc *desc, const u8 *data, | ||
32 | unsigned int len, u8 *out); | ||
33 | int (*digest)(struct shash_desc *desc, const u8 *data, | ||
34 | unsigned int len, u8 *out); | ||
35 | int (*setkey)(struct crypto_shash *tfm, const u8 *key, | ||
36 | unsigned int keylen); | ||
37 | |||
38 | unsigned int descsize; | ||
39 | unsigned int digestsize; | ||
40 | |||
41 | struct crypto_alg base; | ||
42 | }; | ||
43 | |||
18 | struct crypto_ahash { | 44 | struct crypto_ahash { |
19 | struct crypto_tfm base; | 45 | struct crypto_tfm base; |
20 | }; | 46 | }; |
21 | 47 | ||
48 | struct crypto_shash { | ||
49 | struct crypto_tfm base; | ||
50 | }; | ||
51 | |||
22 | static inline struct crypto_ahash *__crypto_ahash_cast(struct crypto_tfm *tfm) | 52 | static inline struct crypto_ahash *__crypto_ahash_cast(struct crypto_tfm *tfm) |
23 | { | 53 | { |
24 | return (struct crypto_ahash *)tfm; | 54 | return (struct crypto_ahash *)tfm; |
@@ -87,6 +117,11 @@ static inline unsigned int crypto_ahash_reqsize(struct crypto_ahash *tfm) | |||
87 | return crypto_ahash_crt(tfm)->reqsize; | 117 | return crypto_ahash_crt(tfm)->reqsize; |
88 | } | 118 | } |
89 | 119 | ||
120 | static inline void *ahash_request_ctx(struct ahash_request *req) | ||
121 | { | ||
122 | return req->__ctx; | ||
123 | } | ||
124 | |||
90 | static inline int crypto_ahash_setkey(struct crypto_ahash *tfm, | 125 | static inline int crypto_ahash_setkey(struct crypto_ahash *tfm, |
91 | const u8 *key, unsigned int keylen) | 126 | const u8 *key, unsigned int keylen) |
92 | { | 127 | { |
@@ -101,6 +136,14 @@ static inline int crypto_ahash_digest(struct ahash_request *req) | |||
101 | return crt->digest(req); | 136 | return crt->digest(req); |
102 | } | 137 | } |
103 | 138 | ||
139 | static inline void crypto_ahash_export(struct ahash_request *req, u8 *out) | ||
140 | { | ||
141 | memcpy(out, ahash_request_ctx(req), | ||
142 | crypto_ahash_reqsize(crypto_ahash_reqtfm(req))); | ||
143 | } | ||
144 | |||
145 | int crypto_ahash_import(struct ahash_request *req, const u8 *in); | ||
146 | |||
104 | static inline int crypto_ahash_init(struct ahash_request *req) | 147 | static inline int crypto_ahash_init(struct ahash_request *req) |
105 | { | 148 | { |
106 | struct ahash_tfm *crt = crypto_ahash_crt(crypto_ahash_reqtfm(req)); | 149 | struct ahash_tfm *crt = crypto_ahash_crt(crypto_ahash_reqtfm(req)); |
@@ -169,4 +212,86 @@ static inline void ahash_request_set_crypt(struct ahash_request *req, | |||
169 | req->result = result; | 212 | req->result = result; |
170 | } | 213 | } |
171 | 214 | ||
215 | struct crypto_shash *crypto_alloc_shash(const char *alg_name, u32 type, | ||
216 | u32 mask); | ||
217 | |||
218 | static inline struct crypto_tfm *crypto_shash_tfm(struct crypto_shash *tfm) | ||
219 | { | ||
220 | return &tfm->base; | ||
221 | } | ||
222 | |||
223 | static inline void crypto_free_shash(struct crypto_shash *tfm) | ||
224 | { | ||
225 | crypto_free_tfm(crypto_shash_tfm(tfm)); | ||
226 | } | ||
227 | |||
228 | static inline unsigned int crypto_shash_alignmask( | ||
229 | struct crypto_shash *tfm) | ||
230 | { | ||
231 | return crypto_tfm_alg_alignmask(crypto_shash_tfm(tfm)); | ||
232 | } | ||
233 | |||
234 | static inline struct shash_alg *__crypto_shash_alg(struct crypto_alg *alg) | ||
235 | { | ||
236 | return container_of(alg, struct shash_alg, base); | ||
237 | } | ||
238 | |||
239 | static inline struct shash_alg *crypto_shash_alg(struct crypto_shash *tfm) | ||
240 | { | ||
241 | return __crypto_shash_alg(crypto_shash_tfm(tfm)->__crt_alg); | ||
242 | } | ||
243 | |||
244 | static inline unsigned int crypto_shash_digestsize(struct crypto_shash *tfm) | ||
245 | { | ||
246 | return crypto_shash_alg(tfm)->digestsize; | ||
247 | } | ||
248 | |||
249 | static inline u32 crypto_shash_get_flags(struct crypto_shash *tfm) | ||
250 | { | ||
251 | return crypto_tfm_get_flags(crypto_shash_tfm(tfm)); | ||
252 | } | ||
253 | |||
254 | static inline void crypto_shash_set_flags(struct crypto_shash *tfm, u32 flags) | ||
255 | { | ||
256 | crypto_tfm_set_flags(crypto_shash_tfm(tfm), flags); | ||
257 | } | ||
258 | |||
259 | static inline void crypto_shash_clear_flags(struct crypto_shash *tfm, u32 flags) | ||
260 | { | ||
261 | crypto_tfm_clear_flags(crypto_shash_tfm(tfm), flags); | ||
262 | } | ||
263 | |||
264 | static inline unsigned int crypto_shash_descsize(struct crypto_shash *tfm) | ||
265 | { | ||
266 | return crypto_shash_alg(tfm)->descsize; | ||
267 | } | ||
268 | |||
269 | static inline void *shash_desc_ctx(struct shash_desc *desc) | ||
270 | { | ||
271 | return desc->__ctx; | ||
272 | } | ||
273 | |||
274 | int crypto_shash_setkey(struct crypto_shash *tfm, const u8 *key, | ||
275 | unsigned int keylen); | ||
276 | int crypto_shash_digest(struct shash_desc *desc, const u8 *data, | ||
277 | unsigned int len, u8 *out); | ||
278 | |||
279 | static inline void crypto_shash_export(struct shash_desc *desc, u8 *out) | ||
280 | { | ||
281 | memcpy(out, shash_desc_ctx(desc), crypto_shash_descsize(desc->tfm)); | ||
282 | } | ||
283 | |||
284 | int crypto_shash_import(struct shash_desc *desc, const u8 *in); | ||
285 | |||
286 | static inline int crypto_shash_init(struct shash_desc *desc) | ||
287 | { | ||
288 | return crypto_shash_alg(desc->tfm)->init(desc); | ||
289 | } | ||
290 | |||
291 | int crypto_shash_update(struct shash_desc *desc, const u8 *data, | ||
292 | unsigned int len); | ||
293 | int crypto_shash_final(struct shash_desc *desc, u8 *out); | ||
294 | int crypto_shash_finup(struct shash_desc *desc, const u8 *data, | ||
295 | unsigned int len, u8 *out); | ||
296 | |||
172 | #endif /* _CRYPTO_HASH_H */ | 297 | #endif /* _CRYPTO_HASH_H */ |
diff --git a/include/crypto/internal/hash.h b/include/crypto/internal/hash.h index 917ae57bad4a..82b70564bcab 100644 --- a/include/crypto/internal/hash.h +++ b/include/crypto/internal/hash.h | |||
@@ -39,6 +39,12 @@ extern const struct crypto_type crypto_ahash_type; | |||
39 | 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); |
40 | int crypto_hash_walk_first(struct ahash_request *req, | 40 | int crypto_hash_walk_first(struct ahash_request *req, |
41 | struct crypto_hash_walk *walk); | 41 | struct crypto_hash_walk *walk); |
42 | int crypto_hash_walk_first_compat(struct hash_desc *hdesc, | ||
43 | struct crypto_hash_walk *walk, | ||
44 | struct scatterlist *sg, unsigned int len); | ||
45 | |||
46 | int crypto_register_shash(struct shash_alg *alg); | ||
47 | int crypto_unregister_shash(struct shash_alg *alg); | ||
42 | 48 | ||
43 | static inline void *crypto_ahash_ctx(struct crypto_ahash *tfm) | 49 | static inline void *crypto_ahash_ctx(struct crypto_ahash *tfm) |
44 | { | 50 | { |
@@ -63,16 +69,16 @@ static inline struct ahash_request *ahash_dequeue_request( | |||
63 | return ahash_request_cast(crypto_dequeue_request(queue)); | 69 | return ahash_request_cast(crypto_dequeue_request(queue)); |
64 | } | 70 | } |
65 | 71 | ||
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 | static inline int ahash_tfm_in_queue(struct crypto_queue *queue, |
72 | struct crypto_ahash *tfm) | 73 | struct crypto_ahash *tfm) |
73 | { | 74 | { |
74 | return crypto_tfm_in_queue(queue, crypto_ahash_tfm(tfm)); | 75 | return crypto_tfm_in_queue(queue, crypto_ahash_tfm(tfm)); |
75 | } | 76 | } |
76 | 77 | ||
78 | static inline void *crypto_shash_ctx(struct crypto_shash *tfm) | ||
79 | { | ||
80 | return crypto_tfm_ctx(&tfm->base); | ||
81 | } | ||
82 | |||
77 | #endif /* _CRYPTO_INTERNAL_HASH_H */ | 83 | #endif /* _CRYPTO_INTERNAL_HASH_H */ |
78 | 84 | ||
diff --git a/include/linux/crc32c.h b/include/linux/crc32c.h index 508f512e5a2f..bd8b44d96bdc 100644 --- a/include/linux/crc32c.h +++ b/include/linux/crc32c.h | |||
@@ -3,9 +3,9 @@ | |||
3 | 3 | ||
4 | #include <linux/types.h> | 4 | #include <linux/types.h> |
5 | 5 | ||
6 | extern u32 crc32c_le(u32 crc, unsigned char const *address, size_t length); | 6 | extern u32 crc32c(u32 crc, const void *address, unsigned int length); |
7 | extern u32 crc32c_be(u32 crc, unsigned char const *address, size_t length); | ||
8 | 7 | ||
9 | #define crc32c(seed, data, length) crc32c_le(seed, (unsigned char const *)data, length) | 8 | /* This macro exists for backwards-compatibility. */ |
9 | #define crc32c_le crc32c | ||
10 | 10 | ||
11 | #endif /* _LINUX_CRC32C_H */ | 11 | #endif /* _LINUX_CRC32C_H */ |
diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 3d2317e4af2e..3bacd71509fb 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h | |||
@@ -36,7 +36,8 @@ | |||
36 | #define CRYPTO_ALG_TYPE_ABLKCIPHER 0x00000005 | 36 | #define CRYPTO_ALG_TYPE_ABLKCIPHER 0x00000005 |
37 | #define CRYPTO_ALG_TYPE_GIVCIPHER 0x00000006 | 37 | #define CRYPTO_ALG_TYPE_GIVCIPHER 0x00000006 |
38 | #define CRYPTO_ALG_TYPE_DIGEST 0x00000008 | 38 | #define CRYPTO_ALG_TYPE_DIGEST 0x00000008 |
39 | #define CRYPTO_ALG_TYPE_HASH 0x00000009 | 39 | #define CRYPTO_ALG_TYPE_HASH 0x00000008 |
40 | #define CRYPTO_ALG_TYPE_SHASH 0x00000009 | ||
40 | #define CRYPTO_ALG_TYPE_AHASH 0x0000000a | 41 | #define CRYPTO_ALG_TYPE_AHASH 0x0000000a |
41 | #define CRYPTO_ALG_TYPE_RNG 0x0000000c | 42 | #define CRYPTO_ALG_TYPE_RNG 0x0000000c |
42 | 43 | ||
@@ -220,6 +221,7 @@ struct ablkcipher_alg { | |||
220 | 221 | ||
221 | struct ahash_alg { | 222 | struct ahash_alg { |
222 | int (*init)(struct ahash_request *req); | 223 | int (*init)(struct ahash_request *req); |
224 | int (*reinit)(struct ahash_request *req); | ||
223 | int (*update)(struct ahash_request *req); | 225 | int (*update)(struct ahash_request *req); |
224 | int (*final)(struct ahash_request *req); | 226 | int (*final)(struct ahash_request *req); |
225 | int (*digest)(struct ahash_request *req); | 227 | int (*digest)(struct ahash_request *req); |
@@ -480,6 +482,8 @@ struct crypto_tfm { | |||
480 | struct compress_tfm compress; | 482 | struct compress_tfm compress; |
481 | struct rng_tfm rng; | 483 | struct rng_tfm rng; |
482 | } crt_u; | 484 | } crt_u; |
485 | |||
486 | void (*exit)(struct crypto_tfm *tfm); | ||
483 | 487 | ||
484 | struct crypto_alg *__crt_alg; | 488 | struct crypto_alg *__crt_alg; |
485 | 489 | ||
@@ -544,7 +548,9 @@ struct crypto_attr_u32 { | |||
544 | * Transform user interface. | 548 | * Transform user interface. |
545 | */ | 549 | */ |
546 | 550 | ||
547 | struct crypto_tfm *crypto_alloc_tfm(const char *alg_name, u32 tfm_flags); | 551 | struct crypto_tfm *crypto_alloc_tfm(const char *alg_name, |
552 | const struct crypto_type *frontend, | ||
553 | u32 type, u32 mask); | ||
548 | struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask); | 554 | struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask); |
549 | void crypto_free_tfm(struct crypto_tfm *tfm); | 555 | void crypto_free_tfm(struct crypto_tfm *tfm); |
550 | 556 | ||