New answers tagged

1

The first 10 lines can be replaced with uint64_t blocks = (len+72)/64; and that will fix the code for the example at hand (as well as extend the message capacity if int is 32-bit and len is 64-bit, which can't be told from the codeĀ¹). My mental process to construct (len+72)/64, which works for many things in crypto that divide things into equal size blocks, ...


2

The padding method for SHA-256 is (assuming you're byte oriented - it appears you are) is 'append an 0x80 byte, and then add 0x00 byte's until the length modulo 64 bytes is 56. This implies that if the original message length modulo 64 is 56 or larger, you'll need to do one more hash compression operation. That means that your computation of the number of ...


Top 50 recent answers are included