Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a limit on the message size for SHA-256?

Tags:

hash

sha256

When hashing a string, like a password, with SHA-256, is there a limit to the length of the string I am hashing? For example, is it only "safe" to hash strings that are smaller than 64 characters?

like image 729
Jackson Avatar asked Jun 30 '13 07:06

Jackson


People also ask

What is the message size used in SHA256?

SHA-256 has the input message size < 264-bits. Block size is 512-bits, and it has a word size of 32-bits. The output is a 256-bit digest. The compression function processes a 512-bit message block and a 256-bit intermediate hash value.

What is the maximum length of a SHA256 hash?

It's always 64 characters, which can be determined by running anything into one of the online SHA-256 calculators.

How many bytes is SHA256?

SHA-256 generates an almost-unique 256-bit (32-byte) signature for a text. See below for the source code. A hash is not 'encryption' – it cannot be decrypted back to the original text (it is a 'one-way' cryptographic function, and is a fixed size for any size of source text).


1 Answers

There is technically a limit, but it's quite large. The padding scheme used for SHA-256 requires that the size of the input (in bits) be expressed as a 64-bit number. Therefore, the maximum size is (264-1)/8 bytes ~= 2'091'752 terabytes.

That renders the limit almost entirely theoretical, not practical.

Most people don't have the storage for nearly that much data anyway, but even if they did, processing it all serially to produce a single hash would take an amount of time most would consider prohibitive.

A quick back-of-the-envelope kind of calculation indicates that even with the fastest enterprise SSDs currently1 listed on Tom's hardware, and striping them 16 wide to improve bandwidth, just reading that quantity of data would still take about 220 years.


1. As of April 2016.

like image 86
Jerry Coffin Avatar answered Sep 18 '22 16:09

Jerry Coffin