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.
9 "crypto/internal/boring"
13 // 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 {
23 func newCipher(key []byte) (cipher.Block, error) {
25 return newCipherGeneric(key)
28 c := aesCipherAsm{aesCipher{make([]uint32, n), make([]uint32, n)}}
39 expandKeyAsm(rounds, &key[0], &c.enc[0], &c.dec[0])
40 if cpu.X86.HasAES && cpu.X86.HasPCLMULQDQ {
41 return &aesCipherGCM{c}, nil
47 func (c *aesCipherAsm) BlockSize() int { return BlockSize }
49 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) {
62 if len(src) < BlockSize {
63 panic("crypto/aes: input not full block")
65 if len(dst) < BlockSize {
66 panic("crypto/aes: output not full block")
68 decryptBlockAsm(len(c.dec)/4-1, &c.dec[0], &dst[0], &src[0])
71 // expandKey is used by BenchmarkExpand to ensure that the asm implementation
72 // of key expansion is used for the benchmark when it is available.
73 func expandKey(key []byte, enc, dec []uint32) {
75 rounds := 10 // rounds needed for AES128
82 expandKeyAsm(rounds, &key[0], &enc[0], &dec[0])
84 expandKeyGo(key, enc, dec)