Commit 54ccb36776eb7e03b592bfab60393c7800851a0b
Committed by
Herbert Xu
1 parent
3b8efb4c41
Exists in
master
and in
39 other branches
crypto: sha1 - Switch to shash
This patch changes sha1 to the new shash interface. Signed-off-by: Adrian-Ken Rueegsegger <ken@codelabs.ch> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Showing 2 changed files with 32 additions and 26 deletions Side-by-side Diff
crypto/Kconfig
crypto/sha1_generic.c
... | ... | @@ -16,10 +16,10 @@ |
16 | 16 | * any later version. |
17 | 17 | * |
18 | 18 | */ |
19 | +#include <crypto/internal/hash.h> | |
19 | 20 | #include <linux/init.h> |
20 | 21 | #include <linux/module.h> |
21 | 22 | #include <linux/mm.h> |
22 | -#include <linux/crypto.h> | |
23 | 23 | #include <linux/cryptohash.h> |
24 | 24 | #include <linux/types.h> |
25 | 25 | #include <crypto/sha.h> |
26 | 26 | |
... | ... | @@ -31,9 +31,10 @@ |
31 | 31 | u8 buffer[64]; |
32 | 32 | }; |
33 | 33 | |
34 | -static void sha1_init(struct crypto_tfm *tfm) | |
34 | +static int sha1_init(struct shash_desc *desc) | |
35 | 35 | { |
36 | - struct sha1_ctx *sctx = crypto_tfm_ctx(tfm); | |
36 | + struct sha1_ctx *sctx = shash_desc_ctx(desc); | |
37 | + | |
37 | 38 | static const struct sha1_ctx initstate = { |
38 | 39 | 0, |
39 | 40 | { SHA1_H0, SHA1_H1, SHA1_H2, SHA1_H3, SHA1_H4 }, |
40 | 41 | |
41 | 42 | |
... | ... | @@ -41,12 +42,14 @@ |
41 | 42 | }; |
42 | 43 | |
43 | 44 | *sctx = initstate; |
45 | + | |
46 | + return 0; | |
44 | 47 | } |
45 | 48 | |
46 | -static void sha1_update(struct crypto_tfm *tfm, const u8 *data, | |
49 | +static int sha1_update(struct shash_desc *desc, const u8 *data, | |
47 | 50 | unsigned int len) |
48 | 51 | { |
49 | - struct sha1_ctx *sctx = crypto_tfm_ctx(tfm); | |
52 | + struct sha1_ctx *sctx = shash_desc_ctx(desc); | |
50 | 53 | unsigned int partial, done; |
51 | 54 | const u8 *src; |
52 | 55 | |
53 | 56 | |
54 | 57 | |
... | ... | @@ -74,13 +77,15 @@ |
74 | 77 | partial = 0; |
75 | 78 | } |
76 | 79 | memcpy(sctx->buffer + partial, src, len - done); |
80 | + | |
81 | + return 0; | |
77 | 82 | } |
78 | 83 | |
79 | 84 | |
80 | 85 | /* Add padding and return the message digest. */ |
81 | -static void sha1_final(struct crypto_tfm *tfm, u8 *out) | |
86 | +static int sha1_final(struct shash_desc *desc, u8 *out) | |
82 | 87 | { |
83 | - struct sha1_ctx *sctx = crypto_tfm_ctx(tfm); | |
88 | + struct sha1_ctx *sctx = shash_desc_ctx(desc); | |
84 | 89 | __be32 *dst = (__be32 *)out; |
85 | 90 | u32 i, index, padlen; |
86 | 91 | __be64 bits; |
87 | 92 | |
... | ... | @@ -91,10 +96,10 @@ |
91 | 96 | /* Pad out to 56 mod 64 */ |
92 | 97 | index = sctx->count & 0x3f; |
93 | 98 | padlen = (index < 56) ? (56 - index) : ((64+56) - index); |
94 | - sha1_update(tfm, padding, padlen); | |
99 | + sha1_update(desc, padding, padlen); | |
95 | 100 | |
96 | 101 | /* Append length */ |
97 | - sha1_update(tfm, (const u8 *)&bits, sizeof(bits)); | |
102 | + sha1_update(desc, (const u8 *)&bits, sizeof(bits)); | |
98 | 103 | |
99 | 104 | /* Store state in digest */ |
100 | 105 | for (i = 0; i < 5; i++) |
101 | 106 | |
102 | 107 | |
103 | 108 | |
... | ... | @@ -102,32 +107,33 @@ |
102 | 107 | |
103 | 108 | /* Wipe context */ |
104 | 109 | memset(sctx, 0, sizeof *sctx); |
110 | + | |
111 | + return 0; | |
105 | 112 | } |
106 | 113 | |
107 | -static struct crypto_alg alg = { | |
108 | - .cra_name = "sha1", | |
109 | - .cra_driver_name= "sha1-generic", | |
110 | - .cra_flags = CRYPTO_ALG_TYPE_DIGEST, | |
111 | - .cra_blocksize = SHA1_BLOCK_SIZE, | |
112 | - .cra_ctxsize = sizeof(struct sha1_ctx), | |
113 | - .cra_module = THIS_MODULE, | |
114 | - .cra_alignmask = 3, | |
115 | - .cra_list = LIST_HEAD_INIT(alg.cra_list), | |
116 | - .cra_u = { .digest = { | |
117 | - .dia_digestsize = SHA1_DIGEST_SIZE, | |
118 | - .dia_init = sha1_init, | |
119 | - .dia_update = sha1_update, | |
120 | - .dia_final = sha1_final } } | |
114 | +static struct shash_alg alg = { | |
115 | + .digestsize = SHA1_DIGEST_SIZE, | |
116 | + .init = sha1_init, | |
117 | + .update = sha1_update, | |
118 | + .final = sha1_final, | |
119 | + .descsize = sizeof(struct sha1_ctx), | |
120 | + .base = { | |
121 | + .cra_name = "sha1", | |
122 | + .cra_driver_name= "sha1-generic", | |
123 | + .cra_flags = CRYPTO_ALG_TYPE_SHASH, | |
124 | + .cra_blocksize = SHA1_BLOCK_SIZE, | |
125 | + .cra_module = THIS_MODULE, | |
126 | + } | |
121 | 127 | }; |
122 | 128 | |
123 | 129 | static int __init sha1_generic_mod_init(void) |
124 | 130 | { |
125 | - return crypto_register_alg(&alg); | |
131 | + return crypto_register_shash(&alg); | |
126 | 132 | } |
127 | 133 | |
128 | 134 | static void __exit sha1_generic_mod_fini(void) |
129 | 135 | { |
130 | - crypto_unregister_alg(&alg); | |
136 | + crypto_unregister_shash(&alg); | |
131 | 137 | } |
132 | 138 | |
133 | 139 | module_init(sha1_generic_mod_init); |