Security Advisories (2)
CVE-2025-15444 (2026-01-06)

Crypt::Sodium::XS module versions prior to 0.000042, for Perl, include a vulnerable version of libsodium libsodium <= 1.0.20 or a version of libsodium released before December 30, 2025 contains a vulnerability documented as CVE-2025-69277  https://www.cve.org/CVERecord?id=CVE-2025-69277 . The libsodium vulnerability states: In atypical use cases involving certain custom cryptography or untrusted data to crypto_core_ed25519_is_valid_point, mishandles checks for whether an elliptic curve point is valid because it sometimes allows points that aren't in the main cryptographic group. 0.000042 includes a version of libsodium updated to 1.0.20-stable, released January 3, 2026, which includes a fix for the vulnerability.

CVE-2026-30910 (2026-03-08)

Crypt::Sodium::XS versions through 0.001000 for Perl has potential integer overflows. Combined aead encryption, combined signature creation, and bin2hex functions do not check that output size will be less than SIZE_MAX, which could lead to integer wraparound causing an undersized output buffer. This can cause a crash in bin2hex and encryption algorithms other than aes256gcm. For aes256gcm encryption and signatures, an undersized buffer could lead to buffer overflow. Encountering this issue is unlikely as the message length would need to be very large. For bin2hex the input size would have to be > SIZE_MAX / 2 For aegis encryption the input size would need to be > SIZE_MAX - 32U For other encryption the input size would need to be > SIZE_MAX - 16U For signatures the input size would need to be > SIZE_MAX - 64U

NAME

Crypt::Sodium::XS::hash - SHA2 cryptographic hashing

SYNOPSIS

use Crypt::Sodium::XS::hash ":default";

my $hash = hash("arbitrary input data");

my $multipart = hash_init();
$multipart->update("arbitrary");
$multipart->update("input", " data");
$hash = $multipart->final;

DESCRIPTION

The SHA-256 and SHA-512 functions are provided for interoperability with other applications. If you are looking for a generic hash function and not specifically SHA-2, using Crypt::Sodium::XS::generichash (BLAKE2b) might be a better choice.

These functions are also not suitable for hashing passwords or deriving keys from passwords. Use Crypt::Sodium::XS::pwhash instead.

These functions are not keyed and are thus deterministic. In addition, the untruncated versions are vulnerable to length extension attacks.

A message can be hashed in a single pass, but a multi-part API is also available to process a message as a sequence of multiple chunks.

FUNCTIONS

Nothing is exported by default. A :default tag imports the functions and constants as documented below. A separate import tag is provided for each of the primitives listed in "PRIMITIVES". For example, :sha256 imports hash_sha256_init. You should use at least one import tag.

hash

my $hash = hash($message);

MULTI-PART INTERFACE

hash_init

my $multipart = hash_init();

Returns a multipart hashing object. See "MULTI-PART INTERFACE".

CONTSANTS

hash_PRIMITIVE

my $default_primitive = hash_PRIMITIVE();

hash_BYTES

my $hash_length = hash_BYTES();

MULTI-PART INTERFACE

A multipart hashing object is created by calling the "hash_init" function. Data to be hashed is added by calling the "update" method of that object as many times as desired. An output hash is generated by calling its "final" method. Do not use the object after calling "final".

The multipart hashing object is an opaque object which provides the following methods:

clone

my $multipart_copy = $multipart->clone;

Returns a cloned copy of the multipart hashing object, duplicating its internal state.

final

my $hash = $multipart->final;

Retruns the final hash for all data added with "update".

Once final has been called, the hashing object must not be used further.

update

$multipart->update($message);
$multipart->update(@messages);

Adds all given arguments (stringified) to hashed data.

PRIMITIVES

All constants (except _PRIMITIVE) and functions have hash_<primitive>-prefixed couterparts (e.g., hash_sha256, hash_sha512_BYTES).

  • sha256

  • sha512

SEE ALSO

Crypt::Sodium::XS
Crypt::Sodium::XS::OO::hash
https://doc.libsodium.org/advanced/sha-2_hash_function

FEEDBACK

For reporting bugs, giving feedback, submitting patches, etc. please use the following:

  • IRC channel #sodium on irc.perl.org.

  • Email the author directly.

AUTHOR

Brad Barden <perlmodules@5c30.org>

COPYRIGHT & LICENSE

Copyright (c) 2022 Brad Barden. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.