NAME
Crypt::Sodium::XS::OO::hash - SHA2 cryptographic hashing
SYNOPSIS
use Crypt::Sodium::XS;
my $xs_hash = Crypt::Sodium::XS->hash;
my $hash = $xs_hash->hash("arbitrary input data");
my $multipart = $xs_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.
CONSTRUCTOR
new
my $xs_hash = Crypt::Sodium::XS::OO::hash->new;
my $xs_hash = Crypt::Sodium::XS::OO::hash->new(primitive => 'sha256';
my $xs_hash = Crypt::Sodium::XS->hash;
Returns a new hash object for the given primitive. If not given, the default primitive is default
.
METHODS
PRIMITIVE
my $xs_hash = Crypt::Sodium::XS::OO::hash->new;
my $default_primitive = $xs_hash->PRIMITIVE;
BYTES
my $xs_hash_length = $xs_hash->BYTES;
primitives
my @primitives = $xs_hash->primitives;
Returns a list of all supported primitive names (including 'default').
hash
my $xs_hash = hash($message);
init
my $multipart = $xs_hash->init;
Returns a multipart hashing object. See "MULTI-PART INTERFACE".
MULTI-PART INTERFACE
A multipart hashing object is created by calling the "init" method. 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 $xs_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.
SEE ALSO
FEEDBACK
For reporting bugs, giving feedback, submitting patches, etc. please use the following:
RT queue at https://rt.cpan.org/Dist/Display.html?Name=Crypt-Sodium-XS
IRC channel
#sodium
onirc.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.