.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Cryptographic API |
---|
3 | 4 | * |
---|
4 | 5 | * Michael MIC (IEEE 802.11i/TKIP) keyed digest |
---|
5 | 6 | * |
---|
6 | 7 | * Copyright (c) 2004 Jouni Malinen <j@w1.fi> |
---|
7 | | - * |
---|
8 | | - * This program is free software; you can redistribute it and/or modify |
---|
9 | | - * it under the terms of the GNU General Public License version 2 as |
---|
10 | | - * published by the Free Software Foundation. |
---|
11 | 8 | */ |
---|
12 | 9 | #include <crypto/internal/hash.h> |
---|
13 | | -#include <asm/byteorder.h> |
---|
| 10 | +#include <asm/unaligned.h> |
---|
14 | 11 | #include <linux/init.h> |
---|
15 | 12 | #include <linux/module.h> |
---|
16 | 13 | #include <linux/string.h> |
---|
.. | .. |
---|
22 | 19 | }; |
---|
23 | 20 | |
---|
24 | 21 | struct michael_mic_desc_ctx { |
---|
25 | | - u8 pending[4]; |
---|
| 22 | + __le32 pending; |
---|
26 | 23 | size_t pending_len; |
---|
27 | 24 | |
---|
28 | 25 | u32 l, r; |
---|
.. | .. |
---|
63 | 60 | unsigned int len) |
---|
64 | 61 | { |
---|
65 | 62 | struct michael_mic_desc_ctx *mctx = shash_desc_ctx(desc); |
---|
66 | | - const __le32 *src; |
---|
67 | 63 | |
---|
68 | 64 | if (mctx->pending_len) { |
---|
69 | 65 | int flen = 4 - mctx->pending_len; |
---|
70 | 66 | if (flen > len) |
---|
71 | 67 | flen = len; |
---|
72 | | - memcpy(&mctx->pending[mctx->pending_len], data, flen); |
---|
| 68 | + memcpy((u8 *)&mctx->pending + mctx->pending_len, data, flen); |
---|
73 | 69 | mctx->pending_len += flen; |
---|
74 | 70 | data += flen; |
---|
75 | 71 | len -= flen; |
---|
.. | .. |
---|
77 | 73 | if (mctx->pending_len < 4) |
---|
78 | 74 | return 0; |
---|
79 | 75 | |
---|
80 | | - src = (const __le32 *)mctx->pending; |
---|
81 | | - mctx->l ^= le32_to_cpup(src); |
---|
| 76 | + mctx->l ^= le32_to_cpu(mctx->pending); |
---|
82 | 77 | michael_block(mctx->l, mctx->r); |
---|
83 | 78 | mctx->pending_len = 0; |
---|
84 | 79 | } |
---|
85 | 80 | |
---|
86 | | - src = (const __le32 *)data; |
---|
87 | | - |
---|
88 | 81 | while (len >= 4) { |
---|
89 | | - mctx->l ^= le32_to_cpup(src++); |
---|
| 82 | + mctx->l ^= get_unaligned_le32(data); |
---|
90 | 83 | michael_block(mctx->l, mctx->r); |
---|
| 84 | + data += 4; |
---|
91 | 85 | len -= 4; |
---|
92 | 86 | } |
---|
93 | 87 | |
---|
94 | 88 | if (len > 0) { |
---|
95 | 89 | mctx->pending_len = len; |
---|
96 | | - memcpy(mctx->pending, src, len); |
---|
| 90 | + memcpy(&mctx->pending, data, len); |
---|
97 | 91 | } |
---|
98 | 92 | |
---|
99 | 93 | return 0; |
---|
.. | .. |
---|
103 | 97 | static int michael_final(struct shash_desc *desc, u8 *out) |
---|
104 | 98 | { |
---|
105 | 99 | struct michael_mic_desc_ctx *mctx = shash_desc_ctx(desc); |
---|
106 | | - u8 *data = mctx->pending; |
---|
107 | | - __le32 *dst = (__le32 *)out; |
---|
| 100 | + u8 *data = (u8 *)&mctx->pending; |
---|
108 | 101 | |
---|
109 | 102 | /* Last block and padding (0x5a, 4..7 x 0) */ |
---|
110 | 103 | switch (mctx->pending_len) { |
---|
.. | .. |
---|
126 | 119 | /* l ^= 0; */ |
---|
127 | 120 | michael_block(mctx->l, mctx->r); |
---|
128 | 121 | |
---|
129 | | - dst[0] = cpu_to_le32(mctx->l); |
---|
130 | | - dst[1] = cpu_to_le32(mctx->r); |
---|
| 122 | + put_unaligned_le32(mctx->l, out); |
---|
| 123 | + put_unaligned_le32(mctx->r, out + 4); |
---|
131 | 124 | |
---|
132 | 125 | return 0; |
---|
133 | 126 | } |
---|
.. | .. |
---|
138 | 131 | { |
---|
139 | 132 | struct michael_mic_ctx *mctx = crypto_shash_ctx(tfm); |
---|
140 | 133 | |
---|
141 | | - const __le32 *data = (const __le32 *)key; |
---|
142 | | - |
---|
143 | | - if (keylen != 8) { |
---|
144 | | - crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); |
---|
| 134 | + if (keylen != 8) |
---|
145 | 135 | return -EINVAL; |
---|
146 | | - } |
---|
147 | 136 | |
---|
148 | | - mctx->l = le32_to_cpu(data[0]); |
---|
149 | | - mctx->r = le32_to_cpu(data[1]); |
---|
| 137 | + mctx->l = get_unaligned_le32(key); |
---|
| 138 | + mctx->r = get_unaligned_le32(key + 4); |
---|
150 | 139 | return 0; |
---|
151 | 140 | } |
---|
152 | 141 | |
---|
.. | .. |
---|
159 | 148 | .descsize = sizeof(struct michael_mic_desc_ctx), |
---|
160 | 149 | .base = { |
---|
161 | 150 | .cra_name = "michael_mic", |
---|
| 151 | + .cra_driver_name = "michael_mic-generic", |
---|
162 | 152 | .cra_blocksize = 8, |
---|
163 | | - .cra_alignmask = 3, |
---|
164 | 153 | .cra_ctxsize = sizeof(struct michael_mic_ctx), |
---|
165 | 154 | .cra_module = THIS_MODULE, |
---|
166 | 155 | } |
---|
.. | .. |
---|
178 | 167 | } |
---|
179 | 168 | |
---|
180 | 169 | |
---|
181 | | -module_init(michael_mic_init); |
---|
| 170 | +subsys_initcall(michael_mic_init); |
---|
182 | 171 | module_exit(michael_mic_exit); |
---|
183 | 172 | |
---|
184 | 173 | MODULE_LICENSE("GPL v2"); |
---|