Timeline for Doubt regarding converting hex to byte in SHA-256 input
Current License: CC BY-SA 4.0
10 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 18, 2021 at 8:07 | history | edited | Maarten Bodewes♦ | CC BY-SA 4.0 |
added 162 characters in body
|
S Aug 18, 2021 at 7:57 | history | suggested | ilkkachu | CC BY-SA 4.0 |
not all echo's process backslash escapes by default, and \2e isn't a valid one anyway. printf is more portable
|
Aug 18, 2021 at 7:49 | review | Suggested edits | |||
S Aug 18, 2021 at 7:57 | |||||
Aug 17, 2021 at 20:56 | comment | added | Maarten Bodewes♦ |
You can just *shift the byte value into the right place, using << and then OR them together (beware of snags, lookup on StackOverflow on how to do this when you get stuck). Literals to define the initial values and constants can be defined using hexadecimal bytes or words are fine of course, e.g. h0 := 0x6a09e667 in the Wikipedia pseudo code is fine, 0x6a09e667 is not a string.
|
|
Aug 17, 2021 at 20:53 | vote | accept | J.Doe | ||
Aug 17, 2021 at 20:51 | comment | added | Maarten Bodewes♦ |
Normally we create an interface using bytes for the SHA-256 hash function. In that case the value 2E 2F 05 EE in bytes would be converted to a single word 0x2E2F05EE when looking at the SHA-256 implementation. But please note that SHA-256 is defined as using big endian. You should never use hexadecimals created from a string, only bytes and words. Hexadecimals are only useful for debugging (the debugger can of course use them, and you can use them in debug print or trace statements), you should never use them for the implementation itself.
|
|
Aug 17, 2021 at 20:44 | comment | added | J.Doe | I am trying to write SHA256 from scratch and this part is terribly confusing. The rest of the logic seems fine.. Lets assume the text in Hexa is: 2E 2F 05 EE that is to be populated in W[0]. How do we go about it and what would be its value ? | |
Aug 17, 2021 at 20:42 | comment | added | J.Doe | thank you. But when we initialize the data i.e. w[i]'s before running the Algorithm what do we do as the data required is in bytes by the variables (w[i]'s) being 32 bits)? Do we change the data to binary and then assign or we work directly on Hex by storing them in w[i]'s in hex format. I don't think latter would work and give the correct hash? | |
Aug 17, 2021 at 20:42 | history | edited | Maarten Bodewes♦ | CC BY-SA 4.0 |
added 59 characters in body
|
Aug 17, 2021 at 20:36 | history | answered | Maarten Bodewes♦ | CC BY-SA 4.0 |