instance method
OpenSSL::Cipher#auth_tag_len=
(::Integer) -> ::Integer
cipher.auth_tag_len = integer
ext/openssl/ossl_cipher.c
View on GitHub ↗
static VALUE
ossl_cipher_set_auth_tag_len(VALUE self, VALUE vlen)
{
int tag_len = NUM2INT(vlen);
EVP_CIPHER_CTX *ctx;
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 (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, tag_len, NULL))
ossl_raise(eCipherError, "unable to set authentication tag length");
/* for #auth_tag */
rb_ivar_set(self, id_auth_tag_len, INT2NUM(tag_len));
return vlen;
}
Sets the length of the expected authentication tag for this Cipher. This method is available for some of AEAD ciphers that require the length to be set before starting encryption or decryption, such as CCM mode or OCB mode.
For CCM mode and OCB mode, the tag length must be set before iv= is set.
See also the “AEAD Interface” section of the man page EVP_EncryptInit(3). This method internally calls EVP_CIPHER_CTX_ctrl() with EVP_CTRL_AEAD_SET_TAG and a NULL buffer.