-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathecb.go
47 lines (36 loc) · 896 Bytes
/
ecb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package seed
import "crypto/cipher"
type ecb struct {
b cipher.Block
blockSize int
}
func newECB(b cipher.Block) *ecb {
return &ecb{
b: b,
blockSize: b.BlockSize(),
}
}
type ecbEncrypter ecb
func newECBEncrypter(b cipher.Block) cipher.BlockMode {
return (*ecbEncrypter)(newECB(b))
}
func (e *ecbEncrypter) BlockSize() int { return e.blockSize }
func (e *ecbEncrypter) CryptBlocks(dst, src []byte) {
for len(src) > 0 {
e.b.Encrypt(dst, src[:e.blockSize])
src = src[e.blockSize:]
dst = dst[e.blockSize:]
}
}
type ecbDecrypter ecb
func NewECBDecrypter(b cipher.Block) cipher.BlockMode {
return (*ecbDecrypter)(newECB(b))
}
func (d *ecbDecrypter) BlockSize() int { return d.blockSize }
func (d *ecbDecrypter) CryptBlocks(dst, src []byte) {
for len(src) > 0 {
d.b.Decrypt(dst, src[:d.blockSize])
src = src[d.blockSize:]
dst = dst[d.blockSize:]
}
}