hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/crypto/michael_mic.c
....@@ -1,16 +1,13 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Cryptographic API
34 *
45 * Michael MIC (IEEE 802.11i/TKIP) keyed digest
56 *
67 * 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.
118 */
129 #include <crypto/internal/hash.h>
13
-#include <asm/byteorder.h>
10
+#include <asm/unaligned.h>
1411 #include <linux/init.h>
1512 #include <linux/module.h>
1613 #include <linux/string.h>
....@@ -22,7 +19,7 @@
2219 };
2320
2421 struct michael_mic_desc_ctx {
25
- u8 pending[4];
22
+ __le32 pending;
2623 size_t pending_len;
2724
2825 u32 l, r;
....@@ -63,13 +60,12 @@
6360 unsigned int len)
6461 {
6562 struct michael_mic_desc_ctx *mctx = shash_desc_ctx(desc);
66
- const __le32 *src;
6763
6864 if (mctx->pending_len) {
6965 int flen = 4 - mctx->pending_len;
7066 if (flen > len)
7167 flen = len;
72
- memcpy(&mctx->pending[mctx->pending_len], data, flen);
68
+ memcpy((u8 *)&mctx->pending + mctx->pending_len, data, flen);
7369 mctx->pending_len += flen;
7470 data += flen;
7571 len -= flen;
....@@ -77,23 +73,21 @@
7773 if (mctx->pending_len < 4)
7874 return 0;
7975
80
- src = (const __le32 *)mctx->pending;
81
- mctx->l ^= le32_to_cpup(src);
76
+ mctx->l ^= le32_to_cpu(mctx->pending);
8277 michael_block(mctx->l, mctx->r);
8378 mctx->pending_len = 0;
8479 }
8580
86
- src = (const __le32 *)data;
87
-
8881 while (len >= 4) {
89
- mctx->l ^= le32_to_cpup(src++);
82
+ mctx->l ^= get_unaligned_le32(data);
9083 michael_block(mctx->l, mctx->r);
84
+ data += 4;
9185 len -= 4;
9286 }
9387
9488 if (len > 0) {
9589 mctx->pending_len = len;
96
- memcpy(mctx->pending, src, len);
90
+ memcpy(&mctx->pending, data, len);
9791 }
9892
9993 return 0;
....@@ -103,8 +97,7 @@
10397 static int michael_final(struct shash_desc *desc, u8 *out)
10498 {
10599 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;
108101
109102 /* Last block and padding (0x5a, 4..7 x 0) */
110103 switch (mctx->pending_len) {
....@@ -126,8 +119,8 @@
126119 /* l ^= 0; */
127120 michael_block(mctx->l, mctx->r);
128121
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);
131124
132125 return 0;
133126 }
....@@ -138,15 +131,11 @@
138131 {
139132 struct michael_mic_ctx *mctx = crypto_shash_ctx(tfm);
140133
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)
145135 return -EINVAL;
146
- }
147136
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);
150139 return 0;
151140 }
152141
....@@ -159,8 +148,8 @@
159148 .descsize = sizeof(struct michael_mic_desc_ctx),
160149 .base = {
161150 .cra_name = "michael_mic",
151
+ .cra_driver_name = "michael_mic-generic",
162152 .cra_blocksize = 8,
163
- .cra_alignmask = 3,
164153 .cra_ctxsize = sizeof(struct michael_mic_ctx),
165154 .cra_module = THIS_MODULE,
166155 }
....@@ -178,7 +167,7 @@
178167 }
179168
180169
181
-module_init(michael_mic_init);
170
+subsys_initcall(michael_mic_init);
182171 module_exit(michael_mic_exit);
183172
184173 MODULE_LICENSE("GPL v2");