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

Function ccp_do_blkcipher

freebsd/crypto/ccp/ccp_hardware.c:1467–1669  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1465}
1466
1467static int __must_check
1468ccp_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.

Callers 2

ccp_blkcipherFunction · 0.85
ccp_authencFunction · 0.85

Calls 12

crypto_get_paramsFunction · 0.85
ccp_collect_ivFunction · 0.85
ccp_do_pst_to_lsbFunction · 0.85
ccp_queue_lsb_addressFunction · 0.85
device_printfFunction · 0.85
ccp_byteswapFunction · 0.85
sglist_resetFunction · 0.85
sglist_append_sglistFunction · 0.85
ccp_queue_get_ring_spaceFunction · 0.85
ccp_do_xtsFunction · 0.85
ccp_queue_lsb_entryFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected