11.1.1 Hashing Algorithms and Perl’s Hashing Packages

11.1.1  Hashing Algorithms and Perl’s Hashing Packages

     

There are several hashing algorithms that are widely used. Among them are the following.

    MD5,

    MD4,

    MD2,

    SHA-1,

  RIPEMD-160, and

    Tiger.

Although they are very different algorithms, using them is very easy. Perl provides us with modules for each one of the hash algorithms given above. They work more or less the same way at the programmer level. Actually, the hash algorithms are implemented mostly in C. The Perl modules provide a friendly and consistent interface to the algorithms.

The Digest:: modules provide implementation of several algorithms for creating hashes of data. The Digest:: modules corresponding to the hash algorithms MD2, MD4, MD5, SHA-1, and Tiger, are called Digest::MD2, Digest::MD4, Digest::MD5, Digest::SHA1 and Digest::Tiger respectively.

RIPEMD-160 is implemented in the module Crypt::RIPEMD160. We will talk about the Digest modules now and discuss

Crypt::RIPEMD160 later. All Digest modules have the same programming interface. Each one provides a function-based interface for simple use. The functional interface is called on a string. Each one also has an object-oriented interface. The object-oriented interface is used with strings or with files directly. The digest can be produced in three formats shown below.

    Binary: The binary digest is the most compact one. However, it cannot be printed easily. Also, it cannot be used in places where binary data cannot be used.

  Hexadecimal: It produces a string of lowercase hexadecimal digits. It is twice as long as the binary digest produced.

    Base 64: The Base 64 digest is a sequence of printable characters. It is based on the Base 64 representation. Base 64 representation is used primarily for Internet mail using the MIME (Multipurpose Internet Mail Extensions) standard.

In the example programs that follow, we primarily use binary digests.

Next, we will start with the description of the Digest::MD5 module. All of the rest are similar and will be discussed briefly.