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.
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 {
23 var useAsm
= cipherhw
.AESGCMSupport()
25 func newCipher(key
[]byte) (cipher
.Block
, error
) {
27 return newCipherGeneric(key
)
30 c
:= aesCipherAsm
{aesCipher
{make([]uint32, n
), make([]uint32, n
)}}
40 expandKeyAsm(rounds
, &key
[0], &c
.enc
[0], &c
.dec
[0])
42 return &aesCipherGCM
{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) {
74 rounds
:= 10 // rounds needed for AES128
81 expandKeyAsm(rounds
, &key
[0], &enc
[0], &dec
[0])
83 expandKeyGo(key
, enc
, dec
)