diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-01-25 11:38:25 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-01-25 11:38:25 -0500 |
commit | eba0e319c12fb098d66316a8eafbaaa9174a07c3 (patch) | |
tree | b2703117db9e36bb3510654efd55361f61c54742 /include | |
parent | df8dc74e8a383eaf2d9b44b80a71ec6f0e52b42e (diff) | |
parent | 15e7b4452b72ae890f2fcb027b4c4fa63a1c9a7a (diff) |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (125 commits)
[CRYPTO] twofish: Merge common glue code
[CRYPTO] hifn_795x: Fixup container_of() usage
[CRYPTO] cast6: inline bloat--
[CRYPTO] api: Set default CRYPTO_MINALIGN to unsigned long long
[CRYPTO] tcrypt: Make xcbc available as a standalone test
[CRYPTO] xcbc: Remove bogus hash/cipher test
[CRYPTO] xcbc: Fix algorithm leak when block size check fails
[CRYPTO] tcrypt: Zero axbuf in the right function
[CRYPTO] padlock: Only reset the key once for each CBC and ECB operation
[CRYPTO] api: Include sched.h for cond_resched in scatterwalk.h
[CRYPTO] salsa20-asm: Remove unnecessary dependency on CRYPTO_SALSA20
[CRYPTO] tcrypt: Add select of AEAD
[CRYPTO] salsa20: Add x86-64 assembly version
[CRYPTO] salsa20_i586: Salsa20 stream cipher algorithm (i586 version)
[CRYPTO] gcm: Introduce rfc4106
[CRYPTO] api: Show async type
[CRYPTO] chainiv: Avoid lock spinning where possible
[CRYPTO] seqiv: Add select AEAD in Kconfig
[CRYPTO] scatterwalk: Handle zero nbytes in scatterwalk_map_and_copy
[CRYPTO] null: Allow setkey on digest_null
...
Diffstat (limited to 'include')
-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 | ||||
-rw-r--r-- | include/linux/crypto.h | 103 | ||||
-rw-r--r-- | include/linux/hw_random.h | 2 |
13 files changed, 723 insertions, 46 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 | |||
diff --git a/include/linux/crypto.h b/include/linux/crypto.h index f3110ebe894a..5e02d1b46370 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h | |||
@@ -33,10 +33,13 @@ | |||
33 | #define CRYPTO_ALG_TYPE_DIGEST 0x00000002 | 33 | #define CRYPTO_ALG_TYPE_DIGEST 0x00000002 |
34 | #define CRYPTO_ALG_TYPE_HASH 0x00000003 | 34 | #define CRYPTO_ALG_TYPE_HASH 0x00000003 |
35 | #define CRYPTO_ALG_TYPE_BLKCIPHER 0x00000004 | 35 | #define CRYPTO_ALG_TYPE_BLKCIPHER 0x00000004 |
36 | #define CRYPTO_ALG_TYPE_COMPRESS 0x00000005 | 36 | #define CRYPTO_ALG_TYPE_ABLKCIPHER 0x00000005 |
37 | #define CRYPTO_ALG_TYPE_AEAD 0x00000006 | 37 | #define CRYPTO_ALG_TYPE_GIVCIPHER 0x00000006 |
38 | #define CRYPTO_ALG_TYPE_COMPRESS 0x00000008 | ||
39 | #define CRYPTO_ALG_TYPE_AEAD 0x00000009 | ||
38 | 40 | ||
39 | #define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e | 41 | #define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e |
42 | #define CRYPTO_ALG_TYPE_BLKCIPHER_MASK 0x0000000c | ||
40 | 43 | ||
41 | #define CRYPTO_ALG_LARVAL 0x00000010 | 44 | #define CRYPTO_ALG_LARVAL 0x00000010 |
42 | #define CRYPTO_ALG_DEAD 0x00000020 | 45 | #define CRYPTO_ALG_DEAD 0x00000020 |
@@ -50,6 +53,12 @@ | |||
50 | #define CRYPTO_ALG_NEED_FALLBACK 0x00000100 | 53 | #define CRYPTO_ALG_NEED_FALLBACK 0x00000100 |
51 | 54 | ||
52 | /* | 55 | /* |
56 | * This bit is set for symmetric key ciphers that have already been wrapped | ||
57 | * with a generic IV generator to prevent them from being wrapped again. | ||
58 | */ | ||
59 | #define CRYPTO_ALG_GENIV 0x00000200 | ||
60 | |||
61 | /* | ||
53 | * Transform masks and values (for crt_flags). | 62 | * Transform masks and values (for crt_flags). |
54 | */ | 63 | */ |
55 | #define CRYPTO_TFM_REQ_MASK 0x000fff00 | 64 | #define CRYPTO_TFM_REQ_MASK 0x000fff00 |
@@ -81,13 +90,11 @@ | |||
81 | #define CRYPTO_MINALIGN ARCH_KMALLOC_MINALIGN | 90 | #define CRYPTO_MINALIGN ARCH_KMALLOC_MINALIGN |
82 | #elif defined(ARCH_SLAB_MINALIGN) | 91 | #elif defined(ARCH_SLAB_MINALIGN) |
83 | #define CRYPTO_MINALIGN ARCH_SLAB_MINALIGN | 92 | #define CRYPTO_MINALIGN ARCH_SLAB_MINALIGN |
93 | #else | ||
94 | #define CRYPTO_MINALIGN __alignof__(unsigned long long) | ||
84 | #endif | 95 | #endif |
85 | 96 | ||
86 | #ifdef CRYPTO_MINALIGN | ||
87 | #define CRYPTO_MINALIGN_ATTR __attribute__ ((__aligned__(CRYPTO_MINALIGN))) | 97 | #define CRYPTO_MINALIGN_ATTR __attribute__ ((__aligned__(CRYPTO_MINALIGN))) |
88 | #else | ||
89 | #define CRYPTO_MINALIGN_ATTR | ||
90 | #endif | ||
91 | 98 | ||
92 | struct scatterlist; | 99 | struct scatterlist; |
93 | struct crypto_ablkcipher; | 100 | struct crypto_ablkcipher; |
@@ -97,6 +104,8 @@ struct crypto_blkcipher; | |||
97 | struct crypto_hash; | 104 | struct crypto_hash; |
98 | struct crypto_tfm; | 105 | struct crypto_tfm; |
99 | struct crypto_type; | 106 | struct crypto_type; |
107 | struct aead_givcrypt_request; | ||
108 | struct skcipher_givcrypt_request; | ||
100 | 109 | ||
101 | typedef void (*crypto_completion_t)(struct crypto_async_request *req, int err); | 110 | typedef void (*crypto_completion_t)(struct crypto_async_request *req, int err); |
102 | 111 | ||
@@ -176,6 +185,10 @@ struct ablkcipher_alg { | |||
176 | unsigned int keylen); | 185 | unsigned int keylen); |
177 | int (*encrypt)(struct ablkcipher_request *req); | 186 | int (*encrypt)(struct ablkcipher_request *req); |
178 | int (*decrypt)(struct ablkcipher_request *req); | 187 | int (*decrypt)(struct ablkcipher_request *req); |
188 | int (*givencrypt)(struct skcipher_givcrypt_request *req); | ||
189 | int (*givdecrypt)(struct skcipher_givcrypt_request *req); | ||
190 | |||
191 | const char *geniv; | ||
179 | 192 | ||
180 | unsigned int min_keysize; | 193 | unsigned int min_keysize; |
181 | unsigned int max_keysize; | 194 | unsigned int max_keysize; |
@@ -185,11 +198,16 @@ struct ablkcipher_alg { | |||
185 | struct aead_alg { | 198 | struct aead_alg { |
186 | int (*setkey)(struct crypto_aead *tfm, const u8 *key, | 199 | int (*setkey)(struct crypto_aead *tfm, const u8 *key, |
187 | unsigned int keylen); | 200 | unsigned int keylen); |
201 | int (*setauthsize)(struct crypto_aead *tfm, unsigned int authsize); | ||
188 | int (*encrypt)(struct aead_request *req); | 202 | int (*encrypt)(struct aead_request *req); |
189 | int (*decrypt)(struct aead_request *req); | 203 | int (*decrypt)(struct aead_request *req); |
204 | int (*givencrypt)(struct aead_givcrypt_request *req); | ||
205 | int (*givdecrypt)(struct aead_givcrypt_request *req); | ||
206 | |||
207 | const char *geniv; | ||
190 | 208 | ||
191 | unsigned int ivsize; | 209 | unsigned int ivsize; |
192 | unsigned int authsize; | 210 | unsigned int maxauthsize; |
193 | }; | 211 | }; |
194 | 212 | ||
195 | struct blkcipher_alg { | 213 | struct blkcipher_alg { |
@@ -202,6 +220,8 @@ struct blkcipher_alg { | |||
202 | struct scatterlist *dst, struct scatterlist *src, | 220 | struct scatterlist *dst, struct scatterlist *src, |
203 | unsigned int nbytes); | 221 | unsigned int nbytes); |
204 | 222 | ||
223 | const char *geniv; | ||
224 | |||
205 | unsigned int min_keysize; | 225 | unsigned int min_keysize; |
206 | unsigned int max_keysize; | 226 | unsigned int max_keysize; |
207 | unsigned int ivsize; | 227 | unsigned int ivsize; |
@@ -317,6 +337,11 @@ struct ablkcipher_tfm { | |||
317 | unsigned int keylen); | 337 | unsigned int keylen); |
318 | int (*encrypt)(struct ablkcipher_request *req); | 338 | int (*encrypt)(struct ablkcipher_request *req); |
319 | int (*decrypt)(struct ablkcipher_request *req); | 339 | int (*decrypt)(struct ablkcipher_request *req); |
340 | int (*givencrypt)(struct skcipher_givcrypt_request *req); | ||
341 | int (*givdecrypt)(struct skcipher_givcrypt_request *req); | ||
342 | |||
343 | struct crypto_ablkcipher *base; | ||
344 | |||
320 | unsigned int ivsize; | 345 | unsigned int ivsize; |
321 | unsigned int reqsize; | 346 | unsigned int reqsize; |
322 | }; | 347 | }; |
@@ -326,6 +351,11 @@ struct aead_tfm { | |||
326 | unsigned int keylen); | 351 | unsigned int keylen); |
327 | int (*encrypt)(struct aead_request *req); | 352 | int (*encrypt)(struct aead_request *req); |
328 | int (*decrypt)(struct aead_request *req); | 353 | int (*decrypt)(struct aead_request *req); |
354 | int (*givencrypt)(struct aead_givcrypt_request *req); | ||
355 | int (*givdecrypt)(struct aead_givcrypt_request *req); | ||
356 | |||
357 | struct crypto_aead *base; | ||
358 | |||
329 | unsigned int ivsize; | 359 | unsigned int ivsize; |
330 | unsigned int authsize; | 360 | unsigned int authsize; |
331 | unsigned int reqsize; | 361 | unsigned int reqsize; |
@@ -525,17 +555,23 @@ static inline struct crypto_ablkcipher *__crypto_ablkcipher_cast( | |||
525 | return (struct crypto_ablkcipher *)tfm; | 555 | return (struct crypto_ablkcipher *)tfm; |
526 | } | 556 | } |
527 | 557 | ||
528 | static inline struct crypto_ablkcipher *crypto_alloc_ablkcipher( | 558 | static inline u32 crypto_skcipher_type(u32 type) |
529 | const char *alg_name, u32 type, u32 mask) | ||
530 | { | 559 | { |
531 | type &= ~CRYPTO_ALG_TYPE_MASK; | 560 | type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV); |
532 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; | 561 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; |
533 | mask |= CRYPTO_ALG_TYPE_MASK; | 562 | return type; |
563 | } | ||
534 | 564 | ||
535 | return __crypto_ablkcipher_cast( | 565 | static inline u32 crypto_skcipher_mask(u32 mask) |
536 | crypto_alloc_base(alg_name, type, mask)); | 566 | { |
567 | mask &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV); | ||
568 | mask |= CRYPTO_ALG_TYPE_BLKCIPHER_MASK; | ||
569 | return mask; | ||
537 | } | 570 | } |
538 | 571 | ||
572 | struct crypto_ablkcipher *crypto_alloc_ablkcipher(const char *alg_name, | ||
573 | u32 type, u32 mask); | ||
574 | |||
539 | static inline struct crypto_tfm *crypto_ablkcipher_tfm( | 575 | static inline struct crypto_tfm *crypto_ablkcipher_tfm( |
540 | struct crypto_ablkcipher *tfm) | 576 | struct crypto_ablkcipher *tfm) |
541 | { | 577 | { |
@@ -550,11 +586,8 @@ static inline void crypto_free_ablkcipher(struct crypto_ablkcipher *tfm) | |||
550 | static inline int crypto_has_ablkcipher(const char *alg_name, u32 type, | 586 | static inline int crypto_has_ablkcipher(const char *alg_name, u32 type, |
551 | u32 mask) | 587 | u32 mask) |
552 | { | 588 | { |
553 | type &= ~CRYPTO_ALG_TYPE_MASK; | 589 | return crypto_has_alg(alg_name, crypto_skcipher_type(type), |
554 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; | 590 | crypto_skcipher_mask(mask)); |
555 | mask |= CRYPTO_ALG_TYPE_MASK; | ||
556 | |||
557 | return crypto_has_alg(alg_name, type, mask); | ||
558 | } | 591 | } |
559 | 592 | ||
560 | static inline struct ablkcipher_tfm *crypto_ablkcipher_crt( | 593 | static inline struct ablkcipher_tfm *crypto_ablkcipher_crt( |
@@ -601,7 +634,9 @@ static inline void crypto_ablkcipher_clear_flags(struct crypto_ablkcipher *tfm, | |||
601 | static inline int crypto_ablkcipher_setkey(struct crypto_ablkcipher *tfm, | 634 | static inline int crypto_ablkcipher_setkey(struct crypto_ablkcipher *tfm, |
602 | const u8 *key, unsigned int keylen) | 635 | const u8 *key, unsigned int keylen) |
603 | { | 636 | { |
604 | return crypto_ablkcipher_crt(tfm)->setkey(tfm, key, keylen); | 637 | struct ablkcipher_tfm *crt = crypto_ablkcipher_crt(tfm); |
638 | |||
639 | return crt->setkey(crt->base, key, keylen); | ||
605 | } | 640 | } |
606 | 641 | ||
607 | static inline struct crypto_ablkcipher *crypto_ablkcipher_reqtfm( | 642 | static inline struct crypto_ablkcipher *crypto_ablkcipher_reqtfm( |
@@ -633,7 +668,7 @@ static inline unsigned int crypto_ablkcipher_reqsize( | |||
633 | static inline void ablkcipher_request_set_tfm( | 668 | static inline void ablkcipher_request_set_tfm( |
634 | struct ablkcipher_request *req, struct crypto_ablkcipher *tfm) | 669 | struct ablkcipher_request *req, struct crypto_ablkcipher *tfm) |
635 | { | 670 | { |
636 | req->base.tfm = crypto_ablkcipher_tfm(tfm); | 671 | req->base.tfm = crypto_ablkcipher_tfm(crypto_ablkcipher_crt(tfm)->base); |
637 | } | 672 | } |
638 | 673 | ||
639 | static inline struct ablkcipher_request *ablkcipher_request_cast( | 674 | static inline struct ablkcipher_request *ablkcipher_request_cast( |
@@ -686,15 +721,7 @@ static inline struct crypto_aead *__crypto_aead_cast(struct crypto_tfm *tfm) | |||
686 | return (struct crypto_aead *)tfm; | 721 | return (struct crypto_aead *)tfm; |
687 | } | 722 | } |
688 | 723 | ||
689 | static inline struct crypto_aead *crypto_alloc_aead(const char *alg_name, | 724 | struct crypto_aead *crypto_alloc_aead(const char *alg_name, u32 type, u32 mask); |
690 | u32 type, u32 mask) | ||
691 | { | ||
692 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
693 | type |= CRYPTO_ALG_TYPE_AEAD; | ||
694 | mask |= CRYPTO_ALG_TYPE_MASK; | ||
695 | |||
696 | return __crypto_aead_cast(crypto_alloc_base(alg_name, type, mask)); | ||
697 | } | ||
698 | 725 | ||
699 | static inline struct crypto_tfm *crypto_aead_tfm(struct crypto_aead *tfm) | 726 | static inline struct crypto_tfm *crypto_aead_tfm(struct crypto_aead *tfm) |
700 | { | 727 | { |
@@ -749,9 +776,13 @@ static inline void crypto_aead_clear_flags(struct crypto_aead *tfm, u32 flags) | |||
749 | static inline int crypto_aead_setkey(struct crypto_aead *tfm, const u8 *key, | 776 | static inline int crypto_aead_setkey(struct crypto_aead *tfm, const u8 *key, |
750 | unsigned int keylen) | 777 | unsigned int keylen) |
751 | { | 778 | { |
752 | return crypto_aead_crt(tfm)->setkey(tfm, key, keylen); | 779 | struct aead_tfm *crt = crypto_aead_crt(tfm); |
780 | |||
781 | return crt->setkey(crt->base, key, keylen); | ||
753 | } | 782 | } |
754 | 783 | ||
784 | int crypto_aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize); | ||
785 | |||
755 | static inline struct crypto_aead *crypto_aead_reqtfm(struct aead_request *req) | 786 | static inline struct crypto_aead *crypto_aead_reqtfm(struct aead_request *req) |
756 | { | 787 | { |
757 | return __crypto_aead_cast(req->base.tfm); | 788 | return __crypto_aead_cast(req->base.tfm); |
@@ -775,7 +806,7 @@ static inline unsigned int crypto_aead_reqsize(struct crypto_aead *tfm) | |||
775 | static inline void aead_request_set_tfm(struct aead_request *req, | 806 | static inline void aead_request_set_tfm(struct aead_request *req, |
776 | struct crypto_aead *tfm) | 807 | struct crypto_aead *tfm) |
777 | { | 808 | { |
778 | req->base.tfm = crypto_aead_tfm(tfm); | 809 | req->base.tfm = crypto_aead_tfm(crypto_aead_crt(tfm)->base); |
779 | } | 810 | } |
780 | 811 | ||
781 | static inline struct aead_request *aead_request_alloc(struct crypto_aead *tfm, | 812 | static inline struct aead_request *aead_request_alloc(struct crypto_aead *tfm, |
@@ -841,9 +872,9 @@ static inline struct crypto_blkcipher *crypto_blkcipher_cast( | |||
841 | static inline struct crypto_blkcipher *crypto_alloc_blkcipher( | 872 | static inline struct crypto_blkcipher *crypto_alloc_blkcipher( |
842 | const char *alg_name, u32 type, u32 mask) | 873 | const char *alg_name, u32 type, u32 mask) |
843 | { | 874 | { |
844 | type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC); | 875 | type &= ~CRYPTO_ALG_TYPE_MASK; |
845 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; | 876 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; |
846 | mask |= CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC; | 877 | mask |= CRYPTO_ALG_TYPE_MASK; |
847 | 878 | ||
848 | return __crypto_blkcipher_cast(crypto_alloc_base(alg_name, type, mask)); | 879 | return __crypto_blkcipher_cast(crypto_alloc_base(alg_name, type, mask)); |
849 | } | 880 | } |
@@ -861,9 +892,9 @@ static inline void crypto_free_blkcipher(struct crypto_blkcipher *tfm) | |||
861 | 892 | ||
862 | static inline int crypto_has_blkcipher(const char *alg_name, u32 type, u32 mask) | 893 | static inline int crypto_has_blkcipher(const char *alg_name, u32 type, u32 mask) |
863 | { | 894 | { |
864 | type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC); | 895 | type &= ~CRYPTO_ALG_TYPE_MASK; |
865 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; | 896 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; |
866 | mask |= CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC; | 897 | mask |= CRYPTO_ALG_TYPE_MASK; |
867 | 898 | ||
868 | return crypto_has_alg(alg_name, type, mask); | 899 | return crypto_has_alg(alg_name, type, mask); |
869 | } | 900 | } |
@@ -1081,6 +1112,7 @@ static inline struct crypto_hash *crypto_alloc_hash(const char *alg_name, | |||
1081 | u32 type, u32 mask) | 1112 | u32 type, u32 mask) |
1082 | { | 1113 | { |
1083 | type &= ~CRYPTO_ALG_TYPE_MASK; | 1114 | type &= ~CRYPTO_ALG_TYPE_MASK; |
1115 | mask &= ~CRYPTO_ALG_TYPE_MASK; | ||
1084 | type |= CRYPTO_ALG_TYPE_HASH; | 1116 | type |= CRYPTO_ALG_TYPE_HASH; |
1085 | mask |= CRYPTO_ALG_TYPE_HASH_MASK; | 1117 | mask |= CRYPTO_ALG_TYPE_HASH_MASK; |
1086 | 1118 | ||
@@ -1100,6 +1132,7 @@ static inline void crypto_free_hash(struct crypto_hash *tfm) | |||
1100 | static inline int crypto_has_hash(const char *alg_name, u32 type, u32 mask) | 1132 | static inline int crypto_has_hash(const char *alg_name, u32 type, u32 mask) |
1101 | { | 1133 | { |
1102 | type &= ~CRYPTO_ALG_TYPE_MASK; | 1134 | type &= ~CRYPTO_ALG_TYPE_MASK; |
1135 | mask &= ~CRYPTO_ALG_TYPE_MASK; | ||
1103 | type |= CRYPTO_ALG_TYPE_HASH; | 1136 | type |= CRYPTO_ALG_TYPE_HASH; |
1104 | mask |= CRYPTO_ALG_TYPE_HASH_MASK; | 1137 | mask |= CRYPTO_ALG_TYPE_HASH_MASK; |
1105 | 1138 | ||
diff --git a/include/linux/hw_random.h b/include/linux/hw_random.h index 21ea7610e177..85d11916e9ea 100644 --- a/include/linux/hw_random.h +++ b/include/linux/hw_random.h | |||
@@ -33,7 +33,7 @@ struct hwrng { | |||
33 | const char *name; | 33 | const char *name; |
34 | int (*init)(struct hwrng *rng); | 34 | int (*init)(struct hwrng *rng); |
35 | void (*cleanup)(struct hwrng *rng); | 35 | void (*cleanup)(struct hwrng *rng); |
36 | int (*data_present)(struct hwrng *rng); | 36 | int (*data_present)(struct hwrng *rng, int wait); |
37 | int (*data_read)(struct hwrng *rng, u32 *data); | 37 | int (*data_read)(struct hwrng *rng, u32 *data); |
38 | unsigned long priv; | 38 | unsigned long priv; |
39 | 39 | ||