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

Function swcr_gcm

freebsd/opencrypto/cryptosoft.c:464–645  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

462}
463
464static int
465swcr_gcm(struct swcr_session *ses, struct cryptop *crp)
466{
467 uint32_t blkbuf[howmany(AES_BLOCK_LEN, sizeof(uint32_t))];
468 u_char *blk = (u_char *)blkbuf;
469 u_char tag[GMAC_DIGEST_LEN];
470 u_char iv[AES_BLOCK_LEN];
471 struct crypto_buffer_cursor cc_in, cc_out;
472 const u_char *inblk;
473 u_char *outblk;
474 union authctx ctx;
475 struct swcr_auth *swa;
476 struct swcr_encdec *swe;
477 struct auth_hash *axf;
478 struct enc_xform *exf;
479 uint32_t *blkp;
480 int blksz, error, ivlen, len, r, resid;
481
482 swa = &ses->swcr_auth;
483 axf = swa->sw_axf;
484
485 bcopy(swa->sw_ictx, &ctx, axf->ctxsize);
486 blksz = GMAC_BLOCK_LEN;
487 KASSERT(axf->blocksize == blksz, ("%s: axf block size mismatch",
488 __func__));
489
490 swe = &ses->swcr_encdec;
491 exf = swe->sw_exf;
492 KASSERT(axf->blocksize == exf->native_blocksize,
493 ("%s: blocksize mismatch", __func__));
494
495 if ((crp->crp_flags & CRYPTO_F_IV_SEPARATE) == 0)
496 return (EINVAL);
497
498 /* Initialize the IV */
499 ivlen = AES_GCM_IV_LEN;
500 bcopy(crp->crp_iv, iv, ivlen);
501
502 /* Supply MAC with IV */
503 axf->Reinit(&ctx, iv, ivlen);
504
505 /* Supply MAC with AAD */
506 if (crp->crp_aad != NULL) {
507 len = rounddown(crp->crp_aad_length, blksz);
508 if (len != 0)
509 axf->Update(&ctx, crp->crp_aad, len);
510 if (crp->crp_aad_length != len) {
511 memset(blk, 0, blksz);
512 memcpy(blk, (char *)crp->crp_aad + len,
513 crp->crp_aad_length - len);
514 axf->Update(&ctx, blk, blksz);
515 }
516 } else {
517 crypto_cursor_init(&cc_in, &crp->crp_buf);
518 crypto_cursor_advance(&cc_in, crp->crp_aad_start);
519 for (resid = crp->crp_aad_length; resid >= blksz;
520 resid -= len) {
521 len = crypto_cursor_seglen(&cc_in);

Callers

nothing calls this directly

Calls 13

memsetFunction · 0.85
crypto_cursor_initFunction · 0.85
crypto_cursor_advanceFunction · 0.85
crypto_cursor_seglenFunction · 0.85
crypto_cursor_segbaseFunction · 0.85
crypto_cursor_copydataFunction · 0.85
crypto_cursor_copybackFunction · 0.85
crypto_copydataFunction · 0.85
timingsafe_bcmpFunction · 0.85
explicit_bzeroFunction · 0.85
crypto_copybackFunction · 0.85
decryptMethod · 0.80

Tested by

no test coverage detected