diff options
Diffstat (limited to 'include/crypto')
-rw-r--r-- | include/crypto/aead.h | 105 | ||||
-rw-r--r-- | include/crypto/aes.h | 31 | ||||
-rw-r--r-- | include/crypto/algapi.h | 31 | ||||
-rw-r--r-- | include/crypto/authenc.h | 27 | ||||
-rw-r--r-- | include/crypto/ctr.h | 20 | ||||
-rw-r--r-- | include/crypto/des.h | 19 | ||||
-rw-r--r-- | include/crypto/internal/aead.h | 80 | ||||
-rw-r--r-- | include/crypto/internal/skcipher.h | 110 | ||||
-rw-r--r-- | include/crypto/scatterwalk.h | 119 | ||||
-rw-r--r-- | include/crypto/sha.h | 12 | ||||
-rw-r--r-- | include/crypto/skcipher.h | 110 |
11 files changed, 654 insertions, 10 deletions
diff --git a/include/crypto/aead.h b/include/crypto/aead.h new file mode 100644 index 000000000000..0edf949f6369 --- /dev/null +++ b/include/crypto/aead.h | |||
@@ -0,0 +1,105 @@ | |||
1 | /* | ||
2 | * AEAD: Authenticated Encryption with Associated Data | ||
3 | * | ||
4 | * Copyright (c) 2007 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_AEAD_H | ||
14 | #define _CRYPTO_AEAD_H | ||
15 | |||
16 | #include <linux/crypto.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/slab.h> | ||
19 | |||
20 | /** | ||
21 | * struct aead_givcrypt_request - AEAD request with IV generation | ||
22 | * @seq: Sequence number for IV generation | ||
23 | * @giv: Space for generated IV | ||
24 | * @areq: The AEAD request itself | ||
25 | */ | ||
26 | struct aead_givcrypt_request { | ||
27 | u64 seq; | ||
28 | u8 *giv; | ||
29 | |||
30 | struct aead_request areq; | ||
31 | }; | ||
32 | |||
33 | static inline struct crypto_aead *aead_givcrypt_reqtfm( | ||
34 | struct aead_givcrypt_request *req) | ||
35 | { | ||
36 | return crypto_aead_reqtfm(&req->areq); | ||
37 | } | ||
38 | |||
39 | static inline int crypto_aead_givencrypt(struct aead_givcrypt_request *req) | ||
40 | { | ||
41 | struct aead_tfm *crt = crypto_aead_crt(aead_givcrypt_reqtfm(req)); | ||
42 | return crt->givencrypt(req); | ||
43 | }; | ||
44 | |||
45 | static inline int crypto_aead_givdecrypt(struct aead_givcrypt_request *req) | ||
46 | { | ||
47 | struct aead_tfm *crt = crypto_aead_crt(aead_givcrypt_reqtfm(req)); | ||
48 | return crt->givdecrypt(req); | ||
49 | }; | ||
50 | |||
51 | static inline void aead_givcrypt_set_tfm(struct aead_givcrypt_request *req, | ||
52 | struct crypto_aead *tfm) | ||
53 | { | ||
54 | req->areq.base.tfm = crypto_aead_tfm(tfm); | ||
55 | } | ||
56 | |||
57 | static inline struct aead_givcrypt_request *aead_givcrypt_alloc( | ||
58 | struct crypto_aead *tfm, gfp_t gfp) | ||
59 | { | ||
60 | struct aead_givcrypt_request *req; | ||
61 | |||
62 | req = kmalloc(sizeof(struct aead_givcrypt_request) + | ||
63 | crypto_aead_reqsize(tfm), gfp); | ||
64 | |||
65 | if (likely(req)) | ||
66 | aead_givcrypt_set_tfm(req, tfm); | ||
67 | |||
68 | return req; | ||
69 | } | ||
70 | |||
71 | static inline void aead_givcrypt_free(struct aead_givcrypt_request *req) | ||
72 | { | ||
73 | kfree(req); | ||
74 | } | ||
75 | |||
76 | static inline void aead_givcrypt_set_callback( | ||
77 | struct aead_givcrypt_request *req, u32 flags, | ||
78 | crypto_completion_t complete, void *data) | ||
79 | { | ||
80 | aead_request_set_callback(&req->areq, flags, complete, data); | ||
81 | } | ||
82 | |||
83 | static inline void aead_givcrypt_set_crypt(struct aead_givcrypt_request *req, | ||
84 | struct scatterlist *src, | ||
85 | struct scatterlist *dst, | ||
86 | unsigned int nbytes, void *iv) | ||
87 | { | ||
88 | aead_request_set_crypt(&req->areq, src, dst, nbytes, iv); | ||
89 | } | ||
90 | |||
91 | static inline void aead_givcrypt_set_assoc(struct aead_givcrypt_request *req, | ||
92 | struct scatterlist *assoc, | ||
93 | unsigned int assoclen) | ||
94 | { | ||
95 | aead_request_set_assoc(&req->areq, assoc, assoclen); | ||
96 | } | ||
97 | |||
98 | static inline void aead_givcrypt_set_giv(struct aead_givcrypt_request *req, | ||
99 | u8 *giv, u64 seq) | ||
100 | { | ||
101 | req->giv = giv; | ||
102 | req->seq = seq; | ||
103 | } | ||
104 | |||
105 | #endif /* _CRYPTO_AEAD_H */ | ||
diff --git a/include/crypto/aes.h b/include/crypto/aes.h new file mode 100644 index 000000000000..d480b76715a8 --- /dev/null +++ b/include/crypto/aes.h | |||
@@ -0,0 +1,31 @@ | |||
1 | /* | ||
2 | * Common values for AES algorithms | ||
3 | */ | ||
4 | |||
5 | #ifndef _CRYPTO_AES_H | ||
6 | #define _CRYPTO_AES_H | ||
7 | |||
8 | #include <linux/types.h> | ||
9 | #include <linux/crypto.h> | ||
10 | |||
11 | #define AES_MIN_KEY_SIZE 16 | ||
12 | #define AES_MAX_KEY_SIZE 32 | ||
13 | #define AES_KEYSIZE_128 16 | ||
14 | #define AES_KEYSIZE_192 24 | ||
15 | #define AES_KEYSIZE_256 32 | ||
16 | #define AES_BLOCK_SIZE 16 | ||
17 | |||
18 | struct crypto_aes_ctx { | ||
19 | u32 key_length; | ||
20 | u32 key_enc[60]; | ||
21 | u32 key_dec[60]; | ||
22 | }; | ||
23 | |||
24 | extern u32 crypto_ft_tab[4][256]; | ||
25 | extern u32 crypto_fl_tab[4][256]; | ||
26 | extern u32 crypto_it_tab[4][256]; | ||
27 | extern u32 crypto_il_tab[4][256]; | ||
28 | |||
29 | int crypto_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, | ||
30 | unsigned int key_len); | ||
31 | #endif | ||
diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index b9b05d399d2b..60d06e784be3 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h | |||
@@ -111,8 +111,15 @@ void crypto_drop_spawn(struct crypto_spawn *spawn); | |||
111 | struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type, | 111 | struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type, |
112 | u32 mask); | 112 | u32 mask); |
113 | 113 | ||
114 | static inline void crypto_set_spawn(struct crypto_spawn *spawn, | ||
115 | struct crypto_instance *inst) | ||
116 | { | ||
117 | spawn->inst = inst; | ||
118 | } | ||
119 | |||
114 | struct crypto_attr_type *crypto_get_attr_type(struct rtattr **tb); | 120 | struct crypto_attr_type *crypto_get_attr_type(struct rtattr **tb); |
115 | int crypto_check_attr_type(struct rtattr **tb, u32 type); | 121 | int crypto_check_attr_type(struct rtattr **tb, u32 type); |
122 | const char *crypto_attr_alg_name(struct rtattr *rta); | ||
116 | struct crypto_alg *crypto_attr_alg(struct rtattr *rta, u32 type, u32 mask); | 123 | struct crypto_alg *crypto_attr_alg(struct rtattr *rta, u32 type, u32 mask); |
117 | int crypto_attr_u32(struct rtattr *rta, u32 *num); | 124 | int crypto_attr_u32(struct rtattr *rta, u32 *num); |
118 | struct crypto_instance *crypto_alloc_instance(const char *name, | 125 | struct crypto_instance *crypto_alloc_instance(const char *name, |
@@ -124,6 +131,10 @@ int crypto_enqueue_request(struct crypto_queue *queue, | |||
124 | struct crypto_async_request *crypto_dequeue_request(struct crypto_queue *queue); | 131 | struct crypto_async_request *crypto_dequeue_request(struct crypto_queue *queue); |
125 | int crypto_tfm_in_queue(struct crypto_queue *queue, struct crypto_tfm *tfm); | 132 | int crypto_tfm_in_queue(struct crypto_queue *queue, struct crypto_tfm *tfm); |
126 | 133 | ||
134 | /* These functions require the input/output to be aligned as u32. */ | ||
135 | void crypto_inc(u8 *a, unsigned int size); | ||
136 | void crypto_xor(u8 *dst, const u8 *src, unsigned int size); | ||
137 | |||
127 | int blkcipher_walk_done(struct blkcipher_desc *desc, | 138 | int blkcipher_walk_done(struct blkcipher_desc *desc, |
128 | struct blkcipher_walk *walk, int err); | 139 | struct blkcipher_walk *walk, int err); |
129 | int blkcipher_walk_virt(struct blkcipher_desc *desc, | 140 | int blkcipher_walk_virt(struct blkcipher_desc *desc, |
@@ -187,20 +198,11 @@ static inline struct crypto_instance *crypto_aead_alg_instance( | |||
187 | return crypto_tfm_alg_instance(&aead->base); | 198 | return crypto_tfm_alg_instance(&aead->base); |
188 | } | 199 | } |
189 | 200 | ||
190 | static inline struct crypto_ablkcipher *crypto_spawn_ablkcipher( | ||
191 | struct crypto_spawn *spawn) | ||
192 | { | ||
193 | u32 type = CRYPTO_ALG_TYPE_BLKCIPHER; | ||
194 | u32 mask = CRYPTO_ALG_TYPE_MASK; | ||
195 | |||
196 | return __crypto_ablkcipher_cast(crypto_spawn_tfm(spawn, type, mask)); | ||
197 | } | ||
198 | |||
199 | static inline struct crypto_blkcipher *crypto_spawn_blkcipher( | 201 | static inline struct crypto_blkcipher *crypto_spawn_blkcipher( |
200 | struct crypto_spawn *spawn) | 202 | struct crypto_spawn *spawn) |
201 | { | 203 | { |
202 | u32 type = CRYPTO_ALG_TYPE_BLKCIPHER; | 204 | u32 type = CRYPTO_ALG_TYPE_BLKCIPHER; |
203 | u32 mask = CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC; | 205 | u32 mask = CRYPTO_ALG_TYPE_MASK; |
204 | 206 | ||
205 | return __crypto_blkcipher_cast(crypto_spawn_tfm(spawn, type, mask)); | 207 | return __crypto_blkcipher_cast(crypto_spawn_tfm(spawn, type, mask)); |
206 | } | 208 | } |
@@ -303,5 +305,14 @@ static inline struct crypto_alg *crypto_get_attr_alg(struct rtattr **tb, | |||
303 | return crypto_attr_alg(tb[1], type, mask); | 305 | return crypto_attr_alg(tb[1], type, mask); |
304 | } | 306 | } |
305 | 307 | ||
308 | /* | ||
309 | * Returns CRYPTO_ALG_ASYNC if type/mask requires the use of sync algorithms. | ||
310 | * Otherwise returns zero. | ||
311 | */ | ||
312 | static inline int crypto_requires_sync(u32 type, u32 mask) | ||
313 | { | ||
314 | return (type ^ CRYPTO_ALG_ASYNC) & mask & CRYPTO_ALG_ASYNC; | ||
315 | } | ||
316 | |||
306 | #endif /* _CRYPTO_ALGAPI_H */ | 317 | #endif /* _CRYPTO_ALGAPI_H */ |
307 | 318 | ||
diff --git a/include/crypto/authenc.h b/include/crypto/authenc.h new file mode 100644 index 000000000000..e47b044929a8 --- /dev/null +++ b/include/crypto/authenc.h | |||
@@ -0,0 +1,27 @@ | |||
1 | /* | ||
2 | * Authenc: Simple AEAD wrapper for IPsec | ||
3 | * | ||
4 | * Copyright (c) 2007 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 | #ifndef _CRYPTO_AUTHENC_H | ||
13 | #define _CRYPTO_AUTHENC_H | ||
14 | |||
15 | #include <linux/types.h> | ||
16 | |||
17 | enum { | ||
18 | CRYPTO_AUTHENC_KEYA_UNSPEC, | ||
19 | CRYPTO_AUTHENC_KEYA_PARAM, | ||
20 | }; | ||
21 | |||
22 | struct crypto_authenc_key_param { | ||
23 | __be32 enckeylen; | ||
24 | }; | ||
25 | |||
26 | #endif /* _CRYPTO_AUTHENC_H */ | ||
27 | |||
diff --git a/include/crypto/ctr.h b/include/crypto/ctr.h new file mode 100644 index 000000000000..4180fc080e3b --- /dev/null +++ b/include/crypto/ctr.h | |||
@@ -0,0 +1,20 @@ | |||
1 | /* | ||
2 | * CTR: Counter mode | ||
3 | * | ||
4 | * Copyright (c) 2007 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_CTR_H | ||
14 | #define _CRYPTO_CTR_H | ||
15 | |||
16 | #define CTR_RFC3686_NONCE_SIZE 4 | ||
17 | #define CTR_RFC3686_IV_SIZE 8 | ||
18 | #define CTR_RFC3686_BLOCK_SIZE 16 | ||
19 | |||
20 | #endif /* _CRYPTO_CTR_H */ | ||
diff --git a/include/crypto/des.h b/include/crypto/des.h new file mode 100644 index 000000000000..2971c6304ade --- /dev/null +++ b/include/crypto/des.h | |||
@@ -0,0 +1,19 @@ | |||
1 | /* | ||
2 | * DES & Triple DES EDE Cipher Algorithms. | ||
3 | */ | ||
4 | |||
5 | #ifndef __CRYPTO_DES_H | ||
6 | #define __CRYPTO_DES_H | ||
7 | |||
8 | #define DES_KEY_SIZE 8 | ||
9 | #define DES_EXPKEY_WORDS 32 | ||
10 | #define DES_BLOCK_SIZE 8 | ||
11 | |||
12 | #define DES3_EDE_KEY_SIZE (3 * DES_KEY_SIZE) | ||
13 | #define DES3_EDE_EXPKEY_WORDS (3 * DES_EXPKEY_WORDS) | ||
14 | #define DES3_EDE_BLOCK_SIZE DES_BLOCK_SIZE | ||
15 | |||
16 | |||
17 | extern unsigned long des_ekey(u32 *pe, const u8 *k); | ||
18 | |||
19 | #endif /* __CRYPTO_DES_H */ | ||
diff --git a/include/crypto/internal/aead.h b/include/crypto/internal/aead.h new file mode 100644 index 000000000000..d838c945575a --- /dev/null +++ b/include/crypto/internal/aead.h | |||
@@ -0,0 +1,80 @@ | |||
1 | /* | ||
2 | * AEAD: Authenticated Encryption with Associated Data | ||
3 | * | ||
4 | * Copyright (c) 2007 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_INTERNAL_AEAD_H | ||
14 | #define _CRYPTO_INTERNAL_AEAD_H | ||
15 | |||
16 | #include <crypto/aead.h> | ||
17 | #include <crypto/algapi.h> | ||
18 | #include <linux/types.h> | ||
19 | |||
20 | struct rtattr; | ||
21 | |||
22 | struct crypto_aead_spawn { | ||
23 | struct crypto_spawn base; | ||
24 | }; | ||
25 | |||
26 | extern const struct crypto_type crypto_nivaead_type; | ||
27 | |||
28 | static inline void crypto_set_aead_spawn( | ||
29 | struct crypto_aead_spawn *spawn, struct crypto_instance *inst) | ||
30 | { | ||
31 | crypto_set_spawn(&spawn->base, inst); | ||
32 | } | ||
33 | |||
34 | int crypto_grab_aead(struct crypto_aead_spawn *spawn, const char *name, | ||
35 | u32 type, u32 mask); | ||
36 | |||
37 | static inline void crypto_drop_aead(struct crypto_aead_spawn *spawn) | ||
38 | { | ||
39 | crypto_drop_spawn(&spawn->base); | ||
40 | } | ||
41 | |||
42 | static inline struct crypto_alg *crypto_aead_spawn_alg( | ||
43 | struct crypto_aead_spawn *spawn) | ||
44 | { | ||
45 | return spawn->base.alg; | ||
46 | } | ||
47 | |||
48 | static inline struct crypto_aead *crypto_spawn_aead( | ||
49 | struct crypto_aead_spawn *spawn) | ||
50 | { | ||
51 | return __crypto_aead_cast( | ||
52 | crypto_spawn_tfm(&spawn->base, CRYPTO_ALG_TYPE_AEAD, | ||
53 | CRYPTO_ALG_TYPE_MASK)); | ||
54 | } | ||
55 | |||
56 | struct crypto_instance *aead_geniv_alloc(struct crypto_template *tmpl, | ||
57 | struct rtattr **tb, u32 type, | ||
58 | u32 mask); | ||
59 | void aead_geniv_free(struct crypto_instance *inst); | ||
60 | int aead_geniv_init(struct crypto_tfm *tfm); | ||
61 | void aead_geniv_exit(struct crypto_tfm *tfm); | ||
62 | |||
63 | static inline struct crypto_aead *aead_geniv_base(struct crypto_aead *geniv) | ||
64 | { | ||
65 | return crypto_aead_crt(geniv)->base; | ||
66 | } | ||
67 | |||
68 | static inline void *aead_givcrypt_reqctx(struct aead_givcrypt_request *req) | ||
69 | { | ||
70 | return aead_request_ctx(&req->areq); | ||
71 | } | ||
72 | |||
73 | static inline void aead_givcrypt_complete(struct aead_givcrypt_request *req, | ||
74 | int err) | ||
75 | { | ||
76 | aead_request_complete(&req->areq, err); | ||
77 | } | ||
78 | |||
79 | #endif /* _CRYPTO_INTERNAL_AEAD_H */ | ||
80 | |||
diff --git a/include/crypto/internal/skcipher.h b/include/crypto/internal/skcipher.h new file mode 100644 index 000000000000..2ba42cd7d6aa --- /dev/null +++ b/include/crypto/internal/skcipher.h | |||
@@ -0,0 +1,110 @@ | |||
1 | /* | ||
2 | * Symmetric key ciphers. | ||
3 | * | ||
4 | * Copyright (c) 2007 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_INTERNAL_SKCIPHER_H | ||
14 | #define _CRYPTO_INTERNAL_SKCIPHER_H | ||
15 | |||
16 | #include <crypto/algapi.h> | ||
17 | #include <crypto/skcipher.h> | ||
18 | #include <linux/types.h> | ||
19 | |||
20 | struct rtattr; | ||
21 | |||
22 | struct crypto_skcipher_spawn { | ||
23 | struct crypto_spawn base; | ||
24 | }; | ||
25 | |||
26 | extern const struct crypto_type crypto_givcipher_type; | ||
27 | |||
28 | static inline void crypto_set_skcipher_spawn( | ||
29 | struct crypto_skcipher_spawn *spawn, struct crypto_instance *inst) | ||
30 | { | ||
31 | crypto_set_spawn(&spawn->base, inst); | ||
32 | } | ||
33 | |||
34 | int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name, | ||
35 | u32 type, u32 mask); | ||
36 | |||
37 | static inline void crypto_drop_skcipher(struct crypto_skcipher_spawn *spawn) | ||
38 | { | ||
39 | crypto_drop_spawn(&spawn->base); | ||
40 | } | ||
41 | |||
42 | static inline struct crypto_alg *crypto_skcipher_spawn_alg( | ||
43 | struct crypto_skcipher_spawn *spawn) | ||
44 | { | ||
45 | return spawn->base.alg; | ||
46 | } | ||
47 | |||
48 | static inline struct crypto_ablkcipher *crypto_spawn_skcipher( | ||
49 | struct crypto_skcipher_spawn *spawn) | ||
50 | { | ||
51 | return __crypto_ablkcipher_cast( | ||
52 | crypto_spawn_tfm(&spawn->base, crypto_skcipher_type(0), | ||
53 | crypto_skcipher_mask(0))); | ||
54 | } | ||
55 | |||
56 | int skcipher_null_givencrypt(struct skcipher_givcrypt_request *req); | ||
57 | int skcipher_null_givdecrypt(struct skcipher_givcrypt_request *req); | ||
58 | const char *crypto_default_geniv(const struct crypto_alg *alg); | ||
59 | |||
60 | struct crypto_instance *skcipher_geniv_alloc(struct crypto_template *tmpl, | ||
61 | struct rtattr **tb, u32 type, | ||
62 | u32 mask); | ||
63 | void skcipher_geniv_free(struct crypto_instance *inst); | ||
64 | int skcipher_geniv_init(struct crypto_tfm *tfm); | ||
65 | void skcipher_geniv_exit(struct crypto_tfm *tfm); | ||
66 | |||
67 | static inline struct crypto_ablkcipher *skcipher_geniv_cipher( | ||
68 | struct crypto_ablkcipher *geniv) | ||
69 | { | ||
70 | return crypto_ablkcipher_crt(geniv)->base; | ||
71 | } | ||
72 | |||
73 | static inline int skcipher_enqueue_givcrypt( | ||
74 | struct crypto_queue *queue, struct skcipher_givcrypt_request *request) | ||
75 | { | ||
76 | return ablkcipher_enqueue_request(queue, &request->creq); | ||
77 | } | ||
78 | |||
79 | static inline struct skcipher_givcrypt_request *skcipher_dequeue_givcrypt( | ||
80 | struct crypto_queue *queue) | ||
81 | { | ||
82 | return container_of(ablkcipher_dequeue_request(queue), | ||
83 | struct skcipher_givcrypt_request, creq); | ||
84 | } | ||
85 | |||
86 | static inline void *skcipher_givcrypt_reqctx( | ||
87 | struct skcipher_givcrypt_request *req) | ||
88 | { | ||
89 | return ablkcipher_request_ctx(&req->creq); | ||
90 | } | ||
91 | |||
92 | static inline void ablkcipher_request_complete(struct ablkcipher_request *req, | ||
93 | int err) | ||
94 | { | ||
95 | req->base.complete(&req->base, err); | ||
96 | } | ||
97 | |||
98 | static inline void skcipher_givcrypt_complete( | ||
99 | struct skcipher_givcrypt_request *req, int err) | ||
100 | { | ||
101 | ablkcipher_request_complete(&req->creq, err); | ||
102 | } | ||
103 | |||
104 | static inline u32 ablkcipher_request_flags(struct ablkcipher_request *req) | ||
105 | { | ||
106 | return req->base.flags; | ||
107 | } | ||
108 | |||
109 | #endif /* _CRYPTO_INTERNAL_SKCIPHER_H */ | ||
110 | |||
diff --git a/include/crypto/scatterwalk.h b/include/crypto/scatterwalk.h new file mode 100644 index 000000000000..224658b8d806 --- /dev/null +++ b/include/crypto/scatterwalk.h | |||
@@ -0,0 +1,119 @@ | |||
1 | /* | ||
2 | * Cryptographic scatter and gather helpers. | ||
3 | * | ||
4 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> | ||
5 | * Copyright (c) 2002 Adam J. Richter <adam@yggdrasil.com> | ||
6 | * Copyright (c) 2004 Jean-Luc Cooke <jlcooke@certainkey.com> | ||
7 | * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify it | ||
10 | * under the terms of the GNU General Public License as published by the Free | ||
11 | * Software Foundation; either version 2 of the License, or (at your option) | ||
12 | * any later version. | ||
13 | * | ||
14 | */ | ||
15 | |||
16 | #ifndef _CRYPTO_SCATTERWALK_H | ||
17 | #define _CRYPTO_SCATTERWALK_H | ||
18 | |||
19 | #include <asm/kmap_types.h> | ||
20 | #include <crypto/algapi.h> | ||
21 | #include <linux/hardirq.h> | ||
22 | #include <linux/highmem.h> | ||
23 | #include <linux/kernel.h> | ||
24 | #include <linux/mm.h> | ||
25 | #include <linux/scatterlist.h> | ||
26 | #include <linux/sched.h> | ||
27 | |||
28 | static inline enum km_type crypto_kmap_type(int out) | ||
29 | { | ||
30 | enum km_type type; | ||
31 | |||
32 | if (in_softirq()) | ||
33 | type = out * (KM_SOFTIRQ1 - KM_SOFTIRQ0) + KM_SOFTIRQ0; | ||
34 | else | ||
35 | type = out * (KM_USER1 - KM_USER0) + KM_USER0; | ||
36 | |||
37 | return type; | ||
38 | } | ||
39 | |||
40 | static inline void *crypto_kmap(struct page *page, int out) | ||
41 | { | ||
42 | return kmap_atomic(page, crypto_kmap_type(out)); | ||
43 | } | ||
44 | |||
45 | static inline void crypto_kunmap(void *vaddr, int out) | ||
46 | { | ||
47 | kunmap_atomic(vaddr, crypto_kmap_type(out)); | ||
48 | } | ||
49 | |||
50 | static inline void crypto_yield(u32 flags) | ||
51 | { | ||
52 | if (flags & CRYPTO_TFM_REQ_MAY_SLEEP) | ||
53 | cond_resched(); | ||
54 | } | ||
55 | |||
56 | static inline void scatterwalk_sg_chain(struct scatterlist *sg1, int num, | ||
57 | struct scatterlist *sg2) | ||
58 | { | ||
59 | sg_set_page(&sg1[num - 1], (void *)sg2, 0, 0); | ||
60 | } | ||
61 | |||
62 | static inline struct scatterlist *scatterwalk_sg_next(struct scatterlist *sg) | ||
63 | { | ||
64 | return (++sg)->length ? sg : (void *)sg_page(sg); | ||
65 | } | ||
66 | |||
67 | static inline unsigned long scatterwalk_samebuf(struct scatter_walk *walk_in, | ||
68 | struct scatter_walk *walk_out) | ||
69 | { | ||
70 | return !(((sg_page(walk_in->sg) - sg_page(walk_out->sg)) << PAGE_SHIFT) + | ||
71 | (int)(walk_in->offset - walk_out->offset)); | ||
72 | } | ||
73 | |||
74 | static inline unsigned int scatterwalk_pagelen(struct scatter_walk *walk) | ||
75 | { | ||
76 | unsigned int len = walk->sg->offset + walk->sg->length - walk->offset; | ||
77 | unsigned int len_this_page = offset_in_page(~walk->offset) + 1; | ||
78 | return len_this_page > len ? len : len_this_page; | ||
79 | } | ||
80 | |||
81 | static inline unsigned int scatterwalk_clamp(struct scatter_walk *walk, | ||
82 | unsigned int nbytes) | ||
83 | { | ||
84 | unsigned int len_this_page = scatterwalk_pagelen(walk); | ||
85 | return nbytes > len_this_page ? len_this_page : nbytes; | ||
86 | } | ||
87 | |||
88 | static inline void scatterwalk_advance(struct scatter_walk *walk, | ||
89 | unsigned int nbytes) | ||
90 | { | ||
91 | walk->offset += nbytes; | ||
92 | } | ||
93 | |||
94 | static inline unsigned int scatterwalk_aligned(struct scatter_walk *walk, | ||
95 | unsigned int alignmask) | ||
96 | { | ||
97 | return !(walk->offset & alignmask); | ||
98 | } | ||
99 | |||
100 | static inline struct page *scatterwalk_page(struct scatter_walk *walk) | ||
101 | { | ||
102 | return sg_page(walk->sg) + (walk->offset >> PAGE_SHIFT); | ||
103 | } | ||
104 | |||
105 | static inline void scatterwalk_unmap(void *vaddr, int out) | ||
106 | { | ||
107 | crypto_kunmap(vaddr, out); | ||
108 | } | ||
109 | |||
110 | void scatterwalk_start(struct scatter_walk *walk, struct scatterlist *sg); | ||
111 | void scatterwalk_copychunks(void *buf, struct scatter_walk *walk, | ||
112 | size_t nbytes, int out); | ||
113 | void *scatterwalk_map(struct scatter_walk *walk, int out); | ||
114 | void scatterwalk_done(struct scatter_walk *walk, int out, int more); | ||
115 | |||
116 | void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg, | ||
117 | unsigned int start, unsigned int nbytes, int out); | ||
118 | |||
119 | #endif /* _CRYPTO_SCATTERWALK_H */ | ||
diff --git a/include/crypto/sha.h b/include/crypto/sha.h index 0686e1f7a24b..c0ccc2b1a2d8 100644 --- a/include/crypto/sha.h +++ b/include/crypto/sha.h | |||
@@ -8,6 +8,9 @@ | |||
8 | #define SHA1_DIGEST_SIZE 20 | 8 | #define SHA1_DIGEST_SIZE 20 |
9 | #define SHA1_BLOCK_SIZE 64 | 9 | #define SHA1_BLOCK_SIZE 64 |
10 | 10 | ||
11 | #define SHA224_DIGEST_SIZE 28 | ||
12 | #define SHA224_BLOCK_SIZE 64 | ||
13 | |||
11 | #define SHA256_DIGEST_SIZE 32 | 14 | #define SHA256_DIGEST_SIZE 32 |
12 | #define SHA256_BLOCK_SIZE 64 | 15 | #define SHA256_BLOCK_SIZE 64 |
13 | 16 | ||
@@ -23,6 +26,15 @@ | |||
23 | #define SHA1_H3 0x10325476UL | 26 | #define SHA1_H3 0x10325476UL |
24 | #define SHA1_H4 0xc3d2e1f0UL | 27 | #define SHA1_H4 0xc3d2e1f0UL |
25 | 28 | ||
29 | #define SHA224_H0 0xc1059ed8UL | ||
30 | #define SHA224_H1 0x367cd507UL | ||
31 | #define SHA224_H2 0x3070dd17UL | ||
32 | #define SHA224_H3 0xf70e5939UL | ||
33 | #define SHA224_H4 0xffc00b31UL | ||
34 | #define SHA224_H5 0x68581511UL | ||
35 | #define SHA224_H6 0x64f98fa7UL | ||
36 | #define SHA224_H7 0xbefa4fa4UL | ||
37 | |||
26 | #define SHA256_H0 0x6a09e667UL | 38 | #define SHA256_H0 0x6a09e667UL |
27 | #define SHA256_H1 0xbb67ae85UL | 39 | #define SHA256_H1 0xbb67ae85UL |
28 | #define SHA256_H2 0x3c6ef372UL | 40 | #define SHA256_H2 0x3c6ef372UL |
diff --git a/include/crypto/skcipher.h b/include/crypto/skcipher.h new file mode 100644 index 000000000000..25fd6126522d --- /dev/null +++ b/include/crypto/skcipher.h | |||
@@ -0,0 +1,110 @@ | |||
1 | /* | ||
2 | * Symmetric key ciphers. | ||
3 | * | ||
4 | * Copyright (c) 2007 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_SKCIPHER_H | ||
14 | #define _CRYPTO_SKCIPHER_H | ||
15 | |||
16 | #include <linux/crypto.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/slab.h> | ||
19 | |||
20 | /** | ||
21 | * struct skcipher_givcrypt_request - Crypto request with IV generation | ||
22 | * @seq: Sequence number for IV generation | ||
23 | * @giv: Space for generated IV | ||
24 | * @creq: The crypto request itself | ||
25 | */ | ||
26 | struct skcipher_givcrypt_request { | ||
27 | u64 seq; | ||
28 | u8 *giv; | ||
29 | |||
30 | struct ablkcipher_request creq; | ||
31 | }; | ||
32 | |||
33 | static inline struct crypto_ablkcipher *skcipher_givcrypt_reqtfm( | ||
34 | struct skcipher_givcrypt_request *req) | ||
35 | { | ||
36 | return crypto_ablkcipher_reqtfm(&req->creq); | ||
37 | } | ||
38 | |||
39 | static inline int crypto_skcipher_givencrypt( | ||
40 | struct skcipher_givcrypt_request *req) | ||
41 | { | ||
42 | struct ablkcipher_tfm *crt = | ||
43 | crypto_ablkcipher_crt(skcipher_givcrypt_reqtfm(req)); | ||
44 | return crt->givencrypt(req); | ||
45 | }; | ||
46 | |||
47 | static inline int crypto_skcipher_givdecrypt( | ||
48 | struct skcipher_givcrypt_request *req) | ||
49 | { | ||
50 | struct ablkcipher_tfm *crt = | ||
51 | crypto_ablkcipher_crt(skcipher_givcrypt_reqtfm(req)); | ||
52 | return crt->givdecrypt(req); | ||
53 | }; | ||
54 | |||
55 | static inline void skcipher_givcrypt_set_tfm( | ||
56 | struct skcipher_givcrypt_request *req, struct crypto_ablkcipher *tfm) | ||
57 | { | ||
58 | req->creq.base.tfm = crypto_ablkcipher_tfm(tfm); | ||
59 | } | ||
60 | |||
61 | static inline struct skcipher_givcrypt_request *skcipher_givcrypt_cast( | ||
62 | struct crypto_async_request *req) | ||
63 | { | ||
64 | return container_of(ablkcipher_request_cast(req), | ||
65 | struct skcipher_givcrypt_request, creq); | ||
66 | } | ||
67 | |||
68 | static inline struct skcipher_givcrypt_request *skcipher_givcrypt_alloc( | ||
69 | struct crypto_ablkcipher *tfm, gfp_t gfp) | ||
70 | { | ||
71 | struct skcipher_givcrypt_request *req; | ||
72 | |||
73 | req = kmalloc(sizeof(struct skcipher_givcrypt_request) + | ||
74 | crypto_ablkcipher_reqsize(tfm), gfp); | ||
75 | |||
76 | if (likely(req)) | ||
77 | skcipher_givcrypt_set_tfm(req, tfm); | ||
78 | |||
79 | return req; | ||
80 | } | ||
81 | |||
82 | static inline void skcipher_givcrypt_free(struct skcipher_givcrypt_request *req) | ||
83 | { | ||
84 | kfree(req); | ||
85 | } | ||
86 | |||
87 | static inline void skcipher_givcrypt_set_callback( | ||
88 | struct skcipher_givcrypt_request *req, u32 flags, | ||
89 | crypto_completion_t complete, void *data) | ||
90 | { | ||
91 | ablkcipher_request_set_callback(&req->creq, flags, complete, data); | ||
92 | } | ||
93 | |||
94 | static inline void skcipher_givcrypt_set_crypt( | ||
95 | struct skcipher_givcrypt_request *req, | ||
96 | struct scatterlist *src, struct scatterlist *dst, | ||
97 | unsigned int nbytes, void *iv) | ||
98 | { | ||
99 | ablkcipher_request_set_crypt(&req->creq, src, dst, nbytes, iv); | ||
100 | } | ||
101 | |||
102 | static inline void skcipher_givcrypt_set_giv( | ||
103 | struct skcipher_givcrypt_request *req, u8 *giv, u64 seq) | ||
104 | { | ||
105 | req->giv = giv; | ||
106 | req->seq = seq; | ||
107 | } | ||
108 | |||
109 | #endif /* _CRYPTO_SKCIPHER_H */ | ||
110 | |||