hashsize#

Return the digest length of a Digest::SHA object in bits.

For a given algorithm the hashsize is a constant: 160 for SHA-1, 224 for SHA-224, 256 for SHA-256 and SHA-512/256, 384 for SHA-384, 512 for SHA-512. Divide by 8 to get the byte length of the output from digest.

Synopsis#

my $bits = $sha->hashsize;

What you get back#

An integer, always a multiple of 8.

Examples#

my $sha = Digest::SHA->new(256);
print $sha->hashsize;         # 256
print $sha->hashsize / 8;     # 32  (bytes per digest)
my $sha = Digest::SHA->new("SHA-512/224");
print $sha->hashsize;         # 224
## Preallocate output buffer for $sha->digest:

my $buf = "\0" x ($sha->hashsize / 8);

Edge cases#

  • Called on a non-Digest::SHA object, returns undef.

Differences from upstream#

Fully compatible with upstream Digest::SHA 6.04.

See also#

  • algorithm — the integer algorithm code for this object.

  • digest — output whose length is hashsize / 8 bytes.