hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/crypto/nx/nx-aes-gcm.c
....@@ -1,20 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /**
23 * AES GCM routines supporting the Power 7+ Nest Accelerators driver
34 *
45 * Copyright (C) 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 */
....@@ -178,8 +166,7 @@
178166 return rc;
179167 }
180168
181
-static int gmac(struct aead_request *req, struct blkcipher_desc *desc,
182
- unsigned int assoclen)
169
+static int gmac(struct aead_request *req, const u8 *iv, unsigned int assoclen)
183170 {
184171 int rc;
185172 struct nx_crypto_ctx *nx_ctx =
....@@ -202,7 +189,7 @@
202189 nx_ctx->ap->databytelen/NX_PAGE_SIZE);
203190
204191 /* Copy IV */
205
- memcpy(csbcpb->cpb.aes_gcm.iv_or_cnt, desc->info, AES_BLOCK_SIZE);
192
+ memcpy(csbcpb->cpb.aes_gcm.iv_or_cnt, iv, AES_BLOCK_SIZE);
206193
207194 do {
208195 /*
....@@ -252,8 +239,7 @@
252239 return rc;
253240 }
254241
255
-static int gcm_empty(struct aead_request *req, struct blkcipher_desc *desc,
256
- int enc)
242
+static int gcm_empty(struct aead_request *req, const u8 *iv, int enc)
257243 {
258244 int rc;
259245 struct nx_crypto_ctx *nx_ctx =
....@@ -280,7 +266,7 @@
280266 len = AES_BLOCK_SIZE;
281267
282268 /* Encrypt the counter/IV */
283
- in_sg = nx_build_sg_list(nx_ctx->in_sg, (u8 *) desc->info,
269
+ in_sg = nx_build_sg_list(nx_ctx->in_sg, (u8 *) iv,
284270 &len, nx_ctx->ap->sglen);
285271
286272 if (len != AES_BLOCK_SIZE)
....@@ -297,7 +283,7 @@
297283 nx_ctx->op.outlen = (nx_ctx->out_sg - out_sg) * sizeof(struct nx_sg);
298284
299285 rc = nx_hcall_sync(nx_ctx, &nx_ctx->op,
300
- desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP);
286
+ req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP);
301287 if (rc)
302288 goto out;
303289 atomic_inc(&(nx_ctx->stats->aes_ops));
....@@ -325,7 +311,6 @@
325311 crypto_aead_ctx(crypto_aead_reqtfm(req));
326312 struct nx_gcm_rctx *rctx = aead_request_ctx(req);
327313 struct nx_csbcpb *csbcpb = nx_ctx->csbcpb;
328
- struct blkcipher_desc desc;
329314 unsigned int nbytes = req->cryptlen;
330315 unsigned int processed = 0, to_process;
331316 unsigned long irq_flags;
....@@ -333,15 +318,14 @@
333318
334319 spin_lock_irqsave(&nx_ctx->lock, irq_flags);
335320
336
- desc.info = rctx->iv;
337321 /* initialize the counter */
338
- *(u32 *)(desc.info + NX_GCM_CTR_OFFSET) = 1;
322
+ *(u32 *)&rctx->iv[NX_GCM_CTR_OFFSET] = 1;
339323
340324 if (nbytes == 0) {
341325 if (assoclen == 0)
342
- rc = gcm_empty(req, &desc, enc);
326
+ rc = gcm_empty(req, rctx->iv, enc);
343327 else
344
- rc = gmac(req, &desc, assoclen);
328
+ rc = gmac(req, rctx->iv, assoclen);
345329 if (rc)
346330 goto out;
347331 else
....@@ -370,7 +354,7 @@
370354 to_process = nbytes - processed;
371355
372356 csbcpb->cpb.aes_gcm.bit_length_data = nbytes * 8;
373
- rc = nx_build_sg_lists(nx_ctx, &desc, req->dst,
357
+ rc = nx_build_sg_lists(nx_ctx, rctx->iv, req->dst,
374358 req->src, &to_process,
375359 processed + req->assoclen,
376360 csbcpb->cpb.aes_gcm.iv_or_cnt);
....@@ -389,7 +373,7 @@
389373 if (rc)
390374 goto out;
391375
392
- memcpy(desc.info, csbcpb->cpb.aes_gcm.out_cnt, AES_BLOCK_SIZE);
376
+ memcpy(rctx->iv, csbcpb->cpb.aes_gcm.out_cnt, AES_BLOCK_SIZE);
393377 memcpy(csbcpb->cpb.aes_gcm.in_pat_or_aad,
394378 csbcpb->cpb.aes_gcm.out_pat_or_mac, AES_BLOCK_SIZE);
395379 memcpy(csbcpb->cpb.aes_gcm.in_s0,
....@@ -483,11 +467,6 @@
483467 return gcm_aes_nx_crypt(req, 0, req->assoclen - 8);
484468 }
485469
486
-/* tell the block cipher walk routines that this is a stream cipher by
487
- * setting cra_blocksize to 1. Even using blkcipher_walk_virt_block
488
- * during encrypt/decrypt doesn't solve this problem, because it calls
489
- * blkcipher_walk_done under the covers, which doesn't use walk->blocksize,
490
- * but instead uses this tfm->blocksize. */
491470 struct aead_alg nx_gcm_aes_alg = {
492471 .base = {
493472 .cra_name = "gcm(aes)",