algorithm - Calculating k for padding of SHA-256 message -


i'm implementing shs sha-256 algorithm in vhdl , having trouble coming way solve equation k when padding message zeroes. equation outlined in shs description follows:

append bit “1” end of message, followed k 0 bits, k smallest, non-negative solution equation l + 1 + k ≡ 448mod512.

i've seen equation k = 448 - (l mod 512 + 1) works if l mod 512 less or equal 448, if larger negative number k. understand in case need append "1", pad "0"s until hit 512, , pad 448 more zeroes followed 64 bit binary representation of message length.

a similar question asked here answered example:

well, if l = 448 (say), solution equation in spec gives k = 511

i understand 511 came from, can't figure out how can change equation number. using equation above results in k = -1. realize add 512 resultant k in case k negative, , me right answer. however, i'd know if there single line equation can avoid having check that.

thanks!

i realized can add 512 rhs of equation , mod entire thing 512 such:

k = (512 + 448 - (l mod 512 + 1)) mod 512

this takes care of negative answer.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -