NAME

Crypt::RIPEMD160::MAC - Perl extension for RIPEMD-160 MAC function

SYNOPSIS

use Crypt::RIPEMD160::MAC;

$key = "This is the secret key";

$mac = Crypt::RIPEMD160::MAC->new($key);

$mac->reset();

$mac->add(LIST);
$mac->addfile(HANDLE);

$digest = $mac->mac();
$string = $mac->hexmac();

DESCRIPTION

The Crypt::RIPEMD160::MAC module implements HMAC-RIPEMD-160 message authentication codes as described in RFC 2104. It uses Crypt::RIPEMD160 as the underlying hash function.

METHODS

new

my $mac = Crypt::RIPEMD160::MAC->new($key);

Creates and returns a new HMAC-RIPEMD-160 context keyed with $key. Keys longer than 64 bytes are hashed with RIPEMD-160 before use, as specified by RFC 2104.

reset

$mac->reset();

Reinitializes the context for a new computation while retaining the original key. Must be called after mac or hexmac before reusing the same context.

add

$mac->add(LIST);

Appends the strings in LIST to the message. Multiple calls are equivalent to a single call with the concatenation of all arguments.

addfile

$mac->addfile(HANDLE);

Reads from the open file-handle in 8192 byte blocks and adds the contents to the context. The handle can be a lexical filehandle, a type-glob reference, or a bare name.

mac

my $digest = $mac->mac();

Returns the final MAC value as a 20-byte binary string. This is a destructive, read-once operation: call reset before computing another MAC with the same key.

hexmac

my $string = $mac->hexmac();

Like mac, but returns the result as a printable string of hexadecimal digits in five space-separated groups of eight characters.

EXAMPLES

use Crypt::RIPEMD160::MAC;

$mac = Crypt::RIPEMD160::MAC->new("secret key");
$mac->add("some data");
$digest = $mac->mac();

print("MAC is " . unpack("H*", $digest) . "\n");

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl you may have available.

See https://dev.perl.org/licenses/ for more information.

AUTHOR

The RIPEMD-160 interface was written by Christian H. Geuer (christian.geuer@crypto.gun.de).

SEE ALSO

Crypt::RIPEMD160