Search code examples
encryptionsha256bitcoincomputation

why is the output result of sha-256 always 256 bits and the execution time always the same?


Why is it, that no matter the size of the input of the SHA-256 algorithm (in bitcoin mining), it always outputs a result of 256 bits?

furthermore, how come that no matter the size of the input, the computation time is always the same?


Solution

  • On your first question, the answer would be that it is by design - the SHA-256 algorithm is intended to take an arbitrary amount of input data and produce 256 bits of output, whilst also maintaining certain properties that make for an effective cryptographic hash. Other hash algorithms produce different output sizes (e.g. SHA-1 produces 160 bits of output, SHA-512 produces 512 bits of output, etc.).

    Your second question is based on an incorrect assumption - the computation time is dependent on the size of the input - it will naturally take longer even just to read say, a 1MB file than it would to read a 1KB file, and since the hash is dependent on every bit of the input, a larger input will take longer to hash than a smaller one.