What exactly is the info_Hash in a torrent file

人走茶凉 提交于 2019-11-27 12:05:19

问题


i am reading lately a lot about hash from torrents an magnetic links etc.

but there is a question i dont understand.

I have the hash of a file and the infohash of a torrent, is the infohash = hash of the file ?

If yes what if the torrent descripes 6 Files to download ?

If no what does it stand for.


回答1:


So I finally figured it out.

The “infohash” is the SHA1 Hash over the part of a torrent file that includes:

  1. ITEM: length(size) and path (path with filename)
  2. Name: The name to search for
  3. Piece length: The length(size) of a single piece
  4. Pieces: SHA1 Hash of EVERY piece of this torrent
  5. Private: flag for restricted access

To show this a little more I took a random torrent file and used the “BEncode Editor” from Ultima to make it more clearly to me.

As you can see the the red box marked the information part of the torrent file. The torrent file includes not the Hash of the items, but the hashes of every piece.

  • For item1 with: 1069496548
  • and item2 with: 223
  • It is together: 1069496771
  • With a piece size of: 524288
  • There are 2040 pieces. (1069496771/524288=2039.9032 approximately)
  • The pieces section includes 40800 byte of data what are 81600 + 2 chars in the file.
  • the +2 because 0x marks that this is hexadecimal.
  • A SHA1 hash has 40 0x chars or 20 Byte of data what are 2040 SHA1 hashes.

I am sorry that this information is about a torrent that leads to a illegal movie, but i wanted to use a torrent that realy exists.




回答2:


Here's how to pull the pertinent segment of a *.torrent datum for a bittorrent “info hash”.

I made this for an example.

0000000: 6438 3A61 6E6E 6F75 6E63 6530 3A31 303A  d8:announce0:10:
0000010: 6372 6561 7465 6420 6279 3133 3A6D 6B74  created by13:mkt
0000020: 6F72 7265 6E74 2031 2E30 3133 3A63 7265  orrent 1.013:cre
0000030: 6174 696F 6E20 6461 7465 6931 3537 3037  ation datei15707
0000040: 3530 3238 3565 343A 696E 666F 6436 3A6C  50285e4:infod6:l
0000050: 656E 6774 6869 3230 6534 3A6E 616D 6534  engthi20e4:name4
0000060: 3A70 7269 7631 323A 7069 6563 6520 6C65  :priv12:piece le
0000070: 6E67 7468 6932 3632 3134 3465 363A 7069  ngthi262144e6:pi
0000080: 6563 6573 3230 3AF1 D7EE 4236 3434 D06F  eces20:...B644.o
0000090: 27C4 BBAD 87F0 F089 7A22 2B37 3A70 7269  '.......z"+7:pri
00000a0: 7661 7465 6931 6565 65                   vatei1eee

The content of the “info” key is between (inclusive) offsets 0x4D and 0xA7. So…

#!/crit/shell/bsh
bbe  \
    -e '
        d 0x0 0x4C ;
        d 0xA8 * ;
      '  \
    ${example}   \
 |
shasum  -a 1  -b

You should see this:

1799a58b9f8ff2b9b9bcecd0d438c5f37f19a31c *-

Here is the xxd output, in–lieu of shasum, for more elucidation:

0000000: 6436 3A6C 656E 6774 6869 3230 6534 3A6E  d6:lengthi20e4:n
0000010: 616D 6534 3A70 7269 7631 323A 7069 6563  ame4:priv12:piec
0000020: 6520 6C65 6E67 7468 6932 3632 3134 3465  e lengthi262144e
0000030: 363A 7069 6563 6573 3230 3AF1 D7EE 4236  6:pieces20:...B6
0000040: 3434 D06F 27C4 BBAD 87F0 F089 7A22 2B37  44.o'.......z"+7
0000050: 3A70 7269 7661 7465 6931 6565            :privatei1ee

You can refer to The BitTorrent Protocol Specification for an explanation, albeit a terse and rather grammatically inelegant one, as to their nomenclature and why the final 0x65 needs be excluded.
Concisely: the entire datum is encased in a pair of US-ASCII ‘d’ and ‘e’; the content of the “info” key, or field, is similarly so encased. You want everything between the first 0x64 — ‘d’, — which succeeds the US-ASCII string 4:info, and the terminal 0x65 — ‘e’, — which is paired with the aforementioned 0x64.



来源:https://stackoverflow.com/questions/28348678/what-exactly-is-the-info-hash-in-a-torrent-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!