| 645 | } |
| 646 | |
| 647 | static int |
| 648 | swcr_ccm_cbc_mac(struct swcr_session *ses, struct cryptop *crp) |
| 649 | { |
| 650 | u_char tag[AES_CBC_MAC_HASH_LEN]; |
| 651 | u_char iv[AES_BLOCK_LEN]; |
| 652 | union authctx ctx; |
| 653 | struct swcr_auth *swa; |
| 654 | struct auth_hash *axf; |
| 655 | int error, ivlen; |
| 656 | |
| 657 | swa = &ses->swcr_auth; |
| 658 | axf = swa->sw_axf; |
| 659 | |
| 660 | bcopy(swa->sw_ictx, &ctx, axf->ctxsize); |
| 661 | |
| 662 | /* Initialize the IV */ |
| 663 | ivlen = AES_CCM_IV_LEN; |
| 664 | crypto_read_iv(crp, iv); |
| 665 | |
| 666 | /* |
| 667 | * AES CCM-CBC-MAC needs to know the length of both the auth |
| 668 | * data and payload data before doing the auth computation. |
| 669 | */ |
| 670 | ctx.aes_cbc_mac_ctx.authDataLength = crp->crp_payload_length; |
| 671 | ctx.aes_cbc_mac_ctx.cryptDataLength = 0; |
| 672 | |
| 673 | axf->Reinit(&ctx, iv, ivlen); |
| 674 | if (crp->crp_aad != NULL) |
| 675 | error = axf->Update(&ctx, crp->crp_aad, crp->crp_aad_length); |
| 676 | else |
| 677 | error = crypto_apply(crp, crp->crp_payload_start, |
| 678 | crp->crp_payload_length, axf->Update, &ctx); |
| 679 | if (error) |
| 680 | return (error); |
| 681 | |
| 682 | /* Finalize MAC */ |
| 683 | axf->Final(tag, &ctx); |
| 684 | |
| 685 | if (crp->crp_op & CRYPTO_OP_VERIFY_DIGEST) { |
| 686 | u_char tag2[AES_CBC_MAC_HASH_LEN]; |
| 687 | |
| 688 | crypto_copydata(crp, crp->crp_digest_start, swa->sw_mlen, |
| 689 | tag2); |
| 690 | if (timingsafe_bcmp(tag, tag2, swa->sw_mlen) != 0) |
| 691 | error = EBADMSG; |
| 692 | explicit_bzero(tag2, sizeof(tag)); |
| 693 | } else { |
| 694 | /* Inject the authentication data */ |
| 695 | crypto_copyback(crp, crp->crp_digest_start, swa->sw_mlen, tag); |
| 696 | } |
| 697 | explicit_bzero(tag, sizeof(tag)); |
| 698 | explicit_bzero(iv, sizeof(iv)); |
| 699 | return (error); |
| 700 | } |
| 701 | |
| 702 | static int |
| 703 | swcr_ccm(struct swcr_session *ses, struct cryptop *crp) |
nothing calls this directly
no test coverage detected