.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /** |
---|
2 | 3 | * AES CCM 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 | */ |
---|
.. | .. |
---|
339 | 327 | } |
---|
340 | 328 | |
---|
341 | 329 | static int ccm_nx_decrypt(struct aead_request *req, |
---|
342 | | - struct blkcipher_desc *desc, |
---|
| 330 | + u8 *iv, |
---|
343 | 331 | unsigned int assoclen) |
---|
344 | 332 | { |
---|
345 | 333 | struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(req->base.tfm); |
---|
.. | .. |
---|
360 | 348 | req->src, nbytes + req->assoclen, authsize, |
---|
361 | 349 | SCATTERWALK_FROM_SG); |
---|
362 | 350 | |
---|
363 | | - rc = generate_pat(desc->info, req, nx_ctx, authsize, nbytes, assoclen, |
---|
| 351 | + rc = generate_pat(iv, req, nx_ctx, authsize, nbytes, assoclen, |
---|
364 | 352 | csbcpb->cpb.aes_ccm.in_pat_or_b0); |
---|
365 | 353 | if (rc) |
---|
366 | 354 | goto out; |
---|
.. | .. |
---|
379 | 367 | |
---|
380 | 368 | NX_CPB_FDM(nx_ctx->csbcpb) &= ~NX_FDM_ENDE_ENCRYPT; |
---|
381 | 369 | |
---|
382 | | - rc = nx_build_sg_lists(nx_ctx, desc, req->dst, req->src, |
---|
| 370 | + rc = nx_build_sg_lists(nx_ctx, iv, req->dst, req->src, |
---|
383 | 371 | &to_process, processed + req->assoclen, |
---|
384 | 372 | csbcpb->cpb.aes_ccm.iv_or_ctr); |
---|
385 | 373 | if (rc) |
---|
.. | .. |
---|
393 | 381 | /* for partial completion, copy following for next |
---|
394 | 382 | * entry into loop... |
---|
395 | 383 | */ |
---|
396 | | - memcpy(desc->info, csbcpb->cpb.aes_ccm.out_ctr, AES_BLOCK_SIZE); |
---|
| 384 | + memcpy(iv, csbcpb->cpb.aes_ccm.out_ctr, AES_BLOCK_SIZE); |
---|
397 | 385 | memcpy(csbcpb->cpb.aes_ccm.in_pat_or_b0, |
---|
398 | 386 | csbcpb->cpb.aes_ccm.out_pat_or_mac, AES_BLOCK_SIZE); |
---|
399 | 387 | memcpy(csbcpb->cpb.aes_ccm.in_s0, |
---|
.. | .. |
---|
417 | 405 | } |
---|
418 | 406 | |
---|
419 | 407 | static int ccm_nx_encrypt(struct aead_request *req, |
---|
420 | | - struct blkcipher_desc *desc, |
---|
| 408 | + u8 *iv, |
---|
421 | 409 | unsigned int assoclen) |
---|
422 | 410 | { |
---|
423 | 411 | struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(req->base.tfm); |
---|
.. | .. |
---|
430 | 418 | |
---|
431 | 419 | spin_lock_irqsave(&nx_ctx->lock, irq_flags); |
---|
432 | 420 | |
---|
433 | | - rc = generate_pat(desc->info, req, nx_ctx, authsize, nbytes, assoclen, |
---|
| 421 | + rc = generate_pat(iv, req, nx_ctx, authsize, nbytes, assoclen, |
---|
434 | 422 | csbcpb->cpb.aes_ccm.in_pat_or_b0); |
---|
435 | 423 | if (rc) |
---|
436 | 424 | goto out; |
---|
.. | .. |
---|
448 | 436 | |
---|
449 | 437 | NX_CPB_FDM(csbcpb) |= NX_FDM_ENDE_ENCRYPT; |
---|
450 | 438 | |
---|
451 | | - rc = nx_build_sg_lists(nx_ctx, desc, req->dst, req->src, |
---|
| 439 | + rc = nx_build_sg_lists(nx_ctx, iv, req->dst, req->src, |
---|
452 | 440 | &to_process, processed + req->assoclen, |
---|
453 | 441 | csbcpb->cpb.aes_ccm.iv_or_ctr); |
---|
454 | 442 | if (rc) |
---|
.. | .. |
---|
462 | 450 | /* for partial completion, copy following for next |
---|
463 | 451 | * entry into loop... |
---|
464 | 452 | */ |
---|
465 | | - memcpy(desc->info, csbcpb->cpb.aes_ccm.out_ctr, AES_BLOCK_SIZE); |
---|
| 453 | + memcpy(iv, csbcpb->cpb.aes_ccm.out_ctr, AES_BLOCK_SIZE); |
---|
466 | 454 | memcpy(csbcpb->cpb.aes_ccm.in_pat_or_b0, |
---|
467 | 455 | csbcpb->cpb.aes_ccm.out_pat_or_mac, AES_BLOCK_SIZE); |
---|
468 | 456 | memcpy(csbcpb->cpb.aes_ccm.in_s0, |
---|
.. | .. |
---|
493 | 481 | { |
---|
494 | 482 | struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(req->base.tfm); |
---|
495 | 483 | struct nx_gcm_rctx *rctx = aead_request_ctx(req); |
---|
496 | | - struct blkcipher_desc desc; |
---|
497 | 484 | u8 *iv = rctx->iv; |
---|
498 | 485 | |
---|
499 | 486 | iv[0] = 3; |
---|
500 | 487 | memcpy(iv + 1, nx_ctx->priv.ccm.nonce, 3); |
---|
501 | 488 | memcpy(iv + 4, req->iv, 8); |
---|
502 | 489 | |
---|
503 | | - desc.info = iv; |
---|
504 | | - |
---|
505 | | - return ccm_nx_encrypt(req, &desc, req->assoclen - 8); |
---|
| 490 | + return ccm_nx_encrypt(req, iv, req->assoclen - 8); |
---|
506 | 491 | } |
---|
507 | 492 | |
---|
508 | 493 | static int ccm_aes_nx_encrypt(struct aead_request *req) |
---|
509 | 494 | { |
---|
510 | | - struct blkcipher_desc desc; |
---|
511 | 495 | int rc; |
---|
512 | 496 | |
---|
513 | | - desc.info = req->iv; |
---|
514 | | - |
---|
515 | | - rc = crypto_ccm_check_iv(desc.info); |
---|
| 497 | + rc = crypto_ccm_check_iv(req->iv); |
---|
516 | 498 | if (rc) |
---|
517 | 499 | return rc; |
---|
518 | 500 | |
---|
519 | | - return ccm_nx_encrypt(req, &desc, req->assoclen); |
---|
| 501 | + return ccm_nx_encrypt(req, req->iv, req->assoclen); |
---|
520 | 502 | } |
---|
521 | 503 | |
---|
522 | 504 | static int ccm4309_aes_nx_decrypt(struct aead_request *req) |
---|
523 | 505 | { |
---|
524 | 506 | struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(req->base.tfm); |
---|
525 | 507 | struct nx_gcm_rctx *rctx = aead_request_ctx(req); |
---|
526 | | - struct blkcipher_desc desc; |
---|
527 | 508 | u8 *iv = rctx->iv; |
---|
528 | 509 | |
---|
529 | 510 | iv[0] = 3; |
---|
530 | 511 | memcpy(iv + 1, nx_ctx->priv.ccm.nonce, 3); |
---|
531 | 512 | memcpy(iv + 4, req->iv, 8); |
---|
532 | 513 | |
---|
533 | | - desc.info = iv; |
---|
534 | | - |
---|
535 | | - return ccm_nx_decrypt(req, &desc, req->assoclen - 8); |
---|
| 514 | + return ccm_nx_decrypt(req, iv, req->assoclen - 8); |
---|
536 | 515 | } |
---|
537 | 516 | |
---|
538 | 517 | static int ccm_aes_nx_decrypt(struct aead_request *req) |
---|
539 | 518 | { |
---|
540 | | - struct blkcipher_desc desc; |
---|
541 | 519 | int rc; |
---|
542 | 520 | |
---|
543 | | - desc.info = req->iv; |
---|
544 | | - |
---|
545 | | - rc = crypto_ccm_check_iv(desc.info); |
---|
| 521 | + rc = crypto_ccm_check_iv(req->iv); |
---|
546 | 522 | if (rc) |
---|
547 | 523 | return rc; |
---|
548 | 524 | |
---|
549 | | - return ccm_nx_decrypt(req, &desc, req->assoclen); |
---|
| 525 | + return ccm_nx_decrypt(req, req->iv, req->assoclen); |
---|
550 | 526 | } |
---|
551 | 527 | |
---|
552 | | -/* tell the block cipher walk routines that this is a stream cipher by |
---|
553 | | - * setting cra_blocksize to 1. Even using blkcipher_walk_virt_block |
---|
554 | | - * during encrypt/decrypt doesn't solve this problem, because it calls |
---|
555 | | - * blkcipher_walk_done under the covers, which doesn't use walk->blocksize, |
---|
556 | | - * but instead uses this tfm->blocksize. */ |
---|
557 | 528 | struct aead_alg nx_ccm_aes_alg = { |
---|
558 | 529 | .base = { |
---|
559 | 530 | .cra_name = "ccm(aes)", |
---|