When hashing a messages of size of n
, does the SHA2 algorithm always produce the same sized hashed value?
SHA-2 output is always fixed.
SHA-512 will always produce a message digest of 512 bits – hence its name – and is practically represented using 64 binary bytes, or 128 chars when HEX-encoding the message digest.
It does not matter how long or short your input is. As an extreme case: one can even produce an SHA-512 output with a zero-length input (aka “no input”) and, as you can see, its output (aka message digest) is exactly 512 bits…
cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
For more details on how the final output of SHA-512 is calculated, see the explanation in RFC4634, on page 14 (quote):
For SHA-512, this is the concatenation of all of H(N)0, H(N)1, through H(N)7.
Since – as the RFC explains – those eight $H(N)_0 \dots H(N)_7$ are each 64 bit values, this concatenation results in a 512 bit (message digest) output value.