...
1
2
3
4
5 package aes
6
7 import (
8 "crypto/cipher"
9 "strconv"
10 )
11
12
13 const BlockSize = 16
14
15
16 type aesCipher struct {
17 enc []uint32
18 dec []uint32
19 }
20
21 type KeySizeError int
22
23 func (k KeySizeError) Error() string {
24 return "crypto/aes: invalid key size " + strconv.Itoa(int(k))
25 }
26
27
28
29
30
31 func NewCipher(key []byte) (cipher.Block, error) {
32 k := len(key)
33 switch k {
34 default:
35 return nil, KeySizeError(k)
36 case 16, 24, 32:
37 break
38 }
39 return newCipher(key)
40 }
41
42
43
44 func newCipherGeneric(key []byte) (cipher.Block, error) {
45 n := len(key) + 28
46 c := aesCipher{make([]uint32, n), make([]uint32, n)}
47 expandKeyGo(key, c.enc, c.dec)
48 return &c, nil
49 }
50
51 func (c *aesCipher) BlockSize() int { return BlockSize }
52
53 func (c *aesCipher) Encrypt(dst, src []byte) {
54 if len(src) < BlockSize {
55 panic("crypto/aes: input not full block")
56 }
57 if len(dst) < BlockSize {
58 panic("crypto/aes: output not full block")
59 }
60 encryptBlockGo(c.enc, dst, src)
61 }
62
63 func (c *aesCipher) Decrypt(dst, src []byte) {
64 if len(src) < BlockSize {
65 panic("crypto/aes: input not full block")
66 }
67 if len(dst) < BlockSize {
68 panic("crypto/aes: output not full block")
69 }
70 decryptBlockGo(c.dec, dst, src)
71 }
72
View as plain text