Source file
src/crypto/aes/cipher_s390x.go
1
2
3
4
5 package aes
6
7 import (
8 "crypto/cipher"
9 "crypto/internal/subtle"
10 "internal/cpu"
11 )
12
13 type code int
14
15
16 const (
17 aes128 code = 18
18 aes192 = 19
19 aes256 = 20
20 )
21
22 type aesCipherAsm struct {
23 function code
24 key []byte
25 storage [32]byte
26 }
27
28
29
30
31
32 func cryptBlocks(c code, key, dst, src *byte, length int)
33
34 func newCipher(key []byte) (cipher.Block, error) {
35
36
37
38
39 if !(cpu.S390X.HasAES && cpu.S390X.HasAESCBC && cpu.S390X.HasAESCTR && (cpu.S390X.HasGHASH || cpu.S390X.HasAESGCM)) {
40 return newCipherGeneric(key)
41 }
42
43 var function code
44 switch len(key) {
45 case 128 / 8:
46 function = aes128
47 case 192 / 8:
48 function = aes192
49 case 256 / 8:
50 function = aes256
51 default:
52 return nil, KeySizeError(len(key))
53 }
54
55 var c aesCipherAsm
56 c.function = function
57 c.key = c.storage[:len(key)]
58 copy(c.key, key)
59 return &c, nil
60 }
61
62 func (c *aesCipherAsm) BlockSize() int { return BlockSize }
63
64 func (c *aesCipherAsm) Encrypt(dst, src []byte) {
65 if len(src) < BlockSize {
66 panic("crypto/aes: input not full block")
67 }
68 if len(dst) < BlockSize {
69 panic("crypto/aes: output not full block")
70 }
71 if subtle.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
72 panic("crypto/aes: invalid buffer overlap")
73 }
74 cryptBlocks(c.function, &c.key[0], &dst[0], &src[0], BlockSize)
75 }
76
77 func (c *aesCipherAsm) Decrypt(dst, src []byte) {
78 if len(src) < BlockSize {
79 panic("crypto/aes: input not full block")
80 }
81 if len(dst) < BlockSize {
82 panic("crypto/aes: output not full block")
83 }
84 if subtle.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
85 panic("crypto/aes: invalid buffer overlap")
86 }
87
88 cryptBlocks(c.function+128, &c.key[0], &dst[0], &src[0], BlockSize)
89 }
90
91
92
93 func expandKey(key []byte, enc, dec []uint32) {
94 expandKeyGo(key, enc, dec)
95 }
96
View as plain text