| 562 | } |
| 563 | |
| 564 | static int |
| 565 | xlp_sec_process(device_t dev, struct cryptop *crp, int hint) |
| 566 | { |
| 567 | struct xlp_sec_softc *sc = device_get_softc(dev); |
| 568 | const struct crypto_session_params *csp; |
| 569 | struct xlp_sec_command *cmd = NULL; |
| 570 | int err = -1, ret = 0; |
| 571 | struct xlp_sec_session *ses; |
| 572 | unsigned int nsegs = 0; |
| 573 | |
| 574 | ses = crypto_get_driver_session(crp->crp_session); |
| 575 | csp = crypto_get_params(crp->crp_session); |
| 576 | |
| 577 | /* |
| 578 | * This device only support AAD requests where the AAD is |
| 579 | * adjacent to the payload. |
| 580 | */ |
| 581 | if (crp->crp_aad_length != 0 && crp->crp_payload_start != |
| 582 | crp->crp_aad_start + crp->crp_aad_length) { |
| 583 | err = EFBIG; |
| 584 | goto errout; |
| 585 | } |
| 586 | |
| 587 | if ((cmd = malloc(sizeof(struct xlp_sec_command), M_DEVBUF, |
| 588 | M_NOWAIT | M_ZERO)) == NULL) { |
| 589 | err = ENOMEM; |
| 590 | goto errout; |
| 591 | } |
| 592 | |
| 593 | cmd->crp = crp; |
| 594 | cmd->ses = ses; |
| 595 | cmd->hash_dst_len = ses->hs_mlen; |
| 596 | |
| 597 | if ((ret = xlp_get_nsegs(crp, &nsegs)) != 0) { |
| 598 | err = EINVAL; |
| 599 | goto errout; |
| 600 | } |
| 601 | |
| 602 | if (crp->crp_flags & CRYPTO_F_IV_SEPARATE) { |
| 603 | /* Since IV is given as separate segment to avoid copy */ |
| 604 | nsegs += 1; |
| 605 | } |
| 606 | cmd->nsegs = nsegs; |
| 607 | |
| 608 | if ((err = xlp_alloc_cmd_params(cmd, nsegs)) != 0) |
| 609 | goto errout; |
| 610 | |
| 611 | switch (csp->csp_mode) { |
| 612 | case CSP_MODE_CIPHER: |
| 613 | if ((ret = nlm_get_cipher_param(cmd, csp)) != 0) { |
| 614 | err = EINVAL; |
| 615 | goto errout; |
| 616 | } |
| 617 | cmd->cipheroff = crp->crp_payload_start; |
| 618 | cmd->cipherlen = crp->crp_payload_length; |
| 619 | if (crp->crp_flags & CRYPTO_F_IV_SEPARATE) { |
| 620 | cmd->cipheroff += cmd->ivlen; |
| 621 | cmd->ivoff = 0; |
nothing calls this directly
no test coverage detected