aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2006-08-21 10:06:54 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2006-09-20 21:41:51 -0400
commite853c3cfa8cc24869ecd2526e589bcb176bc12e9 (patch)
tree24ad223420bdea868e891676ebb7285e3c477a05
parent8f21cf0d2bae04ece761595036c9da8328b279aa (diff)
[CRYPTO] api: Added crypto_type support
This patch adds the crypto_type structure which will be used for all new crypto algorithm types, beginning with block ciphers. The primary purpose of this abstraction is to allow different crypto_type objects for crypto algorithms of the same type, in particular, there will be a different crypto_type objects for asynchronous algorithms. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--crypto/api.c32
-rw-r--r--crypto/proc.c5
-rw-r--r--include/crypto/algapi.h8
-rw-r--r--include/linux/crypto.h3
4 files changed, 38 insertions, 10 deletions
diff --git a/crypto/api.c b/crypto/api.c
index bc4b7901acdf..edaa843d8e83 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -226,17 +226,18 @@ static int crypto_init_flags(struct crypto_tfm *tfm, u32 flags)
226 226
227 case CRYPTO_ALG_TYPE_COMPRESS: 227 case CRYPTO_ALG_TYPE_COMPRESS:
228 return crypto_init_compress_flags(tfm, flags); 228 return crypto_init_compress_flags(tfm, flags);
229
230 default:
231 break;
232 } 229 }
233 230
234 BUG(); 231 return 0;
235 return -EINVAL;
236} 232}
237 233
238static int crypto_init_ops(struct crypto_tfm *tfm) 234static int crypto_init_ops(struct crypto_tfm *tfm)
239{ 235{
236 const struct crypto_type *type = tfm->__crt_alg->cra_type;
237
238 if (type)
239 return type->init(tfm);
240
240 switch (crypto_tfm_alg_type(tfm)) { 241 switch (crypto_tfm_alg_type(tfm)) {
241 case CRYPTO_ALG_TYPE_CIPHER: 242 case CRYPTO_ALG_TYPE_CIPHER:
242 return crypto_init_cipher_ops(tfm); 243 return crypto_init_cipher_ops(tfm);
@@ -257,6 +258,14 @@ static int crypto_init_ops(struct crypto_tfm *tfm)
257 258
258static void crypto_exit_ops(struct crypto_tfm *tfm) 259static void crypto_exit_ops(struct crypto_tfm *tfm)
259{ 260{
261 const struct crypto_type *type = tfm->__crt_alg->cra_type;
262
263 if (type) {
264 if (type->exit)
265 type->exit(tfm);
266 return;
267 }
268
260 switch (crypto_tfm_alg_type(tfm)) { 269 switch (crypto_tfm_alg_type(tfm)) {
261 case CRYPTO_ALG_TYPE_CIPHER: 270 case CRYPTO_ALG_TYPE_CIPHER:
262 crypto_exit_cipher_ops(tfm); 271 crypto_exit_cipher_ops(tfm);
@@ -278,26 +287,31 @@ static void crypto_exit_ops(struct crypto_tfm *tfm)
278 287
279static unsigned int crypto_ctxsize(struct crypto_alg *alg, int flags) 288static unsigned int crypto_ctxsize(struct crypto_alg *alg, int flags)
280{ 289{
290 const struct crypto_type *type = alg->cra_type;
281 unsigned int len; 291 unsigned int len;
282 292
293 len = alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1);
294 if (type)
295 return len + type->ctxsize(alg);
296
283 switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) { 297 switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) {
284 default: 298 default:
285 BUG(); 299 BUG();
286 300
287 case CRYPTO_ALG_TYPE_CIPHER: 301 case CRYPTO_ALG_TYPE_CIPHER:
288 len = crypto_cipher_ctxsize(alg, flags); 302 len += crypto_cipher_ctxsize(alg, flags);
289 break; 303 break;
290 304
291 case CRYPTO_ALG_TYPE_DIGEST: 305 case CRYPTO_ALG_TYPE_DIGEST:
292 len = crypto_digest_ctxsize(alg, flags); 306 len += crypto_digest_ctxsize(alg, flags);
293 break; 307 break;
294 308
295 case CRYPTO_ALG_TYPE_COMPRESS: 309 case CRYPTO_ALG_TYPE_COMPRESS:
296 len = crypto_compress_ctxsize(alg, flags); 310 len += crypto_compress_ctxsize(alg, flags);
297 break; 311 break;
298 } 312 }
299 313
300 return len + (alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1)); 314 return len;
301} 315}
302 316
303void crypto_shoot_alg(struct crypto_alg *alg) 317void crypto_shoot_alg(struct crypto_alg *alg)
diff --git a/crypto/proc.c b/crypto/proc.c
index 9e573b17e887..dabce0676f63 100644
--- a/crypto/proc.c
+++ b/crypto/proc.c
@@ -78,7 +78,10 @@ static int c_show(struct seq_file *m, void *p)
78 seq_printf(m, "type : compression\n"); 78 seq_printf(m, "type : compression\n");
79 break; 79 break;
80 default: 80 default:
81 seq_printf(m, "type : unknown\n"); 81 if (alg->cra_type && alg->cra_type->show)
82 alg->cra_type->show(m, alg);
83 else
84 seq_printf(m, "type : unknown\n");
82 break; 85 break;
83 } 86 }
84 87
diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
index 1a598f829417..c533c0a291af 100644
--- a/include/crypto/algapi.h
+++ b/include/crypto/algapi.h
@@ -15,6 +15,14 @@
15#include <linux/crypto.h> 15#include <linux/crypto.h>
16 16
17struct module; 17struct module;
18struct seq_file;
19
20struct 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};
18 26
19struct crypto_instance { 27struct crypto_instance {
20 struct crypto_alg alg; 28 struct crypto_alg alg;
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index 6847ab0ea30e..8e9c407b00d2 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -90,6 +90,7 @@
90 90
91struct scatterlist; 91struct scatterlist;
92struct crypto_tfm; 92struct crypto_tfm;
93struct crypto_type;
93 94
94struct cipher_desc { 95struct cipher_desc {
95 struct crypto_tfm *tfm; 96 struct crypto_tfm *tfm;
@@ -161,6 +162,8 @@ struct crypto_alg {
161 char cra_name[CRYPTO_MAX_ALG_NAME]; 162 char cra_name[CRYPTO_MAX_ALG_NAME];
162 char cra_driver_name[CRYPTO_MAX_ALG_NAME]; 163 char cra_driver_name[CRYPTO_MAX_ALG_NAME];
163 164
165 const struct crypto_type *cra_type;
166
164 union { 167 union {
165 struct cipher_alg cipher; 168 struct cipher_alg cipher;
166 struct digest_alg digest; 169 struct digest_alg digest;