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

Function swcr_authcompute

freebsd/opencrypto/cryptosoft.c:316–382  ·  view source on GitHub ↗

* Compute or verify hash. */

Source from the content-addressed store, hash-verified

314 * Compute or verify hash.
315 */
316static int
317swcr_authcompute(struct swcr_session *ses, struct cryptop *crp)
318{
319 u_char aalg[HASH_MAX_LEN];
320 const struct crypto_session_params *csp;
321 struct swcr_auth *sw;
322 struct auth_hash *axf;
323 union authctx ctx;
324 int err;
325
326 sw = &ses->swcr_auth;
327
328 axf = sw->sw_axf;
329
330 csp = crypto_get_params(crp->crp_session);
331 if (crp->crp_auth_key != NULL) {
332 swcr_authprepare(axf, sw, crp->crp_auth_key,
333 csp->csp_auth_klen);
334 }
335
336 bcopy(sw->sw_ictx, &ctx, axf->ctxsize);
337
338 if (crp->crp_aad != NULL)
339 err = axf->Update(&ctx, crp->crp_aad, crp->crp_aad_length);
340 else
341 err = crypto_apply(crp, crp->crp_aad_start, crp->crp_aad_length,
342 axf->Update, &ctx);
343 if (err)
344 goto out;
345
346 if (CRYPTO_HAS_OUTPUT_BUFFER(crp) &&
347 CRYPTO_OP_IS_ENCRYPT(crp->crp_op))
348 err = crypto_apply_buf(&crp->crp_obuf,
349 crp->crp_payload_output_start, crp->crp_payload_length,
350 axf->Update, &ctx);
351 else
352 err = crypto_apply(crp, crp->crp_payload_start,
353 crp->crp_payload_length, axf->Update, &ctx);
354 if (err)
355 goto out;
356
357 if (csp->csp_flags & CSP_F_ESN)
358 axf->Update(&ctx, crp->crp_esn, 4);
359
360 axf->Final(aalg, &ctx);
361 if (sw->sw_octx != NULL) {
362 bcopy(sw->sw_octx, &ctx, axf->ctxsize);
363 axf->Update(&ctx, aalg, axf->hashsize);
364 axf->Final(aalg, &ctx);
365 }
366
367 if (crp->crp_op & CRYPTO_OP_VERIFY_DIGEST) {
368 u_char uaalg[HASH_MAX_LEN];
369
370 crypto_copydata(crp, crp->crp_digest_start, sw->sw_mlen, uaalg);
371 if (timingsafe_bcmp(aalg, uaalg, sw->sw_mlen) != 0)
372 err = EBADMSG;
373 explicit_bzero(uaalg, sizeof(uaalg));

Callers 1

swcr_etaFunction · 0.85

Calls 8

crypto_get_paramsFunction · 0.85
swcr_authprepareFunction · 0.85
crypto_applyFunction · 0.85
crypto_apply_bufFunction · 0.85
crypto_copydataFunction · 0.85
timingsafe_bcmpFunction · 0.85
explicit_bzeroFunction · 0.85
crypto_copybackFunction · 0.85

Tested by

no test coverage detected