I am working on a VHDL implementation of the SHA-256 hash function.
I have some 32-bit unsigned
signals defined as such:
SIGNAL a, b : UNSIGNED (31 downto 0);
Within the specifications of the SHA-256 algorithm, it says addition must be performed modulo 2^32 in order to retain the 32-bit size in case of an overflow. Now, according to the answer to this question, it sounds like overflow is already handled with modular addition in VHDL:
There is no overflow handling, the overflow carry is simply lost. Thus the result is simply the integer result of your operation modulo 2^MAX.
I have 2 questions:
- In my case,
MAX = 31
so does that mean that any addition operation I perform ona
andb
will be modded with 2^31? - I need to perform addition modulo 2^32 which obviously doesn't make sense since I am working with 32-bit numbers and 2^32 is one bit too large. So is it somehow implied that I should actually be modding with 2^31?