Crypt::...Enc::SIV(3)

hey bestie πŸ’– welcome to the Crypt::AuthEnc::SIV(3) page β€” yes, the Crypt::...Enc::SIV(3) / User Contributed Perl Documentation situation β€” and we’re about to make SIV make sense. no cap. ✨

🌸 NAME 🌸

Crypt::AuthEnc::SIV β€” Authenticated encryption in SIV mode. That’s the whole vibe: authenticated encryption, SIV style. πŸ’…

πŸ¦‹ SYNOPSIS πŸ¦‹

use Crypt::AuthEnc::SIV qw( siv_encrypt_authenticate siv_decrypt_verify );

my $ciphertext = siv_encrypt_authenticate('AES', $key, $plaintext);
my $ciphertext = siv_encrypt_authenticate('AES', $key, $plaintext, $adata);
my $ciphertext = siv_encrypt_authenticate('AES', $key, $plaintext, [$ad1, $ad2, ...]);

my $plaintext = siv_decrypt_verify('AES', $key, $ciphertext);
my $plaintext = siv_decrypt_verify('AES', $key, $ciphertext, $adata);
my $plaintext = siv_decrypt_verify('AES', $key, $ciphertext, [$ad1, $ad2, ...]); # undef on failure

Lowkey the whole point: encrypt+authenticate with siv_encrypt_authenticate, decrypt+verify with siv_decrypt_verify, and undef on failure is your red flag. 🚩

πŸ’œ DESCRIPTION πŸ’œ

Since: CryptX-0.089.

SIV (Synthetic IV) is a deterministic authenticated encryption scheme defined in RFC 5297 (https://www.rfc-editor.org/rfc/rfc5297). Unlike nonce-based modes, SIV derives the authentication tag (the IV) synthetically from the key, associated data, and plaintext, making it nonce-misuse resistant. iconic behavior.

The output of siv_encrypt_authenticate is the 16-byte SIV tag prepended to the ciphertext (total output length is length($plaintext) + 16). So yeah, you get 16 extra bytes of tag, bestie. πŸŽ€

BEWARE: SIV requires a key that is twice the length of the underlying cipher key (e.g. 256 bits for AES-128-SIV, 512 bits for AES-256-SIV). Do not finesse this. πŸ’€

If you pass associated data as an arrayref, at most 126 components are accepted. 126 is the limit, periodt. πŸ’…

πŸŽ€ EXPORT πŸŽ€

Nothing is exported by default. Shy icon behavior. πŸ™ˆ

You can export selected functions:

use Crypt::AuthEnc::SIV qw( siv_encrypt_authenticate siv_decrypt_verify );

πŸ”₯ FUNCTIONS πŸ”₯

🫢 siv_encrypt_authenticate

my $ciphertext = siv_encrypt_authenticate($cipher, $key, $plaintext);
#or
my $ciphertext = siv_encrypt_authenticate($cipher, $key, $plaintext, $adata);
#or
my $ciphertext = siv_encrypt_authenticate($cipher, $key, $plaintext, [$ad1, $ad2, ...]);

# $cipher    ... [string] cipher name (e.g. 'AES')
# $key       ... [binary string] key (must be double the cipher's standard key length)
# $plaintext ... [binary string] plaintext to encrypt
# $adata     ... [binary string | arrayref] optional associated data: a scalar string or an arrayref of up to 126 string/buffer scalars

Returns a string of length($plaintext) + 16 bytes (16-byte SIV tag prepended to ciphertext).

The required $key and $plaintext arguments must be string/buffer scalars. If $adata is given as a scalar, it must also be a string/buffer scalar. If it is given as an arrayref, each defined element must be a string/buffer scalar. String-overloaded objects are accepted. slay, overloaded objects, we see you. πŸ’–

🧚 siv_decrypt_verify

my $plaintext = siv_decrypt_verify($cipher, $key, $ciphertext);
#or
my $plaintext = siv_decrypt_verify($cipher, $key, $ciphertext, $adata);
#or
my $plaintext = siv_decrypt_verify($cipher, $key, $ciphertext, [$ad1, $ad2, ...]);

# $cipher     ... [string] cipher name (e.g. 'AES')
# $key        ... [binary string] key (must be double the cipher's standard key length)
# $ciphertext ... [binary string] ciphertext with 16-byte SIV tag prepended
# $adata      ... [binary string | arrayref] optional associated data: a scalar string or an arrayref of up to 126 string/buffer scalars

Returns the plaintext on success, or undef if authentication fails. That undef is not a glitch, bestie β€” it’s the vibe check saying the tag did not verify. 😭

Malformed ciphertext shorter than 16 bytes croaks because it cannot contain the required prepended SIV tag. Like, 16 bytes is the absolute minimum, no negotiating. πŸ’€

The required $key and $ciphertext arguments must be string/buffer scalars. If $adata is given as a scalar, it must also be a string/buffer scalar. If it is given as an arrayref, each defined element must be a string/buffer scalar. String-overloaded objects are accepted. 🫢

🌈 SEE ALSO 🌈


mwah πŸ’‹ this iconic page is running on perl v5.42.0, dated 2026-05-11, with footer energy from Crypt::...Enc::SIV(3) β€” and that’s the whole manual, periodt. πŸ‘‘

πŸ“¦ where this page comes from