Source file
src/crypto/aes/cbc_ppc64x.go
1
2
3
4
5
6
7 package aes
8
9 import (
10 "crypto/cipher"
11 "crypto/internal/alias"
12 )
13
14
15 var _ cbcEncAble = (*aesCipherAsm)(nil)
16 var _ cbcDecAble = (*aesCipherAsm)(nil)
17
18 const cbcEncrypt = 1
19 const cbcDecrypt = 0
20
21 type cbc struct {
22 b *aesCipherAsm
23 enc int
24 iv [BlockSize]byte
25 }
26
27 func (b *aesCipherAsm) NewCBCEncrypter(iv []byte) cipher.BlockMode {
28 var c cbc
29 c.b = b
30 c.enc = cbcEncrypt
31 copy(c.iv[:], iv)
32 return &c
33 }
34
35 func (b *aesCipherAsm) NewCBCDecrypter(iv []byte) cipher.BlockMode {
36 var c cbc
37 c.b = b
38 c.enc = cbcDecrypt
39 copy(c.iv[:], iv)
40 return &c
41 }
42
43 func (x *cbc) BlockSize() int { return BlockSize }
44
45
46
47
48 func cryptBlocksChain(src, dst *byte, length int, key *uint32, iv *byte, enc int, nr int)
49
50 func (x *cbc) CryptBlocks(dst, src []byte) {
51 if len(src)%BlockSize != 0 {
52 panic("crypto/cipher: input not full blocks")
53 }
54 if len(dst) < len(src) {
55 panic("crypto/cipher: output smaller than input")
56 }
57 if alias.InexactOverlap(dst[:len(src)], src) {
58 panic("crypto/cipher: invalid buffer overlap")
59 }
60 if len(src) > 0 {
61 if x.enc == cbcEncrypt {
62 cryptBlocksChain(&src[0], &dst[0], len(src), &x.b.enc[0], &x.iv[0], x.enc, int(x.b.l)/4-1)
63 } else {
64 cryptBlocksChain(&src[0], &dst[0], len(src), &x.b.dec[0], &x.iv[0], x.enc, int(x.b.l)/4-1)
65 }
66 }
67 }
68
69 func (x *cbc) SetIV(iv []byte) {
70 if len(iv) != BlockSize {
71 panic("cipher: incorrect length IV")
72 }
73 copy(x.iv[:], iv)
74 }
75
View as plain text