diff options
author | Linus Torvalds <torvalds@g5.osdl.org> | 2006-09-22 15:51:33 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-09-22 15:51:33 -0400 |
commit | 6bbd9b6d694ff7242d63cda2faac4bd59ee4328e (patch) | |
tree | 0641aa896e2ea01f4692973e5fbea429408854f4 /include | |
parent | a489d159229fcc07bbb7566ac4fac745b79197ad (diff) | |
parent | 3c164bd8153c4644a22dc2101b003c67cd2a0d0a (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: (64 commits)
[BLOCK] dm-crypt: trivial comment improvements
[CRYPTO] api: Deprecate crypto_digest_* and crypto_alg_available
[CRYPTO] padlock: Convert padlock-sha to use crypto_hash
[CRYPTO] users: Use crypto_comp and crypto_has_*
[CRYPTO] api: Add crypto_comp and crypto_has_*
[CRYPTO] users: Use crypto_hash interface instead of crypto_digest
[SCSI] iscsi: Use crypto_hash interface instead of crypto_digest
[CRYPTO] digest: Remove old HMAC implementation
[CRYPTO] doc: Update documentation for hash and me
[SCTP]: Use HMAC template and hash interface
[IPSEC]: Use HMAC template and hash interface
[CRYPTO] tcrypt: Use HMAC template and hash interface
[CRYPTO] hmac: Add crypto template implementation
[CRYPTO] digest: Added user API for new hash type
[CRYPTO] api: Mark parts of cipher interface as deprecated
[PATCH] scatterlist: Add const to sg_set_buf/sg_init_one pointer argument
[CRYPTO] drivers: Remove obsolete block cipher operations
[CRYPTO] users: Use block ciphers where applicable
[SUNRPC] GSS: Use block ciphers where applicable
[IPSEC] ESP: Use block ciphers where applicable
...
Diffstat (limited to 'include')
-rw-r--r-- | include/crypto/algapi.h | 156 | ||||
-rw-r--r-- | include/crypto/twofish.h | 22 | ||||
-rw-r--r-- | include/linux/crypto.h | 689 | ||||
-rw-r--r-- | include/linux/scatterlist.h | 4 | ||||
-rw-r--r-- | include/linux/sunrpc/gss_krb5.h | 19 | ||||
-rw-r--r-- | include/linux/sunrpc/gss_spkm3.h | 4 | ||||
-rw-r--r-- | include/net/ah.h | 30 | ||||
-rw-r--r-- | include/net/esp.h | 31 | ||||
-rw-r--r-- | include/net/ipcomp.h | 5 | ||||
-rw-r--r-- | include/net/sctp/constants.h | 4 | ||||
-rw-r--r-- | include/net/sctp/sctp.h | 11 | ||||
-rw-r--r-- | include/net/sctp/structs.h | 3 | ||||
-rw-r--r-- | include/net/xfrm.h | 12 |
13 files changed, 851 insertions, 139 deletions
diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h new file mode 100644 index 000000000000..5748aecdb414 --- /dev/null +++ b/include/crypto/algapi.h | |||
@@ -0,0 +1,156 @@ | |||
1 | /* | ||
2 | * Cryptographic API for algorithms (i.e., low-level API). | ||
3 | * | ||
4 | * Copyright (c) 2006 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_ALGAPI_H | ||
13 | #define _CRYPTO_ALGAPI_H | ||
14 | |||
15 | #include <linux/crypto.h> | ||
16 | |||
17 | struct module; | ||
18 | struct seq_file; | ||
19 | |||
20 | struct crypto_type { | ||
21 | unsigned int (*ctxsize)(struct crypto_alg *alg); | ||
22 | int (*init)(struct crypto_tfm *tfm); | ||
23 | void (*exit)(struct crypto_tfm *tfm); | ||
24 | void (*show)(struct seq_file *m, struct crypto_alg *alg); | ||
25 | }; | ||
26 | |||
27 | struct crypto_instance { | ||
28 | struct crypto_alg alg; | ||
29 | |||
30 | struct crypto_template *tmpl; | ||
31 | struct hlist_node list; | ||
32 | |||
33 | void *__ctx[] CRYPTO_MINALIGN_ATTR; | ||
34 | }; | ||
35 | |||
36 | struct crypto_template { | ||
37 | struct list_head list; | ||
38 | struct hlist_head instances; | ||
39 | struct module *module; | ||
40 | |||
41 | struct crypto_instance *(*alloc)(void *param, unsigned int len); | ||
42 | void (*free)(struct crypto_instance *inst); | ||
43 | |||
44 | char name[CRYPTO_MAX_ALG_NAME]; | ||
45 | }; | ||
46 | |||
47 | struct crypto_spawn { | ||
48 | struct list_head list; | ||
49 | struct crypto_alg *alg; | ||
50 | struct crypto_instance *inst; | ||
51 | }; | ||
52 | |||
53 | struct scatter_walk { | ||
54 | struct scatterlist *sg; | ||
55 | unsigned int offset; | ||
56 | }; | ||
57 | |||
58 | struct blkcipher_walk { | ||
59 | union { | ||
60 | struct { | ||
61 | struct page *page; | ||
62 | unsigned long offset; | ||
63 | } phys; | ||
64 | |||
65 | struct { | ||
66 | u8 *page; | ||
67 | u8 *addr; | ||
68 | } virt; | ||
69 | } src, dst; | ||
70 | |||
71 | struct scatter_walk in; | ||
72 | unsigned int nbytes; | ||
73 | |||
74 | struct scatter_walk out; | ||
75 | unsigned int total; | ||
76 | |||
77 | void *page; | ||
78 | u8 *buffer; | ||
79 | u8 *iv; | ||
80 | |||
81 | int flags; | ||
82 | }; | ||
83 | |||
84 | extern const struct crypto_type crypto_blkcipher_type; | ||
85 | extern const struct crypto_type crypto_hash_type; | ||
86 | |||
87 | void crypto_mod_put(struct crypto_alg *alg); | ||
88 | |||
89 | int crypto_register_template(struct crypto_template *tmpl); | ||
90 | void crypto_unregister_template(struct crypto_template *tmpl); | ||
91 | struct crypto_template *crypto_lookup_template(const char *name); | ||
92 | |||
93 | int crypto_init_spawn(struct crypto_spawn *spawn, struct crypto_alg *alg, | ||
94 | struct crypto_instance *inst); | ||
95 | void crypto_drop_spawn(struct crypto_spawn *spawn); | ||
96 | struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn); | ||
97 | |||
98 | struct crypto_alg *crypto_get_attr_alg(void *param, unsigned int len, | ||
99 | u32 type, u32 mask); | ||
100 | struct crypto_instance *crypto_alloc_instance(const char *name, | ||
101 | struct crypto_alg *alg); | ||
102 | |||
103 | int blkcipher_walk_done(struct blkcipher_desc *desc, | ||
104 | struct blkcipher_walk *walk, int err); | ||
105 | int blkcipher_walk_virt(struct blkcipher_desc *desc, | ||
106 | struct blkcipher_walk *walk); | ||
107 | int blkcipher_walk_phys(struct blkcipher_desc *desc, | ||
108 | struct blkcipher_walk *walk); | ||
109 | |||
110 | static inline void *crypto_tfm_ctx_aligned(struct crypto_tfm *tfm) | ||
111 | { | ||
112 | unsigned long addr = (unsigned long)crypto_tfm_ctx(tfm); | ||
113 | unsigned long align = crypto_tfm_alg_alignmask(tfm); | ||
114 | |||
115 | if (align <= crypto_tfm_ctx_alignment()) | ||
116 | align = 1; | ||
117 | return (void *)ALIGN(addr, align); | ||
118 | } | ||
119 | |||
120 | static inline void *crypto_instance_ctx(struct crypto_instance *inst) | ||
121 | { | ||
122 | return inst->__ctx; | ||
123 | } | ||
124 | |||
125 | static inline void *crypto_blkcipher_ctx(struct crypto_blkcipher *tfm) | ||
126 | { | ||
127 | return crypto_tfm_ctx(&tfm->base); | ||
128 | } | ||
129 | |||
130 | static inline void *crypto_blkcipher_ctx_aligned(struct crypto_blkcipher *tfm) | ||
131 | { | ||
132 | return crypto_tfm_ctx_aligned(&tfm->base); | ||
133 | } | ||
134 | |||
135 | static inline struct cipher_alg *crypto_cipher_alg(struct crypto_cipher *tfm) | ||
136 | { | ||
137 | return &crypto_cipher_tfm(tfm)->__crt_alg->cra_cipher; | ||
138 | } | ||
139 | |||
140 | static inline void *crypto_hash_ctx_aligned(struct crypto_hash *tfm) | ||
141 | { | ||
142 | return crypto_tfm_ctx_aligned(&tfm->base); | ||
143 | } | ||
144 | |||
145 | static inline void blkcipher_walk_init(struct blkcipher_walk *walk, | ||
146 | struct scatterlist *dst, | ||
147 | struct scatterlist *src, | ||
148 | unsigned int nbytes) | ||
149 | { | ||
150 | walk->in.sg = src; | ||
151 | walk->out.sg = dst; | ||
152 | walk->total = nbytes; | ||
153 | } | ||
154 | |||
155 | #endif /* _CRYPTO_ALGAPI_H */ | ||
156 | |||
diff --git a/include/crypto/twofish.h b/include/crypto/twofish.h new file mode 100644 index 000000000000..c408522595c6 --- /dev/null +++ b/include/crypto/twofish.h | |||
@@ -0,0 +1,22 @@ | |||
1 | #ifndef _CRYPTO_TWOFISH_H | ||
2 | #define _CRYPTO_TWOFISH_H | ||
3 | |||
4 | #include <linux/types.h> | ||
5 | |||
6 | #define TF_MIN_KEY_SIZE 16 | ||
7 | #define TF_MAX_KEY_SIZE 32 | ||
8 | #define TF_BLOCK_SIZE 16 | ||
9 | |||
10 | struct crypto_tfm; | ||
11 | |||
12 | /* Structure for an expanded Twofish key. s contains the key-dependent | ||
13 | * S-boxes composed with the MDS matrix; w contains the eight "whitening" | ||
14 | * subkeys, K[0] through K[7]. k holds the remaining, "round" subkeys. Note | ||
15 | * that k[i] corresponds to what the Twofish paper calls K[i+8]. */ | ||
16 | struct twofish_ctx { | ||
17 | u32 s[4][256], w[8], k[32]; | ||
18 | }; | ||
19 | |||
20 | int twofish_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int key_len); | ||
21 | |||
22 | #endif | ||
diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 7f946241b879..8f2ffa4caabf 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h | |||
@@ -17,20 +17,36 @@ | |||
17 | #ifndef _LINUX_CRYPTO_H | 17 | #ifndef _LINUX_CRYPTO_H |
18 | #define _LINUX_CRYPTO_H | 18 | #define _LINUX_CRYPTO_H |
19 | 19 | ||
20 | #include <asm/atomic.h> | ||
20 | #include <linux/module.h> | 21 | #include <linux/module.h> |
21 | #include <linux/kernel.h> | 22 | #include <linux/kernel.h> |
22 | #include <linux/types.h> | ||
23 | #include <linux/list.h> | 23 | #include <linux/list.h> |
24 | #include <linux/slab.h> | ||
24 | #include <linux/string.h> | 25 | #include <linux/string.h> |
25 | #include <asm/page.h> | 26 | #include <linux/uaccess.h> |
26 | 27 | ||
27 | /* | 28 | /* |
28 | * Algorithm masks and types. | 29 | * Algorithm masks and types. |
29 | */ | 30 | */ |
30 | #define CRYPTO_ALG_TYPE_MASK 0x000000ff | 31 | #define CRYPTO_ALG_TYPE_MASK 0x0000000f |
31 | #define CRYPTO_ALG_TYPE_CIPHER 0x00000001 | 32 | #define CRYPTO_ALG_TYPE_CIPHER 0x00000001 |
32 | #define CRYPTO_ALG_TYPE_DIGEST 0x00000002 | 33 | #define CRYPTO_ALG_TYPE_DIGEST 0x00000002 |
33 | #define CRYPTO_ALG_TYPE_COMPRESS 0x00000004 | 34 | #define CRYPTO_ALG_TYPE_HASH 0x00000003 |
35 | #define CRYPTO_ALG_TYPE_BLKCIPHER 0x00000004 | ||
36 | #define CRYPTO_ALG_TYPE_COMPRESS 0x00000005 | ||
37 | |||
38 | #define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e | ||
39 | |||
40 | #define CRYPTO_ALG_LARVAL 0x00000010 | ||
41 | #define CRYPTO_ALG_DEAD 0x00000020 | ||
42 | #define CRYPTO_ALG_DYING 0x00000040 | ||
43 | #define CRYPTO_ALG_ASYNC 0x00000080 | ||
44 | |||
45 | /* | ||
46 | * Set this bit if and only if the algorithm requires another algorithm of | ||
47 | * the same type to handle corner cases. | ||
48 | */ | ||
49 | #define CRYPTO_ALG_NEED_FALLBACK 0x00000100 | ||
34 | 50 | ||
35 | /* | 51 | /* |
36 | * Transform masks and values (for crt_flags). | 52 | * Transform masks and values (for crt_flags). |
@@ -61,8 +77,37 @@ | |||
61 | #define CRYPTO_DIR_ENCRYPT 1 | 77 | #define CRYPTO_DIR_ENCRYPT 1 |
62 | #define CRYPTO_DIR_DECRYPT 0 | 78 | #define CRYPTO_DIR_DECRYPT 0 |
63 | 79 | ||
80 | /* | ||
81 | * The macro CRYPTO_MINALIGN_ATTR (along with the void * type in the actual | ||
82 | * declaration) is used to ensure that the crypto_tfm context structure is | ||
83 | * aligned correctly for the given architecture so that there are no alignment | ||
84 | * faults for C data types. In particular, this is required on platforms such | ||
85 | * as arm where pointers are 32-bit aligned but there are data types such as | ||
86 | * u64 which require 64-bit alignment. | ||
87 | */ | ||
88 | #if defined(ARCH_KMALLOC_MINALIGN) | ||
89 | #define CRYPTO_MINALIGN ARCH_KMALLOC_MINALIGN | ||
90 | #elif defined(ARCH_SLAB_MINALIGN) | ||
91 | #define CRYPTO_MINALIGN ARCH_SLAB_MINALIGN | ||
92 | #endif | ||
93 | |||
94 | #ifdef CRYPTO_MINALIGN | ||
95 | #define CRYPTO_MINALIGN_ATTR __attribute__ ((__aligned__(CRYPTO_MINALIGN))) | ||
96 | #else | ||
97 | #define CRYPTO_MINALIGN_ATTR | ||
98 | #endif | ||
99 | |||
64 | struct scatterlist; | 100 | struct scatterlist; |
101 | struct crypto_blkcipher; | ||
102 | struct crypto_hash; | ||
65 | struct crypto_tfm; | 103 | struct crypto_tfm; |
104 | struct crypto_type; | ||
105 | |||
106 | struct blkcipher_desc { | ||
107 | struct crypto_blkcipher *tfm; | ||
108 | void *info; | ||
109 | u32 flags; | ||
110 | }; | ||
66 | 111 | ||
67 | struct cipher_desc { | 112 | struct cipher_desc { |
68 | struct crypto_tfm *tfm; | 113 | struct crypto_tfm *tfm; |
@@ -72,30 +117,50 @@ struct cipher_desc { | |||
72 | void *info; | 117 | void *info; |
73 | }; | 118 | }; |
74 | 119 | ||
120 | struct hash_desc { | ||
121 | struct crypto_hash *tfm; | ||
122 | u32 flags; | ||
123 | }; | ||
124 | |||
75 | /* | 125 | /* |
76 | * Algorithms: modular crypto algorithm implementations, managed | 126 | * Algorithms: modular crypto algorithm implementations, managed |
77 | * via crypto_register_alg() and crypto_unregister_alg(). | 127 | * via crypto_register_alg() and crypto_unregister_alg(). |
78 | */ | 128 | */ |
129 | struct blkcipher_alg { | ||
130 | int (*setkey)(struct crypto_tfm *tfm, const u8 *key, | ||
131 | unsigned int keylen); | ||
132 | int (*encrypt)(struct blkcipher_desc *desc, | ||
133 | struct scatterlist *dst, struct scatterlist *src, | ||
134 | unsigned int nbytes); | ||
135 | int (*decrypt)(struct blkcipher_desc *desc, | ||
136 | struct scatterlist *dst, struct scatterlist *src, | ||
137 | unsigned int nbytes); | ||
138 | |||
139 | unsigned int min_keysize; | ||
140 | unsigned int max_keysize; | ||
141 | unsigned int ivsize; | ||
142 | }; | ||
143 | |||
79 | struct cipher_alg { | 144 | struct cipher_alg { |
80 | unsigned int cia_min_keysize; | 145 | unsigned int cia_min_keysize; |
81 | unsigned int cia_max_keysize; | 146 | unsigned int cia_max_keysize; |
82 | int (*cia_setkey)(struct crypto_tfm *tfm, const u8 *key, | 147 | int (*cia_setkey)(struct crypto_tfm *tfm, const u8 *key, |
83 | unsigned int keylen, u32 *flags); | 148 | unsigned int keylen); |
84 | void (*cia_encrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); | 149 | void (*cia_encrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); |
85 | void (*cia_decrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); | 150 | void (*cia_decrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); |
86 | 151 | ||
87 | unsigned int (*cia_encrypt_ecb)(const struct cipher_desc *desc, | 152 | unsigned int (*cia_encrypt_ecb)(const struct cipher_desc *desc, |
88 | u8 *dst, const u8 *src, | 153 | u8 *dst, const u8 *src, |
89 | unsigned int nbytes); | 154 | unsigned int nbytes) __deprecated; |
90 | unsigned int (*cia_decrypt_ecb)(const struct cipher_desc *desc, | 155 | unsigned int (*cia_decrypt_ecb)(const struct cipher_desc *desc, |
91 | u8 *dst, const u8 *src, | 156 | u8 *dst, const u8 *src, |
92 | unsigned int nbytes); | 157 | unsigned int nbytes) __deprecated; |
93 | unsigned int (*cia_encrypt_cbc)(const struct cipher_desc *desc, | 158 | unsigned int (*cia_encrypt_cbc)(const struct cipher_desc *desc, |
94 | u8 *dst, const u8 *src, | 159 | u8 *dst, const u8 *src, |
95 | unsigned int nbytes); | 160 | unsigned int nbytes) __deprecated; |
96 | unsigned int (*cia_decrypt_cbc)(const struct cipher_desc *desc, | 161 | unsigned int (*cia_decrypt_cbc)(const struct cipher_desc *desc, |
97 | u8 *dst, const u8 *src, | 162 | u8 *dst, const u8 *src, |
98 | unsigned int nbytes); | 163 | unsigned int nbytes) __deprecated; |
99 | }; | 164 | }; |
100 | 165 | ||
101 | struct digest_alg { | 166 | struct digest_alg { |
@@ -105,7 +170,20 @@ struct digest_alg { | |||
105 | unsigned int len); | 170 | unsigned int len); |
106 | void (*dia_final)(struct crypto_tfm *tfm, u8 *out); | 171 | void (*dia_final)(struct crypto_tfm *tfm, u8 *out); |
107 | int (*dia_setkey)(struct crypto_tfm *tfm, const u8 *key, | 172 | int (*dia_setkey)(struct crypto_tfm *tfm, const u8 *key, |
108 | unsigned int keylen, u32 *flags); | 173 | unsigned int keylen); |
174 | }; | ||
175 | |||
176 | struct hash_alg { | ||
177 | int (*init)(struct hash_desc *desc); | ||
178 | int (*update)(struct hash_desc *desc, struct scatterlist *sg, | ||
179 | unsigned int nbytes); | ||
180 | int (*final)(struct hash_desc *desc, u8 *out); | ||
181 | int (*digest)(struct hash_desc *desc, struct scatterlist *sg, | ||
182 | unsigned int nbytes, u8 *out); | ||
183 | int (*setkey)(struct crypto_hash *tfm, const u8 *key, | ||
184 | unsigned int keylen); | ||
185 | |||
186 | unsigned int digestsize; | ||
109 | }; | 187 | }; |
110 | 188 | ||
111 | struct compress_alg { | 189 | struct compress_alg { |
@@ -115,30 +193,40 @@ struct compress_alg { | |||
115 | unsigned int slen, u8 *dst, unsigned int *dlen); | 193 | unsigned int slen, u8 *dst, unsigned int *dlen); |
116 | }; | 194 | }; |
117 | 195 | ||
196 | #define cra_blkcipher cra_u.blkcipher | ||
118 | #define cra_cipher cra_u.cipher | 197 | #define cra_cipher cra_u.cipher |
119 | #define cra_digest cra_u.digest | 198 | #define cra_digest cra_u.digest |
199 | #define cra_hash cra_u.hash | ||
120 | #define cra_compress cra_u.compress | 200 | #define cra_compress cra_u.compress |
121 | 201 | ||
122 | struct crypto_alg { | 202 | struct crypto_alg { |
123 | struct list_head cra_list; | 203 | struct list_head cra_list; |
204 | struct list_head cra_users; | ||
205 | |||
124 | u32 cra_flags; | 206 | u32 cra_flags; |
125 | unsigned int cra_blocksize; | 207 | unsigned int cra_blocksize; |
126 | unsigned int cra_ctxsize; | 208 | unsigned int cra_ctxsize; |
127 | unsigned int cra_alignmask; | 209 | unsigned int cra_alignmask; |
128 | 210 | ||
129 | int cra_priority; | 211 | int cra_priority; |
212 | atomic_t cra_refcnt; | ||
130 | 213 | ||
131 | char cra_name[CRYPTO_MAX_ALG_NAME]; | 214 | char cra_name[CRYPTO_MAX_ALG_NAME]; |
132 | char cra_driver_name[CRYPTO_MAX_ALG_NAME]; | 215 | char cra_driver_name[CRYPTO_MAX_ALG_NAME]; |
133 | 216 | ||
217 | const struct crypto_type *cra_type; | ||
218 | |||
134 | union { | 219 | union { |
220 | struct blkcipher_alg blkcipher; | ||
135 | struct cipher_alg cipher; | 221 | struct cipher_alg cipher; |
136 | struct digest_alg digest; | 222 | struct digest_alg digest; |
223 | struct hash_alg hash; | ||
137 | struct compress_alg compress; | 224 | struct compress_alg compress; |
138 | } cra_u; | 225 | } cra_u; |
139 | 226 | ||
140 | int (*cra_init)(struct crypto_tfm *tfm); | 227 | int (*cra_init)(struct crypto_tfm *tfm); |
141 | void (*cra_exit)(struct crypto_tfm *tfm); | 228 | void (*cra_exit)(struct crypto_tfm *tfm); |
229 | void (*cra_destroy)(struct crypto_alg *alg); | ||
142 | 230 | ||
143 | struct module *cra_module; | 231 | struct module *cra_module; |
144 | }; | 232 | }; |
@@ -153,20 +241,39 @@ int crypto_unregister_alg(struct crypto_alg *alg); | |||
153 | * Algorithm query interface. | 241 | * Algorithm query interface. |
154 | */ | 242 | */ |
155 | #ifdef CONFIG_CRYPTO | 243 | #ifdef CONFIG_CRYPTO |
156 | int crypto_alg_available(const char *name, u32 flags); | 244 | int crypto_alg_available(const char *name, u32 flags) |
245 | __deprecated_for_modules; | ||
246 | int crypto_has_alg(const char *name, u32 type, u32 mask); | ||
157 | #else | 247 | #else |
248 | static int crypto_alg_available(const char *name, u32 flags); | ||
249 | __deprecated_for_modules; | ||
158 | static inline int crypto_alg_available(const char *name, u32 flags) | 250 | static inline int crypto_alg_available(const char *name, u32 flags) |
159 | { | 251 | { |
160 | return 0; | 252 | return 0; |
161 | } | 253 | } |
254 | |||
255 | static inline int crypto_has_alg(const char *name, u32 type, u32 mask) | ||
256 | { | ||
257 | return 0; | ||
258 | } | ||
162 | #endif | 259 | #endif |
163 | 260 | ||
164 | /* | 261 | /* |
165 | * Transforms: user-instantiated objects which encapsulate algorithms | 262 | * Transforms: user-instantiated objects which encapsulate algorithms |
166 | * and core processing logic. Managed via crypto_alloc_tfm() and | 263 | * and core processing logic. Managed via crypto_alloc_*() and |
167 | * crypto_free_tfm(), as well as the various helpers below. | 264 | * crypto_free_*(), as well as the various helpers below. |
168 | */ | 265 | */ |
169 | 266 | ||
267 | struct blkcipher_tfm { | ||
268 | void *iv; | ||
269 | int (*setkey)(struct crypto_tfm *tfm, const u8 *key, | ||
270 | unsigned int keylen); | ||
271 | int (*encrypt)(struct blkcipher_desc *desc, struct scatterlist *dst, | ||
272 | struct scatterlist *src, unsigned int nbytes); | ||
273 | int (*decrypt)(struct blkcipher_desc *desc, struct scatterlist *dst, | ||
274 | struct scatterlist *src, unsigned int nbytes); | ||
275 | }; | ||
276 | |||
170 | struct cipher_tfm { | 277 | struct cipher_tfm { |
171 | void *cit_iv; | 278 | void *cit_iv; |
172 | unsigned int cit_ivsize; | 279 | unsigned int cit_ivsize; |
@@ -190,20 +297,20 @@ struct cipher_tfm { | |||
190 | struct scatterlist *src, | 297 | struct scatterlist *src, |
191 | unsigned int nbytes, u8 *iv); | 298 | unsigned int nbytes, u8 *iv); |
192 | void (*cit_xor_block)(u8 *dst, const u8 *src); | 299 | void (*cit_xor_block)(u8 *dst, const u8 *src); |
300 | void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); | ||
301 | void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src); | ||
193 | }; | 302 | }; |
194 | 303 | ||
195 | struct digest_tfm { | 304 | struct hash_tfm { |
196 | void (*dit_init)(struct crypto_tfm *tfm); | 305 | int (*init)(struct hash_desc *desc); |
197 | void (*dit_update)(struct crypto_tfm *tfm, | 306 | int (*update)(struct hash_desc *desc, |
198 | struct scatterlist *sg, unsigned int nsg); | 307 | struct scatterlist *sg, unsigned int nsg); |
199 | void (*dit_final)(struct crypto_tfm *tfm, u8 *out); | 308 | int (*final)(struct hash_desc *desc, u8 *out); |
200 | void (*dit_digest)(struct crypto_tfm *tfm, struct scatterlist *sg, | 309 | int (*digest)(struct hash_desc *desc, struct scatterlist *sg, |
201 | unsigned int nsg, u8 *out); | 310 | unsigned int nsg, u8 *out); |
202 | int (*dit_setkey)(struct crypto_tfm *tfm, | 311 | int (*setkey)(struct crypto_hash *tfm, const u8 *key, |
203 | const u8 *key, unsigned int keylen); | 312 | unsigned int keylen); |
204 | #ifdef CONFIG_CRYPTO_HMAC | 313 | unsigned int digestsize; |
205 | void *dit_hmac_block; | ||
206 | #endif | ||
207 | }; | 314 | }; |
208 | 315 | ||
209 | struct compress_tfm { | 316 | struct compress_tfm { |
@@ -215,8 +322,9 @@ struct compress_tfm { | |||
215 | u8 *dst, unsigned int *dlen); | 322 | u8 *dst, unsigned int *dlen); |
216 | }; | 323 | }; |
217 | 324 | ||
325 | #define crt_blkcipher crt_u.blkcipher | ||
218 | #define crt_cipher crt_u.cipher | 326 | #define crt_cipher crt_u.cipher |
219 | #define crt_digest crt_u.digest | 327 | #define crt_hash crt_u.hash |
220 | #define crt_compress crt_u.compress | 328 | #define crt_compress crt_u.compress |
221 | 329 | ||
222 | struct crypto_tfm { | 330 | struct crypto_tfm { |
@@ -224,30 +332,43 @@ struct crypto_tfm { | |||
224 | u32 crt_flags; | 332 | u32 crt_flags; |
225 | 333 | ||
226 | union { | 334 | union { |
335 | struct blkcipher_tfm blkcipher; | ||
227 | struct cipher_tfm cipher; | 336 | struct cipher_tfm cipher; |
228 | struct digest_tfm digest; | 337 | struct hash_tfm hash; |
229 | struct compress_tfm compress; | 338 | struct compress_tfm compress; |
230 | } crt_u; | 339 | } crt_u; |
231 | 340 | ||
232 | struct crypto_alg *__crt_alg; | 341 | struct crypto_alg *__crt_alg; |
233 | 342 | ||
234 | char __crt_ctx[] __attribute__ ((__aligned__)); | 343 | void *__crt_ctx[] CRYPTO_MINALIGN_ATTR; |
344 | }; | ||
345 | |||
346 | #define crypto_cipher crypto_tfm | ||
347 | #define crypto_comp crypto_tfm | ||
348 | |||
349 | struct crypto_blkcipher { | ||
350 | struct crypto_tfm base; | ||
351 | }; | ||
352 | |||
353 | struct crypto_hash { | ||
354 | struct crypto_tfm base; | ||
355 | }; | ||
356 | |||
357 | enum { | ||
358 | CRYPTOA_UNSPEC, | ||
359 | CRYPTOA_ALG, | ||
360 | }; | ||
361 | |||
362 | struct crypto_attr_alg { | ||
363 | char name[CRYPTO_MAX_ALG_NAME]; | ||
235 | }; | 364 | }; |
236 | 365 | ||
237 | /* | 366 | /* |
238 | * Transform user interface. | 367 | * Transform user interface. |
239 | */ | 368 | */ |
240 | 369 | ||
241 | /* | ||
242 | * crypto_alloc_tfm() will first attempt to locate an already loaded algorithm. | ||
243 | * If that fails and the kernel supports dynamically loadable modules, it | ||
244 | * will then attempt to load a module of the same name or alias. A refcount | ||
245 | * is grabbed on the algorithm which is then associated with the new transform. | ||
246 | * | ||
247 | * crypto_free_tfm() frees up the transform and any associated resources, | ||
248 | * then drops the refcount on the associated algorithm. | ||
249 | */ | ||
250 | struct crypto_tfm *crypto_alloc_tfm(const char *alg_name, u32 tfm_flags); | 370 | struct crypto_tfm *crypto_alloc_tfm(const char *alg_name, u32 tfm_flags); |
371 | struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask); | ||
251 | void crypto_free_tfm(struct crypto_tfm *tfm); | 372 | void crypto_free_tfm(struct crypto_tfm *tfm); |
252 | 373 | ||
253 | /* | 374 | /* |
@@ -258,6 +379,16 @@ static inline const char *crypto_tfm_alg_name(struct crypto_tfm *tfm) | |||
258 | return tfm->__crt_alg->cra_name; | 379 | return tfm->__crt_alg->cra_name; |
259 | } | 380 | } |
260 | 381 | ||
382 | static inline const char *crypto_tfm_alg_driver_name(struct crypto_tfm *tfm) | ||
383 | { | ||
384 | return tfm->__crt_alg->cra_driver_name; | ||
385 | } | ||
386 | |||
387 | static inline int crypto_tfm_alg_priority(struct crypto_tfm *tfm) | ||
388 | { | ||
389 | return tfm->__crt_alg->cra_priority; | ||
390 | } | ||
391 | |||
261 | static inline const char *crypto_tfm_alg_modname(struct crypto_tfm *tfm) | 392 | static inline const char *crypto_tfm_alg_modname(struct crypto_tfm *tfm) |
262 | { | 393 | { |
263 | return module_name(tfm->__crt_alg->cra_module); | 394 | return module_name(tfm->__crt_alg->cra_module); |
@@ -268,18 +399,23 @@ static inline u32 crypto_tfm_alg_type(struct crypto_tfm *tfm) | |||
268 | return tfm->__crt_alg->cra_flags & CRYPTO_ALG_TYPE_MASK; | 399 | return tfm->__crt_alg->cra_flags & CRYPTO_ALG_TYPE_MASK; |
269 | } | 400 | } |
270 | 401 | ||
402 | static unsigned int crypto_tfm_alg_min_keysize(struct crypto_tfm *tfm) | ||
403 | __deprecated; | ||
271 | static inline unsigned int crypto_tfm_alg_min_keysize(struct crypto_tfm *tfm) | 404 | static inline unsigned int crypto_tfm_alg_min_keysize(struct crypto_tfm *tfm) |
272 | { | 405 | { |
273 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); | 406 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); |
274 | return tfm->__crt_alg->cra_cipher.cia_min_keysize; | 407 | return tfm->__crt_alg->cra_cipher.cia_min_keysize; |
275 | } | 408 | } |
276 | 409 | ||
410 | static unsigned int crypto_tfm_alg_max_keysize(struct crypto_tfm *tfm) | ||
411 | __deprecated; | ||
277 | static inline unsigned int crypto_tfm_alg_max_keysize(struct crypto_tfm *tfm) | 412 | static inline unsigned int crypto_tfm_alg_max_keysize(struct crypto_tfm *tfm) |
278 | { | 413 | { |
279 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); | 414 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); |
280 | return tfm->__crt_alg->cra_cipher.cia_max_keysize; | 415 | return tfm->__crt_alg->cra_cipher.cia_max_keysize; |
281 | } | 416 | } |
282 | 417 | ||
418 | static unsigned int crypto_tfm_alg_ivsize(struct crypto_tfm *tfm) __deprecated; | ||
283 | static inline unsigned int crypto_tfm_alg_ivsize(struct crypto_tfm *tfm) | 419 | static inline unsigned int crypto_tfm_alg_ivsize(struct crypto_tfm *tfm) |
284 | { | 420 | { |
285 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); | 421 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); |
@@ -302,6 +438,21 @@ static inline unsigned int crypto_tfm_alg_alignmask(struct crypto_tfm *tfm) | |||
302 | return tfm->__crt_alg->cra_alignmask; | 438 | return tfm->__crt_alg->cra_alignmask; |
303 | } | 439 | } |
304 | 440 | ||
441 | static inline u32 crypto_tfm_get_flags(struct crypto_tfm *tfm) | ||
442 | { | ||
443 | return tfm->crt_flags; | ||
444 | } | ||
445 | |||
446 | static inline void crypto_tfm_set_flags(struct crypto_tfm *tfm, u32 flags) | ||
447 | { | ||
448 | tfm->crt_flags |= flags; | ||
449 | } | ||
450 | |||
451 | static inline void crypto_tfm_clear_flags(struct crypto_tfm *tfm, u32 flags) | ||
452 | { | ||
453 | tfm->crt_flags &= ~flags; | ||
454 | } | ||
455 | |||
305 | static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm) | 456 | static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm) |
306 | { | 457 | { |
307 | return tfm->__crt_ctx; | 458 | return tfm->__crt_ctx; |
@@ -316,50 +467,374 @@ static inline unsigned int crypto_tfm_ctx_alignment(void) | |||
316 | /* | 467 | /* |
317 | * API wrappers. | 468 | * API wrappers. |
318 | */ | 469 | */ |
319 | static inline void crypto_digest_init(struct crypto_tfm *tfm) | 470 | static inline struct crypto_blkcipher *__crypto_blkcipher_cast( |
471 | struct crypto_tfm *tfm) | ||
320 | { | 472 | { |
321 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST); | 473 | return (struct crypto_blkcipher *)tfm; |
322 | tfm->crt_digest.dit_init(tfm); | ||
323 | } | 474 | } |
324 | 475 | ||
325 | static inline void crypto_digest_update(struct crypto_tfm *tfm, | 476 | static inline struct crypto_blkcipher *crypto_blkcipher_cast( |
326 | struct scatterlist *sg, | 477 | struct crypto_tfm *tfm) |
327 | unsigned int nsg) | ||
328 | { | 478 | { |
329 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST); | 479 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_BLKCIPHER); |
330 | tfm->crt_digest.dit_update(tfm, sg, nsg); | 480 | return __crypto_blkcipher_cast(tfm); |
331 | } | 481 | } |
332 | 482 | ||
333 | static inline void crypto_digest_final(struct crypto_tfm *tfm, u8 *out) | 483 | static inline struct crypto_blkcipher *crypto_alloc_blkcipher( |
484 | const char *alg_name, u32 type, u32 mask) | ||
334 | { | 485 | { |
335 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST); | 486 | type &= ~CRYPTO_ALG_TYPE_MASK; |
336 | tfm->crt_digest.dit_final(tfm, out); | 487 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; |
488 | mask |= CRYPTO_ALG_TYPE_MASK; | ||
489 | |||
490 | return __crypto_blkcipher_cast(crypto_alloc_base(alg_name, type, mask)); | ||
337 | } | 491 | } |
338 | 492 | ||
339 | static inline void crypto_digest_digest(struct crypto_tfm *tfm, | 493 | static inline struct crypto_tfm *crypto_blkcipher_tfm( |
340 | struct scatterlist *sg, | 494 | struct crypto_blkcipher *tfm) |
341 | unsigned int nsg, u8 *out) | ||
342 | { | 495 | { |
343 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST); | 496 | return &tfm->base; |
344 | tfm->crt_digest.dit_digest(tfm, sg, nsg, out); | ||
345 | } | 497 | } |
346 | 498 | ||
347 | static inline int crypto_digest_setkey(struct crypto_tfm *tfm, | 499 | static inline void crypto_free_blkcipher(struct crypto_blkcipher *tfm) |
500 | { | ||
501 | crypto_free_tfm(crypto_blkcipher_tfm(tfm)); | ||
502 | } | ||
503 | |||
504 | static inline int crypto_has_blkcipher(const char *alg_name, u32 type, u32 mask) | ||
505 | { | ||
506 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
507 | type |= CRYPTO_ALG_TYPE_BLKCIPHER; | ||
508 | mask |= CRYPTO_ALG_TYPE_MASK; | ||
509 | |||
510 | return crypto_has_alg(alg_name, type, mask); | ||
511 | } | ||
512 | |||
513 | static inline const char *crypto_blkcipher_name(struct crypto_blkcipher *tfm) | ||
514 | { | ||
515 | return crypto_tfm_alg_name(crypto_blkcipher_tfm(tfm)); | ||
516 | } | ||
517 | |||
518 | static inline struct blkcipher_tfm *crypto_blkcipher_crt( | ||
519 | struct crypto_blkcipher *tfm) | ||
520 | { | ||
521 | return &crypto_blkcipher_tfm(tfm)->crt_blkcipher; | ||
522 | } | ||
523 | |||
524 | static inline struct blkcipher_alg *crypto_blkcipher_alg( | ||
525 | struct crypto_blkcipher *tfm) | ||
526 | { | ||
527 | return &crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher; | ||
528 | } | ||
529 | |||
530 | static inline unsigned int crypto_blkcipher_ivsize(struct crypto_blkcipher *tfm) | ||
531 | { | ||
532 | return crypto_blkcipher_alg(tfm)->ivsize; | ||
533 | } | ||
534 | |||
535 | static inline unsigned int crypto_blkcipher_blocksize( | ||
536 | struct crypto_blkcipher *tfm) | ||
537 | { | ||
538 | return crypto_tfm_alg_blocksize(crypto_blkcipher_tfm(tfm)); | ||
539 | } | ||
540 | |||
541 | static inline unsigned int crypto_blkcipher_alignmask( | ||
542 | struct crypto_blkcipher *tfm) | ||
543 | { | ||
544 | return crypto_tfm_alg_alignmask(crypto_blkcipher_tfm(tfm)); | ||
545 | } | ||
546 | |||
547 | static inline u32 crypto_blkcipher_get_flags(struct crypto_blkcipher *tfm) | ||
548 | { | ||
549 | return crypto_tfm_get_flags(crypto_blkcipher_tfm(tfm)); | ||
550 | } | ||
551 | |||
552 | static inline void crypto_blkcipher_set_flags(struct crypto_blkcipher *tfm, | ||
553 | u32 flags) | ||
554 | { | ||
555 | crypto_tfm_set_flags(crypto_blkcipher_tfm(tfm), flags); | ||
556 | } | ||
557 | |||
558 | static inline void crypto_blkcipher_clear_flags(struct crypto_blkcipher *tfm, | ||
559 | u32 flags) | ||
560 | { | ||
561 | crypto_tfm_clear_flags(crypto_blkcipher_tfm(tfm), flags); | ||
562 | } | ||
563 | |||
564 | static inline int crypto_blkcipher_setkey(struct crypto_blkcipher *tfm, | ||
565 | const u8 *key, unsigned int keylen) | ||
566 | { | ||
567 | return crypto_blkcipher_crt(tfm)->setkey(crypto_blkcipher_tfm(tfm), | ||
568 | key, keylen); | ||
569 | } | ||
570 | |||
571 | static inline int crypto_blkcipher_encrypt(struct blkcipher_desc *desc, | ||
572 | struct scatterlist *dst, | ||
573 | struct scatterlist *src, | ||
574 | unsigned int nbytes) | ||
575 | { | ||
576 | desc->info = crypto_blkcipher_crt(desc->tfm)->iv; | ||
577 | return crypto_blkcipher_crt(desc->tfm)->encrypt(desc, dst, src, nbytes); | ||
578 | } | ||
579 | |||
580 | static inline int crypto_blkcipher_encrypt_iv(struct blkcipher_desc *desc, | ||
581 | struct scatterlist *dst, | ||
582 | struct scatterlist *src, | ||
583 | unsigned int nbytes) | ||
584 | { | ||
585 | return crypto_blkcipher_crt(desc->tfm)->encrypt(desc, dst, src, nbytes); | ||
586 | } | ||
587 | |||
588 | static inline int crypto_blkcipher_decrypt(struct blkcipher_desc *desc, | ||
589 | struct scatterlist *dst, | ||
590 | struct scatterlist *src, | ||
591 | unsigned int nbytes) | ||
592 | { | ||
593 | desc->info = crypto_blkcipher_crt(desc->tfm)->iv; | ||
594 | return crypto_blkcipher_crt(desc->tfm)->decrypt(desc, dst, src, nbytes); | ||
595 | } | ||
596 | |||
597 | static inline int crypto_blkcipher_decrypt_iv(struct blkcipher_desc *desc, | ||
598 | struct scatterlist *dst, | ||
599 | struct scatterlist *src, | ||
600 | unsigned int nbytes) | ||
601 | { | ||
602 | return crypto_blkcipher_crt(desc->tfm)->decrypt(desc, dst, src, nbytes); | ||
603 | } | ||
604 | |||
605 | static inline void crypto_blkcipher_set_iv(struct crypto_blkcipher *tfm, | ||
606 | const u8 *src, unsigned int len) | ||
607 | { | ||
608 | memcpy(crypto_blkcipher_crt(tfm)->iv, src, len); | ||
609 | } | ||
610 | |||
611 | static inline void crypto_blkcipher_get_iv(struct crypto_blkcipher *tfm, | ||
612 | u8 *dst, unsigned int len) | ||
613 | { | ||
614 | memcpy(dst, crypto_blkcipher_crt(tfm)->iv, len); | ||
615 | } | ||
616 | |||
617 | static inline struct crypto_cipher *__crypto_cipher_cast(struct crypto_tfm *tfm) | ||
618 | { | ||
619 | return (struct crypto_cipher *)tfm; | ||
620 | } | ||
621 | |||
622 | static inline struct crypto_cipher *crypto_cipher_cast(struct crypto_tfm *tfm) | ||
623 | { | ||
624 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); | ||
625 | return __crypto_cipher_cast(tfm); | ||
626 | } | ||
627 | |||
628 | static inline struct crypto_cipher *crypto_alloc_cipher(const char *alg_name, | ||
629 | u32 type, u32 mask) | ||
630 | { | ||
631 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
632 | type |= CRYPTO_ALG_TYPE_CIPHER; | ||
633 | mask |= CRYPTO_ALG_TYPE_MASK; | ||
634 | |||
635 | return __crypto_cipher_cast(crypto_alloc_base(alg_name, type, mask)); | ||
636 | } | ||
637 | |||
638 | static inline struct crypto_tfm *crypto_cipher_tfm(struct crypto_cipher *tfm) | ||
639 | { | ||
640 | return tfm; | ||
641 | } | ||
642 | |||
643 | static inline void crypto_free_cipher(struct crypto_cipher *tfm) | ||
644 | { | ||
645 | crypto_free_tfm(crypto_cipher_tfm(tfm)); | ||
646 | } | ||
647 | |||
648 | static inline int crypto_has_cipher(const char *alg_name, u32 type, u32 mask) | ||
649 | { | ||
650 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
651 | type |= CRYPTO_ALG_TYPE_CIPHER; | ||
652 | mask |= CRYPTO_ALG_TYPE_MASK; | ||
653 | |||
654 | return crypto_has_alg(alg_name, type, mask); | ||
655 | } | ||
656 | |||
657 | static inline struct cipher_tfm *crypto_cipher_crt(struct crypto_cipher *tfm) | ||
658 | { | ||
659 | return &crypto_cipher_tfm(tfm)->crt_cipher; | ||
660 | } | ||
661 | |||
662 | static inline unsigned int crypto_cipher_blocksize(struct crypto_cipher *tfm) | ||
663 | { | ||
664 | return crypto_tfm_alg_blocksize(crypto_cipher_tfm(tfm)); | ||
665 | } | ||
666 | |||
667 | static inline unsigned int crypto_cipher_alignmask(struct crypto_cipher *tfm) | ||
668 | { | ||
669 | return crypto_tfm_alg_alignmask(crypto_cipher_tfm(tfm)); | ||
670 | } | ||
671 | |||
672 | static inline u32 crypto_cipher_get_flags(struct crypto_cipher *tfm) | ||
673 | { | ||
674 | return crypto_tfm_get_flags(crypto_cipher_tfm(tfm)); | ||
675 | } | ||
676 | |||
677 | static inline void crypto_cipher_set_flags(struct crypto_cipher *tfm, | ||
678 | u32 flags) | ||
679 | { | ||
680 | crypto_tfm_set_flags(crypto_cipher_tfm(tfm), flags); | ||
681 | } | ||
682 | |||
683 | static inline void crypto_cipher_clear_flags(struct crypto_cipher *tfm, | ||
684 | u32 flags) | ||
685 | { | ||
686 | crypto_tfm_clear_flags(crypto_cipher_tfm(tfm), flags); | ||
687 | } | ||
688 | |||
689 | static inline int crypto_cipher_setkey(struct crypto_cipher *tfm, | ||
348 | const u8 *key, unsigned int keylen) | 690 | const u8 *key, unsigned int keylen) |
349 | { | 691 | { |
350 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST); | 692 | return crypto_cipher_crt(tfm)->cit_setkey(crypto_cipher_tfm(tfm), |
351 | if (tfm->crt_digest.dit_setkey == NULL) | 693 | key, keylen); |
352 | return -ENOSYS; | 694 | } |
353 | return tfm->crt_digest.dit_setkey(tfm, key, keylen); | 695 | |
696 | static inline void crypto_cipher_encrypt_one(struct crypto_cipher *tfm, | ||
697 | u8 *dst, const u8 *src) | ||
698 | { | ||
699 | crypto_cipher_crt(tfm)->cit_encrypt_one(crypto_cipher_tfm(tfm), | ||
700 | dst, src); | ||
701 | } | ||
702 | |||
703 | static inline void crypto_cipher_decrypt_one(struct crypto_cipher *tfm, | ||
704 | u8 *dst, const u8 *src) | ||
705 | { | ||
706 | crypto_cipher_crt(tfm)->cit_decrypt_one(crypto_cipher_tfm(tfm), | ||
707 | dst, src); | ||
708 | } | ||
709 | |||
710 | void crypto_digest_init(struct crypto_tfm *tfm) __deprecated_for_modules; | ||
711 | void crypto_digest_update(struct crypto_tfm *tfm, | ||
712 | struct scatterlist *sg, unsigned int nsg) | ||
713 | __deprecated_for_modules; | ||
714 | void crypto_digest_final(struct crypto_tfm *tfm, u8 *out) | ||
715 | __deprecated_for_modules; | ||
716 | void crypto_digest_digest(struct crypto_tfm *tfm, | ||
717 | struct scatterlist *sg, unsigned int nsg, u8 *out) | ||
718 | __deprecated_for_modules; | ||
719 | |||
720 | static inline struct crypto_hash *__crypto_hash_cast(struct crypto_tfm *tfm) | ||
721 | { | ||
722 | return (struct crypto_hash *)tfm; | ||
723 | } | ||
724 | |||
725 | static inline struct crypto_hash *crypto_hash_cast(struct crypto_tfm *tfm) | ||
726 | { | ||
727 | BUG_ON((crypto_tfm_alg_type(tfm) ^ CRYPTO_ALG_TYPE_HASH) & | ||
728 | CRYPTO_ALG_TYPE_HASH_MASK); | ||
729 | return __crypto_hash_cast(tfm); | ||
354 | } | 730 | } |
355 | 731 | ||
356 | static inline int crypto_cipher_setkey(struct crypto_tfm *tfm, | 732 | static int crypto_digest_setkey(struct crypto_tfm *tfm, const u8 *key, |
733 | unsigned int keylen) __deprecated; | ||
734 | static inline int crypto_digest_setkey(struct crypto_tfm *tfm, | ||
357 | const u8 *key, unsigned int keylen) | 735 | const u8 *key, unsigned int keylen) |
358 | { | 736 | { |
359 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); | 737 | return tfm->crt_hash.setkey(crypto_hash_cast(tfm), key, keylen); |
360 | return tfm->crt_cipher.cit_setkey(tfm, key, keylen); | 738 | } |
739 | |||
740 | static inline struct crypto_hash *crypto_alloc_hash(const char *alg_name, | ||
741 | u32 type, u32 mask) | ||
742 | { | ||
743 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
744 | type |= CRYPTO_ALG_TYPE_HASH; | ||
745 | mask |= CRYPTO_ALG_TYPE_HASH_MASK; | ||
746 | |||
747 | return __crypto_hash_cast(crypto_alloc_base(alg_name, type, mask)); | ||
748 | } | ||
749 | |||
750 | static inline struct crypto_tfm *crypto_hash_tfm(struct crypto_hash *tfm) | ||
751 | { | ||
752 | return &tfm->base; | ||
753 | } | ||
754 | |||
755 | static inline void crypto_free_hash(struct crypto_hash *tfm) | ||
756 | { | ||
757 | crypto_free_tfm(crypto_hash_tfm(tfm)); | ||
758 | } | ||
759 | |||
760 | static inline int crypto_has_hash(const char *alg_name, u32 type, u32 mask) | ||
761 | { | ||
762 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
763 | type |= CRYPTO_ALG_TYPE_HASH; | ||
764 | mask |= CRYPTO_ALG_TYPE_HASH_MASK; | ||
765 | |||
766 | return crypto_has_alg(alg_name, type, mask); | ||
767 | } | ||
768 | |||
769 | static inline struct hash_tfm *crypto_hash_crt(struct crypto_hash *tfm) | ||
770 | { | ||
771 | return &crypto_hash_tfm(tfm)->crt_hash; | ||
772 | } | ||
773 | |||
774 | static inline unsigned int crypto_hash_blocksize(struct crypto_hash *tfm) | ||
775 | { | ||
776 | return crypto_tfm_alg_blocksize(crypto_hash_tfm(tfm)); | ||
777 | } | ||
778 | |||
779 | static inline unsigned int crypto_hash_alignmask(struct crypto_hash *tfm) | ||
780 | { | ||
781 | return crypto_tfm_alg_alignmask(crypto_hash_tfm(tfm)); | ||
782 | } | ||
783 | |||
784 | static inline unsigned int crypto_hash_digestsize(struct crypto_hash *tfm) | ||
785 | { | ||
786 | return crypto_hash_crt(tfm)->digestsize; | ||
787 | } | ||
788 | |||
789 | static inline u32 crypto_hash_get_flags(struct crypto_hash *tfm) | ||
790 | { | ||
791 | return crypto_tfm_get_flags(crypto_hash_tfm(tfm)); | ||
792 | } | ||
793 | |||
794 | static inline void crypto_hash_set_flags(struct crypto_hash *tfm, u32 flags) | ||
795 | { | ||
796 | crypto_tfm_set_flags(crypto_hash_tfm(tfm), flags); | ||
361 | } | 797 | } |
362 | 798 | ||
799 | static inline void crypto_hash_clear_flags(struct crypto_hash *tfm, u32 flags) | ||
800 | { | ||
801 | crypto_tfm_clear_flags(crypto_hash_tfm(tfm), flags); | ||
802 | } | ||
803 | |||
804 | static inline int crypto_hash_init(struct hash_desc *desc) | ||
805 | { | ||
806 | return crypto_hash_crt(desc->tfm)->init(desc); | ||
807 | } | ||
808 | |||
809 | static inline int crypto_hash_update(struct hash_desc *desc, | ||
810 | struct scatterlist *sg, | ||
811 | unsigned int nbytes) | ||
812 | { | ||
813 | return crypto_hash_crt(desc->tfm)->update(desc, sg, nbytes); | ||
814 | } | ||
815 | |||
816 | static inline int crypto_hash_final(struct hash_desc *desc, u8 *out) | ||
817 | { | ||
818 | return crypto_hash_crt(desc->tfm)->final(desc, out); | ||
819 | } | ||
820 | |||
821 | static inline int crypto_hash_digest(struct hash_desc *desc, | ||
822 | struct scatterlist *sg, | ||
823 | unsigned int nbytes, u8 *out) | ||
824 | { | ||
825 | return crypto_hash_crt(desc->tfm)->digest(desc, sg, nbytes, out); | ||
826 | } | ||
827 | |||
828 | static inline int crypto_hash_setkey(struct crypto_hash *hash, | ||
829 | const u8 *key, unsigned int keylen) | ||
830 | { | ||
831 | return crypto_hash_crt(hash)->setkey(hash, key, keylen); | ||
832 | } | ||
833 | |||
834 | static int crypto_cipher_encrypt(struct crypto_tfm *tfm, | ||
835 | struct scatterlist *dst, | ||
836 | struct scatterlist *src, | ||
837 | unsigned int nbytes) __deprecated; | ||
363 | static inline int crypto_cipher_encrypt(struct crypto_tfm *tfm, | 838 | static inline int crypto_cipher_encrypt(struct crypto_tfm *tfm, |
364 | struct scatterlist *dst, | 839 | struct scatterlist *dst, |
365 | struct scatterlist *src, | 840 | struct scatterlist *src, |
@@ -369,16 +844,23 @@ static inline int crypto_cipher_encrypt(struct crypto_tfm *tfm, | |||
369 | return tfm->crt_cipher.cit_encrypt(tfm, dst, src, nbytes); | 844 | return tfm->crt_cipher.cit_encrypt(tfm, dst, src, nbytes); |
370 | } | 845 | } |
371 | 846 | ||
847 | static int crypto_cipher_encrypt_iv(struct crypto_tfm *tfm, | ||
848 | struct scatterlist *dst, | ||
849 | struct scatterlist *src, | ||
850 | unsigned int nbytes, u8 *iv) __deprecated; | ||
372 | static inline int crypto_cipher_encrypt_iv(struct crypto_tfm *tfm, | 851 | static inline int crypto_cipher_encrypt_iv(struct crypto_tfm *tfm, |
373 | struct scatterlist *dst, | 852 | struct scatterlist *dst, |
374 | struct scatterlist *src, | 853 | struct scatterlist *src, |
375 | unsigned int nbytes, u8 *iv) | 854 | unsigned int nbytes, u8 *iv) |
376 | { | 855 | { |
377 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); | 856 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); |
378 | BUG_ON(tfm->crt_cipher.cit_mode == CRYPTO_TFM_MODE_ECB); | ||
379 | return tfm->crt_cipher.cit_encrypt_iv(tfm, dst, src, nbytes, iv); | 857 | return tfm->crt_cipher.cit_encrypt_iv(tfm, dst, src, nbytes, iv); |
380 | } | 858 | } |
381 | 859 | ||
860 | static int crypto_cipher_decrypt(struct crypto_tfm *tfm, | ||
861 | struct scatterlist *dst, | ||
862 | struct scatterlist *src, | ||
863 | unsigned int nbytes) __deprecated; | ||
382 | static inline int crypto_cipher_decrypt(struct crypto_tfm *tfm, | 864 | static inline int crypto_cipher_decrypt(struct crypto_tfm *tfm, |
383 | struct scatterlist *dst, | 865 | struct scatterlist *dst, |
384 | struct scatterlist *src, | 866 | struct scatterlist *src, |
@@ -388,16 +870,21 @@ static inline int crypto_cipher_decrypt(struct crypto_tfm *tfm, | |||
388 | return tfm->crt_cipher.cit_decrypt(tfm, dst, src, nbytes); | 870 | return tfm->crt_cipher.cit_decrypt(tfm, dst, src, nbytes); |
389 | } | 871 | } |
390 | 872 | ||
873 | static int crypto_cipher_decrypt_iv(struct crypto_tfm *tfm, | ||
874 | struct scatterlist *dst, | ||
875 | struct scatterlist *src, | ||
876 | unsigned int nbytes, u8 *iv) __deprecated; | ||
391 | static inline int crypto_cipher_decrypt_iv(struct crypto_tfm *tfm, | 877 | static inline int crypto_cipher_decrypt_iv(struct crypto_tfm *tfm, |
392 | struct scatterlist *dst, | 878 | struct scatterlist *dst, |
393 | struct scatterlist *src, | 879 | struct scatterlist *src, |
394 | unsigned int nbytes, u8 *iv) | 880 | unsigned int nbytes, u8 *iv) |
395 | { | 881 | { |
396 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); | 882 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); |
397 | BUG_ON(tfm->crt_cipher.cit_mode == CRYPTO_TFM_MODE_ECB); | ||
398 | return tfm->crt_cipher.cit_decrypt_iv(tfm, dst, src, nbytes, iv); | 883 | return tfm->crt_cipher.cit_decrypt_iv(tfm, dst, src, nbytes, iv); |
399 | } | 884 | } |
400 | 885 | ||
886 | static void crypto_cipher_set_iv(struct crypto_tfm *tfm, | ||
887 | const u8 *src, unsigned int len) __deprecated; | ||
401 | static inline void crypto_cipher_set_iv(struct crypto_tfm *tfm, | 888 | static inline void crypto_cipher_set_iv(struct crypto_tfm *tfm, |
402 | const u8 *src, unsigned int len) | 889 | const u8 *src, unsigned int len) |
403 | { | 890 | { |
@@ -405,6 +892,8 @@ static inline void crypto_cipher_set_iv(struct crypto_tfm *tfm, | |||
405 | memcpy(tfm->crt_cipher.cit_iv, src, len); | 892 | memcpy(tfm->crt_cipher.cit_iv, src, len); |
406 | } | 893 | } |
407 | 894 | ||
895 | static void crypto_cipher_get_iv(struct crypto_tfm *tfm, | ||
896 | u8 *dst, unsigned int len) __deprecated; | ||
408 | static inline void crypto_cipher_get_iv(struct crypto_tfm *tfm, | 897 | static inline void crypto_cipher_get_iv(struct crypto_tfm *tfm, |
409 | u8 *dst, unsigned int len) | 898 | u8 *dst, unsigned int len) |
410 | { | 899 | { |
@@ -412,34 +901,70 @@ static inline void crypto_cipher_get_iv(struct crypto_tfm *tfm, | |||
412 | memcpy(dst, tfm->crt_cipher.cit_iv, len); | 901 | memcpy(dst, tfm->crt_cipher.cit_iv, len); |
413 | } | 902 | } |
414 | 903 | ||
415 | static inline int crypto_comp_compress(struct crypto_tfm *tfm, | 904 | static inline struct crypto_comp *__crypto_comp_cast(struct crypto_tfm *tfm) |
905 | { | ||
906 | return (struct crypto_comp *)tfm; | ||
907 | } | ||
908 | |||
909 | static inline struct crypto_comp *crypto_comp_cast(struct crypto_tfm *tfm) | ||
910 | { | ||
911 | BUG_ON((crypto_tfm_alg_type(tfm) ^ CRYPTO_ALG_TYPE_COMPRESS) & | ||
912 | CRYPTO_ALG_TYPE_MASK); | ||
913 | return __crypto_comp_cast(tfm); | ||
914 | } | ||
915 | |||
916 | static inline struct crypto_comp *crypto_alloc_comp(const char *alg_name, | ||
917 | u32 type, u32 mask) | ||
918 | { | ||
919 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
920 | type |= CRYPTO_ALG_TYPE_COMPRESS; | ||
921 | mask |= CRYPTO_ALG_TYPE_MASK; | ||
922 | |||
923 | return __crypto_comp_cast(crypto_alloc_base(alg_name, type, mask)); | ||
924 | } | ||
925 | |||
926 | static inline struct crypto_tfm *crypto_comp_tfm(struct crypto_comp *tfm) | ||
927 | { | ||
928 | return tfm; | ||
929 | } | ||
930 | |||
931 | static inline void crypto_free_comp(struct crypto_comp *tfm) | ||
932 | { | ||
933 | crypto_free_tfm(crypto_comp_tfm(tfm)); | ||
934 | } | ||
935 | |||
936 | static inline int crypto_has_comp(const char *alg_name, u32 type, u32 mask) | ||
937 | { | ||
938 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
939 | type |= CRYPTO_ALG_TYPE_COMPRESS; | ||
940 | mask |= CRYPTO_ALG_TYPE_MASK; | ||
941 | |||
942 | return crypto_has_alg(alg_name, type, mask); | ||
943 | } | ||
944 | |||
945 | static inline const char *crypto_comp_name(struct crypto_comp *tfm) | ||
946 | { | ||
947 | return crypto_tfm_alg_name(crypto_comp_tfm(tfm)); | ||
948 | } | ||
949 | |||
950 | static inline struct compress_tfm *crypto_comp_crt(struct crypto_comp *tfm) | ||
951 | { | ||
952 | return &crypto_comp_tfm(tfm)->crt_compress; | ||
953 | } | ||
954 | |||
955 | static inline int crypto_comp_compress(struct crypto_comp *tfm, | ||
416 | const u8 *src, unsigned int slen, | 956 | const u8 *src, unsigned int slen, |
417 | u8 *dst, unsigned int *dlen) | 957 | u8 *dst, unsigned int *dlen) |
418 | { | 958 | { |
419 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_COMPRESS); | 959 | return crypto_comp_crt(tfm)->cot_compress(tfm, src, slen, dst, dlen); |
420 | return tfm->crt_compress.cot_compress(tfm, src, slen, dst, dlen); | ||
421 | } | 960 | } |
422 | 961 | ||
423 | static inline int crypto_comp_decompress(struct crypto_tfm *tfm, | 962 | static inline int crypto_comp_decompress(struct crypto_comp *tfm, |
424 | const u8 *src, unsigned int slen, | 963 | const u8 *src, unsigned int slen, |
425 | u8 *dst, unsigned int *dlen) | 964 | u8 *dst, unsigned int *dlen) |
426 | { | 965 | { |
427 | BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_COMPRESS); | 966 | return crypto_comp_crt(tfm)->cot_decompress(tfm, src, slen, dst, dlen); |
428 | return tfm->crt_compress.cot_decompress(tfm, src, slen, dst, dlen); | ||
429 | } | 967 | } |
430 | 968 | ||
431 | /* | ||
432 | * HMAC support. | ||
433 | */ | ||
434 | #ifdef CONFIG_CRYPTO_HMAC | ||
435 | void crypto_hmac_init(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen); | ||
436 | void crypto_hmac_update(struct crypto_tfm *tfm, | ||
437 | struct scatterlist *sg, unsigned int nsg); | ||
438 | void crypto_hmac_final(struct crypto_tfm *tfm, u8 *key, | ||
439 | unsigned int *keylen, u8 *out); | ||
440 | void crypto_hmac(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen, | ||
441 | struct scatterlist *sg, unsigned int nsg, u8 *out); | ||
442 | #endif /* CONFIG_CRYPTO_HMAC */ | ||
443 | |||
444 | #endif /* _LINUX_CRYPTO_H */ | 969 | #endif /* _LINUX_CRYPTO_H */ |
445 | 970 | ||
diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h index 66ff545552f7..4efbd9c445f5 100644 --- a/include/linux/scatterlist.h +++ b/include/linux/scatterlist.h | |||
@@ -5,7 +5,7 @@ | |||
5 | #include <linux/mm.h> | 5 | #include <linux/mm.h> |
6 | #include <linux/string.h> | 6 | #include <linux/string.h> |
7 | 7 | ||
8 | static inline void sg_set_buf(struct scatterlist *sg, void *buf, | 8 | static inline void sg_set_buf(struct scatterlist *sg, const void *buf, |
9 | unsigned int buflen) | 9 | unsigned int buflen) |
10 | { | 10 | { |
11 | sg->page = virt_to_page(buf); | 11 | sg->page = virt_to_page(buf); |
@@ -13,7 +13,7 @@ static inline void sg_set_buf(struct scatterlist *sg, void *buf, | |||
13 | sg->length = buflen; | 13 | sg->length = buflen; |
14 | } | 14 | } |
15 | 15 | ||
16 | static inline void sg_init_one(struct scatterlist *sg, void *buf, | 16 | static inline void sg_init_one(struct scatterlist *sg, const void *buf, |
17 | unsigned int buflen) | 17 | unsigned int buflen) |
18 | { | 18 | { |
19 | memset(sg, 0, sizeof(*sg)); | 19 | memset(sg, 0, sizeof(*sg)); |
diff --git a/include/linux/sunrpc/gss_krb5.h b/include/linux/sunrpc/gss_krb5.h index 1279280d7196..e30ba201910a 100644 --- a/include/linux/sunrpc/gss_krb5.h +++ b/include/linux/sunrpc/gss_krb5.h | |||
@@ -46,8 +46,8 @@ struct krb5_ctx { | |||
46 | unsigned char seed[16]; | 46 | unsigned char seed[16]; |
47 | int signalg; | 47 | int signalg; |
48 | int sealalg; | 48 | int sealalg; |
49 | struct crypto_tfm *enc; | 49 | struct crypto_blkcipher *enc; |
50 | struct crypto_tfm *seq; | 50 | struct crypto_blkcipher *seq; |
51 | s32 endtime; | 51 | s32 endtime; |
52 | u32 seq_send; | 52 | u32 seq_send; |
53 | struct xdr_netobj mech_used; | 53 | struct xdr_netobj mech_used; |
@@ -136,26 +136,27 @@ gss_unwrap_kerberos(struct gss_ctx *ctx_id, int offset, | |||
136 | 136 | ||
137 | 137 | ||
138 | u32 | 138 | u32 |
139 | krb5_encrypt(struct crypto_tfm * key, | 139 | krb5_encrypt(struct crypto_blkcipher *key, |
140 | void *iv, void *in, void *out, int length); | 140 | void *iv, void *in, void *out, int length); |
141 | 141 | ||
142 | u32 | 142 | u32 |
143 | krb5_decrypt(struct crypto_tfm * key, | 143 | krb5_decrypt(struct crypto_blkcipher *key, |
144 | void *iv, void *in, void *out, int length); | 144 | void *iv, void *in, void *out, int length); |
145 | 145 | ||
146 | int | 146 | int |
147 | gss_encrypt_xdr_buf(struct crypto_tfm *tfm, struct xdr_buf *outbuf, int offset, | 147 | gss_encrypt_xdr_buf(struct crypto_blkcipher *tfm, struct xdr_buf *outbuf, |
148 | struct page **pages); | 148 | int offset, struct page **pages); |
149 | 149 | ||
150 | int | 150 | int |
151 | gss_decrypt_xdr_buf(struct crypto_tfm *tfm, struct xdr_buf *inbuf, int offset); | 151 | gss_decrypt_xdr_buf(struct crypto_blkcipher *tfm, struct xdr_buf *inbuf, |
152 | int offset); | ||
152 | 153 | ||
153 | s32 | 154 | s32 |
154 | krb5_make_seq_num(struct crypto_tfm * key, | 155 | krb5_make_seq_num(struct crypto_blkcipher *key, |
155 | int direction, | 156 | int direction, |
156 | s32 seqnum, unsigned char *cksum, unsigned char *buf); | 157 | s32 seqnum, unsigned char *cksum, unsigned char *buf); |
157 | 158 | ||
158 | s32 | 159 | s32 |
159 | krb5_get_seq_num(struct crypto_tfm * key, | 160 | krb5_get_seq_num(struct crypto_blkcipher *key, |
160 | unsigned char *cksum, | 161 | unsigned char *cksum, |
161 | unsigned char *buf, int *direction, s32 * seqnum); | 162 | unsigned char *buf, int *direction, s32 * seqnum); |
diff --git a/include/linux/sunrpc/gss_spkm3.h b/include/linux/sunrpc/gss_spkm3.h index 336e218c2782..2cf3fbb40b4f 100644 --- a/include/linux/sunrpc/gss_spkm3.h +++ b/include/linux/sunrpc/gss_spkm3.h | |||
@@ -19,9 +19,9 @@ struct spkm3_ctx { | |||
19 | unsigned int req_flags ; | 19 | unsigned int req_flags ; |
20 | struct xdr_netobj share_key; | 20 | struct xdr_netobj share_key; |
21 | int conf_alg; | 21 | int conf_alg; |
22 | struct crypto_tfm* derived_conf_key; | 22 | struct crypto_blkcipher *derived_conf_key; |
23 | int intg_alg; | 23 | int intg_alg; |
24 | struct crypto_tfm* derived_integ_key; | 24 | struct crypto_blkcipher *derived_integ_key; |
25 | int keyestb_alg; /* alg used to get share_key */ | 25 | int keyestb_alg; /* alg used to get share_key */ |
26 | int owf_alg; /* one way function */ | 26 | int owf_alg; /* one way function */ |
27 | }; | 27 | }; |
diff --git a/include/net/ah.h b/include/net/ah.h index ceff00afae09..8f257c159902 100644 --- a/include/net/ah.h +++ b/include/net/ah.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef _NET_AH_H | 1 | #ifndef _NET_AH_H |
2 | #define _NET_AH_H | 2 | #define _NET_AH_H |
3 | 3 | ||
4 | #include <linux/crypto.h> | ||
4 | #include <net/xfrm.h> | 5 | #include <net/xfrm.h> |
5 | 6 | ||
6 | /* This is the maximum truncated ICV length that we know of. */ | 7 | /* This is the maximum truncated ICV length that we know of. */ |
@@ -14,22 +15,29 @@ struct ah_data | |||
14 | int icv_full_len; | 15 | int icv_full_len; |
15 | int icv_trunc_len; | 16 | int icv_trunc_len; |
16 | 17 | ||
17 | void (*icv)(struct ah_data*, | 18 | struct crypto_hash *tfm; |
18 | struct sk_buff *skb, u8 *icv); | ||
19 | |||
20 | struct crypto_tfm *tfm; | ||
21 | }; | 19 | }; |
22 | 20 | ||
23 | static inline void | 21 | static inline int ah_mac_digest(struct ah_data *ahp, struct sk_buff *skb, |
24 | ah_hmac_digest(struct ah_data *ahp, struct sk_buff *skb, u8 *auth_data) | 22 | u8 *auth_data) |
25 | { | 23 | { |
26 | struct crypto_tfm *tfm = ahp->tfm; | 24 | struct hash_desc desc; |
25 | int err; | ||
26 | |||
27 | desc.tfm = ahp->tfm; | ||
28 | desc.flags = 0; | ||
27 | 29 | ||
28 | memset(auth_data, 0, ahp->icv_trunc_len); | 30 | memset(auth_data, 0, ahp->icv_trunc_len); |
29 | crypto_hmac_init(tfm, ahp->key, &ahp->key_len); | 31 | err = crypto_hash_init(&desc); |
30 | skb_icv_walk(skb, tfm, 0, skb->len, crypto_hmac_update); | 32 | if (unlikely(err)) |
31 | crypto_hmac_final(tfm, ahp->key, &ahp->key_len, ahp->work_icv); | 33 | goto out; |
32 | memcpy(auth_data, ahp->work_icv, ahp->icv_trunc_len); | 34 | err = skb_icv_walk(skb, &desc, 0, skb->len, crypto_hash_update); |
35 | if (unlikely(err)) | ||
36 | goto out; | ||
37 | err = crypto_hash_final(&desc, ahp->work_icv); | ||
38 | |||
39 | out: | ||
40 | return err; | ||
33 | } | 41 | } |
34 | 42 | ||
35 | #endif | 43 | #endif |
diff --git a/include/net/esp.h b/include/net/esp.h index 90cd94fad7d9..064366d66eea 100644 --- a/include/net/esp.h +++ b/include/net/esp.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef _NET_ESP_H | 1 | #ifndef _NET_ESP_H |
2 | #define _NET_ESP_H | 2 | #define _NET_ESP_H |
3 | 3 | ||
4 | #include <linux/crypto.h> | ||
4 | #include <net/xfrm.h> | 5 | #include <net/xfrm.h> |
5 | #include <asm/scatterlist.h> | 6 | #include <asm/scatterlist.h> |
6 | 7 | ||
@@ -21,7 +22,7 @@ struct esp_data | |||
21 | * >= crypto_tfm_alg_ivsize(tfm). */ | 22 | * >= crypto_tfm_alg_ivsize(tfm). */ |
22 | int ivlen; | 23 | int ivlen; |
23 | int padlen; /* 0..255 */ | 24 | int padlen; /* 0..255 */ |
24 | struct crypto_tfm *tfm; /* crypto handle */ | 25 | struct crypto_blkcipher *tfm; /* crypto handle */ |
25 | } conf; | 26 | } conf; |
26 | 27 | ||
27 | /* Integrity. It is active when icv_full_len != 0 */ | 28 | /* Integrity. It is active when icv_full_len != 0 */ |
@@ -34,7 +35,7 @@ struct esp_data | |||
34 | void (*icv)(struct esp_data*, | 35 | void (*icv)(struct esp_data*, |
35 | struct sk_buff *skb, | 36 | struct sk_buff *skb, |
36 | int offset, int len, u8 *icv); | 37 | int offset, int len, u8 *icv); |
37 | struct crypto_tfm *tfm; | 38 | struct crypto_hash *tfm; |
38 | } auth; | 39 | } auth; |
39 | }; | 40 | }; |
40 | 41 | ||
@@ -42,18 +43,22 @@ extern int skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int offset, | |||
42 | extern int skb_cow_data(struct sk_buff *skb, int tailbits, struct sk_buff **trailer); | 43 | extern int skb_cow_data(struct sk_buff *skb, int tailbits, struct sk_buff **trailer); |
43 | extern void *pskb_put(struct sk_buff *skb, struct sk_buff *tail, int len); | 44 | extern void *pskb_put(struct sk_buff *skb, struct sk_buff *tail, int len); |
44 | 45 | ||
45 | static inline void | 46 | static inline int esp_mac_digest(struct esp_data *esp, struct sk_buff *skb, |
46 | esp_hmac_digest(struct esp_data *esp, struct sk_buff *skb, int offset, | 47 | int offset, int len) |
47 | int len, u8 *auth_data) | ||
48 | { | 48 | { |
49 | struct crypto_tfm *tfm = esp->auth.tfm; | 49 | struct hash_desc desc; |
50 | char *icv = esp->auth.work_icv; | 50 | int err; |
51 | 51 | ||
52 | memset(auth_data, 0, esp->auth.icv_trunc_len); | 52 | desc.tfm = esp->auth.tfm; |
53 | crypto_hmac_init(tfm, esp->auth.key, &esp->auth.key_len); | 53 | desc.flags = 0; |
54 | skb_icv_walk(skb, tfm, offset, len, crypto_hmac_update); | 54 | |
55 | crypto_hmac_final(tfm, esp->auth.key, &esp->auth.key_len, icv); | 55 | err = crypto_hash_init(&desc); |
56 | memcpy(auth_data, icv, esp->auth.icv_trunc_len); | 56 | if (unlikely(err)) |
57 | return err; | ||
58 | err = skb_icv_walk(skb, &desc, offset, len, crypto_hash_update); | ||
59 | if (unlikely(err)) | ||
60 | return err; | ||
61 | return crypto_hash_final(&desc, esp->auth.work_icv); | ||
57 | } | 62 | } |
58 | 63 | ||
59 | #endif | 64 | #endif |
diff --git a/include/net/ipcomp.h b/include/net/ipcomp.h index e651a57ecdd5..87c1af3e5e82 100644 --- a/include/net/ipcomp.h +++ b/include/net/ipcomp.h | |||
@@ -1,11 +1,14 @@ | |||
1 | #ifndef _NET_IPCOMP_H | 1 | #ifndef _NET_IPCOMP_H |
2 | #define _NET_IPCOMP_H | 2 | #define _NET_IPCOMP_H |
3 | 3 | ||
4 | #include <linux/crypto.h> | ||
5 | #include <linux/types.h> | ||
6 | |||
4 | #define IPCOMP_SCRATCH_SIZE 65400 | 7 | #define IPCOMP_SCRATCH_SIZE 65400 |
5 | 8 | ||
6 | struct ipcomp_data { | 9 | struct ipcomp_data { |
7 | u16 threshold; | 10 | u16 threshold; |
8 | struct crypto_tfm **tfms; | 11 | struct crypto_comp **tfms; |
9 | }; | 12 | }; |
10 | 13 | ||
11 | #endif | 14 | #endif |
diff --git a/include/net/sctp/constants.h b/include/net/sctp/constants.h index c51541ee0247..57166bfdf8eb 100644 --- a/include/net/sctp/constants.h +++ b/include/net/sctp/constants.h | |||
@@ -312,9 +312,9 @@ enum { SCTP_MAX_GABS = 16 }; | |||
312 | */ | 312 | */ |
313 | 313 | ||
314 | #if defined (CONFIG_SCTP_HMAC_MD5) | 314 | #if defined (CONFIG_SCTP_HMAC_MD5) |
315 | #define SCTP_COOKIE_HMAC_ALG "md5" | 315 | #define SCTP_COOKIE_HMAC_ALG "hmac(md5)" |
316 | #elif defined (CONFIG_SCTP_HMAC_SHA1) | 316 | #elif defined (CONFIG_SCTP_HMAC_SHA1) |
317 | #define SCTP_COOKIE_HMAC_ALG "sha1" | 317 | #define SCTP_COOKIE_HMAC_ALG "hmac(sha1)" |
318 | #else | 318 | #else |
319 | #define SCTP_COOKIE_HMAC_ALG NULL | 319 | #define SCTP_COOKIE_HMAC_ALG NULL |
320 | #endif | 320 | #endif |
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h index 92eae0e0f3f1..1c1abce5f6b6 100644 --- a/include/net/sctp/sctp.h +++ b/include/net/sctp/sctp.h | |||
@@ -330,17 +330,6 @@ static inline void sctp_v6_exit(void) { return; } | |||
330 | 330 | ||
331 | #endif /* #if defined(CONFIG_IPV6) */ | 331 | #endif /* #if defined(CONFIG_IPV6) */ |
332 | 332 | ||
333 | /* Some wrappers, in case crypto not available. */ | ||
334 | #if defined (CONFIG_CRYPTO_HMAC) | ||
335 | #define sctp_crypto_alloc_tfm crypto_alloc_tfm | ||
336 | #define sctp_crypto_free_tfm crypto_free_tfm | ||
337 | #define sctp_crypto_hmac crypto_hmac | ||
338 | #else | ||
339 | #define sctp_crypto_alloc_tfm(x...) NULL | ||
340 | #define sctp_crypto_free_tfm(x...) | ||
341 | #define sctp_crypto_hmac(x...) | ||
342 | #endif | ||
343 | |||
344 | 333 | ||
345 | /* Map an association to an assoc_id. */ | 334 | /* Map an association to an assoc_id. */ |
346 | static inline sctp_assoc_t sctp_assoc2id(const struct sctp_association *asoc) | 335 | static inline sctp_assoc_t sctp_assoc2id(const struct sctp_association *asoc) |
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h index e5aa7ff1f5b5..0412e730c765 100644 --- a/include/net/sctp/structs.h +++ b/include/net/sctp/structs.h | |||
@@ -87,6 +87,7 @@ struct sctp_bind_addr; | |||
87 | struct sctp_ulpq; | 87 | struct sctp_ulpq; |
88 | struct sctp_ep_common; | 88 | struct sctp_ep_common; |
89 | struct sctp_ssnmap; | 89 | struct sctp_ssnmap; |
90 | struct crypto_hash; | ||
90 | 91 | ||
91 | 92 | ||
92 | #include <net/sctp/tsnmap.h> | 93 | #include <net/sctp/tsnmap.h> |
@@ -264,7 +265,7 @@ struct sctp_sock { | |||
264 | struct sctp_pf *pf; | 265 | struct sctp_pf *pf; |
265 | 266 | ||
266 | /* Access to HMAC transform. */ | 267 | /* Access to HMAC transform. */ |
267 | struct crypto_tfm *hmac; | 268 | struct crypto_hash *hmac; |
268 | 269 | ||
269 | /* What is our base endpointer? */ | 270 | /* What is our base endpointer? */ |
270 | struct sctp_endpoint *ep; | 271 | struct sctp_endpoint *ep; |
diff --git a/include/net/xfrm.h b/include/net/xfrm.h index 9c5ee9f20b65..3ecd9fa1ed4b 100644 --- a/include/net/xfrm.h +++ b/include/net/xfrm.h | |||
@@ -8,7 +8,6 @@ | |||
8 | #include <linux/list.h> | 8 | #include <linux/list.h> |
9 | #include <linux/skbuff.h> | 9 | #include <linux/skbuff.h> |
10 | #include <linux/socket.h> | 10 | #include <linux/socket.h> |
11 | #include <linux/crypto.h> | ||
12 | #include <linux/pfkeyv2.h> | 11 | #include <linux/pfkeyv2.h> |
13 | #include <linux/in6.h> | 12 | #include <linux/in6.h> |
14 | #include <linux/mutex.h> | 13 | #include <linux/mutex.h> |
@@ -855,6 +854,7 @@ struct xfrm_algo_comp_info { | |||
855 | 854 | ||
856 | struct xfrm_algo_desc { | 855 | struct xfrm_algo_desc { |
857 | char *name; | 856 | char *name; |
857 | char *compat; | ||
858 | u8 available:1; | 858 | u8 available:1; |
859 | union { | 859 | union { |
860 | struct xfrm_algo_auth_info auth; | 860 | struct xfrm_algo_auth_info auth; |
@@ -984,11 +984,13 @@ extern struct xfrm_algo_desc *xfrm_aalg_get_byname(char *name, int probe); | |||
984 | extern struct xfrm_algo_desc *xfrm_ealg_get_byname(char *name, int probe); | 984 | extern struct xfrm_algo_desc *xfrm_ealg_get_byname(char *name, int probe); |
985 | extern struct xfrm_algo_desc *xfrm_calg_get_byname(char *name, int probe); | 985 | extern struct xfrm_algo_desc *xfrm_calg_get_byname(char *name, int probe); |
986 | 986 | ||
987 | struct crypto_tfm; | 987 | struct hash_desc; |
988 | typedef void (icv_update_fn_t)(struct crypto_tfm *, struct scatterlist *, unsigned int); | 988 | struct scatterlist; |
989 | typedef int (icv_update_fn_t)(struct hash_desc *, struct scatterlist *, | ||
990 | unsigned int); | ||
989 | 991 | ||
990 | extern void skb_icv_walk(const struct sk_buff *skb, struct crypto_tfm *tfm, | 992 | extern int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *tfm, |
991 | int offset, int len, icv_update_fn_t icv_update); | 993 | int offset, int len, icv_update_fn_t icv_update); |
992 | 994 | ||
993 | static inline int xfrm_addr_cmp(xfrm_address_t *a, xfrm_address_t *b, | 995 | static inline int xfrm_addr_cmp(xfrm_address_t *a, xfrm_address_t *b, |
994 | int family) | 996 | int family) |