Content · Web Development · PHP

PHP sodium_crypto_aead_aes256gcm_is_available() Function: Usage and Examples

sodium_crypto_aead_aes256gcm_is_available checks whether this CPU and library support hardware-accelerated.

1 views Published Oct 17, 2026 Updated Oct 17, 2026 admin

sodium_crypto_aead_aes256gcm_is_available checks whether this CPU and library support hardware-accelerated AES-256-GCM.

The examples explain the data format, expected results and the difference between this API and nearby cryptographic operations.

What It Does


The operation is intended for: sodium_crypto_aead_aes256gcm_is_available checks whether this CPU and library support hardware-accelerated AES-256-GCM.

The sodium extension must be enabled.

Syntax and Return Value


sodium_crypto_aead_aes256gcm_is_available(): bool

This API accepts no required parameters, or its signature must be checked on the target runtime.

The declared return type is shown above. Errors can include false results or exceptions depending on this API: Never reuse a nonce with the same key; additional authenticated data is checked but not encrypted. Modified ciphertext fails authentication.

Example 1: Basic Operation


Check the required key length or CPU support without exposing generated key bytes.

<?php
var_dump(sodium_crypto_aead_aes256gcm_is_available());

Example 2: A Different Use Case


Branch on the runtime hardware capability before choosing AES-GCM.

<?php
if (sodium_crypto_aead_aes256gcm_is_available()) {
    echo 'Use hardware-accelerated AEAD when supported';
} else { echo 'Select XChaCha20-Poly1305 instead'; }

Practical Example: Checking the Result


Branch on the runtime hardware capability before choosing AES-GCM.

<?php
$available = sodium_crypto_aead_aes256gcm_is_available();
var_dump(is_bool($available));

Important Behavior and Edge Cases


Never reuse a nonce with the same key; additional authenticated data is checked but not encrypted. Modified ciphertext fails authentication.

Changing even one ciphertext, nonce or associated-data byte should cause authentication to fail. Store or transmit the nonce alongside ciphertext without reusing it for this key.

Comparison with Related Functions


ApproachKey distinction
sodium_crypto_aead_aes256gcm_is_availablesodium_crypto_aead_aes256gcm_is_available checks whether this CPU and library support hardware-accelerated AES-256-GCM.
Related techniquesecretbox authenticates ciphertext but does not accept additional authenticated data.

Common Beginner Mistakes


MistakeCorrect approach
Confusing this operation with a neighboring cryptographic or security mechanismsecretbox authenticates ciphertext but does not accept additional authenticated data.
Ignoring a security prerequisite or failure caseNever reuse a nonce with the same key; additional authenticated data is checked but not encrypted. Modified ciphertext fails authentication.

Key Takeaways


  • sodium_crypto_aead_aes256gcm_is_available checks whether this CPU and library support hardware-accelerated AES-256-GCM.
  • Never reuse a nonce with the same key; additional authenticated data is checked but not encrypted. Modified ciphertext fails authentication.
  • secretbox authenticates ciphertext but does not accept additional authenticated data.

Apply this behavior to a real application only after confirming the required extension, configuration and failure handling on the deployment runtime.

Share this resourceSend this page to someone who may find it useful.