]> Cypherpunks.ru repositories - gogost.git/blobdiff - src/cypherpunks.ru/gogost/gost341194/hash.go
Forbid any later GNU GPL versions autousage
[gogost.git] / src / cypherpunks.ru / gogost / gost341194 / hash.go
index ebbbca5460708d1bd07ee372dfe43b7558f44260..61d506c3f9d3ac6bddbb13fe6989f0185934e31e 100644 (file)
@@ -1,10 +1,9 @@
 // GoGOST -- Pure Go GOST cryptographic functions library
-// Copyright (C) 2015-2016 Sergey Matveev <stargrave@stargrave.org>
+// Copyright (C) 2015-2019 Sergey Matveev <stargrave@stargrave.org>
 //
 // This program is free software: you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
+// the Free Software Foundation, version 3 of the License.
 //
 // This program is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -31,7 +30,7 @@ const (
 )
 
 var (
-       SboxDefault *gost28147.Sbox = &gost28147.GostR3411_94_TestParamSet
+       SboxDefault *gost28147.Sbox = &gost28147.SboxIdGostR341194TestParamSet
 
        c2 [BlockSize]byte = [BlockSize]byte{
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -79,7 +78,7 @@ func (h *Hash) Reset() {
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        }
        h.chk = big.NewInt(0)
-       h.buf = nil
+       h.buf = h.buf[:0]
 }
 
 func (h *Hash) BlockSize() int {
@@ -145,8 +144,7 @@ func (h *Hash) step(hin, m [BlockSize]byte) [BlockSize]byte {
        blockXor(k, u, v)
        k = fP(k)
        blockReverse(k[:], k[:])
-       kk := *k
-       c := gost28147.NewCipher(kk, h.sbox)
+       c := gost28147.NewCipher(k[:], h.sbox)
        s := make([]byte, gost28147.BlockSize)
        c.Encrypt(s, []byte{
                hin[31], hin[30], hin[29], hin[28], hin[27], hin[26], hin[25], hin[24],
@@ -165,7 +163,7 @@ func (h *Hash) step(hin, m [BlockSize]byte) [BlockSize]byte {
        blockXor(k, u, v)
        k = fP(k)
        blockReverse(k[:], k[:])
-       c = gost28147.NewCipher(*k, h.sbox)
+       c = gost28147.NewCipher(k[:], h.sbox)
        c.Encrypt(s, []byte{
                hin[23], hin[22], hin[21], hin[20], hin[19], hin[18], hin[17], hin[16],
        })
@@ -183,7 +181,7 @@ func (h *Hash) step(hin, m [BlockSize]byte) [BlockSize]byte {
        blockXor(k, u, v)
        k = fP(k)
        blockReverse(k[:], k[:])
-       c = gost28147.NewCipher(*k, h.sbox)
+       c = gost28147.NewCipher(k[:], h.sbox)
        c.Encrypt(s, []byte{
                hin[15], hin[14], hin[13], hin[12], hin[11], hin[10], hin[9], hin[8],
        })
@@ -201,7 +199,7 @@ func (h *Hash) step(hin, m [BlockSize]byte) [BlockSize]byte {
        blockXor(k, u, v)
        k = fP(k)
        blockReverse(k[:], k[:])
-       c = gost28147.NewCipher(*k, h.sbox)
+       c = gost28147.NewCipher(k[:], h.sbox)
        c.Encrypt(s, []byte{
                hin[7], hin[6], hin[5], hin[4], hin[3], hin[2], hin[1], hin[0],
        })
@@ -266,5 +264,6 @@ func (h *Hash) Sum(in []byte) []byte {
        chkBytes := chk.Bytes()
        copy(block[BlockSize-len(chkBytes):], chkBytes)
        hsh = h.step(hsh, *block)
+       blockReverse(hsh[:], hsh[:])
        return append(in, hsh[:]...)
 }