I was going through the Python hashlib
package documentation and wanted some clarification on two hash object attributes (namely hash.block_size
and hash.digest_size
). Here is the definition of each attribute:
hash.digest_size
= "The size of the resulting hash in bytes."
hash.block_size
= "The internal block size of the hash algorithm in bytes."
source: https://docs.python.org/2/library/hashlib.html
So I understand that hash.digest_size
is simply the length or size (in bytes) of the data once it is hashed or "digested" by the hash_object. For for example from the code below getting the digest of the string 'Hello World' via a SHA256 hash object returns a digest_size of 32 bytes (or 256 bits).
import hashlib
hash_object = hashlib.sha256()
hash_object.update(b'Hello World')
hex_dig = hash_object.hexdigest()
print(hex_dig)
>>>a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e
print(hash_object.digest_size)
>>>32
print(hash_object.block_size)
>>>64
print(len(hex_dig))
>>>64
What I don't understand is this hash.block_size
attribute. Is it simply the length of characters required to represent the hexadecimal representation of the hashed data? Is it something else entirely? I don't quite understand the definition of this attribute so any clarification on this would be very helpful & insightful!