instance method
OpenSSL::Cipher#auth_tag
(?::Integer tag_len) -> ::String
cipher.auth_tag(tag_len = 16) → String
ext/openssl/ossl_cipher.c
View on GitHub ↗
static VALUE
ossl_cipher_get_auth_tag(int argc, VALUE *argv, VALUE self)
{
VALUE vtag_len, ret;
EVP_CIPHER_CTX *ctx;
int tag_len = 16;
rb_scan_args(argc, argv, "01", &vtag_len);
if (NIL_P(vtag_len))
vtag_len = rb_attr_get(self, id_auth_tag_len);
if (!NIL_P(vtag_len))
tag_len = NUM2INT(vtag_len);
GetCipher(self, ctx);
if (!(EVP_CIPHER_flags(EVP_CIPHER_CTX_cipher(ctx)) & EVP_CIPH_FLAG_AEAD_CIPHER))
ossl_raise(eCipherError, "authentication tag not supported by this cipher");
ret = rb_str_new(NULL, tag_len);
if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, tag_len, RSTRING_PTR(ret)))
ossl_raise(eCipherError, "retrieving the authentication tag failed");
return ret;
}
Gets the generated authentication tag. This method is available for AEAD ciphers, and should be called after encryption has been finalized by calling final.
The returned tag will be tag_len bytes long. Some cipher modes require the desired length in advance using a separate call to auth_tag_len=, before starting encryption.
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_GET_TAG.
See also
#auth_tag=
#authenticated?
#auth_data=
#auth_tag_len=
also in
4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0