mirror of
https://github.com/golang/go
synced 2024-10-04 15:11:20 -06:00
crypto/aes: use asm for BenchmarkExpand on amd64
This reverses the change to this benchmark made in 9b6bf20
.
Change-Id: I79ab88286c3028d3be561957140375bbc413e7ab
Reviewed-on: https://go-review.googlesource.com/22340
Run-TryBot: Michael Munday <munday@ca.ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Minux Ma <minux@golang.org>
This commit is contained in:
parent
5833d843de
commit
babd5da61f
@ -380,6 +380,6 @@ func BenchmarkExpand(b *testing.B) {
|
||||
c := &aesCipher{make([]uint32, n), make([]uint32, n)}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
expandKeyGo(tt.key, c.enc, c.dec)
|
||||
expandKey(tt.key, c.enc, c.dec)
|
||||
}
|
||||
}
|
||||
|
@ -64,3 +64,20 @@ func (c *aesCipherAsm) Decrypt(dst, src []byte) {
|
||||
}
|
||||
decryptBlockAsm(len(c.dec)/4-1, &c.dec[0], &dst[0], &src[0])
|
||||
}
|
||||
|
||||
// expandKey is used by BenchmarkExpand to ensure that the asm implementation
|
||||
// of key expansion is used for the benchmark when it is available.
|
||||
func expandKey(key []byte, enc, dec []uint32) {
|
||||
if useAsm {
|
||||
rounds := 10 // rounds needed for AES128
|
||||
switch len(key) {
|
||||
case 192 / 8:
|
||||
rounds = 12
|
||||
case 256 / 8:
|
||||
rounds = 14
|
||||
}
|
||||
expandKeyAsm(rounds, &key[0], &enc[0], &dec[0])
|
||||
} else {
|
||||
expandKeyGo(key, enc, dec)
|
||||
}
|
||||
}
|
||||
|
@ -18,3 +18,9 @@ import (
|
||||
func newCipher(key []byte) (cipher.Block, error) {
|
||||
return newCipherGeneric(key)
|
||||
}
|
||||
|
||||
// expandKey is used by BenchmarkExpand and should
|
||||
// call an assembly implementation if one is available.
|
||||
func expandKey(key []byte, enc, dec []uint32) {
|
||||
expandKeyGo(key, enc, dec)
|
||||
}
|
||||
|
@ -82,3 +82,9 @@ func (c *aesCipherAsm) Decrypt(dst, src []byte) {
|
||||
// The decrypt function code is equal to the function code + 128.
|
||||
cryptBlocks(c.function+128, &c.key[0], &dst[0], &src[0], BlockSize)
|
||||
}
|
||||
|
||||
// expandKey is used by BenchmarkExpand. cipher message (KM) does not need key
|
||||
// expansion so there is no assembly equivalent.
|
||||
func expandKey(key []byte, enc, dec []uint32) {
|
||||
expandKeyGo(key, enc, dec)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user