diff options
| author | Michael Munday <munday@ca.ibm.com> | 2016-04-17 21:26:23 -0400 |
|---|---|---|
| committer | Adam Langley <agl@golang.org> | 2016-04-29 21:17:31 +0000 |
| commit | c717675c35cb436bdab62091a6288843aa1c863c (patch) | |
| tree | 8ff59b094b483fac13f4071e78351842cc7295a7 /src/crypto/cipher/ctr.go | |
| parent | 2f8475648a5500830561ea03960a1425e1ff0993 (diff) | |
| download | go-c717675c35cb436bdab62091a6288843aa1c863c.tar.xz | |
crypto/cipher, crypto/aes: add s390x implementation of AES-CTR
This commit adds the new 'ctrAble' interface to the crypto/cipher
package. The role of ctrAble is the same as gcmAble but for CTR
instead of GCM. It allows block ciphers to provide optimized CTR
implementations.
The primary benefit of adding CTR support to the s390x AES
implementation is that it allows us to encrypt the counter values
in bulk, giving the cipher message instruction a larger chunk of
data to work on per invocation.
The xorBytes assembly is necessary because xorBytes becomes a
bottleneck when CTR is done in this way. Hopefully it will be
possible to remove this once s390x has migrated to the ssa
backend.
name old speed new speed delta
AESCTR1K 160MB/s ± 6% 867MB/s ± 0% +442.42% (p=0.000 n=9+10)
Change-Id: I1ae16b0ce0e2641d2bdc7d7eabc94dd35f6e9318
Reviewed-on: https://go-review.googlesource.com/22195
Reviewed-by: Adam Langley <agl@golang.org>
Diffstat (limited to 'src/crypto/cipher/ctr.go')
| -rw-r--r-- | src/crypto/cipher/ctr.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/crypto/cipher/ctr.go b/src/crypto/cipher/ctr.go index 16baa6d17d..75f46cfe51 100644 --- a/src/crypto/cipher/ctr.go +++ b/src/crypto/cipher/ctr.go @@ -21,9 +21,19 @@ type ctr struct { const streamBufferSize = 512 +// ctrAble is an interface implemented by ciphers that have a specific optimized +// implementation of CTR, like crypto/aes. NewCTR will check for this interface +// and return the specific Stream if found. +type ctrAble interface { + NewCTR(iv []byte) Stream +} + // NewCTR returns a Stream which encrypts/decrypts using the given Block in // counter mode. The length of iv must be the same as the Block's block size. func NewCTR(block Block, iv []byte) Stream { + if ctr, ok := block.(ctrAble); ok { + return ctr.NewCTR(iv) + } if len(iv) != block.BlockSize() { panic("cipher.NewCTR: IV length must equal block size") } |
