Click here to Skip to main content
Click here to Skip to main content

ReHash - A console-based hash calculator

By , 11 Apr 2003
 

Sample Image - rehash.jpg


Contents


Introduction

ReHash is a free, open source console-based hash calculator.

You can disable hash algorithms selectively per command-line if you don't need or like them, you can choose if you want to use recursive directory scanning or not.

This tool is ideal for webmasters who wish to provide their users hash values of their (downloadable) files. The complete hashing process can be automated by using a shell/batch script. No additional user interaction is needed (i.e. the program won't ask for anything, it's just using the command-line).

ReHash is distributed under the terms of the GNU General Public License v2.


Supported algorithms

The current version of ReHash supports the following hash algorithms:

Algorithm
Standard
Inventor
Hash Digest Size
CRC-16    
16 bits
CRC-16-CCITT    
16 bits
CRC-32 ANSI X3.66, FIPS PUB 71  
32 bits
FCS-16    
16 bits
FCS-32    
32 bits
GHash (GHash-32-3, GHash-32-5) - -
32 bits
GOST-Hash R 34.11-94  
256 bits
HAVAL (5 passes, 256 bits)   Zheng, Pieprzyk,
Seberry
256 bits
MD2 RFC 1319 Rivest
128 bits
MD4 RFC 1320 Rivest
128 bits
MD5 RFC 1321 Rivest
128 bits
SHA-1 FIPS PUB 180-1 NIST/NSA
160 bits
SHA-2 (SHA256/SHA384/SHA512)   NIST/NSA
256/384/512 bits
SizeHash-32 - -
32 bits
Tiger   Anderson, Biham
192 bits


Usage

rehash.exe [options] filespec [> outputfile]

The command-line is parsed from the left to the right. So if you execute ReHash like this:
rehash.exe -all -none *.*
it will output nothing, because you first activate all algorithms and then deactivate them all.


Some usage examples:

Hash all INI files in C:\Windows (including subdirectories) using all hash algorithms:
rehash.exe C:\Windows\*.ini

Hash all INI files in C:\Windows (excluding subdirectories) using all hash algorithms:
rehash.exe -norecur C:\Windows

Hash all BAT files on C:\ (including subdirectories) using only MD5 and SHA-1 (remember command-line is parsed from the left to the right):
rehash.exe -none -md5 -sha1 C:\*.bat

Hash all files in C:\Temp (excluding subdirectories) using only the GOST algorithm:
rehash.exe -norecur -none -gost C:\Temp\*

Hash all ZIP files in C:\homepage (including subdirectories) using only the MD5 algorithm and output the hashes to C:\homepage\downloads\hashes.txt:
rehash.exe -none -md5 C:\homepage\*.zip > C:\homepage\downloads\hashes.txt

All options:

Option
Description
-help / -h / -?/
-version / -v
Print some information about ReHash.
-fullpath / -f Output the full paths of hashed files.
-nopath Just output the filenames of hashed files, not the full paths to the files.
-rcrsv / -recur / -r Recursive scanning. Scan all files in the specified path including files in subdirectories.
-norcrsv / -norecur Disable recursive scanning. Scan only the files in the specified path not including subdirectories.
-all / -a Enable all algorithms.
-none / -n Disable all algorithms.
-crc16 / -nocrc16 Enable/disable the CRC-16 algorithm.
-crc16c / -nocrc16c Enable/disable the CRC-16-CCITT algorithm.
-crc32 / -nocrc32 Enable/disable the CRC-32 algorithm.
-fcs16 / -nofcs16 Enable/disable the FCS-16 algorithm.
-fcs32 / -nofcs32 Enable/disable the FCS-32 algorithm.
-ghash3 / -noghash3 Enable/disable the GHash-3 algorithm.
-ghash5 / -noghash5 Enable/disable the GHash-5 algorithm.
-gost / -nogost Enable/disable the GOST-Hash algorithm.
-haval / -nohaval Enable/disable the HAVAL-5-256 algorithm.
-md2 / -nomd2 Enable/disable the MD2 algorithm.
-md4 / -nomd4 Enable/disable the MD4 algorithm.
-md5 / -nomd5 Enable/disable the MD5 algorithm.
-sha1 / -nosha1 Enable/disable the SHA-1 algorithm.
-sha256 / -nosha256 Enable/disable the SHA-256 algorithm.
-sha384 / -nosha384 Enable/disable the SHA-384 algorithm.
-sha512 / -nosha512 Enable/disable the SHA-512 algorithm.
-size32 / -nosize32 Enable/disable the Size-32 algorithm (simply the byte-count of the message).
-tiger / -notiger Enable/disable the TIGER algorithm.


