GOST processes a variable-length message into a fixed-length output of 256 bits. The input message is broken up into chunks of 256-bit blocks (eight 32-bit little endian integers); the message is padded by appending as many zeros to it as are required to bring the length of the message up to 256 bits. The remaining bits are filled up with a 256-bit integer arithmetic sum of all previously hashed blocks and then a 256-bit integer representing the length of the original message, in bits.
The algorithm descriptions uses the following notation:
Further we consider that the little-order bit is located at the left of a block, and the high-order bit at the right.
The input message M {\displaystyle M} is split into 256-bit blocks m n , m n − 1 , m n − 2 , … , m 1 {\displaystyle m_{n},\,m_{n-1},\,m_{n-2},\,\ldots ,\,m_{1}} . In the case the last block m n {\displaystyle m_{n}} contains less than 256 bits, it is prepended left by zero bits to achieve the desired length.
Each block is processed by the step hash function H out = f ( H in , m ) {\displaystyle H_{\text{out}}=f(H_{\text{in}},\,m)} , where H out {\displaystyle H_{\text{out}}} , H in {\displaystyle H_{\text{in}}} , m {\displaystyle m} are a 256-bit blocks.
Each message block, starting the first one, is processed by the step hash function f {\displaystyle f} , to calculate intermediate hash value
The H 1 {\displaystyle H_{1}} value can be arbitrary chosen, and usually is 0 256 {\displaystyle 0^{256}} .
After H n + 1 {\displaystyle H_{n+1}} is calculated, the final hash value is obtained in the following way
The h {\displaystyle h} is the desired value of the hash function of the message M.
So, the algorithm works as follows.
The step hash function f {\displaystyle f} maps two 256-bit blocks into one: H out = f ( H in , m ) {\displaystyle H_{\text{out}}=f(H_{\text{in}},\,m)} .
It consist of three parts:
The keys generating algorithm uses:
The algorithm:
After the keys generation, the enciphering of H in {\displaystyle H_{\text{in}}} is done using GOST 28147-89 in the mode of simple substitution on keys K 1 , K 2 , K 3 , K 4 {\displaystyle K_{1},\,K_{2},\,K_{3},\,K_{4}} . Let's denote the enciphering transformation as E (enciphering 64-bit data using 256-bit key). For enciphering, the H in {\displaystyle H_{\text{in}}} is split into four 64-bit blocks: H in = h 4 k h 3 k h 2 k h 1 {\displaystyle H_{\text{in}}=h_{4}{\mathcal {k}}h_{3}{\mathcal {k}}h_{2}{\mathcal {k}}h_{1}} , and each of these blocks is enciphered as:
After this, the result blocks are concatenated into one 256-bit block: S = s 4 k s 3 k s 2 k s 1 {\displaystyle S=s_{4}{\mathcal {k}}s_{3}{\mathcal {k}}s_{2}{\mathcal {k}}s_{1}} .
On the last step, the shuffle transformation is applied to H in {\displaystyle H_{\text{in}}} , S and m using a linear-feedback shift register. In the result, the intermediate hash value H out {\displaystyle H_{\text{out}}} is obtained.
First we define the ψ function, doing LFSR on a 256-bit block:
where y 16 , y 15 , … , y 2 , y 1 {\displaystyle y_{16},y_{15},\ldots ,y_{2},y_{1}} are 16-bit sub-blocks of the Y.
The shuffle transformation is H out = ψ 61 ( H in ⊕ ψ ( m ⊕ ψ 12 ( S ) ) ) {\displaystyle H_{\text{out}}=\psi ^{61}{\mathord {\left(H_{\text{in}}\oplus \psi \left(m\oplus \psi ^{12}(S)\right)\right)}}} , where ψ i {\displaystyle \psi ^{i}} denotes an i-th power of the ψ {\displaystyle \psi } function.
There are two commonly used sets of initial parameters for GOST R 34.11 94. The starting vector for both the sets is
Although the GOST R 34.11 94 standard itself doesn't specify the algorithm initial value H 1 {\displaystyle H_{1}} and S-box of the enciphering transformation E {\displaystyle E} , but uses the following "test parameters" in the samples sections.2
RFC 5831 specifies only these parameters, but RFC 4357 names them as "test parameters" and does not recommend them for use in production applications.
The CryptoPro S-box comes from "production ready" parameter set developed by CryptoPro company, it is also specified as part of RFC 4357, section 11.2.
In 2008, an attack was published that breaks the full-round GOST hash function. The paper presents a collision attack in 2105 time, and first and second preimage attacks in 2192 time (2n time refers to the approximate number of times the algorithm was calculated in the attack).3
The 256-bit (32-byte) GOST hashes are typically represented as 64-digit hexadecimal numbers.
Here are test vectors for the GOST hash with "test parameters"
Even a small change in the message will, with overwhelming probability, result in a completely different hash due to the avalanche effect. For example, changing d to c:
Two samples coming from the GOST R 34.11-94 standard:4
More test vectors:
GOST algorithm with CryptoPro S-box generates different set of hash values.
GOST R 34.11-2012: Streebog Hash Function https://www.streebog.net/ ↩
"GOST R 34.11-94 standard. Information technology. Cryptographic data security. Hashing function. Addition A." 1994. {{cite journal}}: Cite journal requires |journal= (help) http://protect.gost.ru/document.aspx?control=7&id=134550 ↩
Mendel, Florian; Pramstaller, Norbert; Rechberger, Christian; Kontak, Marcin; Szmidt, Janusz (2008). "Cryptanalysis of the GOST Hash Function". In Wagner, David (ed.). Advances in Cryptology – CRYPTO 2008. Lecture Notes in Computer Science. Vol. 5157. Germany: Springer Berlin Heidelberg. pp. 162–178. doi:10.1007/978-3-540-85174-5_10. ISBN 978-3-540-85173-8. 978-3-540-85173-8 ↩