Adding VHDL modulo 2 ^ 32

I am working on implementing the VHDL SHA-256 function . I have 32-bit signals unsigned, defined as such:

SIGNAL a, b : UNSIGNED (31 downto 0);

The specifications of the SHA-256 algorithm say that the addition must be done modulo 2 ^ 32 in order to preserve the 32-bit size in case of overflow. Now, answering this question , it looks like the overflow is already being handled with a modular addition in VHDL:

There is no overflow handling, overflow transfer is simply lost. Thus, the result is just the integer result of your work modulo 2 ^ MAX.

I have 2 questions:

  • In my case MAX = 31, does this mean that any addition operation performed on aand bwill be changed to 2 ^ 31?
  • I need to add modulo 2 ^ 32 , which obviously does not make sense, since I work with 32-bit numbers, and 2 ^ 32 is too large. So for some reason, it means that I really have to be modding with 2 ^ 31 ?
0
source share
1 answer

In order with unsigned(31 downto 0). 2^MAXin the message you are referring is an error and should read 2^length. The length 31 downto 0is 32.

Think about it, it 31 downto 0can represent numbers from 0 to 2 ^ 32-1, it does not make much sense if any addition of this range is modulo 2 ^ 31, if you can represent large numbers!

, , 2 ^ 32 0 2 ^ 32-1. 2 ^ 32 , , .

+4

All Articles