]> Cypherpunks.ru repositories - gogost.git/blob - gost28147/ecb.go
0c47ec3886ed593c9944796dfe4f65057e9f88f3
[gogost.git] / gost28147 / ecb.go
1 // GoGOST -- Pure Go GOST cryptographic functions library
2 // Copyright (C) 2015-2019 Sergey Matveev <stargrave@stargrave.org>
3 //
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, version 3 of the License.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 package gost28147
17
18 type ECBEncrypter struct {
19         c *Cipher
20 }
21
22 func (c *Cipher) NewECBEncrypter() *ECBEncrypter {
23         e := ECBEncrypter{c}
24         return &e
25 }
26
27 func (e *ECBEncrypter) CryptBlocks(dst, src []byte) {
28         for i := 0; i < len(src); i += BlockSize {
29                 e.c.Encrypt(dst[i:i+BlockSize], src[i:i+BlockSize])
30         }
31 }
32
33 func (e *ECBEncrypter) BlockSize() int {
34         return e.c.BlockSize()
35 }
36
37 type ECBDecrypter struct {
38         c *Cipher
39 }
40
41 func (c *Cipher) NewECBDecrypter() *ECBDecrypter {
42         d := ECBDecrypter{c}
43         return &d
44 }
45
46 func (e *ECBDecrypter) CryptBlocks(dst, src []byte) {
47         for i := 0; i < len(src); i += BlockSize {
48                 e.c.Decrypt(dst[i:i+BlockSize], src[i:i+BlockSize])
49         }
50 }
51
52 func (e *ECBDecrypter) BlockSize() int {
53         return e.c.BlockSize()
54 }