Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the SHA-256 hash of a single "1" bit?

The definition of SHA-256 appears to be such that the input consisting of a single "1" bit has a well-defined hash value, distinct from that of the "01" byte (since the padding is done based on input's length in bits).

However, due to endianness issues and the fact that no implementations that I can find support feeding in single bits, I can't quite figure out what this correct value is.

So, what is the correct hash of the 1-bit long input consisting of the bit "1"? (not the 8-bit long byte[] { 1 } input).

like image 610
Roman Starkov Avatar asked Dec 12 '10 17:12

Roman Starkov


People also ask

How many bits is SHA256 hash?

SHA-256 generates an almost-unique 256-bit (32-byte) signature for a text. See below for the source code. A hash is not 'encryption' – it cannot be decrypted back to the original text (it is a 'one-way' cryptographic function, and is a fixed size for any size of source text).

How is SHA256 calculated?

For SHA-256 these are calculated from the first 8 primes. These always remain the same for any message. The primes are firstly square rooted and then taken to the modulus 1. The result is then multiplied by 16⁸ and rounded down to the nearest integer.

What is SHA1 SHA256?

SHA256 or SHA1 vs SHA2 is the length of the key used to encrypt the data transferred online. SHA1 uses 160 bit long key to encrypt data while SHA256 uses 256 bit long key to encrypt data. SHA2 is a family of algorithms developed by the US government to secure the data online.

How long is a 256-bit hash?

It's always 64 characters, which can be determined by running anything into one of the online SHA-256 calculators.


1 Answers

OK, according to my own implementation:

1-bit string "1":

B9DEBF7D 52F36E64 68A54817 C1FA0711 66C3A63D 384850E1 575B42F7 02DC5AA1

1-bit string "0":

BD4F9E98 BEB68C6E AD3243B1 B4C7FED7 5FA4FEAA B1F84795 CBD8A986 76A2A375

I have tested this implementation on several standard multiples-of-8-bits inputs, including the 0-bit string, and the results were correct.

(of course the point of this question was to validate the above outputs in the first place, so use with care...)

like image 114
Roman Starkov Avatar answered Nov 16 '22 02:11

Roman Starkov