1 // GoGOST -- Pure Go GOST cryptographic functions library
2 // Copyright (C) 2015-2019 Sergey Matveev <stargrave@stargrave.org>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // GOST 34.12-2015 64-bit (Магма (Magma)) block cipher.
21 "cypherpunks.ru/gogost/gost28147"
34 func NewCipher(key [KeySize]byte) *Cipher {
35 keyCompatible := new([KeySize]byte)
36 for i := 0; i < KeySize/4; i++ {
37 keyCompatible[i*4+0] = key[i*4+3]
38 keyCompatible[i*4+1] = key[i*4+2]
39 keyCompatible[i*4+2] = key[i*4+1]
40 keyCompatible[i*4+3] = key[i*4+0]
43 c: gost28147.NewCipher(
45 &gost28147.SboxIdtc26gost28147paramZ,
47 blk: new([BlockSize]byte),
51 func (c *Cipher) BlockSize() int {
55 func (c *Cipher) Encrypt(dst, src []byte) {
64 c.c.Encrypt(c.blk[:], c.blk[:])
75 func (c *Cipher) Decrypt(dst, src []byte) {
84 c.c.Decrypt(c.blk[:], c.blk[:])