| 1465 | } |
| 1466 | |
| 1467 | static int __must_check |
| 1468 | ccp_do_blkcipher(struct ccp_queue *qp, struct ccp_session *s, |
| 1469 | struct cryptop *crp, const struct ccp_completion_ctx *cctx) |
| 1470 | { |
| 1471 | const struct crypto_session_params *csp; |
| 1472 | struct ccp_desc *desc; |
| 1473 | char *keydata; |
| 1474 | device_t dev; |
| 1475 | enum ccp_cipher_dir dir; |
| 1476 | int error, iv_len; |
| 1477 | size_t keydata_len; |
| 1478 | unsigned i, j; |
| 1479 | |
| 1480 | dev = qp->cq_softc->dev; |
| 1481 | |
| 1482 | if (s->blkcipher.key_len == 0 || crp->crp_payload_length == 0) { |
| 1483 | DPRINTF(dev, "%s: empty\n", __func__); |
| 1484 | return (EINVAL); |
| 1485 | } |
| 1486 | if ((crp->crp_payload_length % AES_BLOCK_LEN) != 0) { |
| 1487 | DPRINTF(dev, "%s: len modulo: %d\n", __func__, |
| 1488 | crp->crp_payload_length); |
| 1489 | return (EINVAL); |
| 1490 | } |
| 1491 | |
| 1492 | /* |
| 1493 | * Individual segments must be multiples of AES block size for the HW |
| 1494 | * to process it. Non-compliant inputs aren't bogus, just not doable |
| 1495 | * on this hardware. |
| 1496 | */ |
| 1497 | for (i = 0; i < qp->cq_sg_crp->sg_nseg; i++) |
| 1498 | if ((qp->cq_sg_crp->sg_segs[i].ss_len % AES_BLOCK_LEN) != 0) { |
| 1499 | DPRINTF(dev, "%s: seg modulo: %zu\n", __func__, |
| 1500 | qp->cq_sg_crp->sg_segs[i].ss_len); |
| 1501 | return (EINVAL); |
| 1502 | } |
| 1503 | |
| 1504 | /* Gather IV/nonce data */ |
| 1505 | csp = crypto_get_params(crp->crp_session); |
| 1506 | ccp_collect_iv(crp, csp, s->blkcipher.iv); |
| 1507 | iv_len = csp->csp_ivlen; |
| 1508 | if (csp->csp_cipher_alg == CRYPTO_AES_XTS) |
| 1509 | iv_len = AES_BLOCK_LEN; |
| 1510 | |
| 1511 | if (CRYPTO_OP_IS_ENCRYPT(crp->crp_op)) |
| 1512 | dir = CCP_CIPHER_DIR_ENCRYPT; |
| 1513 | else |
| 1514 | dir = CCP_CIPHER_DIR_DECRYPT; |
| 1515 | |
| 1516 | /* Set up passthrough op(s) to copy IV into LSB */ |
| 1517 | error = ccp_do_pst_to_lsb(qp, ccp_queue_lsb_address(qp, LSB_ENTRY_IV), |
| 1518 | s->blkcipher.iv, iv_len); |
| 1519 | if (error != 0) |
| 1520 | return (error); |
| 1521 | |
| 1522 | /* |
| 1523 | * Initialize keydata and keydata_len for GCC. The default case of the |
| 1524 | * following switch is impossible to reach, but GCC doesn't know that. |
no test coverage detected