| 385 | CTASSERT(INT_MAX <= (uint64_t)-1); /* GCM: associated data <= 2^64-1 */ |
| 386 | |
| 387 | static int |
| 388 | swcr_gmac(struct swcr_session *ses, struct cryptop *crp) |
| 389 | { |
| 390 | uint32_t blkbuf[howmany(AES_BLOCK_LEN, sizeof(uint32_t))]; |
| 391 | u_char *blk = (u_char *)blkbuf; |
| 392 | u_char tag[GMAC_DIGEST_LEN]; |
| 393 | u_char iv[AES_BLOCK_LEN]; |
| 394 | struct crypto_buffer_cursor cc; |
| 395 | const u_char *inblk; |
| 396 | union authctx ctx; |
| 397 | struct swcr_auth *swa; |
| 398 | struct auth_hash *axf; |
| 399 | uint32_t *blkp; |
| 400 | int blksz, error, ivlen, len, resid; |
| 401 | |
| 402 | swa = &ses->swcr_auth; |
| 403 | axf = swa->sw_axf; |
| 404 | |
| 405 | bcopy(swa->sw_ictx, &ctx, axf->ctxsize); |
| 406 | blksz = GMAC_BLOCK_LEN; |
| 407 | KASSERT(axf->blocksize == blksz, ("%s: axf block size mismatch", |
| 408 | __func__)); |
| 409 | |
| 410 | /* Initialize the IV */ |
| 411 | ivlen = AES_GCM_IV_LEN; |
| 412 | crypto_read_iv(crp, iv); |
| 413 | |
| 414 | axf->Reinit(&ctx, iv, ivlen); |
| 415 | crypto_cursor_init(&cc, &crp->crp_buf); |
| 416 | crypto_cursor_advance(&cc, crp->crp_payload_start); |
| 417 | for (resid = crp->crp_payload_length; resid >= blksz; resid -= len) { |
| 418 | len = crypto_cursor_seglen(&cc); |
| 419 | if (len >= blksz) { |
| 420 | inblk = crypto_cursor_segbase(&cc); |
| 421 | len = rounddown(MIN(len, resid), blksz); |
| 422 | crypto_cursor_advance(&cc, len); |
| 423 | } else { |
| 424 | len = blksz; |
| 425 | crypto_cursor_copydata(&cc, len, blk); |
| 426 | inblk = blk; |
| 427 | } |
| 428 | axf->Update(&ctx, inblk, len); |
| 429 | } |
| 430 | if (resid > 0) { |
| 431 | memset(blk, 0, blksz); |
| 432 | crypto_cursor_copydata(&cc, resid, blk); |
| 433 | axf->Update(&ctx, blk, blksz); |
| 434 | } |
| 435 | |
| 436 | /* length block */ |
| 437 | memset(blk, 0, blksz); |
| 438 | blkp = (uint32_t *)blk + 1; |
| 439 | *blkp = htobe32(crp->crp_payload_length * 8); |
| 440 | axf->Update(&ctx, blk, blksz); |
| 441 | |
| 442 | /* Finalize MAC */ |
| 443 | axf->Final(tag, &ctx); |
| 444 |
nothing calls this directly
no test coverage detected