Thanks / acknowledgements

Thanks to (no particular order):
  • Markku-Juhani O. Saarinen - GOST-Hash implementation
  • Yuliang Zheng - HAVAL implementation
  • Wei Dai - implementations of various algorithms
  • Dr Brian Gladman - SHA-1/SHA-2 implementation
  • Tom St Denis - Tiger implementation

History

  • 12 April 2003 - v1.0
    First public release

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Dominik Reichl
Software Developer
Germany Germany
Member
Dominik started programming in Omikron Basic, a programming language for the good old Atari ST. After this, there was some short period of QBasic programming on the PC, but soon he began learning C++, which is his favorite language up to now.
 
Today, his programming experience includes C / C++ / [Visual] C++ [MFC], C#/.NET, Java, JavaScript, PHP and HTML and the basics of pure assembler.
 
He is interested in almost everything that has to do with computing, his special interests are security and data compression.
 
You can find his latest freeware, open-source projects and all articles on his homepage: http://www.dominik-reichl.de/

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionThank youmemberjuankre29 Dec '11 - 12:12 
Thank you
Generalsha1 16 bitsmemberwassimznaidi15 May '08 - 7:35 
have you tried to implement sha1 with a 16-bits processeur ?
GeneralSHA-0memberGelly Mazour24 Feb '08 - 22:57 
I know it has been broken many times over but for completness sake will you consider implementing it as well? nice article got my 5
GeneralNice work!memberWillian.BR7 Feb '08 - 4:23 
It's a very good work.
But, the option -fullpath and -nopath is incomple.
I think it's missing Sigh | :sigh: something like -relpath to
relative path.
If combined with -recur it can be used to make a hash
file to be included inside a ZIP/CAB Big Grin | :-D file to prevent
somethings.
 
But, You have done a great work here!
 
Gook luck on new projects! Laugh | :laugh:
 
Willian S. Rodrigues
willian_cpp_br@hotmail.com

QuestionThanksmembergamakanna30 Jan '07 - 23:34 
Thanks mate
It was really helpful
Can I omit the zero addition of MD5 encription?
GeneralDoesn't beat crypto++memberhaploid30 Nov '06 - 2:32 
Thank you for your efforts but everyone should check-out crypto++ for a solution they can use..
QuestionMistake in SHA-512 calculation.memberpatti ashwin17 Nov '06 - 17:37 
Hi in sha2.h you have written wrong declaration.
 
Your code is as follows;
 
/* define an unsigned 64-bit type */
 
#if defined( _MSC_VER )
typedef unsigned __int64 sha2_64t;
#define s_u64 ui64
#elif ULONG_MAX == 0xffffffffffffffff
typedef unsigned long sha2_64t;
#define s_u64 ul
#elif ULONG_MAX == 0xffffffff
typedef unsigned long long sha2_64t; /* a somewhat dangerous guess */
#define s_u64 ull
#else
#error Please define sha2_64t as an unsigned 64 bit type in sha2.h
#endif

 
Here the conditions given are in reverse order and i think u should check for ULONG_MAX == 0xffffffffffffffff for declaration of unsigned long long and not for unsigned long as you have done.
 
Also are you sure about the padding scheme you have followed?

 
Ashwin Patti
Questionwhat is the polynomial used in the CRC-16 algorithm?memberPauMs2 Oct '06 - 12:22 
what is the polynomial used in the CRC-16 algorithm?
 
PauMS
Generala small bugmemberwaldermort30 Sep '06 - 21:47 
When checking the return value of _findfile in the HashPath function, you are checking the wrong variable. _findfile always returns -1 on failure and sets errno to the error value. Here is the fix:
	if (lHandle == -1)
	{
		if(errno == EINVAL) return RH_INVALID_PATH;
		if(errno == ENOENT) return RH_NO_PATTERN_MATCH;
		return RH_CANNOT_OPEN_FILE;
	}

GeneralThank you so muchmembercalsurferpunk28 Aug '06 - 5:28 
Just wanted to say thank you very much. I was having difficulty understanding how to calculate crc16 values and this made my life much easier Smile | :)
GeneralNice workmemberHatemMostafa24 Mar '06 - 0:08 
Nice work
 
