aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2007-12-17 08:51:27 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2008-01-10 16:16:43 -0500
commit61da88e2b800eed2b03834a73c46cc89ad48716d (patch)
tree00926f29041a08feefe379f2ce164099d7f82f45 /crypto
parent378f4f51f9fdd8df80ea875320e2bf1d7c6e6e77 (diff)
[CRYPTO] skcipher: Add givcrypt operations and givcipher type
Different block cipher modes have different requirements for intialisation vectors. For example, CBC can use a simple randomly generated IV while modes such as CTR must use an IV generation mechanisms that give a stronger guarantee on the lack of collisions. Furthermore, disk encryption modes have their own IV generation algorithms. Up until now IV generation has been left to the users of the symmetric key cipher API. This is inconvenient as the number of block cipher modes increase because the user needs to be aware of which mode is supposed to be paired with which IV generation algorithm. Therefore it makes sense to integrate the IV generation into the crypto API. This patch takes the first step in that direction by creating two new ablkcipher operations, givencrypt and givdecrypt that generates an IV before performing the actual encryption or decryption. The operations are currently not exposed to the user. That will be done once the underlying functionality has actually been implemented. It also creates the underlying givcipher type. Algorithms that directly generate IVs would use it instead of ablkcipher. All other algorithms (including all existing ones) would generate a givcipher algorithm upon registration. This givcipher algorithm will be constructed from the geniv string that's stored in every algorithm. That string will locate a template which is instantiated by the blkcipher/ablkcipher algorithm in question to give a givcipher algorithm. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/ablkcipher.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
index 0083140304d2..e403d8137ecd 100644
--- a/crypto/ablkcipher.c
+++ b/crypto/ablkcipher.c
@@ -107,6 +107,52 @@ const struct crypto_type crypto_ablkcipher_type = {
107}; 107};
108EXPORT_SYMBOL_GPL(crypto_ablkcipher_type); 108EXPORT_SYMBOL_GPL(crypto_ablkcipher_type);
109 109
110static int no_givdecrypt(struct skcipher_givcrypt_request *req)
111{
112 return -ENOSYS;
113}
114
115static int crypto_init_givcipher_ops(struct crypto_tfm *tfm, u32 type,
116 u32 mask)
117{
118 struct ablkcipher_alg *alg = &tfm->__crt_alg->cra_ablkcipher;
119 struct ablkcipher_tfm *crt = &tfm->crt_ablkcipher;
120
121 if (alg->ivsize > PAGE_SIZE / 8)
122 return -EINVAL;
123
124 crt->setkey = setkey;
125 crt->encrypt = alg->encrypt;
126 crt->decrypt = alg->decrypt;
127 crt->givencrypt = alg->givencrypt;
128 crt->givdecrypt = alg->givdecrypt ?: no_givdecrypt;
129 crt->ivsize = alg->ivsize;
130
131 return 0;
132}
133
134static void crypto_givcipher_show(struct seq_file *m, struct crypto_alg *alg)
135 __attribute__ ((unused));
136static void crypto_givcipher_show(struct seq_file *m, struct crypto_alg *alg)
137{
138 struct ablkcipher_alg *ablkcipher = &alg->cra_ablkcipher;
139
140 seq_printf(m, "type : givcipher\n");
141 seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
142 seq_printf(m, "min keysize : %u\n", ablkcipher->min_keysize);
143 seq_printf(m, "max keysize : %u\n", ablkcipher->max_keysize);
144 seq_printf(m, "ivsize : %u\n", ablkcipher->ivsize);
145}
146
147const struct crypto_type crypto_givcipher_type = {
148 .ctxsize = crypto_ablkcipher_ctxsize,
149 .init = crypto_init_givcipher_ops,
150#ifdef CONFIG_PROC_FS
151 .show = crypto_givcipher_show,
152#endif
153};
154EXPORT_SYMBOL_GPL(crypto_givcipher_type);
155
110int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name, 156int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name,
111 u32 type, u32 mask) 157 u32 type, u32 mask)
112{ 158{