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