GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
EMAC(3) User Contributed Perl Documentation EMAC(3)

Digest::EMAC

    use Digest::EMAC qw(emac hexdigest base64digest);

    print "Enter key: ";
    my $key = <STDIN>;
    chomp $key;

    print "Enter cipher: ";
    my $cipher = <STDIN>;
    chomp $cipher;

    print "Enter string: ";
    my $str = <STDIN>;
    chomp $str;

    my $mac = emac($key, $cipher, $str);
    print hexdigest($mac), "\n";
    print base64digest($mac), "\n";

    use Digest::EMAC qw(emac hexdigest base64digest);

    print "Enter key: ";
    my $key = <STDIN>;
    chomp $key;

    print "Enter cipher: ";
    my $cipher = <STDIN>;
    chomp $cipher;

    print "Enter file: ";
    my $infile = <STDIN>;
    chomp $infile;
    local $/ = undef;
    open F, $infile;
    my $data = <F>;

    my $mac = emac($key, $cipher, $data);
    close F;
    print hexdigest($mac), "\n";
    print base64digest($mac), "\n";

    use Digest::EMAC qw(emac hexdigest base64digest);

    print "Enter key: ";
    my $key = <STDIN>;
    chomp $key;

    print "Enter cipher: ";
    my $cipher = <STDIN>;
    chomp $cipher;
    local $/ = undef;

    while (<>) {
        my $mac = emac($key, $cipher, $_);
        print hexdigest($mac), "\n";
    }

This is Encrypted MAC (EMAC), also known as Double MAC (DMAC). Unlike HMAC, which reuses an existing one-way hash function, such as MD5, SHA-1 or RIPEMD-160, EMAC reuses an existing block cipher to produce a secure message authentication code (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 more 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 EMAC are reasonable. EMAC is preferable for short messages because the block length is smaller compared to the schemes based on a hash function. EMAC 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.

The module Crypt::CBC is required, plus any block cipher that is capable of returning its block size when queried. RC5 is not supported, however, because its block size is variable.

MIME::Base64 is also required for base64 encoding of output.

This program is free software; you can redistribute it or modify it under the terms of the GNU General Public License.

Julius C. Duque <jcduque (AT) lycos (DOT) com>
2004-07-03 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.