aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/ablkcipher.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/ablkcipher.c')
-rw-r--r--crypto/ablkcipher.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
new file mode 100644
index 000000000000..9348ddd84a56
--- /dev/null
+++ b/crypto/ablkcipher.c
@@ -0,0 +1,83 @@
1/*
2 * Asynchronous block chaining cipher operations.
3 *
4 * This is the asynchronous version of blkcipher.c indicating completion
5 * via a callback.
6 *
7 * Copyright (c) 2006 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#include <crypto/algapi.h>
17#include <linux/errno.h>
18#include <linux/init.h>
19#include <linux/module.h>
20#include <linux/seq_file.h>
21
22static int setkey(struct crypto_ablkcipher *tfm, const u8 *key,
23 unsigned int keylen)
24{
25 struct ablkcipher_alg *cipher = crypto_ablkcipher_alg(tfm);
26
27 if (keylen < cipher->min_keysize || keylen > cipher->max_keysize) {
28 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
29 return -EINVAL;
30 }
31
32 return cipher->setkey(tfm, key, keylen);
33}
34
35static unsigned int crypto_ablkcipher_ctxsize(struct crypto_alg *alg, u32 type,
36 u32 mask)
37{
38 return alg->cra_ctxsize;
39}
40
41static int crypto_init_ablkcipher_ops(struct crypto_tfm *tfm, u32 type,
42 u32 mask)
43{
44 struct ablkcipher_alg *alg = &tfm->__crt_alg->cra_ablkcipher;
45 struct ablkcipher_tfm *crt = &tfm->crt_ablkcipher;
46
47 if (alg->ivsize > PAGE_SIZE / 8)
48 return -EINVAL;
49
50 crt->setkey = setkey;
51 crt->encrypt = alg->encrypt;
52 crt->decrypt = alg->decrypt;
53 crt->ivsize = alg->ivsize;
54
55 return 0;
56}
57
58static void crypto_ablkcipher_show(struct seq_file *m, struct crypto_alg *alg)
59 __attribute__ ((unused));
60static void crypto_ablkcipher_show(struct seq_file *m, struct crypto_alg *alg)
61{
62 struct ablkcipher_alg *ablkcipher = &alg->cra_ablkcipher;
63
64 seq_printf(m, "type : ablkcipher\n");
65 seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
66 seq_printf(m, "min keysize : %u\n", ablkcipher->min_keysize);
67 seq_printf(m, "max keysize : %u\n", ablkcipher->max_keysize);
68 seq_printf(m, "ivsize : %u\n", ablkcipher->ivsize);
69 seq_printf(m, "qlen : %u\n", ablkcipher->queue->qlen);
70 seq_printf(m, "max qlen : %u\n", ablkcipher->queue->max_qlen);
71}
72
73const struct crypto_type crypto_ablkcipher_type = {
74 .ctxsize = crypto_ablkcipher_ctxsize,
75 .init = crypto_init_ablkcipher_ops,
76#ifdef CONFIG_PROC_FS
77 .show = crypto_ablkcipher_show,
78#endif
79};
80EXPORT_SYMBOL_GPL(crypto_ablkcipher_type);
81
82MODULE_LICENSE("GPL");
83MODULE_DESCRIPTION("Asynchronous block chaining cipher type");