The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Digest::Haval256 - A 5-round, 256-bit one-way hash function

ABSTRACT

Haval is a variable-length, variable-round one-way hash function.

SYNOPSIS

use Digest::Haval256;

$haval = new Digest::Haval256;
$haval->add(LIST);
$haval->addfile(*HANDLE);
$haval->reset();

$digest = $haval->digest();
$digest = $haval->hexdigest();
$digest = $haval->base64digest();

$digest = $haval->hashsize();
$digest = $haval->rounds();

DESCRIPTION

Haval is a variable-length, variable-round one-way hash function designed by Yuliang Zheng, Josef Pieprzyk, and Jennifer Seberry. The number of rounds can be 3, 4, or 5, while the hash length can be 128, 160, 192, 224, or 256 bits. Thus, there are a total of 15 different outputs. For better security, however, this module implements the 5-round, 256-bit output.

Functions

hashsize()

Returns the size (in bits) of the hash (256, in this case)

rounds()

Returns the number of rounds used (5, in this case)

add(LIST)

Hashes a string or a list of strings

addfile(*HANDLE)

Hashes a file

reset()

Re-initializes the hash state. Before calculating another digest, the hash state must be refreshed.

digest()

Generates the hash output (a 32-byte binary string)

hexdigest()

Generates a hexadecimal representation of the hash output

base64digest()

Generates a base64 representation of the hash output. MIME::Base64 must be installed first for this function to work.

EXAMPLE 1

#!/usr/local/bin/perl

use diagnostics;
use strict;
use warnings;
use Digest::Haval256;

my $string1 = "This is a string.";
my $string2 = "This is another string.";
my $string3 = "This is a string.This is another string.";

my $haval = new Digest::Haval256;
print "hash size=", $haval->hashsize, "\n";
print "number of rounds=", $haval->rounds, "\n\n";

$haval->add($string1);
my $digest = $haval->hexdigest();
print "Hash string1 only\n";
print "$digest\n\n";

$haval->reset();
$haval->add($string1, $string2);
my $digest2 = $haval->hexdigest();
print "Hash string1 and then hash string2\n";
print "$digest2\n\n";

$haval->reset();
$haval->add($string3);
print "Hash the two concatenated strings\n";
my $digest3 = $haval->hexdigest();
print "$digest3\n";

EXAMPLE 2

#!/usr/local/bin/perl

use diagnostics;
use strict;
use warnings;
use MIME::Base64;
use Digest::Haval256;

my $file = "strings.pl";
open INFILE, $file or die "$file not found";

my $haval = new Digest::Haval256;
$haval->addfile(*INFILE);
my $hex_output = $haval->hexdigest();
my $base64_output = $haval->base64digest();
close INFILE;
print "$file\n";
print "$hex_output\n";
print "$base64_output\n";

MORE EXAMPLES

See the "examples" and "t" directories for more examples.

COPYRIGHT AND LICENSE

Copyright 2003 by Julius C. Duque <jcduque (AT) lycos (DOT) com>

This library is free software; you can redistribute it and/or modify it under the same terms as the GNU General Public License.