I'm using the SHA1/2 family of algorithms for a particular project. I'm was wondering if all the SHA algos return a fixed length hash regardless of the length of the data?
|
Essentially yes, they do. Depending on the exact hash function you choose depends on the length of output you'd expect. For example, SHA256 produces 256 bits of output. This does then beg the question "but the length of the hash is fixed and there are infinite possible inputs??!!". That's correct, except that $2^{256}$ is 115792089237316195423570985008687907853269984665640564039457584007913129639936. That's an awful lot of unique possible inputs which may be passed in. You may be interested to know the same concept is used in file systems - they're called bitmaps and provide a block to bit mapping so the file system can quickly find free blocks. The numbers do scale :) |
|||||||
|
|
By the definition in FIPS 180-4, published March 2012, there are |
|||||||
|
Others have noted that the output is indeed a constant, fixed size, so let me nit-pick one point just for completeness: It is worth noting that these hash functions do have a limit to the input size of their data. So that input length itself has an upper bound. From FIPS 180-4:
These are insanely large sizes (and it seems likely that only the ones for SHA-1, SHA-224, and SHA-256 could practically apply to electromagnetic storage). But in theory $2^{64}$ bit (approx. 1 exbibyte) restriction could prohibit calculating one hash from something like a very large database or distributed filesystem. But for most developer concerns, these input size restrictions are practically nonexistent. |
|||||||
|