D
D
Danil Tunev2018-02-25 18:00:26
Algorithms
Danil Tunev, 2018-02-25 18:00:26

How to correctly initialize (complete) the input message according to the sha-1 algorithm?

Hello. I'm trying to write a C program that implements this algorithm. I am guided by this page. Everything seems to be clear, but initialization (a verbal description of the addition of an array to 512 bits) does not sound clear, for example, in my case. I calculate the sum of the symbol 'B' (01000010) extracted from the file, i.e. if we talk about bits, then the length is 7? Next, add 1(bit) to the end of the message, and fill with zeros to the end of 512 bits, then insert the length of the original message in bits (in ,big-endian ) into the remaining 64 bits, then the message length should be 512bit and have such a representation in binary form ( 01000011('B'+1=C(67))00000.......0000000111(original message length-7))? What am I doing wrong, what position should the first unit bit be in, and what will happen if the length of the original message is 448 bits? It is also not clear on the page below the pseudo-code has "+" signs, is it an exclusive OR operation modulo 2 ^ 32 or stupid arithmetic addition? And yet, tell me from the pseudocode this operation ((a leftrotate 5)) or ((b leftrotate 30)) to be performed with further assignment to the variable a b, or introduce a couple of new variables so that the original value of a and b remains? I just constantly check with the value that gives sha1sum / the same file and the amounts do not match! or introduce a couple of new variables so that the original value of a and b remains? I just constantly check with the value that gives sha1sum / the same file and the amounts do not match! or introduce a couple of new variables so that the original value of a and b remains? I just constantly check with the value that gives sha1sum / the same file and the amounts do not match!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shamanov, 2018-02-25
@SilenceOfWinter

https://ru.wikipedia.org/wiki/SHA-1 pseudocode available. Why write a bike from scratch? https://tls.mbed.org/source-code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question