diff options
author | Adrian-Ken Rueegsegger <ken@codelabs.ch> | 2008-12-07 06:35:38 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2008-12-24 19:02:24 -0500 |
commit | 19e2bf146759aea38fd6c2daea08cb7a6367149b (patch) | |
tree | b8b49a02dc72ddf29f36bbfdc3d80056a64aea09 | |
parent | 4946510baac6aaa8658528e3deefc7e9ba2951a9 (diff) |
crypto: michael_mic - Switch to shash
This patch changes michael_mic to the new shash interface.
Signed-off-by: Adrian-Ken Rueegsegger <ken@codelabs.ch>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/Kconfig | 2 | ||||
-rw-r--r-- | crypto/michael_mic.c | 72 |
2 files changed, 42 insertions, 32 deletions
diff --git a/crypto/Kconfig b/crypto/Kconfig index bc29216aaada..3f88a526d2da 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig | |||
@@ -288,7 +288,7 @@ config CRYPTO_MD5 | |||
288 | 288 | ||
289 | config CRYPTO_MICHAEL_MIC | 289 | config CRYPTO_MICHAEL_MIC |
290 | tristate "Michael MIC keyed digest algorithm" | 290 | tristate "Michael MIC keyed digest algorithm" |
291 | select CRYPTO_ALGAPI | 291 | select CRYPTO_HASH |
292 | help | 292 | help |
293 | Michael MIC is used for message integrity protection in TKIP | 293 | Michael MIC is used for message integrity protection in TKIP |
294 | (IEEE 802.11i). This algorithm is required for TKIP, but it | 294 | (IEEE 802.11i). This algorithm is required for TKIP, but it |
diff --git a/crypto/michael_mic.c b/crypto/michael_mic.c index 9e917b8011b1..079b761bc70d 100644 --- a/crypto/michael_mic.c +++ b/crypto/michael_mic.c | |||
@@ -9,23 +9,25 @@ | |||
9 | * it under the terms of the GNU General Public License version 2 as | 9 | * it under the terms of the GNU General Public License version 2 as |
10 | * published by the Free Software Foundation. | 10 | * published by the Free Software Foundation. |
11 | */ | 11 | */ |
12 | 12 | #include <crypto/internal/hash.h> | |
13 | #include <asm/byteorder.h> | 13 | #include <asm/byteorder.h> |
14 | #include <linux/init.h> | 14 | #include <linux/init.h> |
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/string.h> | 16 | #include <linux/string.h> |
17 | #include <linux/crypto.h> | ||
18 | #include <linux/types.h> | 17 | #include <linux/types.h> |
19 | 18 | ||
20 | 19 | ||
21 | struct michael_mic_ctx { | 20 | struct michael_mic_ctx { |
21 | u32 l, r; | ||
22 | }; | ||
23 | |||
24 | struct michael_mic_desc_ctx { | ||
22 | u8 pending[4]; | 25 | u8 pending[4]; |
23 | size_t pending_len; | 26 | size_t pending_len; |
24 | 27 | ||
25 | u32 l, r; | 28 | u32 l, r; |
26 | }; | 29 | }; |
27 | 30 | ||
28 | |||
29 | static inline u32 xswap(u32 val) | 31 | static inline u32 xswap(u32 val) |
30 | { | 32 | { |
31 | return ((val & 0x00ff00ff) << 8) | ((val & 0xff00ff00) >> 8); | 33 | return ((val & 0x00ff00ff) << 8) | ((val & 0xff00ff00) >> 8); |
@@ -45,17 +47,22 @@ do { \ | |||
45 | } while (0) | 47 | } while (0) |
46 | 48 | ||
47 | 49 | ||
48 | static void michael_init(struct crypto_tfm *tfm) | 50 | static int michael_init(struct shash_desc *desc) |
49 | { | 51 | { |
50 | struct michael_mic_ctx *mctx = crypto_tfm_ctx(tfm); | 52 | struct michael_mic_desc_ctx *mctx = shash_desc_ctx(desc); |
53 | struct michael_mic_ctx *ctx = crypto_shash_ctx(desc->tfm); | ||
51 | mctx->pending_len = 0; | 54 | mctx->pending_len = 0; |
55 | mctx->l = ctx->l; | ||
56 | mctx->r = ctx->r; | ||
57 | |||
58 | return 0; | ||
52 | } | 59 | } |
53 | 60 | ||
54 | 61 | ||
55 | static void michael_update(struct crypto_tfm *tfm, const u8 *data, | 62 | static int michael_update(struct shash_desc *desc, const u8 *data, |
56 | unsigned int len) | 63 | unsigned int len) |
57 | { | 64 | { |
58 | struct michael_mic_ctx *mctx = crypto_tfm_ctx(tfm); | 65 | struct michael_mic_desc_ctx *mctx = shash_desc_ctx(desc); |
59 | const __le32 *src; | 66 | const __le32 *src; |
60 | 67 | ||
61 | if (mctx->pending_len) { | 68 | if (mctx->pending_len) { |
@@ -68,7 +75,7 @@ static void michael_update(struct crypto_tfm *tfm, const u8 *data, | |||
68 | len -= flen; | 75 | len -= flen; |
69 | 76 | ||
70 | if (mctx->pending_len < 4) | 77 | if (mctx->pending_len < 4) |
71 | return; | 78 | return 0; |
72 | 79 | ||
73 | src = (const __le32 *)mctx->pending; | 80 | src = (const __le32 *)mctx->pending; |
74 | mctx->l ^= le32_to_cpup(src); | 81 | mctx->l ^= le32_to_cpup(src); |
@@ -88,12 +95,14 @@ static void michael_update(struct crypto_tfm *tfm, const u8 *data, | |||
88 | mctx->pending_len = len; | 95 | mctx->pending_len = len; |
89 | memcpy(mctx->pending, src, len); | 96 | memcpy(mctx->pending, src, len); |
90 | } | 97 | } |
98 | |||
99 | return 0; | ||
91 | } | 100 | } |
92 | 101 | ||
93 | 102 | ||
94 | static void michael_final(struct crypto_tfm *tfm, u8 *out) | 103 | static int michael_final(struct shash_desc *desc, u8 *out) |
95 | { | 104 | { |
96 | struct michael_mic_ctx *mctx = crypto_tfm_ctx(tfm); | 105 | struct michael_mic_desc_ctx *mctx = shash_desc_ctx(desc); |
97 | u8 *data = mctx->pending; | 106 | u8 *data = mctx->pending; |
98 | __le32 *dst = (__le32 *)out; | 107 | __le32 *dst = (__le32 *)out; |
99 | 108 | ||
@@ -119,17 +128,20 @@ static void michael_final(struct crypto_tfm *tfm, u8 *out) | |||
119 | 128 | ||
120 | dst[0] = cpu_to_le32(mctx->l); | 129 | dst[0] = cpu_to_le32(mctx->l); |
121 | dst[1] = cpu_to_le32(mctx->r); | 130 | dst[1] = cpu_to_le32(mctx->r); |
131 | |||
132 | return 0; | ||
122 | } | 133 | } |
123 | 134 | ||
124 | 135 | ||
125 | static int michael_setkey(struct crypto_tfm *tfm, const u8 *key, | 136 | static int michael_setkey(struct crypto_shash *tfm, const u8 *key, |
126 | unsigned int keylen) | 137 | unsigned int keylen) |
127 | { | 138 | { |
128 | struct michael_mic_ctx *mctx = crypto_tfm_ctx(tfm); | 139 | struct michael_mic_ctx *mctx = crypto_shash_ctx(tfm); |
140 | |||
129 | const __le32 *data = (const __le32 *)key; | 141 | const __le32 *data = (const __le32 *)key; |
130 | 142 | ||
131 | if (keylen != 8) { | 143 | if (keylen != 8) { |
132 | tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; | 144 | crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); |
133 | return -EINVAL; | 145 | return -EINVAL; |
134 | } | 146 | } |
135 | 147 | ||
@@ -138,33 +150,31 @@ static int michael_setkey(struct crypto_tfm *tfm, const u8 *key, | |||
138 | return 0; | 150 | return 0; |
139 | } | 151 | } |
140 | 152 | ||
141 | 153 | static struct shash_alg alg = { | |
142 | static struct crypto_alg michael_mic_alg = { | 154 | .digestsize = 8, |
143 | .cra_name = "michael_mic", | 155 | .setkey = michael_setkey, |
144 | .cra_flags = CRYPTO_ALG_TYPE_DIGEST, | 156 | .init = michael_init, |
145 | .cra_blocksize = 8, | 157 | .update = michael_update, |
146 | .cra_ctxsize = sizeof(struct michael_mic_ctx), | 158 | .final = michael_final, |
147 | .cra_module = THIS_MODULE, | 159 | .descsize = sizeof(struct michael_mic_desc_ctx), |
148 | .cra_alignmask = 3, | 160 | .base = { |
149 | .cra_list = LIST_HEAD_INIT(michael_mic_alg.cra_list), | 161 | .cra_name = "michael_mic", |
150 | .cra_u = { .digest = { | 162 | .cra_blocksize = 8, |
151 | .dia_digestsize = 8, | 163 | .cra_alignmask = 3, |
152 | .dia_init = michael_init, | 164 | .cra_ctxsize = sizeof(struct michael_mic_ctx), |
153 | .dia_update = michael_update, | 165 | .cra_module = THIS_MODULE, |
154 | .dia_final = michael_final, | 166 | } |
155 | .dia_setkey = michael_setkey } } | ||
156 | }; | 167 | }; |
157 | 168 | ||
158 | |||
159 | static int __init michael_mic_init(void) | 169 | static int __init michael_mic_init(void) |
160 | { | 170 | { |
161 | return crypto_register_alg(&michael_mic_alg); | 171 | return crypto_register_shash(&alg); |
162 | } | 172 | } |
163 | 173 | ||
164 | 174 | ||
165 | static void __exit michael_mic_exit(void) | 175 | static void __exit michael_mic_exit(void) |
166 | { | 176 | { |
167 | crypto_unregister_alg(&michael_mic_alg); | 177 | crypto_unregister_shash(&alg); |
168 | } | 178 | } |
169 | 179 | ||
170 | 180 | ||