| 700 | } |
| 701 | |
| 702 | static int |
| 703 | swcr_ccm(struct swcr_session *ses, struct cryptop *crp) |
| 704 | { |
| 705 | uint32_t blkbuf[howmany(AES_BLOCK_LEN, sizeof(uint32_t))]; |
| 706 | u_char *blk = (u_char *)blkbuf; |
| 707 | u_char tag[AES_CBC_MAC_HASH_LEN]; |
| 708 | u_char iv[AES_BLOCK_LEN]; |
| 709 | struct crypto_buffer_cursor cc_in, cc_out; |
| 710 | const u_char *inblk; |
| 711 | u_char *outblk; |
| 712 | union authctx ctx; |
| 713 | struct swcr_auth *swa; |
| 714 | struct swcr_encdec *swe; |
| 715 | struct auth_hash *axf; |
| 716 | struct enc_xform *exf; |
| 717 | int blksz, error, ivlen, r, resid; |
| 718 | |
| 719 | swa = &ses->swcr_auth; |
| 720 | axf = swa->sw_axf; |
| 721 | |
| 722 | bcopy(swa->sw_ictx, &ctx, axf->ctxsize); |
| 723 | blksz = AES_BLOCK_LEN; |
| 724 | KASSERT(axf->blocksize == blksz, ("%s: axf block size mismatch", |
| 725 | __func__)); |
| 726 | |
| 727 | swe = &ses->swcr_encdec; |
| 728 | exf = swe->sw_exf; |
| 729 | KASSERT(axf->blocksize == exf->native_blocksize, |
| 730 | ("%s: blocksize mismatch", __func__)); |
| 731 | |
| 732 | if ((crp->crp_flags & CRYPTO_F_IV_SEPARATE) == 0) |
| 733 | return (EINVAL); |
| 734 | |
| 735 | /* Initialize the IV */ |
| 736 | ivlen = AES_CCM_IV_LEN; |
| 737 | bcopy(crp->crp_iv, iv, ivlen); |
| 738 | |
| 739 | /* |
| 740 | * AES CCM-CBC-MAC needs to know the length of both the auth |
| 741 | * data and payload data before doing the auth computation. |
| 742 | */ |
| 743 | ctx.aes_cbc_mac_ctx.authDataLength = crp->crp_aad_length; |
| 744 | ctx.aes_cbc_mac_ctx.cryptDataLength = crp->crp_payload_length; |
| 745 | |
| 746 | /* Supply MAC with IV */ |
| 747 | axf->Reinit(&ctx, iv, ivlen); |
| 748 | |
| 749 | /* Supply MAC with AAD */ |
| 750 | if (crp->crp_aad != NULL) |
| 751 | error = axf->Update(&ctx, crp->crp_aad, crp->crp_aad_length); |
| 752 | else |
| 753 | error = crypto_apply(crp, crp->crp_aad_start, |
| 754 | crp->crp_aad_length, axf->Update, &ctx); |
| 755 | if (error) |
| 756 | return (error); |
| 757 | |
| 758 | exf->reinit(swe->sw_kschedule, iv); |
| 759 |
nothing calls this directly
no test coverage detected