hc
2024-05-11 04dd17822334871b23ea2862f7798fb0e0007777
kernel/arch/x86/crypto/camellia_aesni_avx_glue.c
....@@ -1,13 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Glue Code for x86_64/AVX/AES-NI assembler optimized version of Camellia
34 *
45 * Copyright © 2012-2013 Jussi Kivilinna <jussi.kivilinna@iki.fi>
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (at your option) any later version.
10
- *
116 */
127
138 #include <asm/crypto/camellia.h>
....@@ -23,41 +18,36 @@
2318 #define CAMELLIA_AESNI_PARALLEL_BLOCKS 16
2419
2520 /* 16-way parallel cipher functions (avx/aes-ni) */
26
-asmlinkage void camellia_ecb_enc_16way(struct camellia_ctx *ctx, u8 *dst,
27
- const u8 *src);
21
+asmlinkage void camellia_ecb_enc_16way(const void *ctx, u8 *dst, const u8 *src);
2822 EXPORT_SYMBOL_GPL(camellia_ecb_enc_16way);
2923
30
-asmlinkage void camellia_ecb_dec_16way(struct camellia_ctx *ctx, u8 *dst,
31
- const u8 *src);
24
+asmlinkage void camellia_ecb_dec_16way(const void *ctx, u8 *dst, const u8 *src);
3225 EXPORT_SYMBOL_GPL(camellia_ecb_dec_16way);
3326
34
-asmlinkage void camellia_cbc_dec_16way(struct camellia_ctx *ctx, u8 *dst,
35
- const u8 *src);
27
+asmlinkage void camellia_cbc_dec_16way(const void *ctx, u8 *dst, const u8 *src);
3628 EXPORT_SYMBOL_GPL(camellia_cbc_dec_16way);
3729
38
-asmlinkage void camellia_ctr_16way(struct camellia_ctx *ctx, u8 *dst,
39
- const u8 *src, le128 *iv);
30
+asmlinkage void camellia_ctr_16way(const void *ctx, u8 *dst, const u8 *src,
31
+ le128 *iv);
4032 EXPORT_SYMBOL_GPL(camellia_ctr_16way);
4133
42
-asmlinkage void camellia_xts_enc_16way(struct camellia_ctx *ctx, u8 *dst,
43
- const u8 *src, le128 *iv);
34
+asmlinkage void camellia_xts_enc_16way(const void *ctx, u8 *dst, const u8 *src,
35
+ le128 *iv);
4436 EXPORT_SYMBOL_GPL(camellia_xts_enc_16way);
4537
46
-asmlinkage void camellia_xts_dec_16way(struct camellia_ctx *ctx, u8 *dst,
47
- const u8 *src, le128 *iv);
38
+asmlinkage void camellia_xts_dec_16way(const void *ctx, u8 *dst, const u8 *src,
39
+ le128 *iv);
4840 EXPORT_SYMBOL_GPL(camellia_xts_dec_16way);
4941
50
-void camellia_xts_enc(void *ctx, u128 *dst, const u128 *src, le128 *iv)
42
+void camellia_xts_enc(const void *ctx, u8 *dst, const u8 *src, le128 *iv)
5143 {
52
- glue_xts_crypt_128bit_one(ctx, dst, src, iv,
53
- GLUE_FUNC_CAST(camellia_enc_blk));
44
+ glue_xts_crypt_128bit_one(ctx, dst, src, iv, camellia_enc_blk);
5445 }
5546 EXPORT_SYMBOL_GPL(camellia_xts_enc);
5647
57
-void camellia_xts_dec(void *ctx, u128 *dst, const u128 *src, le128 *iv)
48
+void camellia_xts_dec(const void *ctx, u8 *dst, const u8 *src, le128 *iv)
5849 {
59
- glue_xts_crypt_128bit_one(ctx, dst, src, iv,
60
- GLUE_FUNC_CAST(camellia_dec_blk));
50
+ glue_xts_crypt_128bit_one(ctx, dst, src, iv, camellia_dec_blk);
6151 }
6252 EXPORT_SYMBOL_GPL(camellia_xts_dec);
6353
....@@ -67,13 +57,13 @@
6757
6858 .funcs = { {
6959 .num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS,
70
- .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_ecb_enc_16way) }
60
+ .fn_u = { .ecb = camellia_ecb_enc_16way }
7161 }, {
7262 .num_blocks = 2,
73
- .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_enc_blk_2way) }
63
+ .fn_u = { .ecb = camellia_enc_blk_2way }
7464 }, {
7565 .num_blocks = 1,
76
- .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_enc_blk) }
66
+ .fn_u = { .ecb = camellia_enc_blk }
7767 } }
7868 };
7969
....@@ -83,13 +73,13 @@
8373
8474 .funcs = { {
8575 .num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS,
86
- .fn_u = { .ctr = GLUE_CTR_FUNC_CAST(camellia_ctr_16way) }
76
+ .fn_u = { .ctr = camellia_ctr_16way }
8777 }, {
8878 .num_blocks = 2,
89
- .fn_u = { .ctr = GLUE_CTR_FUNC_CAST(camellia_crypt_ctr_2way) }
79
+ .fn_u = { .ctr = camellia_crypt_ctr_2way }
9080 }, {
9181 .num_blocks = 1,
92
- .fn_u = { .ctr = GLUE_CTR_FUNC_CAST(camellia_crypt_ctr) }
82
+ .fn_u = { .ctr = camellia_crypt_ctr }
9383 } }
9484 };
9585
....@@ -99,10 +89,10 @@
9989
10090 .funcs = { {
10191 .num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS,
102
- .fn_u = { .xts = GLUE_XTS_FUNC_CAST(camellia_xts_enc_16way) }
92
+ .fn_u = { .xts = camellia_xts_enc_16way }
10393 }, {
10494 .num_blocks = 1,
105
- .fn_u = { .xts = GLUE_XTS_FUNC_CAST(camellia_xts_enc) }
95
+ .fn_u = { .xts = camellia_xts_enc }
10696 } }
10797 };
10898
....@@ -112,13 +102,13 @@
112102
113103 .funcs = { {
114104 .num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS,
115
- .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_ecb_dec_16way) }
105
+ .fn_u = { .ecb = camellia_ecb_dec_16way }
116106 }, {
117107 .num_blocks = 2,
118
- .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_dec_blk_2way) }
108
+ .fn_u = { .ecb = camellia_dec_blk_2way }
119109 }, {
120110 .num_blocks = 1,
121
- .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_dec_blk) }
111
+ .fn_u = { .ecb = camellia_dec_blk }
122112 } }
123113 };
124114
....@@ -128,13 +118,13 @@
128118
129119 .funcs = { {
130120 .num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS,
131
- .fn_u = { .cbc = GLUE_CBC_FUNC_CAST(camellia_cbc_dec_16way) }
121
+ .fn_u = { .cbc = camellia_cbc_dec_16way }
132122 }, {
133123 .num_blocks = 2,
134
- .fn_u = { .cbc = GLUE_CBC_FUNC_CAST(camellia_decrypt_cbc_2way) }
124
+ .fn_u = { .cbc = camellia_decrypt_cbc_2way }
135125 }, {
136126 .num_blocks = 1,
137
- .fn_u = { .cbc = GLUE_CBC_FUNC_CAST(camellia_dec_blk) }
127
+ .fn_u = { .cbc = camellia_dec_blk }
138128 } }
139129 };
140130
....@@ -144,18 +134,17 @@
144134
145135 .funcs = { {
146136 .num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS,
147
- .fn_u = { .xts = GLUE_XTS_FUNC_CAST(camellia_xts_dec_16way) }
137
+ .fn_u = { .xts = camellia_xts_dec_16way }
148138 }, {
149139 .num_blocks = 1,
150
- .fn_u = { .xts = GLUE_XTS_FUNC_CAST(camellia_xts_dec) }
140
+ .fn_u = { .xts = camellia_xts_dec }
151141 } }
152142 };
153143
154144 static int camellia_setkey(struct crypto_skcipher *tfm, const u8 *key,
155145 unsigned int keylen)
156146 {
157
- return __camellia_setkey(crypto_skcipher_ctx(tfm), key, keylen,
158
- &tfm->base.crt_flags);
147
+ return __camellia_setkey(crypto_skcipher_ctx(tfm), key, keylen);
159148 }
160149
161150 static int ecb_encrypt(struct skcipher_request *req)
....@@ -170,8 +159,7 @@
170159
171160 static int cbc_encrypt(struct skcipher_request *req)
172161 {
173
- return glue_cbc_encrypt_req_128bit(GLUE_FUNC_CAST(camellia_enc_blk),
174
- req);
162
+ return glue_cbc_encrypt_req_128bit(camellia_enc_blk, req);
175163 }
176164
177165 static int cbc_decrypt(struct skcipher_request *req)
....@@ -188,7 +176,6 @@
188176 unsigned int keylen)
189177 {
190178 struct camellia_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
191
- u32 *flags = &tfm->base.crt_flags;
192179 int err;
193180
194181 err = xts_verify_key(tfm, key, keylen);
....@@ -196,13 +183,12 @@
196183 return err;
197184
198185 /* first half of xts-key is for crypt */
199
- err = __camellia_setkey(&ctx->crypt_ctx, key, keylen / 2, flags);
186
+ err = __camellia_setkey(&ctx->crypt_ctx, key, keylen / 2);
200187 if (err)
201188 return err;
202189
203190 /* second half of xts-key is for tweak */
204
- return __camellia_setkey(&ctx->tweak_ctx, key + keylen / 2, keylen / 2,
205
- flags);
191
+ return __camellia_setkey(&ctx->tweak_ctx, key + keylen / 2, keylen / 2);
206192 }
207193 EXPORT_SYMBOL_GPL(xts_camellia_setkey);
208194
....@@ -211,9 +197,8 @@
211197 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
212198 struct camellia_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
213199
214
- return glue_xts_req_128bit(&camellia_enc_xts, req,
215
- XTS_TWEAK_CAST(camellia_enc_blk),
216
- &ctx->tweak_ctx, &ctx->crypt_ctx);
200
+ return glue_xts_req_128bit(&camellia_enc_xts, req, camellia_enc_blk,
201
+ &ctx->tweak_ctx, &ctx->crypt_ctx, false);
217202 }
218203
219204 static int xts_decrypt(struct skcipher_request *req)
....@@ -221,9 +206,8 @@
221206 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
222207 struct camellia_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
223208
224
- return glue_xts_req_128bit(&camellia_dec_xts, req,
225
- XTS_TWEAK_CAST(camellia_enc_blk),
226
- &ctx->tweak_ctx, &ctx->crypt_ctx);
209
+ return glue_xts_req_128bit(&camellia_dec_xts, req, camellia_enc_blk,
210
+ &ctx->tweak_ctx, &ctx->crypt_ctx, true);
227211 }
228212
229213 static struct skcipher_alg camellia_algs[] = {