Hatem
GeneralRe: Nice workmemberElNoNo15 Aug '06 - 4:28 
Yhea this is godly =)
Generalhelp maual Crypto++sussAnonymous25 Dec '03 - 0:23 
i don't like all these manuals writen like the msdn all these stuff i don't get it only what i want is HOW TO use it
only some lines code not all functions off all classes with more classes and......
 
do someone understand what i'm trying to say in my bad english?
 
have someone these lines code for me Wink | ;-)
(or a better maual for beginners)
 
thx
Generalneed a way to be able to use this in VB 6memberwtyd66612 May '03 - 6:19 
Hi,
 
I really liked this hash calculator. I am a software developer and would appreciate it if I could be able to use this from VB 6. I am only interested in the FCS 16 and FCS 32 algorithms. The problem I am running into is that VB does not support bit shifting and because of this I have to do it manually. But that gives me incorrect CRC values some times. If anyone can point me to something that could do this in VB or be called from VB it would be nice. If anyone can figure out code anomalies that would be nice too. I am attaching my code below.
 
Thanks in advance.
 
Vishal.
 
Option Explicit
 
Public CRCArray As Variant
 
Public Function CalcCRC(DataString As String) As String
Dim DataLen As Integer
Dim CRCValue As Long
Dim CRCShiftRight As Integer
Dim X As Integer
Dim NextPieceofData As Integer
Dim CRCShiftRightStr As String
Dim ArrayPointer As Integer
'invert
Dim CRCIntStr As String
Dim CRCFinalString As String
Dim CRCletter As String
Dim TempStr As String
Dim CRCShiftRightLONG As Long
 
'invert
DataLen = Len(DataString)
'init variables
CRCShiftRight = 0
ArrayPointer = 0
' Enought potatoes
' fcs = (fcs >> 8) ^ fcstab[(fcs ^ datapiece) & 0xff];
' int CRC to 0xffff
CRCValue = &HFFFF
' Loop thru data
For X = 1 To DataLen
NextPieceofData = Asc(Mid(DataString, X, 1))
' SHIFT RIGHT (By turning to Hex movng letters and then back to integer)
CRCShiftRightLONG = CRCValue And &HFF00
'Long to short conversion
If CRCShiftRightLONG < 32767 Then
CRCShiftRight = CRCShiftRightLONG
TempStr = Hex(CRCShiftRight)
Else
TempStr = Hex(CRCShiftRightLONG)
End If
' End Long to short conversion
'Take care of extra or not enough Hex Characters
If Len(TempStr) = 4 Then
CRCShiftRightStr = Mid(TempStr, 1, 2)
Else
If Len(TempStr) = 3 Then
CRCShiftRightStr = Mid(TempStr, 1, 1)
Else
If Len(TempStr) < 3 Then
CRCShiftRightStr = "00"
Else
If Len(TempStr) > 4 Then
CRCShiftRightStr = "00"
Debug.Print "lentempstr error"
End If
End If
End If
End If


'End Take care of extra or not enough Hex Characters

CRCShiftRight = Val("&H" & CRCShiftRightStr)
 
' END SHIFT RIGHT

'ArrayPointer
ArrayPointer = (CRCValue Xor NextPieceofData) And &HFF
'End ArrayPointer


'XOR
CRCValue = (CRCShiftRight) Xor CRCArray(ArrayPointer)
'End XOR
Next
 
'Fix neg Numbers
If CRCValue < 0 Then
CRCValue = 65536 + CRCValue
End If
'End Fix Ned Numbers
 

 
CRCValue = CRCValue Xor &HFFFF
CRCFinalString = Hex(CRCValue)
 

Dim HiCRC As String
Dim LoCRC As String
Dim Hi As Byte
Dim Lo As Byte
 
HiCRC = Hex(CRCValue And &HFF)
Hi = Val("&H" & HiCRC)
LoCRC = Mid(CRCFinalString, 5, 2)
Lo = Val("&H" & LoCRC)
 
DataString = DataString & Chr(Hi) & Chr(Lo)
CalcCRC = DataString
 
End Function
 
