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. 4 5 // +build amd64 6 7 package aes 8 9 // defined in asm_$GOARCH.s 10 func hasAsm() bool 11 func encryptBlockAsm(nr int, xk *uint32, dst, src *byte) 12 func decryptBlockAsm(nr int, xk *uint32, dst, src *byte) 13 func expandKeyAsm(nr int, key *byte, enc *uint32, dec *uint32) 14 15 var useAsm = hasAsm() 16 17 func encryptBlock(xk []uint32, dst, src []byte) { 18 if useAsm { 19 encryptBlockAsm(len(xk)/4-1, &xk[0], &dst[0], &src[0]) 20 } else { 21 encryptBlockGo(xk, dst, src) 22 } 23 } 24 25 func decryptBlock(xk []uint32, dst, src []byte) { 26 if useAsm { 27 decryptBlockAsm(len(xk)/4-1, &xk[0], &dst[0], &src[0]) 28 } else { 29 decryptBlockGo(xk, dst, src) 30 } 31 } 32 33 func expandKey(key []byte, enc, dec []uint32) { 34 if useAsm { 35 rounds := 10 36 switch len(key) { 37 case 128 / 8: 38 rounds = 10 39 case 192 / 8: 40 rounds = 12 41 case 256 / 8: 42 rounds = 14 43 } 44 expandKeyAsm(rounds, &key[0], &enc[0], &dec[0]) 45 } else { 46 expandKeyGo(key, enc, dec) 47 } 48 } 49