diff options
| author | Russ Cox <rsc@golang.org> | 2022-08-05 13:34:29 -0400 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2022-08-17 18:47:33 +0000 |
| commit | 57d05512feebed4fbe1e7a19305c8722a4ac627f (patch) | |
| tree | d76190998eba10aa0750666a99a5ebfa4eb8e35b /src/crypto/cipher/ctr.go | |
| parent | 90466e1ddf0e4305bc56f6eac61a690704e6fab8 (diff) | |
| download | go-57d05512feebed4fbe1e7a19305c8722a4ac627f.tar.xz | |
crypto/subtle: add XORBytes
Export cipher.xorBytes as subtle.XORBytes, for proposal #53021,
to provide fast XOR to cryptography libraries outside crypto/cipher.
Along with the move, implement the alignment check TODO
in xor_generic.go, so that systems with neither unaligned
accesses nor custom assembly can still XOR a word at a time
in word-based algorithms like GCM. This removes the need
for the separate cipher.xorWords.
Fixes #53021.
Change-Id: I58f80a922f1cff671b5ebc6168eb046e702b5a4c
Reviewed-on: https://go-review.googlesource.com/c/go/+/421435
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Diffstat (limited to 'src/crypto/cipher/ctr.go')
| -rw-r--r-- | src/crypto/cipher/ctr.go | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/crypto/cipher/ctr.go b/src/crypto/cipher/ctr.go index 3b8e32a9a4..2b434ef832 100644 --- a/src/crypto/cipher/ctr.go +++ b/src/crypto/cipher/ctr.go @@ -12,7 +12,10 @@ package cipher -import "crypto/internal/alias" +import ( + "crypto/internal/alias" + "crypto/subtle" +) type ctr struct { b Block @@ -83,7 +86,7 @@ func (x *ctr) XORKeyStream(dst, src []byte) { if x.outUsed >= len(x.out)-x.b.BlockSize() { x.refill() } - n := xorBytes(dst, src, x.out[x.outUsed:]) + n := subtle.XORBytes(dst, src, x.out[x.outUsed:]) dst = dst[n:] src = src[n:] x.outUsed += n |
