Changeset View
Standalone View
sys/crypto/aesni/aesni.c
Show First 20 Lines • Show All 397 Lines • ▼ Show 20 Lines | out: | ||||
crypto_done(crp); | crypto_done(crp); | ||||
return (error); | return (error); | ||||
} | } | ||||
static uint8_t * | static uint8_t * | ||||
aesni_cipher_alloc(struct cryptodesc *enccrd, struct cryptop *crp, | aesni_cipher_alloc(struct cryptodesc *enccrd, struct cryptop *crp, | ||||
bool *allocated) | bool *allocated) | ||||
{ | { | ||||
struct mbuf *m; | |||||
struct uio *uio; | |||||
struct iovec *iov; | |||||
uint8_t *addr; | uint8_t *addr; | ||||
if (crp->crp_flags & CRYPTO_F_IMBUF) { | addr = crypto_contiguous_subsegment(crp->crp_flags, | ||||
cem: This would be reduced to:
```
addr = crypto_contiguous_subsegment(crp->crp_flags, crp->crp_buf… | |||||
m = (struct mbuf *)crp->crp_buf; | crp->crp_buf, enccrd->crd_skip, enccrd->crd_len); | ||||
if (m->m_next != NULL) | if (addr != NULL) { | ||||
goto alloc; | |||||
addr = mtod(m, uint8_t *); | |||||
} else if (crp->crp_flags & CRYPTO_F_IOV) { | |||||
uio = (struct uio *)crp->crp_buf; | |||||
if (uio->uio_iovcnt != 1) | |||||
goto alloc; | |||||
iov = uio->uio_iov; | |||||
addr = (uint8_t *)iov->iov_base; | |||||
} else | |||||
addr = (uint8_t *)crp->crp_buf; | |||||
*allocated = false; | *allocated = false; | ||||
addr += enccrd->crd_skip; | |||||
return (addr); | return (addr); | ||||
} | |||||
alloc: | |||||
addr = malloc(enccrd->crd_len, M_AESNI, M_NOWAIT); | addr = malloc(enccrd->crd_len, M_AESNI, M_NOWAIT); | ||||
if (addr != NULL) { | if (addr != NULL) { | ||||
Not Done Inline Actionsfalse for bool false values cem: `false` for bool false values | |||||
Done Inline ActionsEasily enough done. sef: Easily enough done. | |||||
*allocated = true; | *allocated = true; | ||||
crypto_copydata(crp->crp_flags, crp->crp_buf, enccrd->crd_skip, | crypto_copydata(crp->crp_flags, crp->crp_buf, enccrd->crd_skip, | ||||
enccrd->crd_len, addr); | enccrd->crd_len, addr); | ||||
} else | } else | ||||
*allocated = false; | *allocated = false; | ||||
return (addr); | return (addr); | ||||
} | } | ||||
static device_method_t aesni_methods[] = { | static device_method_t aesni_methods[] = { | ||||
DEVMETHOD(device_identify, aesni_identify), | DEVMETHOD(device_identify, aesni_identify), | ||||
DEVMETHOD(device_probe, aesni_probe), | DEVMETHOD(device_probe, aesni_probe), | ||||
DEVMETHOD(device_attach, aesni_attach), | DEVMETHOD(device_attach, aesni_attach), | ||||
DEVMETHOD(device_detach, aesni_detach), | DEVMETHOD(device_detach, aesni_detach), | ||||
DEVMETHOD(cryptodev_newsession, aesni_newsession), | DEVMETHOD(cryptodev_newsession, aesni_newsession), | ||||
DEVMETHOD(cryptodev_process, aesni_process), | DEVMETHOD(cryptodev_process, aesni_process), | ||||
Not Done Inline ActionsLike I mentioned in the other review, I think this is more broadly useful to OCF consumers than just aesni. E.g., armv8_crypto_cipher_alloc was basically copy-pasted from aesni and has the same issue. And the identical optimization can be applied to mbuf chains. Given the general trend of OCF crypto_* methods that are agnostic to type, maybe it makes sense to just make this an OCF subroutine that operates generically, like crypto_copydata? static inline void * m_contiguous_subsegment(struct mbuf *m, size_t skip, size_t len) { int rel_off; MPASS(skip <= INT_MAX); m = m_getptr(m, (int)skip, &rel_off); if (m == NULL) return (NULL); MPASS(rel_off >= 0); skip = rel_off; if (skip + len > m->m_len) return (NULL); return (mtod(m, char *) + skip); } static void * cuio_contiguous_subsegment(struct uio *uio, size_t skip, size_t len) { int rel_off, idx; MPASS(skip <= INT_MAX); idx = cuio_getptr(uio, (int)skip, &rel_off); if (idx < 0) return (NULL); MPASS(rel_off >= 0); skip = rel_off; if (skip + len > uio->uio_iov[idx].iov_len) return (NULL); return ((char *)uio->uio_iov[idx].iov_base + skip); } void * crypto_contiguous_subsegment(int crpflags, void *crpbuf, size_t skip, size_t len) { if ((flags & CRYPTO_F_IMBUF) != 0) return (m_contiguous_subsegment(crpbuf, off, size, out)); else if ((flags & CRYPTO_F_IOV) != 0) return (cuio_contiguous_subsegment(crpbuf, off, size, out)); else { MPASS((crp_flags & (CRYPTO_F_IMBUF | CRYPTO_F_IOV)) != (CRYPTO_F_IMBUF | CRYPTO_F_IOV)); return ((char *)crpbuf + skip); } } (Either way, the poorly named cuio_getptr already does most of this logic for you.) cem: Like I mentioned in the other review, I think this is more broadly useful to OCF consumers than… | |||||
Done Inline ActionsI'm *perfectly* happy to have another version of it done. The existing one is a bit of a hack, and I just extended the hack for a case I cared about. I tried to touch the greater crypto code as minimally as possible, which means that I didn't refactor anything. sef: I'm *perfectly* happy to have another version of it done. The existing one is a bit of a hack… | |||||
DEVMETHOD_END | DEVMETHOD_END | ||||
}; | }; | ||||
static driver_t aesni_driver = { | static driver_t aesni_driver = { | ||||
"aesni", | "aesni", | ||||
aesni_methods, | aesni_methods, | ||||
sizeof(struct aesni_softc), | sizeof(struct aesni_softc), | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 480 Lines • Show Last 20 Lines |
This would be reduced to: