* Compute keyed-hash authenticator. */
| 279 | * Compute keyed-hash authenticator. |
| 280 | */ |
| 281 | static int |
| 282 | padlock_authcompute(struct padlock_session *ses, struct cryptop *crp) |
| 283 | { |
| 284 | u_char hash[HASH_MAX_LEN], hash2[HASH_MAX_LEN]; |
| 285 | struct auth_hash *axf; |
| 286 | union authctx ctx; |
| 287 | int error; |
| 288 | |
| 289 | axf = ses->ses_axf; |
| 290 | |
| 291 | padlock_copy_ctx(axf, ses->ses_ictx, &ctx); |
| 292 | error = crypto_apply(crp, crp->crp_aad_start, crp->crp_aad_length, |
| 293 | axf->Update, &ctx); |
| 294 | if (error != 0) { |
| 295 | padlock_free_ctx(axf, &ctx); |
| 296 | return (error); |
| 297 | } |
| 298 | error = crypto_apply(crp, crp->crp_payload_start, |
| 299 | crp->crp_payload_length, axf->Update, &ctx); |
| 300 | if (error != 0) { |
| 301 | padlock_free_ctx(axf, &ctx); |
| 302 | return (error); |
| 303 | } |
| 304 | axf->Final(hash, &ctx); |
| 305 | |
| 306 | padlock_copy_ctx(axf, ses->ses_octx, &ctx); |
| 307 | axf->Update(&ctx, hash, axf->hashsize); |
| 308 | axf->Final(hash, &ctx); |
| 309 | |
| 310 | if (crp->crp_op & CRYPTO_OP_VERIFY_DIGEST) { |
| 311 | crypto_copydata(crp, crp->crp_digest_start, ses->ses_mlen, |
| 312 | hash2); |
| 313 | if (timingsafe_bcmp(hash, hash2, ses->ses_mlen) != 0) |
| 314 | return (EBADMSG); |
| 315 | } else |
| 316 | crypto_copyback(crp, crp->crp_digest_start, ses->ses_mlen, |
| 317 | hash); |
| 318 | return (0); |
| 319 | } |
| 320 | |
| 321 | /* Find software structure which describes HMAC algorithm. */ |
| 322 | static struct auth_hash * |
no test coverage detected