Jump to content

How is the SHA-1 hash generated


Recommended Posts


I have some technical questions concerning the protocol.

I know that each torrent file has a unique SHA hash value. But how is that value generated and from what. I know that the message to be hashed should be somewhere in the torrent file but how can you get it.

Thanks in advance.


Link to comment
Share on other sites

Thanks for the replies. I checked out the info_hash on the specification website posted above. It says that the hash value should come from the value of the info dictionary. My question now is, what does it mean by the value of the info?

The info dictionary has many things like the list of files, paths, torrent name...

Also, at the end of the torrent file there is a string called pieces that contains unreadable characters. What is that used for?

Link to comment
Share on other sites

The specification states that I need to hash the info dictionary

value, what does this mean exactly? What part of the following


would I hash?



Do I hash the 'e' encapsulation value at the end of the list

dictionary value?

Do I hash the massive 'pieces' value?

Do I put the 'infod' value into the hash?

Also, I have noticed that there are two 'e' values at the very end of

the torrent file. Should I be placing both of these values into the

hash, or one, or none?


Link to comment
Share on other sites

... If you really want to understand this (and judging by the type of questions you're asking, you actually need to), then you might want to take some time out to really figure out how bencoding itself works. To answer you any other way wouldn't really be helping you; it'd just be stalling the pain. If you have specific questions trying to understand bencoding, then that's fine, but asking us whether or not to include that second e is a very obvious indication that it'll be dangerous for you to proceed without the necessary fundamental understanding on hand, because there isn't a simple yes-or-no answer to that question.

The 'info' dictionary is the value pointed to by the 'info' key in the root dictionary. The 'info' key is bencoded as 4:info. The 'info' dictionary (value) is bencoded as d...e. The specs very deliberately/explicitly state that the bencoded value is what gets hashed.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...