0
$\begingroup$

Is the file just read bit by bit to calculate the hash with those values or is there more to it?

Are there any resources to read a bit more about file hashing?

$\endgroup$
11
  • $\begingroup$ The question is only loosely related to cryptography. Crypto algorithms work on binary data, how the data is stored before it's submitted as input to a hash algo - in a file, in a memory buffer or otherwise - is irrelevant. Programming questions are better suited for StackOverflow. $\endgroup$ – tum_ Apr 26 '19 at 21:27
  • $\begingroup$ @tum_ Idk, I think it doesn't really fit into either of them but i felt like this here was a little bit better suited... $\endgroup$ – b3nj4m1n Apr 26 '19 at 21:30
  • $\begingroup$ Well, to be honest, it is still not clear what exactly you are looking for. So, now that you have the feedback, you might consider editing your question and be more specific, $\endgroup$ – tum_ Apr 26 '19 at 21:34
  • $\begingroup$ What is unclear about it? What do i need to give to the alg to get the file hash. $\endgroup$ – b3nj4m1n Apr 26 '19 at 21:35
  • 1
    $\begingroup$ Yeah, now it's finally clear what you were after. I can't name any off the top of my head but I can imagine certain crypto applications built on top of SHA-2 where the metadata would be involved. But sha-1,2,3 on its own just processes a bit string. $\endgroup$ – tum_ Apr 26 '19 at 22:02
2
$\begingroup$

Hash functions operate on blocks like SHA-256 has 512-bit input block. In SHA-256, your data $m$ is divided into 512-bits blocks $m_1,\ldots,m_n$ where each entered into the hash function. The final block, $m_n$ is padded as

$$k=(447−l) \bmod 512$$ where data size is $l$ and $k$ is the number of zeros following the 1 after $m$ and finally the message size in 64 bits. The message size can also 128 which allows larger files to be hashed. So the input to SHA-256 is

$$m\|1\|0\ldots0\|\text{size_of(m)}.$$

Each other hash function defined in a similar way, an example from FRC4634

The hash functions specified herein are used to compute a message digest for a message or data file that is provided as input. The message or data file should be considered to be a bit string. The length of the message is the number of bits in the message (the empty message has length 0). If the number of bits in a message is a multiple of 8, for compactness we can represent the message in hex. The purpose of message padding is to make the total length of a padded message a multiple of 512 for SHA-224 and SHA-256 or a multiple of 1024 for SHA-384 and SHA-512.

Note: The 64-bit (or 128-bit) message size also determines the maximum input size for a SHA-256 hash.

$\endgroup$
10
  • $\begingroup$ So it's just the file in binary? $\endgroup$ – b3nj4m1n Apr 26 '19 at 21:05
  • 1
    $\begingroup$ Always. What you else you expect? $\endgroup$ – kelalaka Apr 26 '19 at 21:06
  • $\begingroup$ Idk that's why I asked the question. $\endgroup$ – b3nj4m1n Apr 26 '19 at 21:07
  • 1
    $\begingroup$ if you can verify the answer how come you didn't discover the answer yourself? :-) $\endgroup$ – kodlu Apr 26 '19 at 21:17
  • 1
    $\begingroup$ The RFC4634 explains in details, and you can find test vector at Nist $\endgroup$ – kelalaka Apr 26 '19 at 21:23
0
$\begingroup$

Not quite. File hashing is a way of creating a unique identifier for a specific input with incredibly low chance of collision. A collision happens when two inputs map to the same output. So far we have not seen any cases of collision for SHA256 or SHA3; two of the most prominent hashing algorithms. In terms of what goes on inside a hashing algorithm, its not just mapping one bit to another bit. There can be different methods including (but not limited to) bit substitution, logical operations, and many other bitwise operations. A good hashing algorithm should be complex enough that two very similar inputs map to very different outputs, again making it a unique identifier.

For example: SHA256(0000000) = ABD4562B6AEE9F SHA256(0000001) = 255FBA9C5C33ED

$\endgroup$
3
  • 1
    $\begingroup$ Just to clearify, I know how sha256 works. I just need to know what to put inside of it to get the hash for a file. Also, isn't SHA-3 a family of algorithms? Anyways, i'm sorry but I don't really see an answer to my question in your answer.... Thanks anyways. $\endgroup$ – b3nj4m1n Apr 26 '19 at 21:22
  • $\begingroup$ It's "collision", not "collusion" $\endgroup$ – Ella Rose Apr 26 '19 at 22:52
  • $\begingroup$ @b3nj4m1n Yes, SHA-3 is a family of algorithms, but Ronald is still correct in saying that we haven't seen any collisions for any of the SHA-3 hashes. $\endgroup$ – forest Apr 27 '19 at 6:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.