forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/arch/x86/crypto/twofish_avx_glue.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Glue Code for AVX assembler version of Twofish Cipher
34 *
....@@ -5,22 +6,6 @@
56 * <Johannes.Goetzfried@informatik.stud.uni-erlangen.de>
67 *
78 * Copyright © 2013 Jussi Kivilinna <jussi.kivilinna@iki.fi>
8
- *
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation; either version 2 of the License, or
12
- * (at your option) any later version.
13
- *
14
- * This program is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- * GNU General Public License for more details.
18
- *
19
- * You should have received a copy of the GNU General Public License
20
- * along with this program; if not, write to the Free Software
21
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22
- * USA
23
- *
249 */
2510
2611 #include <linux/module.h>
....@@ -37,20 +22,17 @@
3722 #define TWOFISH_PARALLEL_BLOCKS 8
3823
3924 /* 8-way parallel cipher functions */
40
-asmlinkage void twofish_ecb_enc_8way(struct twofish_ctx *ctx, u8 *dst,
41
- const u8 *src);
42
-asmlinkage void twofish_ecb_dec_8way(struct twofish_ctx *ctx, u8 *dst,
43
- const u8 *src);
25
+asmlinkage void twofish_ecb_enc_8way(const void *ctx, u8 *dst, const u8 *src);
26
+asmlinkage void twofish_ecb_dec_8way(const void *ctx, u8 *dst, const u8 *src);
4427
45
-asmlinkage void twofish_cbc_dec_8way(struct twofish_ctx *ctx, u8 *dst,
46
- const u8 *src);
47
-asmlinkage void twofish_ctr_8way(struct twofish_ctx *ctx, u8 *dst,
48
- const u8 *src, le128 *iv);
28
+asmlinkage void twofish_cbc_dec_8way(const void *ctx, u8 *dst, const u8 *src);
29
+asmlinkage void twofish_ctr_8way(const void *ctx, u8 *dst, const u8 *src,
30
+ le128 *iv);
4931
50
-asmlinkage void twofish_xts_enc_8way(struct twofish_ctx *ctx, u8 *dst,
51
- const u8 *src, le128 *iv);
52
-asmlinkage void twofish_xts_dec_8way(struct twofish_ctx *ctx, u8 *dst,
53
- const u8 *src, le128 *iv);
32
+asmlinkage void twofish_xts_enc_8way(const void *ctx, u8 *dst, const u8 *src,
33
+ le128 *iv);
34
+asmlinkage void twofish_xts_dec_8way(const void *ctx, u8 *dst, const u8 *src,
35
+ le128 *iv);
5436
5537 static int twofish_setkey_skcipher(struct crypto_skcipher *tfm,
5638 const u8 *key, unsigned int keylen)
....@@ -58,22 +40,19 @@
5840 return twofish_setkey(&tfm->base, key, keylen);
5941 }
6042
61
-static inline void twofish_enc_blk_3way(struct twofish_ctx *ctx, u8 *dst,
62
- const u8 *src)
43
+static inline void twofish_enc_blk_3way(const void *ctx, u8 *dst, const u8 *src)
6344 {
6445 __twofish_enc_blk_3way(ctx, dst, src, false);
6546 }
6647
67
-static void twofish_xts_enc(void *ctx, u128 *dst, const u128 *src, le128 *iv)
48
+static void twofish_xts_enc(const void *ctx, u8 *dst, const u8 *src, le128 *iv)
6849 {
69
- glue_xts_crypt_128bit_one(ctx, dst, src, iv,
70
- GLUE_FUNC_CAST(twofish_enc_blk));
50
+ glue_xts_crypt_128bit_one(ctx, dst, src, iv, twofish_enc_blk);
7151 }
7252
73
-static void twofish_xts_dec(void *ctx, u128 *dst, const u128 *src, le128 *iv)
53
+static void twofish_xts_dec(const void *ctx, u8 *dst, const u8 *src, le128 *iv)
7454 {
75
- glue_xts_crypt_128bit_one(ctx, dst, src, iv,
76
- GLUE_FUNC_CAST(twofish_dec_blk));
55
+ glue_xts_crypt_128bit_one(ctx, dst, src, iv, twofish_dec_blk);
7756 }
7857
7958 struct twofish_xts_ctx {
....@@ -85,7 +64,6 @@
8564 unsigned int keylen)
8665 {
8766 struct twofish_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
88
- u32 *flags = &tfm->base.crt_flags;
8967 int err;
9068
9169 err = xts_verify_key(tfm, key, keylen);
....@@ -93,13 +71,12 @@
9371 return err;
9472
9573 /* first half of xts-key is for crypt */
96
- err = __twofish_setkey(&ctx->crypt_ctx, key, keylen / 2, flags);
74
+ err = __twofish_setkey(&ctx->crypt_ctx, key, keylen / 2);
9775 if (err)
9876 return err;
9977
10078 /* second half of xts-key is for tweak */
101
- return __twofish_setkey(&ctx->tweak_ctx, key + keylen / 2, keylen / 2,
102
- flags);
79
+ return __twofish_setkey(&ctx->tweak_ctx, key + keylen / 2, keylen / 2);
10380 }
10481
10582 static const struct common_glue_ctx twofish_enc = {
....@@ -108,13 +85,13 @@
10885
10986 .funcs = { {
11087 .num_blocks = TWOFISH_PARALLEL_BLOCKS,
111
- .fn_u = { .ecb = GLUE_FUNC_CAST(twofish_ecb_enc_8way) }
88
+ .fn_u = { .ecb = twofish_ecb_enc_8way }
11289 }, {
11390 .num_blocks = 3,
114
- .fn_u = { .ecb = GLUE_FUNC_CAST(twofish_enc_blk_3way) }
91
+ .fn_u = { .ecb = twofish_enc_blk_3way }
11592 }, {
11693 .num_blocks = 1,
117
- .fn_u = { .ecb = GLUE_FUNC_CAST(twofish_enc_blk) }
94
+ .fn_u = { .ecb = twofish_enc_blk }
11895 } }
11996 };
12097
....@@ -124,13 +101,13 @@
124101
125102 .funcs = { {
126103 .num_blocks = TWOFISH_PARALLEL_BLOCKS,
127
- .fn_u = { .ctr = GLUE_CTR_FUNC_CAST(twofish_ctr_8way) }
104
+ .fn_u = { .ctr = twofish_ctr_8way }
128105 }, {
129106 .num_blocks = 3,
130
- .fn_u = { .ctr = GLUE_CTR_FUNC_CAST(twofish_enc_blk_ctr_3way) }
107
+ .fn_u = { .ctr = twofish_enc_blk_ctr_3way }
131108 }, {
132109 .num_blocks = 1,
133
- .fn_u = { .ctr = GLUE_CTR_FUNC_CAST(twofish_enc_blk_ctr) }
110
+ .fn_u = { .ctr = twofish_enc_blk_ctr }
134111 } }
135112 };
136113
....@@ -140,10 +117,10 @@
140117
141118 .funcs = { {
142119 .num_blocks = TWOFISH_PARALLEL_BLOCKS,
143
- .fn_u = { .xts = GLUE_XTS_FUNC_CAST(twofish_xts_enc_8way) }
120
+ .fn_u = { .xts = twofish_xts_enc_8way }
144121 }, {
145122 .num_blocks = 1,
146
- .fn_u = { .xts = GLUE_XTS_FUNC_CAST(twofish_xts_enc) }
123
+ .fn_u = { .xts = twofish_xts_enc }
147124 } }
148125 };
149126
....@@ -153,13 +130,13 @@
153130
154131 .funcs = { {
155132 .num_blocks = TWOFISH_PARALLEL_BLOCKS,
156
- .fn_u = { .ecb = GLUE_FUNC_CAST(twofish_ecb_dec_8way) }
133
+ .fn_u = { .ecb = twofish_ecb_dec_8way }
157134 }, {
158135 .num_blocks = 3,
159
- .fn_u = { .ecb = GLUE_FUNC_CAST(twofish_dec_blk_3way) }
136
+ .fn_u = { .ecb = twofish_dec_blk_3way }
160137 }, {
161138 .num_blocks = 1,
162
- .fn_u = { .ecb = GLUE_FUNC_CAST(twofish_dec_blk) }
139
+ .fn_u = { .ecb = twofish_dec_blk }
163140 } }
164141 };
165142
....@@ -169,13 +146,13 @@
169146
170147 .funcs = { {
171148 .num_blocks = TWOFISH_PARALLEL_BLOCKS,
172
- .fn_u = { .cbc = GLUE_CBC_FUNC_CAST(twofish_cbc_dec_8way) }
149
+ .fn_u = { .cbc = twofish_cbc_dec_8way }
173150 }, {
174151 .num_blocks = 3,
175
- .fn_u = { .cbc = GLUE_CBC_FUNC_CAST(twofish_dec_blk_cbc_3way) }
152
+ .fn_u = { .cbc = twofish_dec_blk_cbc_3way }
176153 }, {
177154 .num_blocks = 1,
178
- .fn_u = { .cbc = GLUE_CBC_FUNC_CAST(twofish_dec_blk) }
155
+ .fn_u = { .cbc = twofish_dec_blk }
179156 } }
180157 };
181158
....@@ -185,10 +162,10 @@
185162
186163 .funcs = { {
187164 .num_blocks = TWOFISH_PARALLEL_BLOCKS,
188
- .fn_u = { .xts = GLUE_XTS_FUNC_CAST(twofish_xts_dec_8way) }
165
+ .fn_u = { .xts = twofish_xts_dec_8way }
189166 }, {
190167 .num_blocks = 1,
191
- .fn_u = { .xts = GLUE_XTS_FUNC_CAST(twofish_xts_dec) }
168
+ .fn_u = { .xts = twofish_xts_dec }
192169 } }
193170 };
194171
....@@ -204,8 +181,7 @@
204181
205182 static int cbc_encrypt(struct skcipher_request *req)
206183 {
207
- return glue_cbc_encrypt_req_128bit(GLUE_FUNC_CAST(twofish_enc_blk),
208
- req);
184
+ return glue_cbc_encrypt_req_128bit(twofish_enc_blk, req);
209185 }
210186
211187 static int cbc_decrypt(struct skcipher_request *req)
....@@ -223,9 +199,8 @@
223199 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
224200 struct twofish_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
225201
226
- return glue_xts_req_128bit(&twofish_enc_xts, req,
227
- XTS_TWEAK_CAST(twofish_enc_blk),
228
- &ctx->tweak_ctx, &ctx->crypt_ctx);
202
+ return glue_xts_req_128bit(&twofish_enc_xts, req, twofish_enc_blk,
203
+ &ctx->tweak_ctx, &ctx->crypt_ctx, false);
229204 }
230205
231206 static int xts_decrypt(struct skcipher_request *req)
....@@ -233,9 +208,8 @@
233208 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
234209 struct twofish_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
235210
236
- return glue_xts_req_128bit(&twofish_dec_xts, req,
237
- XTS_TWEAK_CAST(twofish_enc_blk),
238
- &ctx->tweak_ctx, &ctx->crypt_ctx);
211
+ return glue_xts_req_128bit(&twofish_dec_xts, req, twofish_enc_blk,
212
+ &ctx->tweak_ctx, &ctx->crypt_ctx, true);
239213 }
240214
241215 static struct skcipher_alg twofish_algs[] = {