NAME

Digest::DMAC 1.0

EXAMPLE 1

use Crypt::CBC;

use Digest::DMAC qw(dmac hexdigest base64digest);

my $key = "jcd";

my $cipher = "Serpent";

my $data = "This is a test";

my $mac = &dmac($key, $cipher, $data);

print hexdigest($mac), "\n";

print base64digest($mac), "\n";

EXAMPLE 2

use Crypt::CBC;

use Digest::DMAC qw(dmac hexdigest base64digest);

local $/ = undef; # slurp whole file

$infile = "../DMAC.pm";

open F, $infile;

while (<F>) {

$mac1 = &dmac($key, $cipher, $_);

$hexmac1 = hexdigest($mac1);

$base64mac1 = base64digest($mac1);
}

DESCRIPTION

This is Double MAC (DMAC), also known as Encrypted MAC (EMAC). Unlike HMAC, which reuses an existing one-way hash function, such as MD5, SHA-1 or RIPEMD-160, DMAC reuses an existing block cipher to produce a secure MAC. Using the block cipher, a message is encrypted in CBC mode. The last block is taken as the MAC of the message. For fixed-length messages, this method is provably secure. In reality, however, messages have arbitrary lengths, and this method is not secure. To make secure MACs for variable length messages, the last block is encrypted once again with a different key. The security of this construction has been proved in the paper, ``CBC MAC for Real-Time Data Sources'' by Erez Petrank and Charles Rackoff. The security can be proved on the assumption that the underlying block cipher is pseudo-random. The performance and key-agility of DMAC are reasonable. DMAC is preferable for short messages because the block length is smaller compared to the schemes based on a hash function. DMAC is also chosen as one of the NESSIE winners for Message Authentication Codes, along with UMAC, TTMAC and HMAC. The current NESSIE specification chooses the AES as block cipher.

Also specified in the paper by Petrank and Rackoff is the construction of two encryption keys from a single key. The first subkey is derived by encrypting "0" (zero) using the original secret key. To produce the second subkey, a "1" (one) is encrypted using the original secret key. The first subkey is used in CBC mode to encrypt the entire message. The last ciphertext block is then re-encrypted with the second subkey. The result is a MAC whose length is equal to the block length of the cipher used.

PREREQUISITES

The module Crypt::CBC is required, plus any block cipher that is capable of returning its block size when queried. RC5 is not supported because its block size is variable. Supported block ciphers are DES, Blowfish, IDEA, TEA (64-bit blocks), Serpent, Rijndael (AES), Twofish, RC6 (128-bit blocks), and many others.

AUTHOR

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