| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /** |
|---|
| 2 | 3 | * AES GCM routines supporting the Power 7+ Nest Accelerators driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * 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. |
|---|
| 18 | 6 | * |
|---|
| 19 | 7 | * Author: Kent Yoder <yoder1@us.ibm.com> |
|---|
| 20 | 8 | */ |
|---|
| .. | .. |
|---|
| 178 | 166 | return rc; |
|---|
| 179 | 167 | } |
|---|
| 180 | 168 | |
|---|
| 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) |
|---|
| 183 | 170 | { |
|---|
| 184 | 171 | int rc; |
|---|
| 185 | 172 | struct nx_crypto_ctx *nx_ctx = |
|---|
| .. | .. |
|---|
| 202 | 189 | nx_ctx->ap->databytelen/NX_PAGE_SIZE); |
|---|
| 203 | 190 | |
|---|
| 204 | 191 | /* 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); |
|---|
| 206 | 193 | |
|---|
| 207 | 194 | do { |
|---|
| 208 | 195 | /* |
|---|
| .. | .. |
|---|
| 252 | 239 | return rc; |
|---|
| 253 | 240 | } |
|---|
| 254 | 241 | |
|---|
| 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) |
|---|
| 257 | 243 | { |
|---|
| 258 | 244 | int rc; |
|---|
| 259 | 245 | struct nx_crypto_ctx *nx_ctx = |
|---|
| .. | .. |
|---|
| 280 | 266 | len = AES_BLOCK_SIZE; |
|---|
| 281 | 267 | |
|---|
| 282 | 268 | /* 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, |
|---|
| 284 | 270 | &len, nx_ctx->ap->sglen); |
|---|
| 285 | 271 | |
|---|
| 286 | 272 | if (len != AES_BLOCK_SIZE) |
|---|
| .. | .. |
|---|
| 297 | 283 | nx_ctx->op.outlen = (nx_ctx->out_sg - out_sg) * sizeof(struct nx_sg); |
|---|
| 298 | 284 | |
|---|
| 299 | 285 | 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); |
|---|
| 301 | 287 | if (rc) |
|---|
| 302 | 288 | goto out; |
|---|
| 303 | 289 | atomic_inc(&(nx_ctx->stats->aes_ops)); |
|---|
| .. | .. |
|---|
| 325 | 311 | crypto_aead_ctx(crypto_aead_reqtfm(req)); |
|---|
| 326 | 312 | struct nx_gcm_rctx *rctx = aead_request_ctx(req); |
|---|
| 327 | 313 | struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; |
|---|
| 328 | | - struct blkcipher_desc desc; |
|---|
| 329 | 314 | unsigned int nbytes = req->cryptlen; |
|---|
| 330 | 315 | unsigned int processed = 0, to_process; |
|---|
| 331 | 316 | unsigned long irq_flags; |
|---|
| .. | .. |
|---|
| 333 | 318 | |
|---|
| 334 | 319 | spin_lock_irqsave(&nx_ctx->lock, irq_flags); |
|---|
| 335 | 320 | |
|---|
| 336 | | - desc.info = rctx->iv; |
|---|
| 337 | 321 | /* initialize the counter */ |
|---|
| 338 | | - *(u32 *)(desc.info + NX_GCM_CTR_OFFSET) = 1; |
|---|
| 322 | + *(u32 *)&rctx->iv[NX_GCM_CTR_OFFSET] = 1; |
|---|
| 339 | 323 | |
|---|
| 340 | 324 | if (nbytes == 0) { |
|---|
| 341 | 325 | if (assoclen == 0) |
|---|
| 342 | | - rc = gcm_empty(req, &desc, enc); |
|---|
| 326 | + rc = gcm_empty(req, rctx->iv, enc); |
|---|
| 343 | 327 | else |
|---|
| 344 | | - rc = gmac(req, &desc, assoclen); |
|---|
| 328 | + rc = gmac(req, rctx->iv, assoclen); |
|---|
| 345 | 329 | if (rc) |
|---|
| 346 | 330 | goto out; |
|---|
| 347 | 331 | else |
|---|
| .. | .. |
|---|
| 370 | 354 | to_process = nbytes - processed; |
|---|
| 371 | 355 | |
|---|
| 372 | 356 | 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, |
|---|
| 374 | 358 | req->src, &to_process, |
|---|
| 375 | 359 | processed + req->assoclen, |
|---|
| 376 | 360 | csbcpb->cpb.aes_gcm.iv_or_cnt); |
|---|
| .. | .. |
|---|
| 389 | 373 | if (rc) |
|---|
| 390 | 374 | goto out; |
|---|
| 391 | 375 | |
|---|
| 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); |
|---|
| 393 | 377 | memcpy(csbcpb->cpb.aes_gcm.in_pat_or_aad, |
|---|
| 394 | 378 | csbcpb->cpb.aes_gcm.out_pat_or_mac, AES_BLOCK_SIZE); |
|---|
| 395 | 379 | memcpy(csbcpb->cpb.aes_gcm.in_s0, |
|---|
| .. | .. |
|---|
| 483 | 467 | return gcm_aes_nx_crypt(req, 0, req->assoclen - 8); |
|---|
| 484 | 468 | } |
|---|
| 485 | 469 | |
|---|
| 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. */ |
|---|
| 491 | 470 | struct aead_alg nx_gcm_aes_alg = { |
|---|
| 492 | 471 | .base = { |
|---|
| 493 | 472 | .cra_name = "gcm(aes)", |
|---|