What is FileDigest?
FileDigest
is a cryptographic product useful for generating digital signatures for files or typed text (strings) applying one of the following message-digesting methods: MD5
, RIPEMD128
, RIPEMD160
, SHA-1
(SHA160
), SHA-2
(SHA256, SHA384 and SHA512
).
Short Presentation of the Algorithms
MD5
is part of the family of message-digest algorithms MD2
, MD4
and MD5
developed by R. Rivest
in collaboration with MIT Laboratory for Computer Science
and RSA Data Security, Inc
. The MD5
algorithm is an extension of the MD4
message-digest algorithm, slightly slower than MD4
, but on the other side more secure. All three algorithms take a message of arbitrary length and produce a 128-bit message digest.
RIPEMD128
and RIPEMD160
are upgrades to MD4
, MD5
, and RIPEMD
methods. RIPEMD
was developed in the framework of the EU
project RIPE
(RACE Integrity Primitives Evaluation, 1988-1992
). 128-bit hash results are considered to not offer anymore sufficient protection, and applications using 128-bit hash functions should consider upgrading to 160-bit hash functions. RIPEMD160
is a 160-bit cryptographic hash function, designed by Hans Dobbertin
, Antoon Bosselaers
, and Bart Preneel
. It is intended to be used as a secure replacement for the 128-bit hash functions MD4
, MD5
, and RIPEMD
.
The Secure Hash Algorithm
(SHA
) algorithm specified in the Secure Hash Standard
(SHS
), was developed by NIST
and published as a federal information processing standard (FIPS PUB 180
). SHA-1
was a revision to SHA
that was published in 1994. The revision corrected an unpublished flaw in SHA
. Its design is very similar to the MD4
family of hash functions developed by R. Rivest
. The SHA-1
algorithm takes a message of any length and produces a 160-bit message digest. The algorithm is slightly slower than MD5
, but the larger message digest makes it more secure against brute-force collision and inversion attacks. Motivated by the recent AES
selection, NIST
proposed replacements of the SHA-1
hash algorithm with the SHA-256
, SHA-384
, and SHA-512
, together known as SHA-2
, algorithms considered to provide a level of collision resistance equivalent to the security of each AES
key sizes. The message digest length for SHA-1
is 160 bits (20 bytes). The message digest lengths for the new SHA-256
, SHA-384
, and SHA-512
are respectively 256 bits (32 bytes), 384 bits (48 bytes), 512 bits (64 bytes). The increase in size is significant, making difficult to break the new algorithms.
The table bellow is summarizing the key features of the FileDigest
's implemented message-digest algorithms:
Method | Digest Length (bytes) | Security |
MD5 | 16 | Moderate |
RIPEMD128 | 16 | Moderate |
RIPEMD160 | 20 | High |
SHA-1 | 20 | High |
SHA256 | 32 | Very High |
SHA384 | 48 | Very High |
SHA512 | 64 | Very High |
All the algorithms are implemented using a common interface, IMessageDigest
, which is partially presented bellow:
class IMessageDigest
{
public:
IMessageDigest();
virtual ~IMessageDigest();
virtual void AddData(char const* pcData, int iDataLength) = 0;
virtual void FinalDigest(char* pcDigest) = 0;
virtual void Reset() = 0;
void DigestFile(string const& rostrFileIn, char* pcDigest);
protected:
virtual void Transform() = 0;
};
Notice that all the classes implementing the IMessageDigest
interface have to overdide the pure virtual member functions: AddData()
, FinalDigest()
, Reset()
and DigestFile()
, while the function DigestFile()
is general and already implemented.
The function Reset()
is used to prepare the same object for a new message-digesting operation.
The function AddData()
is adding a new buffer of data to the current message-digesting operation.
The function FinalDigest()
is concluding any current message-digesting operation.
The function DigestFile()
is used for digesting an entire file.
If you want to use the implemented algorithms in your own project, you need to copy the following files from the FileDigest
project, and integrate them in your project: MessageDigest.h
, MessageDigest.cpp
, MD5.h
, MD5.cpp
, RIPEMD.h
, RIPEMD.cpp
, SHA.h
, SHA.cpp
, DoubleBuffering.h
and DoubleBuffering.cpp
. The use is easy, as is demonstrated by the following code snippet:
char acDigest[33];
CSHA oSHA(CSHA::SHA256);
oSHA.AddData("string1", 7);
oSHA.AddData("string2", 7);
oSHA.AddData("string3", 7);
oSHA.FinalDigest(acDigest);
Notice that the result is a binary array of characters, so it cannot be manipulated as usual 0 terminated strings of characters.
Using the FileDigest program
A Help
menu of the FileDigest
program is not implemented right now. The information given in the following paragraphs can be considered as a small User Manual
.
There are two modes of operations of FileDigest
selectable from the Mode Group
: String Mode
and File Mode
.
How to use FileDigest in String Mode
The message-digest method can be selected from the Method Group Combo Box
one of the values: MD5
, RIPEMD128
, RIPEMD160
, SHA-1
(SHA160
), SHA-2
(SHA256, SHA384, SHA512
).
The text (string) can to be introduced in one of the Edit Boxes
in the String Group
, depending on the selected mode: Alpha
or Hex
. In the Hex Edit Box
only hexadecimal characters (0-9,A-F) can be introduced, if you try to type any other characters an error signaling beep will be generated. Also if you try to copy a text from the Clipboard
it will be first verified if is in hexa format (restricted to the set of hexa characters and even in length). These restrictions apply to all the other Hex Edit Boxes
used in FileCrypt
.
After pressing the String Digest Button
the result will be displayed in the Digest Result (string) Edit Box
as a string of characters and in the Digest Result (hexadecimal) Edit Box
as a hexadecimal format string.
How to use FileDigest in File mode
The message-digest method is selected similarly as in the String Mode
.
The File
can be typed in the File Edit Box
, or browsed from the browsing button located near the File Edit Box
. By pressing the File Digest
button the result will be displayed in Digest Result (string) Edit Box
as a string of characters and in Digest Result (hexadecimal) Edit Box
as a string in hexadecimal format. The result can be saved in a file (default extension .fdg
) from the Save As... Button
.
When you need to check a digital signature against a file, you can load the digital signature from a digest file using the Load... Button
, and then check against the file selected in the File Edit Box
using the Check Button
.
Conclusion
The project FileDigest.zip
attached to this article is including the source code of the presented message-digest algorithms and FileDigest
program. I am interested in any opinions and new ideas about this implementation.
Typical Disclaimer: This Article and attached code are Copyright (C) 2003 by George Anescu. You have the right to use and distribute the article's content and code in any way you see fit as long as this paragraph is included with the distribution. No warranties or claims are made as to the validity of the information and code contained herein, so use it at your own risk.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.