forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-11 297b60346df8beafee954a0fd7c2d64f33f3b9bc
kernel/arch/x86/crypto/camellia_glue.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Glue Code for assembler optimized version of Camellia
34 *
....@@ -5,22 +6,6 @@
56 *
67 * Camellia parts based on code by:
78 * Copyright (C) 2006 NTT (Nippon Telegraph and Telephone Corporation)
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 <asm/unaligned.h>
....@@ -33,19 +18,17 @@
3318 #include <asm/crypto/glue_helper.h>
3419
3520 /* regular block cipher functions */
36
-asmlinkage void __camellia_enc_blk(struct camellia_ctx *ctx, u8 *dst,
37
- const u8 *src, bool xor);
21
+asmlinkage void __camellia_enc_blk(const void *ctx, u8 *dst, const u8 *src,
22
+ bool xor);
3823 EXPORT_SYMBOL_GPL(__camellia_enc_blk);
39
-asmlinkage void camellia_dec_blk(struct camellia_ctx *ctx, u8 *dst,
40
- const u8 *src);
24
+asmlinkage void camellia_dec_blk(const void *ctx, u8 *dst, const u8 *src);
4125 EXPORT_SYMBOL_GPL(camellia_dec_blk);
4226
4327 /* 2-way parallel cipher functions */
44
-asmlinkage void __camellia_enc_blk_2way(struct camellia_ctx *ctx, u8 *dst,
45
- const u8 *src, bool xor);
28
+asmlinkage void __camellia_enc_blk_2way(const void *ctx, u8 *dst, const u8 *src,
29
+ bool xor);
4630 EXPORT_SYMBOL_GPL(__camellia_enc_blk_2way);
47
-asmlinkage void camellia_dec_blk_2way(struct camellia_ctx *ctx, u8 *dst,
48
- const u8 *src);
31
+asmlinkage void camellia_dec_blk_2way(const void *ctx, u8 *dst, const u8 *src);
4932 EXPORT_SYMBOL_GPL(camellia_dec_blk_2way);
5033
5134 static void camellia_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
....@@ -1244,12 +1227,10 @@
12441227 }
12451228
12461229 int __camellia_setkey(struct camellia_ctx *cctx, const unsigned char *key,
1247
- unsigned int key_len, u32 *flags)
1230
+ unsigned int key_len)
12481231 {
1249
- if (key_len != 16 && key_len != 24 && key_len != 32) {
1250
- *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
1232
+ if (key_len != 16 && key_len != 24 && key_len != 32)
12511233 return -EINVAL;
1252
- }
12531234
12541235 cctx->key_length = key_len;
12551236
....@@ -1272,8 +1253,7 @@
12721253 static int camellia_setkey(struct crypto_tfm *tfm, const u8 *key,
12731254 unsigned int key_len)
12741255 {
1275
- return __camellia_setkey(crypto_tfm_ctx(tfm), key, key_len,
1276
- &tfm->crt_flags);
1256
+ return __camellia_setkey(crypto_tfm_ctx(tfm), key, key_len);
12771257 }
12781258
12791259 static int camellia_setkey_skcipher(struct crypto_skcipher *tfm, const u8 *key,
....@@ -1282,8 +1262,10 @@
12821262 return camellia_setkey(&tfm->base, key, key_len);
12831263 }
12841264
1285
-void camellia_decrypt_cbc_2way(void *ctx, u128 *dst, const u128 *src)
1265
+void camellia_decrypt_cbc_2way(const void *ctx, u8 *d, const u8 *s)
12861266 {
1267
+ u128 *dst = (u128 *)d;
1268
+ const u128 *src = (const u128 *)s;
12871269 u128 iv = *src;
12881270
12891271 camellia_dec_blk_2way(ctx, (u8 *)dst, (u8 *)src);
....@@ -1292,9 +1274,11 @@
12921274 }
12931275 EXPORT_SYMBOL_GPL(camellia_decrypt_cbc_2way);
12941276
1295
-void camellia_crypt_ctr(void *ctx, u128 *dst, const u128 *src, le128 *iv)
1277
+void camellia_crypt_ctr(const void *ctx, u8 *d, const u8 *s, le128 *iv)
12961278 {
12971279 be128 ctrblk;
1280
+ u128 *dst = (u128 *)d;
1281
+ const u128 *src = (const u128 *)s;
12981282
12991283 if (dst != src)
13001284 *dst = *src;
....@@ -1306,9 +1290,11 @@
13061290 }
13071291 EXPORT_SYMBOL_GPL(camellia_crypt_ctr);
13081292
1309
-void camellia_crypt_ctr_2way(void *ctx, u128 *dst, const u128 *src, le128 *iv)
1293
+void camellia_crypt_ctr_2way(const void *ctx, u8 *d, const u8 *s, le128 *iv)
13101294 {
13111295 be128 ctrblks[2];
1296
+ u128 *dst = (u128 *)d;
1297
+ const u128 *src = (const u128 *)s;
13121298
13131299 if (dst != src) {
13141300 dst[0] = src[0];
....@@ -1330,10 +1316,10 @@
13301316
13311317 .funcs = { {
13321318 .num_blocks = 2,
1333
- .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_enc_blk_2way) }
1319
+ .fn_u = { .ecb = camellia_enc_blk_2way }
13341320 }, {
13351321 .num_blocks = 1,
1336
- .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_enc_blk) }
1322
+ .fn_u = { .ecb = camellia_enc_blk }
13371323 } }
13381324 };
13391325
....@@ -1343,10 +1329,10 @@
13431329
13441330 .funcs = { {
13451331 .num_blocks = 2,
1346
- .fn_u = { .ctr = GLUE_CTR_FUNC_CAST(camellia_crypt_ctr_2way) }
1332
+ .fn_u = { .ctr = camellia_crypt_ctr_2way }
13471333 }, {
13481334 .num_blocks = 1,
1349
- .fn_u = { .ctr = GLUE_CTR_FUNC_CAST(camellia_crypt_ctr) }
1335
+ .fn_u = { .ctr = camellia_crypt_ctr }
13501336 } }
13511337 };
13521338
....@@ -1356,10 +1342,10 @@
13561342
13571343 .funcs = { {
13581344 .num_blocks = 2,
1359
- .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_dec_blk_2way) }
1345
+ .fn_u = { .ecb = camellia_dec_blk_2way }
13601346 }, {
13611347 .num_blocks = 1,
1362
- .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_dec_blk) }
1348
+ .fn_u = { .ecb = camellia_dec_blk }
13631349 } }
13641350 };
13651351
....@@ -1369,10 +1355,10 @@
13691355
13701356 .funcs = { {
13711357 .num_blocks = 2,
1372
- .fn_u = { .cbc = GLUE_CBC_FUNC_CAST(camellia_decrypt_cbc_2way) }
1358
+ .fn_u = { .cbc = camellia_decrypt_cbc_2way }
13731359 }, {
13741360 .num_blocks = 1,
1375
- .fn_u = { .cbc = GLUE_CBC_FUNC_CAST(camellia_dec_blk) }
1361
+ .fn_u = { .cbc = camellia_dec_blk }
13761362 } }
13771363 };
13781364
....@@ -1388,8 +1374,7 @@
13881374
13891375 static int cbc_encrypt(struct skcipher_request *req)
13901376 {
1391
- return glue_cbc_encrypt_req_128bit(GLUE_FUNC_CAST(camellia_enc_blk),
1392
- req);
1377
+ return glue_cbc_encrypt_req_128bit(camellia_enc_blk, req);
13931378 }
13941379
13951380 static int cbc_decrypt(struct skcipher_request *req)