Public Sub Init()
CRCArray = Array( _
&H0, &H1189, &H2312, &H329B, &H4624, &H57AD, &H6536, &H74BF0, &H8C48, &H9DC1, &HAF5A, &HBED3, &HCA6C, &HDBE5, &HE97E, &HF8F7, _
&H1081, &H108, &H3393, &H221A, &H56A5, &H472C, &H75B7, &H643E, &H9CC9, &H8D40, &HBFDB, &HAE52, &HDAED, &HCB64, &HF9FF, &HE876, _
&H2102, &H308B, &H210, &H1399, &H6726, &H76AF, &H4434, &H55BD, &HAD4A, &HBCC3, &H8E58, &H9FD1, &HEB6E, &HFAE7, &HC87C, &HD9F5, _
&H3183, &H200A, &H1291, &H318, &H77A7, &H662E, &H54B5, &H453C, &HBDCB, &HAC42, &H9ED9, &H8F50, &HFBEF, &HEA66, &HD8FD, &HC974, _
&H4204, &H538D, &H6116, &H709F, &H420, &H15A9, &H2732, &H36BB, &HCE4C, &HDFC5, &HED5E, &HFCD7, &H8868, &H99E1, &HAB7A, &HBAF3, _
&H5285, &H430C, &H7197, &H601E, &H14A1, &H528, &H37B3, &H263A, &HDECD, &HCF44, &HFDDF, &HEC56, &H98E9, &H8960, &HBBFB, &HAA72, _
&H6306, &H728F, &H4014, &H519D, &H2522, &H34AB, &H630, &H17B9, &HEF4E, &HFEC7, &HCC5C, &HDDD5, &HA96A, &HB8E3, &H8A78, &H9BF1, _
&H7387, &H620E, &H5095, &H411C, &H35A3, &H242A, &H16B1, &H738, &HFFCF, &HEE46, &HDCDD, &HCD54, &HB9EB, &HA862, &H9AF9, &H8B70, _
&H8408, &H9581, &HA71A, &HB693, &HC22C, &HD3A5, &HE13E, &HF0B7, &H840, &H19C9, &H2B52, &H3ADB, &H4E64, &H5FED, &H6D76, &H7CFF, _
&H9489, &H8500, &HB79B, &HA612, &HD2AD, &HC324, &HF1BF, &HE036, &H18C1, &H948, &H3BD3, &H2A5A, &H5EE5, &H4F6C, &H7DF7, &H6C7E, _
&HA50A, &HB483, &H8618, &H9791, &HE32E, &HF2A7, &HC03C, &HD1B5, &H2942, &H38CB, &HA50, &H1BD9, &H6F66, &H7EEF, &H4C74, &H5DFD, _
&HB58B, &HA402, &H9699, &H8710, &HF3AF, &HE226, &HD0BD, &HC134, &H39C3, &H284A, &H1AD1, &HB58, &H7FE7, &H6E6E, &H5CF5, &H4D7C, _
&HC60C, &HD785, &HE51E, &HF497, &H8028, &H91A1, &HA33A, &HB2B3, &H4A44, &H5BCD, &H6956, &H78DF, &HC60, &H1DE9, &H2F72, &H3EFB, _
&HD68D, &HC704, &HF59F, &HE416, &H90A9, &H8120, &HB3BB, &HA232, _
&H5AC5, &H4B4C, &H79D7, &H685E, &H1CE1, &HD68, &H3FF3, &H2E7A, _
&HE70E, &HF687, &HC41C, &HD595, &HA12A, &HB0A3, &H8238, &H93B1, _
&H6B46, &H7ACF, &H4854, &H59DD, &H2D62, &H3CEB, &HE70, &H1FF9, _
&HF78F, &HE606, &HD49D, &HC514, &HB1AB, &HA022, &H92B9, &H8330, _
&H7BC7, &H6A4E, &H58D5, &H495C, &H3DE3, &H2C6A, &H1EF1, &HF78)
End Sub

Generalprova0memberocean06 May '03 - 2:04 
prova1
 
prova2
GeneralCRC algorithmsmemberTim Smith13 Apr '03 - 6:09 
http://www.repairfaq.org/filipg/LINK/F_crc_v3.html[^]
 
This document talks about the theory behind CRC computations and how to generate table driven CRCs for any polynomial. All the CRCs and FDC (another word for CRC?) use the same algorithm. The CCITT version listed here is just the hardware method of computing a CRC and it is slower than a table driven implementation.
 
Tim Smith
 
I'm going to patent thought. I have yet to see any prior art.
GeneralRe: CRC algorithmsmemberjacques_freedom31 Mar '04 - 22:10 
I have a question about CRC and MD5 algorithms:
 
