I see that a block contains 80 bytes. SHA256 expects integral multiples of 64 bytes as input. How are the remaining 48 bytes calculated?
Asked
Active
Viewed 480 times
1 Answers
2
According to section 5.1.1 of FIPS-180-4, SHA-256 messages are padded with a binary 1, followed by a number of 0s, and finally a 64-bit binary representation of the length of the message:
Suppose that the length of the message, M, is bits. Append the bit "1" to the end of the message, followed by k zero bits, where k is the smallest, non- negative solution to the equation + 1 + k ≡ 448 mod 512. Then append the 64-bit block that is equal to the number expressed using a binary representation.
This is not specific to Bitcoin, and any correct SHA-256 implementation will do this. For Bitcoin, a remaining 48 bytes of padding would be a single binary 1, a bunch of 0s, and the binary representation of the number 640 (80 bytes in bits). In binary, the remaining 48 bytes would be:
1 00...00 0110 0100 0000
Note that the SHA family of functions represent binary in big-endian format.
![](../../users/profiles/106285.webp)
forest
- 64,616
- 20
- 206
- 257