# Using negative values / unsigned integers to implement SHA-2

What happens if we allow implementation of SHA-2 using negative values?

What happens if a negative value was used in the first round? Would the algorithm still result in a secure value?

I have a basic understanding of how the maths work. However, before I go writing my own function - could somebody indicate if they have any experience using negative values?

• It's unclear what your asking. Do you mean what happens if the input is a negative value? Or if the constants in the compression function are negative? Negative input value is still just a sequence of bits, would be handled just fine. Changing the compression function would mean it's not SHA256 anymore. Commented Jul 14, 2017 at 22:52
• @puzzleplace I'm not concerned with it being pure, functional SHA256, I'm trying to find ways to make it do unexpected things. So, what I was trying to ask was, when the input of any value in any round is switched to binary, what happens if it's a negative value? As far as I can tell, everything is always positive...maybe an easier way to ask would be...if all the IVs were negative at the start of the first round, does it change anything? What? How? Commented Jul 14, 2017 at 22:57
• Well SHA256 operates on binary input, for how to convert a negative number to binary take a look at two's complement, it's a common way used to represent negative numbers. The internals of SHA256 have no notion of "positive" or "negative", they're operating on purely binary data. The IV is also binary data, it can be convenient to represent them as 32 bit unsigned integers but they again have no real notion of "positive" or "negative". Commented Jul 14, 2017 at 23:06
• @puzzleplace So, if a value is negative, when it gets converted to binary, it will have the same value as it would if it had been positive to start? Commented Jul 14, 2017 at 23:09
• (I may have inadvertently asked a question I am not smart enough to understand the answer too...) Commented Jul 14, 2017 at 23:15