Is it easy to generate the same int or long value with different strings?
 

 
I wait for your answer!
GeneralRe: CRC algorithmsmemberDominik Reichl1 Apr '04 - 0:19 
I have a question about CRC and MD5 algorithms:
Is it easy to generate the same int or long value with different strings?

 
For CRC: CRC has been designed to detect random transmission errors, so you can easily verify corrupted downloads or something like this. BUT you can easily find strings that hash to the same CRC value. In other words: CRCs aren't resistant against attacks, but are fine to quickly check for transmission errors.
 
For MD5: MD5 is cryptographically secure. This means that it is computationally infeasible ( = it's not impossible but currently nobody can do it) to find two strings that hash to the same MD5 value. MD5 is a 128-bit hash, so compared to a CRC-32 it should also be more collision-resistant.
 
So, to sum it up: if you need a secure hash then use MD5. If you just want to quickly check if a downloaded file isn't corrupted then use CRC.
 
Best regards,
Dominik

 

_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do?? Wink | ;)
(doesn't work on NT)

GeneralRe: CRC algorithmsmemberPanic2k324 Jan '05 - 13:34 
MD5 To Be Considered Harmful Someday
 
http://developers.slashdot.org/developers/04/12/07/2019244.shtml?tid=93&tid=172&tid=8[^]
 
"demonstrates the use of colliding datasets to create two executable packages with wildly different behavior but the same MD5 hash. The faults discovered are problematic but not yet fatal; developers (particularly of P2P software) who claim they'd like advance notice that their systems will fail should take note."

 
/// Don't PANIC ...
/// http://en.wikibooks.org/wiki/User:Panic2k4
Generalcould be cool but...memberJim Crafton13 Apr '03 - 5:01 
First off thanks for putting this out there, however some thoughts:
 
You have this licensed as GPL code - this makes it largely unusable for many of us out there, even those of us working on freebie projects.
 
There seems to be no coherent C++ design to this. It is largely a collection of c style functions. Not neccessarily bad, but it would have been interesting to see a little framework evolve out of this.
 
An article discussing the various algorithms in a bit more depth would also have been cool.
 
Anyways cheers
 
Jim
 
¡El diablo está en mis pantalones! ¡Mire, mire!
 
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
GeneralRe: could be cool but...memberChris Losinger13 Apr '03 - 6:50 
Jim Crafton wrote:
There seems to be no coherent C++ design to this. It is largely a collection of c style functions. Not neccessarily bad, but it would have been interesting to see a little framework evolve out of this.
 
just FYI,
 
check out crypto++: http://www.eskimo.com/~weidai/cryptlib.html[^]
 
it has tons of hash algorithms, all wrapped in one the most extensive C++ frameworks i've ever seen. Smile | :)
 
-c
 


Image tools: ThumbNailer, Bobber, TIFFAssembler

GeneralRe: could be cool but...memberJim Crafton13 Apr '03 - 11:05 
crypto++ - you know that is exactly what i was thinking of! But I was too lazy to track down the URL.
 
I have looked at it - really good stuff
 
¡El diablo está en mis pantalones! ¡Mire, mire!
 
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
GeneralRe: could be cool but...memberTim Smith14 Apr '03 - 5:11 
all wrapped in one the most extensive C++ frameworks i've ever seen.
 
Laugh | :laugh:
 
No kidding.
 
Tim Smith
 
I'm going to patent thought. I have yet to see any prior art.
GeneralUseful... but would like to see a managed code version :-)memberJabes12 Apr '03 - 5:53 
Useful little utility. I clicked on it because I thought it was in C#. Silly me. I'd love to see a framework that did all of these hash styles in C#, with a nice consistent class hierarchy.
 
It'd be nice to have some explanatory text in the article about the code, and hashing in general.
 
Best wishes
James

GeneralRe: Useful... but would like to see a managed code version :-)sussdarkfader9 Jul '03 - 8:06 
I just converted the stuff to classes, so it's easy to add an algorithm. I added ED2K hashes (which uses the MD4 class but it does it per 9.something megabytes).
And I'm trying to put XML into it. Text output isn't useful Smile | :)
Anyone interested in making some P2P hash-exchange protocol so (known) files can be hashed in one algorithm and verified against another.
An example: finding a list of filenames for a given CRC32 but unknown file.
Extending with plugins for P2P sharing apps and WINFS... plenty of ideas.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 12 Apr 2003
Article Copyright 2003 by Dominik Reichl
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid