* Compute or verify hash. */
| 314 | * Compute or verify hash. |
| 315 | */ |
| 316 | static int |
| 317 | swcr_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)); |
no test coverage detected