The GOST hash function, defined in the standards GOST R 34.11-94 and GOST 34.311-95 is a 256-bit cryptographic hash function. It was initially defined in the Russian national standard GOST R 34.11-94 Information Technology – Cryptographic Information Security – Hash Function. The equivalent standard used by other member-states of the CIS is GOST 34.311-95. This function must not be confused with a different Streebog hash function, which is defined in the new revision of the standard GOST R 34.11-2012. The GOST hash function is based on the GOST block cipher.
Algorithm 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.
Basic notation The algorithm descriptions uses the following notation:
𝒻0ℊj — j-bit block filled with zeroes. 𝒿M𝒿 — length of the M block in bits modulo 2256. 𝓀 — concatenation of two blocks. + — arithmetic sum of two blocks modulo 2256. ⊕ — logical xor of two blocks. Further we consider that the little-order bit is located at the left of a block, and the high-order bit at the right.
Description The input message M is split into 256-bit blocks mn,mn−1,mn−2,…,m1. In the case the last block mn 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 Hout=f(Hin,m), where Hout, Hin, m are a 256-bit blocks. Each message block, starting the first one, is processed by the step hash function f, to calculate intermediate hash value
Hi+1=f(Hi,mi) The H1 value can be arbitrary chosen, and usually is 0256. After Hn+1 is calculated, the final hash value is obtained in the following way
Hn+2=f(Hn+1,L), where L — is the length of the message M in bits modulo 2256 h=f(Hn+2,K), where K — is 256-bit control sum of M: m1+m2+m3+…+mn The h is the desired value of the hash function of the message M.
So, the algorithm works as follows.
Initialization: h:=initial — Initial 256-bit value of the hash function, determined by user. Σ:=0 — Control sum L:=0 — Message length Compression function of internal iterations: for i = 1 … n — 1 do the following (while |M|>256): h:=f(h,mi) – apply step hash function L:=L+256 – recalculate message length Σ:=Σ+mi – calculate control sum Compression function of final iteration: L:=L+𝒿mn𝒿 – calculate the full message length in bits mn:=0256−𝒿mn𝒿𝓀mn – pad the last message with zeroes Σ:=Σ+mn – update control sum h:=f(h,mn) – process the last message block h:=f(h,L) – MD – strengthen up by hashing message length h:=f(h,Σ) – hash control sum The output value is h.
Step hash function The step hash function f maps two 256-bit blocks into one: Hout=f(Hin,m). It consist of three parts:
Generating of keys K1,K2,K3,K4 Enciphering transformation Hin using keys K1,K2,K3,K4 Shuffle transformation
Key generation The keys generating algorithm uses:
Two transformations of 256-bit blocks: Transformation A(Y)=A(y4 𝓀 y3 𝓀 y2 𝓀 y1)=(y1⊕y2) 𝓀 y4 𝓀 y3 𝓀 y2, where y1,y2,y3,y4 are 64-bit sub-blocks of Y. Transformation P(Y)=P(y32𝓀y31𝓀…𝓀y1)=yφ(32)𝓀yφ(31)𝓀…𝓀yφ(1), where φ(i+1+4(k−1))=8i+k,i=0,…,3,k=1,…,8, and y32,y31,…,y1 are 8-bit sub-blocks of Y. Three constants: C2 = 0 C3 = 0xff00ffff000000ffff0000ff00ffff0000ff00ff00ff00ffff00ff00ff00ff00 C4 = 0 The algorithm:
U:=Hin,V:=m,W:=U ⊕ V,K1=P(W) For j = 2, 3, 4 do the following: U:=A(U)⊕Cj,V:=A(A(V)),W:=U⊕V,Kj=P(W)
Enciphering transformation After the keys generation, the enciphering of Hin is done using GOST 28147-89 in the mode of simple substitution on keys K1,K2,K3,K4. Let's denote the enciphering transformation as E (enciphering 64-bit data using 256-bit key). For enciphering, the Hin is split into four 64-bit blocks: Hin=h4𝓀h3𝓀h2𝓀h1, and each of these blocks is enciphered as:
s1=E(h1,K1) s2=E(h2,K2) s3=E(h3,K3) s4=E(h4,K4) After this, the result blocks are concatenated into one 256-bit block: S=s4𝓀s3𝓀s2𝓀s1.
Shuffle transformation On the last step, the shuffle transformation is applied to Hin, S and m using a linear-feedback shift register. In the result, the intermediate hash value Hout is obtained. First we define the ψ function, doing LFSR on a 256-bit block:
ψ(Y)=ψ(y16𝓀y15𝓀…𝓀y2𝓀y1)=(y1⊕y2⊕y3⊕y4⊕y13⊕y16)𝓀y16𝓀y15𝓀…𝓀y3𝓀y2, where y16,y15,…,y2,y1 are 16-bit sub-blocks of the Y.
The shuffle transformation is Hout=ψ61(Hin⊕ψ(m⊕ψ12(S))), where ψi denotes an i-th power of the ψ function.
Initial values There are two commonly used sets of initial parameters for GOST R 34.11 94. The starting vector for both the sets is
H1 = 0x00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000. Although the GOST R 34.11 94 standard itself doesn't specify the algorithm initial value H1 and S-box of the enciphering transformation E, but uses the following "test parameters" in the samples sections.
"Test parameters" S-box RFC 5831 specifies only these parameters, but RFC 4357 names them as "test parameters" and does not recommend them for use in production applications.
CryptoPro S-box 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.
Cryptanalysis 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).
GOST hash test vectors
Hashes for "test parameters" 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"
GOST("The quick brown fox jumps over the lazy dog") = 77b7fa410c9ac58a25f49bca7d0468c9296529315eaca76bd1a10f376d1f4294
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:
GOST("The quick brown fox jumps over the lazy cog") = a3ebc4daaab78b0be131dab5737a7f67e602670d543521319150d2e14eeec445
Two samples coming from the GOST R 34.11-94 standard:
… excerpt ends here. Continue reading the full article.



