Is the message divided into chunks, each chunk hashed separately, or something else?

  • $\begingroup$ are you using a library or thinking about the internals? $\endgroup$
    – kelalaka
    Sep 23, 2019 at 9:04
  • $\begingroup$ just overall how it usually works $\endgroup$
    – H45hish
    Sep 23, 2019 at 9:05

2 Answers 2


Hashing small messages works identical to hashing large messages.

Merkle–Damgård construction:

Currently the most common hash functions are based on the Merkle–Damgård construction (i.e. MD5, SHA1 and SHA2).

A message is divided into equal sized blocks and then each block goes through a one way compression function (to be exact, the next to be compressed block is appended to the compressed result so far to get a size-reduction). If you have a large message then it just has more blocks and therefore takes a little bit longer.

  • $\begingroup$ Thanks. I have an idea for a one-way function that uses a public ledger as a "labyrinth", and the message as a "map", and thought that most of the technical issues such as... how to hash large messages, have been solved long ago. What you describe is my exact own ideas for how to combine my one way function with large messages. $\endgroup$
    – H45hish
    Sep 23, 2019 at 9:50

While hashing, the messages are divided into chunks and padded so that a message is fit into the chunks, properly. For example in SHA-256 the message appended 1, then many zeroes and finally the message size in 64-bit added. The total size must be $x$ multiple of 512 where $x$ is minimum.

No, they are not separately hashed, they are chained. If not it how would you combine the output? If you don't combine what is a hash there? There is actually, hash trees famously know as Merkle Trees used to verify data blocks, or many files where you only keep the root hash.

SHA-256, for example, uses Merkle–Damgård (MD) construction in which a compression function $F$ which is


The 512-bit input space is the message space. 256-bit input space is the previous hash, if it is the first block then an IV is used.

let $$M\mathbin\|pad=m_1\mathbin\|m_2\mathbin\|\ldots\mathbin\|m_\ell $$ $$H_i = F(m_i,H_{i-1})$$ with $H_0 = IV$ then

$$\operatorname{SHA-256}(M||pad) = F(m_\ell, F\ldots F(IV,m_1)\ldots))$$

This tells you about the MD construction, MD5, SHA-1, SHA-2 uses MD. There is also sponge construction that SHA-3 is based on, which left the OP as an exercise.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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