forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 ee930fffee469d076998274a2ca55e13dc1efb67
kernel/drivers/crypto/nx/nx-aes-ctr.c
....@@ -1,20 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /**
23 * AES CTR 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 */
....@@ -31,11 +19,11 @@
3119 #include "nx.h"
3220
3321
34
-static int ctr_aes_nx_set_key(struct crypto_tfm *tfm,
35
- const u8 *in_key,
36
- unsigned int key_len)
22
+static int ctr_aes_nx_set_key(struct crypto_skcipher *tfm,
23
+ const u8 *in_key,
24
+ unsigned int key_len)
3725 {
38
- struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(tfm);
26
+ struct nx_crypto_ctx *nx_ctx = crypto_skcipher_ctx(tfm);
3927 struct nx_csbcpb *csbcpb = nx_ctx->csbcpb;
4028
4129 nx_ctx_init(nx_ctx, HCOP_FC_AES);
....@@ -63,11 +51,11 @@
6351 return 0;
6452 }
6553
66
-static int ctr3686_aes_nx_set_key(struct crypto_tfm *tfm,
67
- const u8 *in_key,
68
- unsigned int key_len)
54
+static int ctr3686_aes_nx_set_key(struct crypto_skcipher *tfm,
55
+ const u8 *in_key,
56
+ unsigned int key_len)
6957 {
70
- struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(tfm);
58
+ struct nx_crypto_ctx *nx_ctx = crypto_skcipher_ctx(tfm);
7159
7260 if (key_len < CTR_RFC3686_NONCE_SIZE)
7361 return -EINVAL;
....@@ -81,12 +69,10 @@
8169 return ctr_aes_nx_set_key(tfm, in_key, key_len);
8270 }
8371
84
-static int ctr_aes_nx_crypt(struct blkcipher_desc *desc,
85
- struct scatterlist *dst,
86
- struct scatterlist *src,
87
- unsigned int nbytes)
72
+static int ctr_aes_nx_crypt(struct skcipher_request *req, u8 *iv)
8873 {
89
- struct nx_crypto_ctx *nx_ctx = crypto_blkcipher_ctx(desc->tfm);
74
+ struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
75
+ struct nx_crypto_ctx *nx_ctx = crypto_skcipher_ctx(tfm);
9076 struct nx_csbcpb *csbcpb = nx_ctx->csbcpb;
9177 unsigned long irq_flags;
9278 unsigned int processed = 0, to_process;
....@@ -95,10 +81,11 @@
9581 spin_lock_irqsave(&nx_ctx->lock, irq_flags);
9682
9783 do {
98
- to_process = nbytes - processed;
84
+ to_process = req->cryptlen - processed;
9985
100
- rc = nx_build_sg_lists(nx_ctx, desc, dst, src, &to_process,
101
- processed, csbcpb->cpb.aes_ctr.iv);
86
+ rc = nx_build_sg_lists(nx_ctx, iv, req->dst, req->src,
87
+ &to_process, processed,
88
+ csbcpb->cpb.aes_ctr.iv);
10289 if (rc)
10390 goto out;
10491
....@@ -108,60 +95,51 @@
10895 }
10996
11097 rc = nx_hcall_sync(nx_ctx, &nx_ctx->op,
111
- desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP);
98
+ req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP);
11299 if (rc)
113100 goto out;
114101
115
- memcpy(desc->info, csbcpb->cpb.aes_cbc.cv, AES_BLOCK_SIZE);
102
+ memcpy(iv, csbcpb->cpb.aes_cbc.cv, AES_BLOCK_SIZE);
116103
117104 atomic_inc(&(nx_ctx->stats->aes_ops));
118105 atomic64_add(csbcpb->csb.processed_byte_count,
119106 &(nx_ctx->stats->aes_bytes));
120107
121108 processed += to_process;
122
- } while (processed < nbytes);
109
+ } while (processed < req->cryptlen);
123110 out:
124111 spin_unlock_irqrestore(&nx_ctx->lock, irq_flags);
125112 return rc;
126113 }
127114
128
-static int ctr3686_aes_nx_crypt(struct blkcipher_desc *desc,
129
- struct scatterlist *dst,
130
- struct scatterlist *src,
131
- unsigned int nbytes)
115
+static int ctr3686_aes_nx_crypt(struct skcipher_request *req)
132116 {
133
- struct nx_crypto_ctx *nx_ctx = crypto_blkcipher_ctx(desc->tfm);
117
+ struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
118
+ struct nx_crypto_ctx *nx_ctx = crypto_skcipher_ctx(tfm);
134119 u8 iv[16];
135120
136
- memcpy(iv, nx_ctx->priv.ctr.nonce, CTR_RFC3686_IV_SIZE);
137
- memcpy(iv + CTR_RFC3686_NONCE_SIZE,
138
- desc->info, CTR_RFC3686_IV_SIZE);
121
+ memcpy(iv, nx_ctx->priv.ctr.nonce, CTR_RFC3686_NONCE_SIZE);
122
+ memcpy(iv + CTR_RFC3686_NONCE_SIZE, req->iv, CTR_RFC3686_IV_SIZE);
139123 iv[12] = iv[13] = iv[14] = 0;
140124 iv[15] = 1;
141125
142
- desc->info = iv;
143
-
144
- return ctr_aes_nx_crypt(desc, dst, src, nbytes);
126
+ return ctr_aes_nx_crypt(req, iv);
145127 }
146128
147
-struct crypto_alg nx_ctr3686_aes_alg = {
148
- .cra_name = "rfc3686(ctr(aes))",
149
- .cra_driver_name = "rfc3686-ctr-aes-nx",
150
- .cra_priority = 300,
151
- .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
152
- .cra_blocksize = 1,
153
- .cra_ctxsize = sizeof(struct nx_crypto_ctx),
154
- .cra_type = &crypto_blkcipher_type,
155
- .cra_module = THIS_MODULE,
156
- .cra_init = nx_crypto_ctx_aes_ctr_init,
157
- .cra_exit = nx_crypto_ctx_exit,
158
- .cra_blkcipher = {
159
- .min_keysize = AES_MIN_KEY_SIZE + CTR_RFC3686_NONCE_SIZE,
160
- .max_keysize = AES_MAX_KEY_SIZE + CTR_RFC3686_NONCE_SIZE,
161
- .ivsize = CTR_RFC3686_IV_SIZE,
162
- .geniv = "seqiv",
163
- .setkey = ctr3686_aes_nx_set_key,
164
- .encrypt = ctr3686_aes_nx_crypt,
165
- .decrypt = ctr3686_aes_nx_crypt,
166
- }
129
+struct skcipher_alg nx_ctr3686_aes_alg = {
130
+ .base.cra_name = "rfc3686(ctr(aes))",
131
+ .base.cra_driver_name = "rfc3686-ctr-aes-nx",
132
+ .base.cra_priority = 300,
133
+ .base.cra_blocksize = 1,
134
+ .base.cra_ctxsize = sizeof(struct nx_crypto_ctx),
135
+ .base.cra_module = THIS_MODULE,
136
+ .init = nx_crypto_ctx_aes_ctr_init,
137
+ .exit = nx_crypto_ctx_skcipher_exit,
138
+ .min_keysize = AES_MIN_KEY_SIZE + CTR_RFC3686_NONCE_SIZE,
139
+ .max_keysize = AES_MAX_KEY_SIZE + CTR_RFC3686_NONCE_SIZE,
140
+ .ivsize = CTR_RFC3686_IV_SIZE,
141
+ .setkey = ctr3686_aes_nx_set_key,
142
+ .encrypt = ctr3686_aes_nx_crypt,
143
+ .decrypt = ctr3686_aes_nx_crypt,
144
+ .chunksize = AES_BLOCK_SIZE,
167145 };