Debian Codegraph @

aes/ecb.go

raw symbols SCIP
1 // Package aes contains provides AES Key Wrap and ECB mode implementations
2 package aes
3
4 import (
5 "crypto/cipher"
6 )
7
8 type ecb struct {
9 b cipher.Block
10 }
11
12 type ecbEncrypter ecb
13 type ecbDecrypter ecb
14
15 // NewECBEncrypter creates BlockMode for AES encryption in ECB mode
16 func NewECBEncrypter(b cipher.Block) cipher.BlockMode {
17 return &ecbEncrypter{b: b}
18 }
19
20 // NewECBDecrypter creates BlockMode for AES decryption in ECB mode
21 func NewECBDecrypter(b cipher.Block) cipher.BlockMode {
22 return &ecbDecrypter{b: b}
23 }
24
25 func (x *ecbEncrypter) BlockSize() int { return x.b.BlockSize() }
26 func (x *ecbDecrypter) BlockSize() int { return x.b.BlockSize() }
27
28 func (x *ecbDecrypter) CryptBlocks(dst, src []byte) {
29 bs := x.BlockSize()
30
31 if len(src)%bs != 0 {
32 panic("ecbDecrypter.CryptBlocks(): input not full blocks")
33 }
34
35 if len(dst) < len(src) {
36 panic("ecbDecrypter.CryptBlocks(): output smaller than input")
37 }
38
39 if len(src) == 0 {
40 return
41 }
42
43 for len(src) > 0 {
44 x.b.Decrypt(dst, src)
45 src = src[bs:]
46 }
47 }
48
49 func (x *ecbEncrypter) CryptBlocks(dst, src []byte) {
50 bs := x.BlockSize()
51
52 if len(src)%bs != 0 {
53 panic("ecbEncrypter.CryptBlocks(): input not full blocks")
54 }
55
56 if len(dst) < len(src) {
57 panic("ecbEncrypter.CryptBlocks(): output smaller than input")
58 }
59
60 if len(src) == 0 {
61 return
62 }
63
64 for len(src) > 0 {
65 x.b.Encrypt(dst, src)
66 src = src[bs:]
67 }
68 }