gnutls_aead_cipher_set_key - Linux


gnutls_aead_cipher_set_key is a GnuTLS function for setting the key for an Authenticated Encryption with Associated Data (AEAD) cipher. AEAD ciphers combine encryption with authentication to provide both confidentiality and integrity.


gnutls_aead_cipher_set_key(gnutls_aead_cipher_t aead, const void *key, size_t key_size);


The following options are available:

  • aead: The gnutls_aead_cipher_t object to set the key for.
  • key: The key to set.
  • key_size: The size of the key in bytes.


The following example shows how to set the key for an AES-GCM cipher:

#include <gnutls/gnutls.h>

int main() {
  gnutls_aead_cipher_t aead;
  uint8_t key[16];

  // Initialize the AEAD cipher

  // Set the key
  gnutls_aead_cipher_set_key(&aead, key, 16);

  // Use the AEAD cipher

  // Destroy the AEAD cipher

  return 0;

Common Issues

One common issue is trying to set the key for a cipher that is not an AEAD cipher. This will result in an error.

Another common issue is trying to set a key that is too large or too small for the cipher. This will also result in an error.


gnutls_aead_cipher_set_key can be used with other GnuTLS functions to create a complete encryption and authentication system. For example, it can be used with gnutls_aead_cipher_encrypt() and gnutls_aead_cipher_decrypt() to encrypt and decrypt data.

Related Commands