Click here to Skip to main content
11,932,677 members (50,150 online)
Click here to Skip to main content
Add your own
alternative version


37 bookmarked

A Tiger Hash Implementation for C#

, 9 Mar 2012 CDDL
Rate this:
Please Sign up or sign in to vote.
A Tiger hash Implementation for C#, based on .NET's HashAlgorithm class.
This is an old version of the currently published article.


This set of pure C# classes implements the cryptographic Tiger hash algorithm. It inherits from .NET's HashAlgorithm class and so is usable as drop-in in any place where .NET's built-in hash functions are already used. Although not as fast as native machine code generated by C++ or ASM, it's still about 30% faster than the other C# implementations I found (2010).

The program has been tested with a number of different binaries, and most of the test vectors supplied by the creators of Tiger.


A cryptographic hash maps an arbitrary-length data block (e.g., password, file) to a fixed-length hash value as one-way function (= irreversible).

Tiger was designed in 1995, so it had enough time to be well-analyzed, and no successful attacks on full 24-round Tiger are known to date. It is always a good idea to consult Wikipedia or The Hash Function Lounge to check if new vulnerabilities have been found since this article was written.

Its level of security is comparable to RIPEMD-160 or SHA-256. It works on whole 512-bit input data blocks, and produces 192 bits of hash value output. Input data that doesn't align to 512-bit boundaries (as usually is the case) is padded accordingly.

Tiger itself is a 64-bit-optimized algorithm, but still runs well on narrower buses. This implementation does some optimizations that do not drag down the 64-bit performance noticeably but help the 32-bit systems very much.

The underlying cryptographic design is basically described on Wikipedia and in more detail on the inventors´ webpage. The data for the S-Boxes has been taken from the reference implementation.

Some of the functionality (e.g., FileStream processing) is provided by the .NET Framework through the abstract HashAlgorithm base class.

Using the code

The class is being created/instantiated directly, but used/called through the abstract HashAlgorithm class:

using System.Security.Cryptography;
using softwareunion;

HashAlgorithm myhash;

{   case "MD5":   myhash=new MD5CryptoServiceProvider();
    case "TIGER": myhash=new Tiger();  // <<-- create the object
// [...]
    default: throw new NotImplementedException();

// vv-- then ask framework's HashAlgorithm class to
//      coordinate and call our own class methods
myhash.ComputeHash( File.OpenRead("myfile.bin") );

byte[] the_hash_result=myhash.HashValue;

There is a version 2 of Tiger that only differs in the padding value of 0x01 being upgraded to 0x80 (there's already a comment for it in the ProcessFinalBlock function).


  • Using Array.Copy(...) can also process arrays of different types, and runs with highly optimized native code, while pure C# loops that copy element per element are only as good as the JIT allows them to be.
  • Calling functions inside a loop may be comfortable, but is rarely a good idea and is not always optimized by the JIT compiler.
  • Loop unrolling often gives good results under C++, but my tests on this code (using .NET 2.0) have shown compact loops giving better performance.
  • Converting to (byte) is slightly faster than &0xFF.
  • Arrays are fastest when indexed by an int.
  • Functions with no local variables are called faster.

Room for Future Improvements

  • Test where "unchecked" clauses could bring performance improvement.
  • Can the BitTools.RotLeft functions be further optimized? 
  • Can the Array type or any other part of the framework provide the functionality of TypeBlindCopy(...) - that is pack an array of bytes into an array of ulongs?
  • Can any more temporary gcheap allocations be removed? 


  • 2011-01-21: Tests finished, going public.
  • 2012-03-09: Adding some weblinks.


This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)


About the Author

Chief Technology Officer Software Union
Austria Austria
has been working a total of 14 years as programmer and system developer, plus some years of working as network technician and application supporter. Also experienced modeling, optimizing and administering FireBird and SqlServer databases. Loathes MySql.
Works with C++, C++/CLI, C#, JavaScript, PHP, PSQL and TextPad.

You may also be interested in...

Comments and Discussions

Discussions on this specific version of this article. Add your comments on how to improve this article here. These comments will not be visible on the final published version of this article.
-- There are no messages in this forum --

Discussions posted for the Published version of this article. Posting a message here will take you to the publicly available article in order to continue your conversation in public.
QuestionSame algorithm produce different output than this! Pin
Manir Uzzaman23-May-14 10:37
memberManir Uzzaman23-May-14 10:37 
AnswerRe: Same algorithm produce different output than this! Pin
mastamac22-Aug-14 10:27
membermastamac22-Aug-14 10:27 
QuestionTypeBlindCopy & GetBytes Pin
kornman0011-Mar-12 7:46
memberkornman0011-Mar-12 7:46 
SuggestionRegarding MD5 Hashing Pin
Ed Nutting10-Mar-12 7:43
memberEd Nutting10-Mar-12 7:43 
AnswerRe: Regarding MD5 Hashing Pin
mastamac10-Mar-12 13:04
membermastamac10-Mar-12 13:04 
GeneralRe: Regarding MD5 Hashing Pin
Ed Nutting11-Mar-12 1:26
memberEd Nutting11-Mar-12 1:26 
QuestionCode Link Broken Pin
Dewey9-Mar-12 9:25
memberDewey9-Mar-12 9:25 
AnswerRe: Code Link Broken Pin
Ravi Bhavnani9-Mar-12 21:06
memberRavi Bhavnani9-Mar-12 21:06 
GeneralRe: Code Link Broken Pin
Dewey9-Mar-12 23:34
memberDewey9-Mar-12 23:34 
AnswerRe: Code Link Broken Pin
mastamac10-Mar-12 2:39
membermastamac10-Mar-12 2:39 
BugRe: Code Link Broken Pin
robertjb2010-Mar-12 3:16
memberrobertjb2010-Mar-12 3:16 
GeneralRe: Code Link Broken Pin
Ed Nutting10-Mar-12 7:38
memberEd Nutting10-Mar-12 7:38 
GeneralPerformance Pin
Zaibot26-Jan-11 0:03
memberZaibot26-Jan-11 0:03 
GeneralMy vote of 3 Pin
Philippe Bouteleux24-Jan-11 3:49
memberPhilippe Bouteleux24-Jan-11 3:49 
QuestionHow did you figure out the S-Boxes? Pin
Manfred R. Bihy22-Jan-11 10:18
memberManfred R. Bihy22-Jan-11 10:18 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151126.1 | Last Updated 9 Mar 2012
Article Copyright 2011 by mastamac
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid