9

I am using C# with RHash in order to calculate the btih hashes of of file. Currently I'm using 3 tools in order to generate the btih hash:

  1. rhash-1.2.9-src\bindings\mono with librhash-1.2.9-win dll
  2. rhash-1.2.9-win32 command line tool
  3. uTorrent

The problem is that every tool generates different btih signatures for the same file (the photo was taken by me, it's royal free):

1:  2FF7858CC0A0B216C3676A807D619FA30101E45F
2:  E6F07BB3C3B3B67531C84E3452980698AC1B0DAA  A:\IMG_0400.JPG
3:  D0B96839A14A8C45BB81AD157805AE73425998E5

For the C# hash generation I use Hasher.GetHashForFile(f.Name, HashType.BTIH); and rhash --bith in the cmd tool.

What am I doing wrong? Is there another way to calculate the btih?

TheJoeIaut
  • 1,522
  • 2
  • 26
  • 59
SimSimY
  • 3,616
  • 2
  • 30
  • 35
  • are you sure you use the right encoding? show the code by that you read the file and encrypt it – thumbmunkeys Dec 14 '12 at 11:21
  • Encoding? those are binary files... the rhash binding uses simple FileStream (see line 163 and 77 of the sorcecode https://github.com/rhash/RHash/blob/master/bindings/mono/Hasher.cs) – SimSimY Dec 14 '12 at 11:41
  • thought you might have read the file it into a string – thumbmunkeys Dec 14 '12 at 11:59

1 Answers1

3

The difference between the first two is that, according to the RHash source code, BTIH hashes requires additional data to be correctly computed.

The init_btih_data function in calc_sums.c is documented with:

Initialize BTIH hash function. Unlike other algorithms BTIH requires more data for correct computation.

In test_hashes.c, the BTIH examples are actually treated differently depending on whether USE_BTIH_WITH_TEST_FILENAME has been defined.

That init_btih_data function (which only seems to get called when running the command line application) in turn calls the rhash_trasmit function a number of times depending on various parameters. At a minimum, it will call it twice, which probably explains the difference between the first two. It can, however, call it a number of other times, which I think explains the difference we see with uTorrent.

The difficulty is that while the unmanaged DLL exposes the rhash_trasmit function, the .NET bindings do not, which means that it is not possible to supply the additional data that is expected.

nick_w
  • 14,758
  • 3
  • 51
  • 71