Introduction

This code was originally written for a project called
SharpConnect
- a C# client of the DirectConnect protocol.

Several updates have been posted, this is the fourth update. This newest version now includes:

optional getting the whole TTH tree instead of just the TTH root value.

use of threads for better CPU usage.

tree compression for better memory usage.

If you are looking for the best time processing performance use ThexOptimized, if you like to keep your CPU usage low try ThexThread. The oldest version (Thex.cs) is also included into the zip file but that is just to keep track on the updates.

Problems on the way

Threads colliding in the FileStream.Read stage which throw an
exception that was caused from two or more threads reading the file at the same time. Solution: I tried fixing it up with Monitor which made it
thread-safe but slower and overloaded the CPU. Finally, a FileStream was added for each thread which required a rewrite of the threads code.
I also decide to update the way data is pulled into memory - the new method is to read data in big blocks instead of reading it leaf (1024K) by leaf which improve the file I/O reads number dramatically).

Usage tips

You should have a look at the Block_Size value to adjust performance.

If you use ThexThreaded you should try and test ThreadCount value for your own needs. I recommend 4-6 threads for stable CPU usage, 1-3 threads for faster results

When compared to HashCalc, the hash differs when the remainder block is 55 bytes.

It looks like HashCalc has the correct value:

The tiger algorithm padding scheme appends 1 byte (value 0x01) to its hashing data and
the data length (shifted by 3 bit to the left) is then written to the last 8 bytes in the buffer
(bytes between the appended byte and first length byte are zeroed) and then compressed.

If the remaining data (+ last appended byte) takes more than 56 bytes (not enough space for the data length) the unused bytes are zeroed then compressed.
The buffer is zeroed, the formated length is written to the last 8 bytes in the buffer and then it is compressed again.

In the code that is offered here the second case (not enough space for the data length) is already used when the remainder data + appended byte is 56 bytes long,
even though there is enough buffer space left for the formated length.

Your solution is very good but it works little slow. On my computer it hashes at 20 MB/s. I have implemented c++ Tiger hash algorithm, and have used in your managed code. Speed risen 2 times (to 40 MB/s).

hi i am doing dessertation on merkle hash tree,
if you can provide your code , that will be very helpful to me,
i cant find it on this page.
you can mail me at tanmay.svnit@yahoo.co.in or tanmay832003@yahoo.com

i think you can use my code in C++.Net. but i'm pretty sure that it's possible to find a c++ version because almost all the Direct Connect clients are writtin in c++ and they use the Tiger Tree Hash. so it's just a matter of getting the source of one of the open source projects (there are a lot..) and getting the code you need.

ugh you have to send to my email and I have to get a secondary binary and then uh to product did it would be to 3rd or 4th division depending on how many zeros I can't count uh but a better look at it would give me more referencing and uh your Canon by stop byby South tix:confused:

ofcourse i tested the and it matches the values in (both the tiger hash and the thex values).

i supply this interface as a tth tool not a tth tree you can change the code as you wise to get you the tree you want the base is here save the values won't be so hard (and won't take much time from the cpu as well)

about the rating i don't care about them as long as they don't commet just putting bad / good rating without a commet to explain why they put it is not helpful.