MCPcopy Create free account
hub / github.com/F-Stack/f-stack / swcr_ccm_cbc_mac

Function swcr_ccm_cbc_mac

freebsd/opencrypto/cryptosoft.c:647–700  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

645}
646
647static int
648swcr_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
702static int
703swcr_ccm(struct swcr_session *ses, struct cryptop *crp)

Callers

nothing calls this directly

Calls 6

crypto_read_ivFunction · 0.85
crypto_applyFunction · 0.85
crypto_copydataFunction · 0.85
timingsafe_bcmpFunction · 0.85
explicit_bzeroFunction · 0.85
crypto_copybackFunction · 0.85

Tested by

no test coverage detected