diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2006-08-19 08:24:23 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2006-09-20 21:46:17 -0400 |
commit | 055bcee3102dc35f019b69df9c2618e9d6dd1c09 (patch) | |
tree | 3f7c68abbbb5041d570e4cb8588f3943530bc0b7 /crypto/hash.c | |
parent | 7226bc877a22244e8003924031435a4bffd52654 (diff) |
[CRYPTO] digest: Added user API for new hash type
The existing digest user interface is inadequate for support asynchronous
operations. For one it doesn't return a value to indicate success or
failure, nor does it take a per-operation descriptor which is essential
for the issuing of requests while other requests are still outstanding.
This patch is the first in a series of steps to remodel the interface
for asynchronous operations.
For the ease of transition the new interface will be known as "hash"
while the old one will remain as "digest".
This patch also changes sg_next to allow chaining.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/hash.c')
-rw-r--r-- | crypto/hash.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/crypto/hash.c b/crypto/hash.c new file mode 100644 index 000000000000..cdec23d885fe --- /dev/null +++ b/crypto/hash.c | |||
@@ -0,0 +1,61 @@ | |||
1 | /* | ||
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 | |||
19 | static unsigned int crypto_hash_ctxsize(struct crypto_alg *alg) | ||
20 | { | ||
21 | return alg->cra_ctxsize; | ||
22 | } | ||
23 | |||
24 | static int crypto_init_hash_ops(struct crypto_tfm *tfm) | ||
25 | { | ||
26 | struct hash_tfm *crt = &tfm->crt_hash; | ||
27 | struct hash_alg *alg = &tfm->__crt_alg->cra_hash; | ||
28 | |||
29 | if (alg->digestsize > crypto_tfm_alg_blocksize(tfm)) | ||
30 | return -EINVAL; | ||
31 | |||
32 | crt->init = alg->init; | ||
33 | crt->update = alg->update; | ||
34 | crt->final = alg->final; | ||
35 | crt->digest = alg->digest; | ||
36 | crt->setkey = alg->setkey; | ||
37 | crt->digestsize = alg->digestsize; | ||
38 | |||
39 | return 0; | ||
40 | } | ||
41 | |||
42 | static void crypto_hash_show(struct seq_file *m, struct crypto_alg *alg) | ||
43 | __attribute_used__; | ||
44 | static void crypto_hash_show(struct seq_file *m, struct crypto_alg *alg) | ||
45 | { | ||
46 | seq_printf(m, "type : hash\n"); | ||
47 | seq_printf(m, "blocksize : %u\n", alg->cra_blocksize); | ||
48 | seq_printf(m, "digestsize : %u\n", alg->cra_hash.digestsize); | ||
49 | } | ||
50 | |||
51 | const struct crypto_type crypto_hash_type = { | ||
52 | .ctxsize = crypto_hash_ctxsize, | ||
53 | .init = crypto_init_hash_ops, | ||
54 | #ifdef CONFIG_PROC_FS | ||
55 | .show = crypto_hash_show, | ||
56 | #endif | ||
57 | }; | ||
58 | EXPORT_SYMBOL_GPL(crypto_hash_type); | ||
59 | |||
60 | MODULE_LICENSE("GPL"); | ||
61 | MODULE_DESCRIPTION("Generic cryptographic hash type"); | ||