forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-11 297b60346df8beafee954a0fd7c2d64f33f3b9bc
kernel/drivers/crypto/nx/nx-aes-cbc.c
....@@ -1,20 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /**
23 * AES CBC routines supporting the Power 7+ Nest Accelerators driver
34 *
45 * Copyright (C) 2011-2012 International Business Machines Inc.
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; version 2 only.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program; if not, write to the Free Software
17
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
186 *
197 * Author: Kent Yoder <yoder1@us.ibm.com>
208 */
....@@ -30,11 +18,11 @@
3018 #include "nx.h"
3119
3220
33
-static int cbc_aes_nx_set_key(struct crypto_tfm *tfm,
34
- const u8 *in_key,
35
- unsigned int key_len)
21
+static int cbc_aes_nx_set_key(struct crypto_skcipher *tfm,
22
+ const u8 *in_key,
23
+ unsigned int key_len)
3624 {
37
- struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(tfm);
25
+ struct nx_crypto_ctx *nx_ctx = crypto_skcipher_ctx(tfm);
3826 struct nx_csbcpb *csbcpb = nx_ctx->csbcpb;
3927
4028 nx_ctx_init(nx_ctx, HCOP_FC_AES);
....@@ -62,13 +50,11 @@
6250 return 0;
6351 }
6452
65
-static int cbc_aes_nx_crypt(struct blkcipher_desc *desc,
66
- struct scatterlist *dst,
67
- struct scatterlist *src,
68
- unsigned int nbytes,
69
- int enc)
53
+static int cbc_aes_nx_crypt(struct skcipher_request *req,
54
+ int enc)
7055 {
71
- struct nx_crypto_ctx *nx_ctx = crypto_blkcipher_ctx(desc->tfm);
56
+ struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
57
+ struct nx_crypto_ctx *nx_ctx = crypto_skcipher_ctx(tfm);
7258 struct nx_csbcpb *csbcpb = nx_ctx->csbcpb;
7359 unsigned long irq_flags;
7460 unsigned int processed = 0, to_process;
....@@ -82,10 +68,11 @@
8268 NX_CPB_FDM(csbcpb) &= ~NX_FDM_ENDE_ENCRYPT;
8369
8470 do {
85
- to_process = nbytes - processed;
71
+ to_process = req->cryptlen - processed;
8672
87
- rc = nx_build_sg_lists(nx_ctx, desc, dst, src, &to_process,
88
- processed, csbcpb->cpb.aes_cbc.iv);
73
+ rc = nx_build_sg_lists(nx_ctx, req->iv, req->dst, req->src,
74
+ &to_process, processed,
75
+ csbcpb->cpb.aes_cbc.iv);
8976 if (rc)
9077 goto out;
9178
....@@ -95,56 +82,46 @@
9582 }
9683
9784 rc = nx_hcall_sync(nx_ctx, &nx_ctx->op,
98
- desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP);
85
+ req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP);
9986 if (rc)
10087 goto out;
10188
102
- memcpy(desc->info, csbcpb->cpb.aes_cbc.cv, AES_BLOCK_SIZE);
89
+ memcpy(req->iv, csbcpb->cpb.aes_cbc.cv, AES_BLOCK_SIZE);
10390 atomic_inc(&(nx_ctx->stats->aes_ops));
10491 atomic64_add(csbcpb->csb.processed_byte_count,
10592 &(nx_ctx->stats->aes_bytes));
10693
10794 processed += to_process;
108
- } while (processed < nbytes);
95
+ } while (processed < req->cryptlen);
10996 out:
11097 spin_unlock_irqrestore(&nx_ctx->lock, irq_flags);
11198 return rc;
11299 }
113100
114
-static int cbc_aes_nx_encrypt(struct blkcipher_desc *desc,
115
- struct scatterlist *dst,
116
- struct scatterlist *src,
117
- unsigned int nbytes)
101
+static int cbc_aes_nx_encrypt(struct skcipher_request *req)
118102 {
119
- return cbc_aes_nx_crypt(desc, dst, src, nbytes, 1);
103
+ return cbc_aes_nx_crypt(req, 1);
120104 }
121105
122
-static int cbc_aes_nx_decrypt(struct blkcipher_desc *desc,
123
- struct scatterlist *dst,
124
- struct scatterlist *src,
125
- unsigned int nbytes)
106
+static int cbc_aes_nx_decrypt(struct skcipher_request *req)
126107 {
127
- return cbc_aes_nx_crypt(desc, dst, src, nbytes, 0);
108
+ return cbc_aes_nx_crypt(req, 0);
128109 }
129110
130
-struct crypto_alg nx_cbc_aes_alg = {
131
- .cra_name = "cbc(aes)",
132
- .cra_driver_name = "cbc-aes-nx",
133
- .cra_priority = 300,
134
- .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
135
- .cra_blocksize = AES_BLOCK_SIZE,
136
- .cra_ctxsize = sizeof(struct nx_crypto_ctx),
137
- .cra_type = &crypto_blkcipher_type,
138
- .cra_alignmask = 0xf,
139
- .cra_module = THIS_MODULE,
140
- .cra_init = nx_crypto_ctx_aes_cbc_init,
141
- .cra_exit = nx_crypto_ctx_exit,
142
- .cra_blkcipher = {
143
- .min_keysize = AES_MIN_KEY_SIZE,
144
- .max_keysize = AES_MAX_KEY_SIZE,
145
- .ivsize = AES_BLOCK_SIZE,
146
- .setkey = cbc_aes_nx_set_key,
147
- .encrypt = cbc_aes_nx_encrypt,
148
- .decrypt = cbc_aes_nx_decrypt,
149
- }
111
+struct skcipher_alg nx_cbc_aes_alg = {
112
+ .base.cra_name = "cbc(aes)",
113
+ .base.cra_driver_name = "cbc-aes-nx",
114
+ .base.cra_priority = 300,
115
+ .base.cra_blocksize = AES_BLOCK_SIZE,
116
+ .base.cra_ctxsize = sizeof(struct nx_crypto_ctx),
117
+ .base.cra_alignmask = 0xf,
118
+ .base.cra_module = THIS_MODULE,
119
+ .init = nx_crypto_ctx_aes_cbc_init,
120
+ .exit = nx_crypto_ctx_skcipher_exit,
121
+ .min_keysize = AES_MIN_KEY_SIZE,
122
+ .max_keysize = AES_MAX_KEY_SIZE,
123
+ .ivsize = AES_BLOCK_SIZE,
124
+ .setkey = cbc_aes_nx_set_key,
125
+ .encrypt = cbc_aes_nx_encrypt,
126
+ .decrypt = cbc_aes_nx_decrypt,
150127 };