PR c++/86342 - -Wdeprecated-copy and system headers.
[official-gcc.git] / libgo / go / crypto / aes / cipher_amd64.go
blobfbd157e49e7d4423924472fcb8500164e434428e
1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // +build ignore
7 package aes
9 import (
10 "crypto/cipher"
11 "crypto/internal/cipherhw"
14 // defined in asm_amd64.s
15 func encryptBlockAsm(nr int, xk *uint32, dst, src *byte)
16 func decryptBlockAsm(nr int, xk *uint32, dst, src *byte)
17 func expandKeyAsm(nr int, key *byte, enc *uint32, dec *uint32)
19 type aesCipherAsm struct {
20 aesCipher
23 var useAsm = cipherhw.AESGCMSupport()
25 func newCipher(key []byte) (cipher.Block, error) {
26 if !useAsm {
27 return newCipherGeneric(key)
29 n := len(key) + 28
30 c := aesCipherAsm{aesCipher{make([]uint32, n), make([]uint32, n)}}
31 rounds := 10
32 switch len(key) {
33 case 128 / 8:
34 rounds = 10
35 case 192 / 8:
36 rounds = 12
37 case 256 / 8:
38 rounds = 14
40 expandKeyAsm(rounds, &key[0], &c.enc[0], &c.dec[0])
41 if hasGCMAsm() {
42 return &aesCipherGCM{c}, nil
45 return &c, nil
48 func (c *aesCipherAsm) BlockSize() int { return BlockSize }
50 func (c *aesCipherAsm) Encrypt(dst, src []byte) {
51 if len(src) < BlockSize {
52 panic("crypto/aes: input not full block")
54 if len(dst) < BlockSize {
55 panic("crypto/aes: output not full block")
57 encryptBlockAsm(len(c.enc)/4-1, &c.enc[0], &dst[0], &src[0])
60 func (c *aesCipherAsm) Decrypt(dst, src []byte) {
61 if len(src) < BlockSize {
62 panic("crypto/aes: input not full block")
64 if len(dst) < BlockSize {
65 panic("crypto/aes: output not full block")
67 decryptBlockAsm(len(c.dec)/4-1, &c.dec[0], &dst[0], &src[0])
70 // expandKey is used by BenchmarkExpand to ensure that the asm implementation
71 // of key expansion is used for the benchmark when it is available.
72 func expandKey(key []byte, enc, dec []uint32) {
73 if useAsm {
74 rounds := 10 // rounds needed for AES128
75 switch len(key) {
76 case 192 / 8:
77 rounds = 12
78 case 256 / 8:
79 rounds = 14
81 expandKeyAsm(rounds, &key[0], &enc[0], &dec[0])
82 } else {
83 expandKeyGo(key, enc, dec)