Click here to Skip to main content
15,438,393 members
Articles / General Programming / Algorithms
Article
Posted 21 Jan 2011

Stats

55.6K views
1.4K downloads
53 bookmarked

A Tiger Hash Implementation for C#

Rate me:
Please Sign up or sign in to vote.
4.86/5 (21 votes)
9 Jul 2022GPL32 min read
A Tiger hash Implementation for C#, invocable through dotnet's HashAlgorithm class
This post is about a set of pure C# classes that implement the cryptographic Tiger Hash algorithm.

Introduction

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).

Instead of having ready-made S-box tables bloating the source code, these are generated on first use, taking about 1ms (one millisecond) on current hardware (2022).

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

Background

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:

C#
using System.Security.Cryptography;
using Tiger=SoftwareUnion.Tiger;

HashAlgorithm myhash;

switch(AlgorithmToUse)
{   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).

History

  • 21st January, 2011: Tests finished, going public
  • 9th March, 2012: Adding some weblinks
  • 28th June, 2022: On-first-use S-box creation

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
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.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Member 1370414311-Jul-22 6:26
MemberMember 1370414311-Jul-22 6:26 
QuestionBut why? PinPopular
Andreas Saurwein11-Jul-22 0:09
MemberAndreas Saurwein11-Jul-22 0:09 
AnswerRe: But why? Pin
den2k8811-Jul-22 23:38
professionalden2k8811-Jul-22 23:38 
GeneralRe: But why? Pin
Andreas Saurwein12-Jul-22 0:02
MemberAndreas Saurwein12-Jul-22 0:02 
AnswerRe: But why? Pin
captnmac18-Jul-22 7:23
Membercaptnmac18-Jul-22 7:23 
GeneralRe: But why? Pin
Andreas Saurwein19-Jul-22 23:03
MemberAndreas Saurwein19-Jul-22 23:03 

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.