instance method
OpenSSL::Cipher#auth_data=
(::String) -> ::String
cipher.auth_data = string
ext/openssl/ossl_cipher.c
View on GitHub ↗
static VALUE
ossl_cipher_set_auth_data(VALUE self, VALUE data)
{
EVP_CIPHER_CTX *ctx;
unsigned char *in;
long in_len, out_len;
StringValue(data);
in = (unsigned char *) RSTRING_PTR(data);
in_len = RSTRING_LEN(data);
GetCipher(self, ctx);
if (!(EVP_CIPHER_flags(EVP_CIPHER_CTX_cipher(ctx)) & EVP_CIPH_FLAG_AEAD_CIPHER))
ossl_raise(eCipherError, "AEAD not supported by this cipher");
if (!ossl_cipher_update_long(ctx, NULL, &out_len, in, in_len))
ossl_raise(eCipherError, "couldn't set additional authenticated data");
return data;
}
Sets additional authenticated data (AAD), also called associated data, for this Cipher. This method is available for AEAD ciphers.
The contents of this field should be non-sensitive data which will be added to the ciphertext to generate the authentication tag which validates the contents of the ciphertext.
This method must be called after key= and iv= have been set, but before starting actual encryption or decryption with update. In some cipher modes, auth_tag_len= and ccm_data_len= may also need to be called before this method.
See also the “AEAD Interface” section of the man page EVP_EncryptInit(3). This method internally calls EVP_CipherUpdate() with the output buffer set to NULL.