aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/ahash.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2009-07-14 00:28:26 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2009-07-14 03:54:07 -0400
commit88056ec346ccf41f63dbc7080b24b5fd19d1358d (patch)
treeb78a82cbce49183e587ab8a1a5a5922611468361 /crypto/ahash.c
parent2ca33da1dea3ba53d1425226a6bac073c5e8568c (diff)
crypto: ahash - Convert to new style algorithms
This patch converts crypto_ahash to the new style. The old ahash algorithm type is retained until the existing ahash implementations are also converted. All ahash users will automatically get the new crypto_ahash type. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/ahash.c')
-rw-r--r--crypto/ahash.c82
1 files changed, 57 insertions, 25 deletions
diff --git a/crypto/ahash.c b/crypto/ahash.c
index f3476374f764..838519386215 100644
--- a/crypto/ahash.c
+++ b/crypto/ahash.c
@@ -24,6 +24,12 @@
24 24
25#include "internal.h" 25#include "internal.h"
26 26
27static inline struct ahash_alg *crypto_ahash_alg(struct crypto_ahash *hash)
28{
29 return container_of(crypto_hash_alg_common(hash), struct ahash_alg,
30 halg);
31}
32
27static int hash_walk_next(struct crypto_hash_walk *walk) 33static int hash_walk_next(struct crypto_hash_walk *walk)
28{ 34{
29 unsigned int alignmask = walk->alignmask; 35 unsigned int alignmask = walk->alignmask;
@@ -169,30 +175,11 @@ static int ahash_nosetkey(struct crypto_ahash *tfm, const u8 *key,
169 return -ENOSYS; 175 return -ENOSYS;
170} 176}
171 177
172int crypto_ahash_import(struct ahash_request *req, const u8 *in)
173{
174 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
175 struct ahash_alg *alg = crypto_ahash_alg(tfm);
176
177 memcpy(ahash_request_ctx(req), in, crypto_ahash_reqsize(tfm));
178
179 if (alg->reinit)
180 alg->reinit(req);
181
182 return 0;
183}
184EXPORT_SYMBOL_GPL(crypto_ahash_import);
185
186static unsigned int crypto_ahash_ctxsize(struct crypto_alg *alg, u32 type,
187 u32 mask)
188{
189 return alg->cra_ctxsize;
190}
191
192static int crypto_init_ahash_ops(struct crypto_tfm *tfm, u32 type, u32 mask) 178static int crypto_init_ahash_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
193{ 179{
194 struct ahash_alg *alg = &tfm->__crt_alg->cra_ahash; 180 struct old_ahash_alg *alg = &tfm->__crt_alg->cra_ahash;
195 struct ahash_tfm *crt = &tfm->crt_ahash; 181 struct crypto_ahash *crt = __crypto_ahash_cast(tfm);
182 struct ahash_alg *nalg = crypto_ahash_alg(crt);
196 183
197 if (alg->digestsize > PAGE_SIZE / 8) 184 if (alg->digestsize > PAGE_SIZE / 8)
198 return -EINVAL; 185 return -EINVAL;
@@ -204,9 +191,42 @@ static int crypto_init_ahash_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
204 crt->setkey = alg->setkey ? ahash_setkey : ahash_nosetkey; 191 crt->setkey = alg->setkey ? ahash_setkey : ahash_nosetkey;
205 crt->digestsize = alg->digestsize; 192 crt->digestsize = alg->digestsize;
206 193
194 nalg->setkey = alg->setkey;
195 nalg->halg.digestsize = alg->digestsize;
196
207 return 0; 197 return 0;
208} 198}
209 199
200static int crypto_ahash_init_tfm(struct crypto_tfm *tfm)
201{
202 struct crypto_ahash *hash = __crypto_ahash_cast(tfm);
203 struct ahash_alg *alg = crypto_ahash_alg(hash);
204 struct old_ahash_alg *oalg = crypto_old_ahash_alg(hash);
205
206 if (tfm->__crt_alg->cra_type != &crypto_ahash_type)
207 return crypto_init_shash_ops_async(tfm);
208
209 if (oalg->init)
210 return crypto_init_ahash_ops(tfm, 0, 0);
211
212 hash->init = alg->init;
213 hash->update = alg->update;
214 hash->final = alg->final;
215 hash->digest = alg->digest;
216 hash->setkey = alg->setkey ? ahash_setkey : ahash_nosetkey;
217 hash->digestsize = alg->halg.digestsize;
218
219 return 0;
220}
221
222static unsigned int crypto_ahash_extsize(struct crypto_alg *alg)
223{
224 if (alg->cra_type == &crypto_ahash_type)
225 return alg->cra_ctxsize;
226
227 return sizeof(struct crypto_shash *);
228}
229
210static void crypto_ahash_show(struct seq_file *m, struct crypto_alg *alg) 230static void crypto_ahash_show(struct seq_file *m, struct crypto_alg *alg)
211 __attribute__ ((unused)); 231 __attribute__ ((unused));
212static void crypto_ahash_show(struct seq_file *m, struct crypto_alg *alg) 232static void crypto_ahash_show(struct seq_file *m, struct crypto_alg *alg)
@@ -215,17 +235,29 @@ static void crypto_ahash_show(struct seq_file *m, struct crypto_alg *alg)
215 seq_printf(m, "async : %s\n", alg->cra_flags & CRYPTO_ALG_ASYNC ? 235 seq_printf(m, "async : %s\n", alg->cra_flags & CRYPTO_ALG_ASYNC ?
216 "yes" : "no"); 236 "yes" : "no");
217 seq_printf(m, "blocksize : %u\n", alg->cra_blocksize); 237 seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
218 seq_printf(m, "digestsize : %u\n", alg->cra_ahash.digestsize); 238 seq_printf(m, "digestsize : %u\n",
239 __crypto_hash_alg_common(alg)->digestsize);
219} 240}
220 241
221const struct crypto_type crypto_ahash_type = { 242const struct crypto_type crypto_ahash_type = {
222 .ctxsize = crypto_ahash_ctxsize, 243 .extsize = crypto_ahash_extsize,
223 .init = crypto_init_ahash_ops, 244 .init_tfm = crypto_ahash_init_tfm,
224#ifdef CONFIG_PROC_FS 245#ifdef CONFIG_PROC_FS
225 .show = crypto_ahash_show, 246 .show = crypto_ahash_show,
226#endif 247#endif
248 .maskclear = ~CRYPTO_ALG_TYPE_MASK,
249 .maskset = CRYPTO_ALG_TYPE_AHASH_MASK,
250 .type = CRYPTO_ALG_TYPE_AHASH,
251 .tfmsize = offsetof(struct crypto_ahash, base),
227}; 252};
228EXPORT_SYMBOL_GPL(crypto_ahash_type); 253EXPORT_SYMBOL_GPL(crypto_ahash_type);
229 254
255struct crypto_ahash *crypto_alloc_ahash(const char *alg_name, u32 type,
256 u32 mask)
257{
258 return crypto_alloc_tfm(alg_name, &crypto_ahash_type, type, mask);
259}
260EXPORT_SYMBOL_GPL(crypto_alloc_ahash);
261
230MODULE_LICENSE("GPL"); 262MODULE_LICENSE("GPL");
231MODULE_DESCRIPTION("Asynchronous cryptographic hash type"); 263MODULE_DESCRIPTION("Asynchronous cryptographic hash type");