You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
explore hashlib use of the Linux Kernel CryptoAPI #91258
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2022-03-23.19:30:13.093>labels= ['type-feature']
title='explore hashlib use of the Linux Kernel CryptoAPI'updated_at=<Date2022-03-29.15:34:13.058>user='https://github.com/gpshead'
Linux kernels provide a CryptoAPI. This is a common place for platform specific hardware accelerated hash algorithms to be exposed to the user (especially on SoCs which often have non-standard hardware).
hashlib currently uses OpenSSL when possible for performance. We could also look at querying the kernel API. How to decide between the two implementations when both are present is something TBD.
This would probably be best done via a configure time check for libkcapi?
Neat. I've never used the API, just filing a breadcrumb suggesting we see if it makes sense. Being I/O based, that even takes care of GIL releasing from Python. :)
Playing with your draft PR branch and testing things out... the performance of the Linux kernel crypto API for hash algorithms is several times slower on a modern AMD Zen, regardless of data size.
I realize it probably gets a tad better in limited situations where sendfile or splice can used, but it doesn't seem like a useful API on modern mainstream hardware. It could still make sense on low performance things that have non-userspace accelerator hardware. But this doesn't leave much motivation to implement code using it.
Playing with your draft PR branch and testing things out... the performance of the Linux kernel crypto API for hash algorithms is several times slower on a modern AMD Zen, regardless of data size.
Probably, this should be added into the documentation if this issue gets rejected. Otherwise, there will be another attempts to introduce CryptoAPI, and one of them can even accidentally slip through.
Probably, this should be added into the documentation if this issue gets rejected. Otherwise, there will be another attempts to introduce CryptoAPI, and one of them can even accidentally slip through.
I'm not worried about that. This issue existing in our issue tracker is sufficient documentation.
Activity
gpshead commentedon Mar 23, 2022
Linux kernels provide a CryptoAPI. This is a common place for platform specific hardware accelerated hash algorithms to be exposed to the user (especially on SoCs which often have non-standard hardware).
https://www.kernel.org/doc/html/v4.10/crypto/userspace-if.html
https://www.kernel.org/doc/html/v5.17/crypto/userspace-if.html
https://www.chronox.de/libkcapi.html
hashlib currently uses OpenSSL when possible for performance. We could also look at querying the kernel API. How to decide between the two implementations when both are present is something TBD.
This would probably be best done via a configure time check for libkcapi?
tiran commentedon Mar 23, 2022
We don't need libkcapi. I added AF_ALG support a while ago:
gpshead commentedon Mar 23, 2022
Neat. I've never used the API, just filing a breadcrumb suggesting we see if it makes sense. Being I/O based, that even takes care of GIL releasing from Python. :)
tiran commentedon Mar 23, 2022
test_socket has examples for HMAC, AES-CBC, and AES-GCM.
tiran commentedon Mar 23, 2022
And sendfile() is zero-copy. Data does not have to leave Kernel space.
tiran commentedon Mar 29, 2022
I figured out how to implement copy(). dup() does not work as expected, but accept() on an AF_ALG client socket creates an independent copy.
gpshead commentedon Feb 6, 2023
Playing with your draft PR branch and testing things out... the performance of the Linux kernel crypto API for hash algorithms is several times slower on a modern AMD Zen, regardless of data size.
I realize it probably gets a tad better in limited situations where sendfile or splice can used, but it doesn't seem like a useful API on modern mainstream hardware. It could still make sense on low performance things that have non-userspace accelerator hardware. But this doesn't leave much motivation to implement code using it.
This one sounds like it could be a bit faster https://github.com/cryptodev-linux/cryptodev-linux (and is what would be needed for this on FreeBSD and OpenBSD), but is not in mainline in Linux.
arhadthedev commentedon Feb 6, 2023
Probably, this should be added into the documentation if this issue gets rejected. Otherwise, there will be another attempts to introduce CryptoAPI, and one of them can even accidentally slip through.
gpshead commentedon May 20, 2023
I'm not worried about that. This issue existing in our issue tracker is sufficient documentation.