note 126145 added to function.sodium-crypto-aead-aes256gcm-is-available
| From: | SoatokDreamseeker at main dot php dot net | Date: | Mon, 07 Jun 2021 08:12:45 +0000 |
| Subject: | note 126145 added to function.sodium-crypto-aead-aes256gcm-is-available | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-216482@lists.php.net to get a copy of this message | ||
The reason libsodium has an "is_available()" API for AES-GCM and not the ChaCha-Poly AEAD
ciphers is that, unlike OpenSSL, libsodium will not expose AES-GCM unless your processor supports
hardware-accelerated AES and PCLMULQDQ instructions.
If you're wondering what that means: software AES is vulnerable to cache-timing
vulnerabilities, due to its internal dependence on table look-ups: https://cr.yp.to/antiforgery/cachetiming-20050414.pdf
(PDF)
There's a similar attack on the authentication step in GCM (called GMAC or GHASH, depending on
context), which leaks the GHASH key (called H) and can be used to perform chosen-ciphertext attacks
freely.
- You can learn more about GCM exploits here (under the condition of nonce reuse rather than timing
leaks, but the consequence is the same): https://www.youtube.com/watch?v=uxuXFK5XKEU
- You can learn more about AES-GCM here: https://soatok.blog/2020/05/13/why-aes-gcm-sucks/
- You can learn more about how it compares to other encryption modes here: https://soatok.blog/2020/07/12/comparison-of-symmetric-encryption-methods/
The other AEAD modes are safe to implement in software without risk of side-channel leakage.
The take-away is: AES-GCM isn't guaranteed to be available on all hardware because, without
hardware support, libsodium will not provide insecure implementations.
If you want something guaranteed to be available even on hardware you do not control (hello open
source maintainers), your choices are ChaCha20-Poly1305 and XChaCha20-Poly1305.
If you can control the hardware and explicitly need AES-GCM (n.b. for FIPS 140-2 validation), feel
free to use AES-256-GCM.
<?php
function do_something(string $message, CryptoKeyObject $key): string {
if (!sodium_crypto_aead_aes256gcm_is_available()) {
throw new Exception("AES-256-GCM isn't available on your hardware");
}
// ... your code here ...
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.242 (proxied: 2603:3017:300:2e00:7c1f:9ec8:979c:6f00)
----
Manual Page -- https://php.net/manual/en/function.sodium-crypto-aead-aes256gcm-is-available.php
Edit -- https://main.php.net/note/edit/126145
Del: integrated -- https://main.php.net/note/delete/126145/integrated
Del: useless -- https://main.php.net/note/delete/126145/useless
Del: bad code -- https://main.php.net/note/delete/126145/bad+code
Del: spam -- https://main.php.net/note/delete/126145/spam
Del: non-english -- https://main.php.net/note/delete/126145/non-english
Del: in docs -- https://main.php.net/note/delete/126145/in+docs
Del: other reasons-- https://main.php.net/note/delete/126145
Reject -- https://main.php.net/note/reject/126145
Search -- https://main.php.net/manage/user-notes.php