blob: 4ccd22deef399aa477ba9e5c958d1516ff5dc50f [file] [log] [blame]
Herbert Xu055bcee2006-08-19 22:24:23 +10001/*
2 * Cryptographic Hash operations.
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#include <linux/errno.h>
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/seq_file.h>
16
17#include "internal.h"
18
Herbert Xu27d2a332007-01-24 20:50:26 +110019static unsigned int crypto_hash_ctxsize(struct crypto_alg *alg, u32 type,
20 u32 mask)
Herbert Xu055bcee2006-08-19 22:24:23 +100021{
22 return alg->cra_ctxsize;
23}
24
Herbert Xu27d2a332007-01-24 20:50:26 +110025static int crypto_init_hash_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
Herbert Xu055bcee2006-08-19 22:24:23 +100026{
27 struct hash_tfm *crt = &tfm->crt_hash;
28 struct hash_alg *alg = &tfm->__crt_alg->cra_hash;
29
30 if (alg->digestsize > crypto_tfm_alg_blocksize(tfm))
31 return -EINVAL;
32
33 crt->init = alg->init;
34 crt->update = alg->update;
35 crt->final = alg->final;
36 crt->digest = alg->digest;
37 crt->setkey = alg->setkey;
38 crt->digestsize = alg->digestsize;
39
40 return 0;
41}
42
43static void crypto_hash_show(struct seq_file *m, struct crypto_alg *alg)
Herbert Xu03f5d8c2006-12-31 10:42:06 +110044 __attribute__ ((unused));
Herbert Xu055bcee2006-08-19 22:24:23 +100045static void crypto_hash_show(struct seq_file *m, struct crypto_alg *alg)
46{
47 seq_printf(m, "type : hash\n");
48 seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
49 seq_printf(m, "digestsize : %u\n", alg->cra_hash.digestsize);
50}
51
52const struct crypto_type crypto_hash_type = {
53 .ctxsize = crypto_hash_ctxsize,
54 .init = crypto_init_hash_ops,
55#ifdef CONFIG_PROC_FS
56 .show = crypto_hash_show,
57#endif
58};
59EXPORT_SYMBOL_GPL(crypto_hash_type);
60
61MODULE_LICENSE("GPL");
62MODULE_DESCRIPTION("Generic cryptographic hash type");