aboutsummaryrefslogtreecommitdiff
path: root/src/crypto/cipher
AgeCommit message (Collapse)Author
2019-05-24syscall/js: replace TypedArrayOf with CopyBytesToGo/CopyBytesToJSRichard Musiol
The typed arrays returned by TypedArrayOf were backed by WebAssembly memory. They became invalid each time we grow the WebAssembly memory. This made them very error prone and hard to use correctly. This change removes TypedArrayOf completely and instead introduces CopyBytesToGo and CopyBytesToJS for copying bytes between a byte slice and an Uint8Array. This breaking change is still allowed for the syscall/js package. Fixes #31980. Fixes #31812. Change-Id: I14c76fdd60b48dd517c1593972a56d04965cb272 Reviewed-on: https://go-review.googlesource.com/c/go/+/177537 Run-TryBot: Richard Musiol <neelance@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-05-22all: shorten some testsRuss Cox
Shorten some of the longest tests that run during all.bash. Removes 7r 50u 21s from all.bash. After this change, all.bash is under 5 minutes again on my laptop. For #26473. Change-Id: Ie0460aa935808d65460408feaed210fbaa1d5d79 Reviewed-on: https://go-review.googlesource.com/c/go/+/177559 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-05-02crypto/cipher: disable broken js/wasm test from nodejs v8 to v12 upgradeBrad Fitzpatrick
Updates #31812 Change-Id: Id9898f89205c116009e25033afb5b9026594e80f Reviewed-on: https://go-review.googlesource.com/c/go/+/175099 Reviewed-by: Andrew Bonventre <andybons@golang.org>
2019-03-08crypto/cipher: fix duplicated arguments to bytes.Equal in testIskander Sharipov
Args were duplicated by a mistake. Found using static analysis tools. Change-Id: I2f61e09844bc409b1f687d654767332d93dd39a2 Reviewed-on: https://go-review.googlesource.com/c/go/+/164937 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2018-11-01crypto/cipher: add VSX implementation of xorBytes for ppc64xCarlos Eduardo Seo
This change adds asm implementations of xorBytes for ppc64x that takes advantage of VSX registers and instructions. name old time/op new time/op delta XORBytes/8Bytes-8 16.4ns ± 0% 11.1ns ± 0% -32.32% (p=0.000 n=5+4) XORBytes/128Bytes-8 45.6ns ± 0% 16.2ns ± 0% -64.50% (p=0.008 n=5+5) XORBytes/2048Bytes-8 433ns ±13% 129ns ± 1% -70.29% (p=0.000 n=5+4) XORBytes/32768Bytes-8 7.16µs ± 0% 1.83µs ± 0% -74.39% (p=0.008 n=5+5) name old speed new speed delta XORBytes/8Bytes-8 488MB/s ± 0% 721MB/s ± 0% +47.75% (p=0.016 n=5+4) XORBytes/128Bytes-8 2.80GB/s ± 0% 7.89GB/s ± 0% +181.33% (p=0.008 n=5+5) XORBytes/2048Bytes-8 4.77GB/s ±13% 15.87GB/s ± 0% +232.68% (p=0.016 n=5+4) XORBytes/32768Bytes-8 4.58GB/s ± 0% 17.88GB/s ± 0% +290.47% (p=0.008 n=5+5) Change-Id: Ic27d9b858f8ec2d597fdabc68a288d6844eba701 Reviewed-on: https://go-review.googlesource.com/c/145997 Run-TryBot: Carlos Eduardo Seo <cseo@linux.vnet.ibm.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
2018-10-30crypto/cipher: use SIMD for xor on amd64templexxx
cpu: Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz Benchmark: xor name old time/op new time/op delta XORBytes/8Bytes-8 8.21ns ± 1% 6.35ns ± 3% -22.66% (p=0.008 n=5+5) XORBytes/128Bytes-8 17.9ns ± 1% 10.4ns ± 1% -41.68% (p=0.008 n=5+5) XORBytes/2048Bytes-8 187ns ± 1% 78ns ± 0% -58.44% (p=0.008 n=5+5) XORBytes/32768Bytes-8 2.87µs ± 1% 1.38µs ± 0% -52.05% (p=0.008 n=5+5) name old speed new speed delta XORBytes/8Bytes-8 974MB/s ± 1% 1260MB/s ± 2% +29.33% (p=0.008 n=5+5) XORBytes/128Bytes-8 7.15GB/s ± 0% 12.25GB/s ± 1% +71.17% (p=0.008 n=5+5) XORBytes/2048Bytes-8 10.9GB/s ± 1% 26.4GB/s ± 0% +140.99% (p=0.008 n=5+5) XORBytes/32768Bytes-8 11.4GB/s ± 1% 23.8GB/s ± 0% +108.52% (p=0.008 n=5+5) Benchmark: cipher name old time/op new time/op delta AESGCMSeal1K-8 269ns ± 6% 261ns ± 2% ~ (p=0.246 n=5+5) AESGCMOpen1K-8 242ns ± 1% 240ns ± 2% ~ (p=0.190 n=5+5) AESGCMSign8K-8 869ns ± 0% 870ns ± 1% ~ (p=0.683 n=5+5) AESGCMSeal8K-8 1.64µs ± 6% 1.59µs ± 7% ~ (p=0.151 n=5+5) AESGCMOpen8K-8 1.48µs ± 2% 1.46µs ± 0% -1.39% (p=0.008 n=5+5) AESCFBEncrypt1K-8 1.88µs ± 5% 1.62µs ± 1% -13.52% (p=0.008 n=5+5) AESCFBDecrypt1K-8 1.76µs ± 1% 1.58µs ± 1% -10.24% (p=0.016 n=4+5) AESOFB1K-8 1.10µs ± 4% 1.03µs ± 2% -6.36% (p=0.008 n=5+5) AESCTR1K-8 1.24µs ± 1% 1.17µs ± 0% -5.96% (p=0.008 n=5+5) AESCBCEncrypt1K-8 1.74µs ± 0% 1.14µs ± 1% -34.36% (p=0.008 n=5+5) AESCBCDecrypt1K-8 1.28µs ± 1% 1.10µs ± 1% -14.04% (p=0.008 n=5+5) name old speed new speed delta AESGCMSeal1K-8 3.81GB/s ± 6% 3.91GB/s ± 2% ~ (p=0.310 n=5+5) AESGCMOpen1K-8 4.23GB/s ± 1% 4.27GB/s ± 2% ~ (p=0.222 n=5+5) AESGCMSign8K-8 9.43GB/s ± 0% 9.41GB/s ± 1% ~ (p=0.841 n=5+5) AESGCMSeal8K-8 5.01GB/s ± 6% 5.16GB/s ± 6% ~ (p=0.151 n=5+5) AESGCMOpen8K-8 5.54GB/s ± 2% 5.62GB/s ± 0% +1.41% (p=0.008 n=5+5) AESCFBEncrypt1K-8 543MB/s ± 5% 627MB/s ± 1% +15.55% (p=0.008 n=5+5) AESCFBDecrypt1K-8 580MB/s ± 1% 646MB/s ± 1% +11.40% (p=0.016 n=4+5) AESOFB1K-8 925MB/s ± 4% 988MB/s ± 2% +6.73% (p=0.008 n=5+5) AESCTR1K-8 821MB/s ± 1% 873MB/s ± 1% +6.34% (p=0.008 n=5+5) AESCBCEncrypt1K-8 588MB/s ± 1% 897MB/s ± 1% +52.36% (p=0.008 n=5+5) AESCBCDecrypt1K-8 799MB/s ± 1% 929MB/s ± 1% +16.32% (p=0.008 n=5+5) Change-Id: I42e6ba66c23dad853d33c924fca7b0ed805cefdd Reviewed-on: https://go-review.googlesource.com/c/125316 Reviewed-by: Ilya Tocar <ilya.tocar@intel.com> Run-TryBot: Ilya Tocar <ilya.tocar@intel.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-10-30crypto/cipher: make stream examples runnable in the playgroundYury Smolsky
Updates #9679 Change-Id: I53412cf0142364de5f76e8affc15d607bfa2ad23 Reviewed-on: https://go-review.googlesource.com/c/145838 Run-TryBot: Yury Smolsky <yury@smolsky.by> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
2018-09-25crypto/cipher: 8K benchmarks for AES stream modesMichael McLoughlin
Some parallelizable cipher modes may achieve peak performance for larger block sizes. For this reason the AES-GCM mode already has an 8K benchmark alongside the 1K version. This change introduces 8K benchmarks for additional AES stream cipher modes. Updates #20967 Change-Id: If97c6fbf31222602dcc200f8f418d95908ec1202 Reviewed-on: https://go-review.googlesource.com/136897 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-08-21crypto/{aes,cipher,rand}: use binary.{Big,Little}Endian methodsMichael Munday
Use the binary.{Big,Little}Endian integer encoding methods rather than unsafe or local implementations. These methods are tested to ensure they inline correctly and don't add unnecessary bounds checks, so it seems better to use them wherever possible. This introduces a dependency on encoding/binary to crypto/cipher. I think this is OK because other "L3" packages already import encoding/binary. Change-Id: I5cf01800d08554ca364e46cfc1d9445cf3c711a0 Reviewed-on: https://go-review.googlesource.com/115555 Run-TryBot: Michael Munday <mike.munday@ibm.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-07-20crypto/aes: implement AES-GCM AEAD for arm64Vlad Krasnov
Use the dedicated AES* and PMULL* instructions to accelerate AES-GCM name old time/op new time/op delta AESGCMSeal1K-46 12.1µs ± 0% 0.9µs ± 0% -92.66% (p=0.000 n=9+10) AESGCMOpen1K-46 12.1µs ± 0% 0.9µs ± 0% -92.43% (p=0.000 n=10+10) AESGCMSign8K-46 58.6µs ± 0% 2.1µs ± 0% -96.41% (p=0.000 n=9+8) AESGCMSeal8K-46 92.8µs ± 0% 5.7µs ± 0% -93.86% (p=0.000 n=9+9) AESGCMOpen8K-46 92.9µs ± 0% 5.7µs ± 0% -93.84% (p=0.000 n=8+9) name old speed new speed delta AESGCMSeal1K-46 84.7MB/s ± 0% 1153.4MB/s ± 0% +1262.21% (p=0.000 n=9+10) AESGCMOpen1K-46 84.4MB/s ± 0% 1115.2MB/s ± 0% +1220.53% (p=0.000 n=10+10) AESGCMSign8K-46 140MB/s ± 0% 3894MB/s ± 0% +2687.50% (p=0.000 n=9+10) AESGCMSeal8K-46 88.2MB/s ± 0% 1437.5MB/s ± 0% +1529.30% (p=0.000 n=9+9) AESGCMOpen8K-46 88.2MB/s ± 0% 1430.5MB/s ± 0% +1522.01% (p=0.000 n=8+9) This change mirrors the current amd64 implementation, and provides optimal performance on a range of arm64 processors including Centriq 2400 and Apple A12. By and large it is implicitly tested by the robustness of the already existing amd64 implementation. The implementation interleaves GHASH with CTR mode to achieve the highest possible throughput, it also aggregates GHASH with a factor of 8, to decrease the cost of the reduction step. Even thought there is a significant amount of assembly, the code reuses the go code for the amd64 implementation, so there is little additional go code. Since AES-GCM is critical for performance of all web servers, this change is required to level the playfield for arm64 CPUs, where amd64 currently enjoys an unfair advantage. Ideally both amd64 and arm64 codepaths could be replaced by hypothetical AES and CLMUL intrinsics, with a few additional vector instructions. Fixes #18498 Fixes #19840 Change-Id: Icc57b868cd1f67ac695c1ac163a8e215f74c7910 Reviewed-on: https://go-review.googlesource.com/107298 Run-TryBot: Vlad Krasnov <vlad@cloudflare.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-19crypto: panic on illegal input and output overlapFilippo Valsorda
Normalized all panic checks and added inexact aliasing panics across Stream, Block, BlockMode and AEAD implementations. Also, tweaked the aliasing docs of cipher.AEAD, as they did not account for the append nature of the API. Fixes #21624 Change-Id: I075c4415f59b3c06e3099bd9f76de6d12af086bf Reviewed-on: https://go-review.googlesource.com/109697 Run-TryBot: Filippo Valsorda <filippo@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-07crypto/cipher: replace NewGCMWithNonceAndTagSize with NewGCMWithTagSize212472270
This function was added during the Go 1.11 dev cycle and isn't part of the API compatibility promise yet. In the previous implementation, NewGCMWithNonceAndTagSize was being used as a helper function for NewGCM, NewGCMWithTagSize, and NewGCMWithNonceSize. With the removal of Nonce size from the name and parameters, we needed to add an unexported helper function newGCMWithNonceAndTagSize. Fixes #24977 Change-Id: Ie70f2a192d0556c4f890deb62e68cff6bbbccd33 Reviewed-on: https://go-review.googlesource.com/116435 Reviewed-by: Filippo Valsorda <filippo@golang.org> Run-TryBot: Filippo Valsorda <filippo@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-06-01all: update comment URLs from HTTP to HTTPS, where possibleTim Cooper
Each URL was manually verified to ensure it did not serve up incorrect content. Change-Id: I4dc846227af95a73ee9a3074d0c379ff0fa955df Reviewed-on: https://go-review.googlesource.com/115798 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org>
2018-05-08cmd/compile,test: combine byte loads and stores on ppc64leLynn Boger
CL 74410 added rules to combine consecutive byte loads and stores when the byte order was little endian for ppc64le. This is the corresponding change for bytes that are in big endian order. These rules are all intended for a little endian target arch. This adds new testcases in test/codegen/memcombine.go Fixes #22496 Updates #24242 Benchmark improvement for encoding/binary: name old time/op new time/op delta ReadSlice1000Int32s-16 11.0µs ± 0% 9.0µs ± 0% -17.47% (p=0.029 n=4+4) ReadStruct-16 2.47µs ± 1% 2.48µs ± 0% +0.67% (p=0.114 n=4+4) ReadInts-16 642ns ± 1% 630ns ± 1% -2.02% (p=0.029 n=4+4) WriteInts-16 654ns ± 0% 653ns ± 1% -0.08% (p=0.629 n=4+4) WriteSlice1000Int32s-16 8.75µs ± 0% 8.20µs ± 0% -6.19% (p=0.029 n=4+4) PutUint16-16 1.16ns ± 0% 0.93ns ± 0% -19.83% (p=0.029 n=4+4) PutUint32-16 1.16ns ± 0% 0.93ns ± 0% -19.83% (p=0.029 n=4+4) PutUint64-16 1.85ns ± 0% 0.93ns ± 0% -49.73% (p=0.029 n=4+4) LittleEndianPutUint16-16 1.03ns ± 0% 0.93ns ± 0% -9.71% (p=0.029 n=4+4) LittleEndianPutUint32-16 0.93ns ± 0% 0.93ns ± 0% ~ (all equal) LittleEndianPutUint64-16 0.93ns ± 0% 0.93ns ± 0% ~ (all equal) PutUvarint32-16 43.0ns ± 0% 43.1ns ± 0% +0.12% (p=0.429 n=4+4) PutUvarint64-16 174ns ± 0% 175ns ± 0% +0.29% (p=0.429 n=4+4) Updates made to functions in gcm.go to enable their matching. An existing testcase prevents these functions from being replaced by those in encoding/binary due to import dependencies. Change-Id: Idb3bd1e6e7b12d86cd828fb29cb095848a3e485a Reviewed-on: https://go-review.googlesource.com/98136 Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2018-02-14crypto/cipher: add NewGCMWithNonceAndTagSize for custom tag sizes.Conrado Gouvea
GCM allows using tag sizes smaller than the block size. This adds a NewGCMWithNonceAndTagSize function which allows specifying the tag size. Fixes #19594 Change-Id: Ib2008c6f13ad6d916638b1523c0ded8a80eaf42d Reviewed-on: https://go-review.googlesource.com/48510 Reviewed-by: Filippo Valsorda <hi@filippo.io> Run-TryBot: Filippo Valsorda <hi@filippo.io> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-11-16crypto/cipher: use raw bytes for keys in docsKevin Burke
Using ASCII values for keys is a bad idea since it makes them vastly easier to guess. Instead, use the same method as the examples in the golang.org/x/crypto/nacl package to load keys from a hex value. Changing the key required updating the ciphertext in many of the examples. I am still worried about the fact the examples ask the user to authenticate messages; authentication isn't trivial, and to be honest it may be better to steer people to a higher level primitive like secretbox, unless people really need AES. Fixes #21012. Change-Id: I8d918cf194694cd380b06c2d561178167ca61adb Reviewed-on: https://go-review.googlesource.com/48596 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-10-31crypto/cipher, crypto/rc4: make overlap rules wording consistentFilippo Valsorda
Closes #21279 Change-Id: I84d6b168a684fa9f3c046028d0c9f00292d7c110 Reviewed-on: https://go-review.googlesource.com/61132 Reviewed-by: Adam Langley <agl@golang.org> Run-TryBot: Adam Langley <agl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-09-06crypto/cipher: panic when IV length does not equal block size in NewOFBJoe Kyo
Functions like NewCBCDecrypter, NewCBCEncrypter, NewCFBDecrypter, NewCFBEncrypter and NewCTR all panic when IV length does not equal block size. This commit changes NewOFB to panic too, instead of returning nil silently. Change-Id: Ic4d3ebfad79bb0cf4759fa1c1a400c1a8d043490 Reviewed-on: https://go-review.googlesource.com/61850 Reviewed-by: Filippo Valsorda <hi@filippo.io> Run-TryBot: Filippo Valsorda <hi@filippo.io> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-09-01crypto/cipher: extend the docs of BlockMode and StreamFilippo Valsorda
Change-Id: Iebb5b67c8defec22edd482d587edaf399a7ba82a Reviewed-on: https://go-review.googlesource.com/37418 Reviewed-by: Adam Langley <agl@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-08-29all: join some chained ifs to unindent codeDaniel Martí
Found with mvdan.cc/unindent. It skipped the cases where parentheses would need to be added, where comments would have to be moved elsewhere, or where actions and simple logic would mix. One of them was of the form "err != nil && err == io.EOF", so the first part was removed. Change-Id: Ie504c2b03a2c87d10ecbca1b9270069be1171b91 Reviewed-on: https://go-review.googlesource.com/57690 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-08-18crypto/aes: make the GHASH part of AES-GCM fasterVlad Krasnov
By processing 8 blocks in parallel GHASH achieves higher throughput on amd64 Results on Skylake i7: benchmark old ns/op new ns/op delta BenchmarkAESGCMSeal1K-8 316 314 -0.63% BenchmarkAESGCMOpen1K-8 282 281 -0.35% BenchmarkAESGCMSign8K-8 5611 1099 -80.41% BenchmarkAESGCMSeal8K-8 1869 1922 +2.84% BenchmarkAESGCMOpen8K-8 1718 1724 +0.35% benchmark old MB/s new MB/s speedup BenchmarkAESGCMSeal1K-8 3237.10 3260.94 1.01x BenchmarkAESGCMOpen1K-8 3629.74 3638.10 1.00x BenchmarkAESGCMSign8K-8 1459.82 7452.99 5.11x BenchmarkAESGCMSeal8K-8 4382.45 4260.93 0.97x BenchmarkAESGCMOpen8K-8 4766.41 4750.54 1.00x Change-Id: I479f2a791a968caa1c516115b0b6b96a791a20d2 Reviewed-on: https://go-review.googlesource.com/57150 Reviewed-by: Adam Langley <agl@golang.org>
2017-08-09crypto/{aes,cipher,rc4}: fix out of bounds write in stream ciphersWei Congrui
Functions XORKeyStream should panic if len(dst) < len(src), but it write to dst before bounds checking. In asm routines and fastXORBytes, this is an out of bounds write. Fixes #21104 Change-Id: I354346cda8d63910f3bb619416ffd54cd0a04a0b Reviewed-on: https://go-review.googlesource.com/52050 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-12-08all: make spelling consistentBrad Fitzpatrick
Fixes #17938 Change-Id: Iad12155f4976846bd4a9a53869f89e40e5b3deb3 Reviewed-on: https://go-review.googlesource.com/34147 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2016-12-07crypto/*: document use or non-use of constant-time algorithmsRuss Cox
Fixes #16821. Change-Id: I63d5f3d7cfba1c76259912d754025c5f3cbe4a56 Reviewed-on: https://go-review.googlesource.com/31573 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-10-13crypto/{aes,cipher}: fix panic in CBC on s390x when src length is 0Michael Munday
Adds a test to check that block cipher modes accept a zero-length input. Fixes #17435. Change-Id: Ie093c4cdff756b5c2dcb79342e167b3de5622389 Reviewed-on: https://go-review.googlesource.com/31070 Run-TryBot: Michael Munday <munday@ca.ibm.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-10-05crypto/{aes,cipher}: add optimized implementation of AES-GCM for s390xMichael Munday
Also adds two tests: one to exercise the counter incrementing code and one which checks the output of the optimized implementation against that of the generic implementation for large/unaligned data sizes. Uses the KIMD instruction for GHASH and the KMCTR instruction for AES in counter mode. AESGCMSeal1K 75.0MB/s ± 2% 1008.7MB/s ± 1% +1245.71% (p=0.000 n=10+10) AESGCMOpen1K 75.3MB/s ± 1% 1006.0MB/s ± 1% +1235.59% (p=0.000 n=10+9) AESGCMSeal8K 78.5MB/s ± 1% 1748.4MB/s ± 1% +2127.34% (p=0.000 n=9+10) AESGCMOpen8K 78.5MB/s ± 0% 1752.7MB/s ± 0% +2134.07% (p=0.000 n=10+9) Change-Id: I88dbcfcb5988104bfd290ae15a60a2721c1338be Reviewed-on: https://go-review.googlesource.com/30361 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-09-02crypto/cipher: enforce message size limits for GCM.Adam Langley
The maximum input plaintext for GCM is 64GiB - 64. Since the GCM interface is one-shot, it's very hard to hit this in Go (one would need a 64GiB buffer in memory), but we should still enforce this limit. Thanks to Quan Nguyen for pointing it out. Change-Id: Icced47bf8d4d5dfbefa165cf13e893205c9577b8 Reviewed-on: https://go-review.googlesource.com/28410 Run-TryBot: Adam Langley <agl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Andrew Gerrand <adg@golang.org>
2016-08-16crypto/cipher, math/big: fix example namesJosh Bleecher Snyder
Fixes (legit) vet warnings. Fix some verb tenses while we're here. Updates #11041 Change-Id: I27e995f55b38f4cf584e97a67b8545e8247e83d6 Reviewed-on: https://go-review.googlesource.com/27122 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-05-09crypto/cipher: execute AES-GCM decryption exampleTilman Dilo
The decryption example for AES-GCM was not executed, hiding the fact that the provided ciphertext could not be authenticated. This commit adds the required output comment, replaces the ciphertext with a working example, and removes an unnecessary string conversion along the way. Change-Id: Ie6729ca76cf4a56c48b33fb3b39872105faa604b Reviewed-on: https://go-review.googlesource.com/22953 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-04-29crypto/cipher, crypto/aes: add s390x implementation of AES-CTRMichael Munday
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>
2016-04-29crypto/cipher, crypto/aes: add s390x implementation of AES-CBCMichael Munday
This commit adds the cbcEncAble and cbcDecAble interfaces that can be implemented by block ciphers that support an optimized implementation of CBC. This is similar to what is done for GCM with the gcmAble interface. The cbcEncAble, cbcDecAble and gcmAble interfaces all now have tests to ensure they are detected correctly in the cipher package. name old speed new speed delta AESCBCEncrypt1K 152MB/s ± 1% 1362MB/s ± 0% +795.59% (p=0.000 n=10+9) AESCBCDecrypt1K 143MB/s ± 1% 1362MB/s ± 0% +853.00% (p=0.000 n=10+9) Change-Id: I715f686ab3686b189a3dac02f86001178fa60580 Reviewed-on: https://go-review.googlesource.com/22523 Run-TryBot: Michael Munday <munday@ca.ibm.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Adam Langley <agl@golang.org>
2016-04-14crypto/cipher: enable fastXORBytes on s390xMichael Munday
s390x can handle unaligned loads and stores of 64-bit values. Change-Id: Iae5621781e3ba56e27b4a1f4788772c86e4f6475 Reviewed-on: https://go-review.googlesource.com/22086 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-04-01all: use bytes.Equal, bytes.Contains and strings.ContainsDominik Honnef
Change-Id: Iba82a5bd3846f7ab038cc10ec72ff6bcd2c0b484 Reviewed-on: https://go-review.googlesource.com/21377 Run-TryBot: Dave Cheney <dave@cheney.net> Reviewed-by: Dave Cheney <dave@cheney.net>
2016-03-05crypto/cipher: xorBytes performance ppc64le/ppc64Lynn Boger
Update supportsUnaligned in xor.go to be true for GOARCH values ppc64le and ppc64. This allows the xor of long buffers to be done on double words (8 bytes) instead of a single byte at a time, which significantly improves performance. Fixes #14350 Change-Id: Iccc6b9d3df2e604a55f4c1e4890bdd3bb0d77ab0 Reviewed-on: https://go-review.googlesource.com/19519 Reviewed-by: Minux Ma <minux@golang.org>
2016-03-02all: single space after period.Brad Fitzpatrick
The tree's pretty inconsistent about single space vs double space after a period in documentation. Make it consistently a single space, per earlier decisions. This means contributors won't be confused by misleading precedence. This CL doesn't use go/doc to parse. It only addresses // comments. It was generated with: $ perl -i -npe 's,^(\s*// .+[a-z]\.) +([A-Z]),$1 $2,' $(git grep -l -E '^\s*//(.+\.) +([A-Z])') $ go test go/doc -update Change-Id: Iccdb99c37c797ef1f804a94b22ba5ee4b500c4f7 Reviewed-on: https://go-review.googlesource.com/20022 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Dave Day <djd@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-01all: make copyright headers consistent with one space after periodBrad Fitzpatrick
This is a subset of https://golang.org/cl/20022 with only the copyright header lines, so the next CL will be smaller and more reviewable. Go policy has been single space after periods in comments for some time. The copyright header template at: https://golang.org/doc/contribute.html#copyright also uses a single space. Make them all consistent. Change-Id: Icc26c6b8495c3820da6b171ca96a74701b4a01b0 Reviewed-on: https://go-review.googlesource.com/20111 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-01-26crypto/cipher: Add AES-GCM encryption and decryption exampleKevin Kirsche
Add example of how to use the aes package to implement AES encryption and decryption within an application. Per feedback, use more secure AES-GCM implementation as an example in crypto/cipher instead of AES directly. Change-Id: I84453ebb18e0bc79344a24171a031ec0d7ccec2e Reviewed-on: https://go-review.googlesource.com/18803 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2016-01-10crypto/cipher: always zero dst buffer on GCM authentication failure.Adam Langley
The AESNI GCM code decrypts and authenticates concurrently and so overwrites the destination buffer even in the case of an authentication failure. This change updates the documentation to make that clear and also mimics that behaviour in the generic code so that different platforms act identically. Fixes #13886 Change-Id: Idc54e51f01e27b0fc60c1745d50bb4c099d37e94 Reviewed-on: https://go-review.googlesource.com/18480 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Adam Langley <agl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-12-22crypto/cipher: fix typo from last changeRob Pike
s/encrypt/decrypt/ The text is unsafe to cut and paste... Change-Id: Iab19ddf8182d087e9a4b4d34a9eeabd1d2aa02d6 Reviewed-on: https://go-review.googlesource.com/18104 Reviewed-by: Rob Pike <r@golang.org>
2015-12-22crypto/cipher: improve documentation for AEADRob Pike
Give a link to the wikipedia page describing the mechanism and explain better how to use the same buffer for input and output. Change-Id: If6dfd6cf9c6dff0517cb715f60a11349dbdd91e0 Reviewed-on: https://go-review.googlesource.com/18103 Reviewed-by: Russ Cox <rsc@golang.org>
2015-10-20crypto/cipher: fix CTR infinite loop with large block sizesCaleb Spare
Additionally, add a test for CTR mode to cover a range of block sizes. Fixes #12975 Change-Id: I458aac1616228747e62f92f823768d55e874877a Reviewed-on: https://go-review.googlesource.com/16050 Reviewed-by: Adam Langley <agl@golang.org>
2015-08-29crypto/aes: dedicated asm version of AES-GCMVlad Krasnov
The existing implementation didn't use the CLMUL instructions for fast and constant time binary-field multiplication. With this change, amd64 CPUs that support both AES and CLMUL instructions will use an optimised asm implementation. benchmark old ns/op new ns/op delta BenchmarkAESGCMSeal8K 91723 3200 -96.51% BenchmarkAESGCMOpen8K 91487 3324 -96.37% BenchmarkAESGCMSeal1K 11873 546 -95.40% BenchmarkAESGCMOpen1K 11833 594 -94.98% benchmark old MB/s new MB/s speedup BenchmarkAESGCMSeal8K 89.31 2559.62 28.66x BenchmarkAESGCMOpen8K 89.54 2463.78 27.52x BenchmarkAESGCMSeal1K 86.24 1872.49 21.71x BenchmarkAESGCMOpen1K 86.53 1721.78 19.90x Change-Id: Idd63233098356d8b353d16624747b74d0c3f193e Reviewed-on: https://go-review.googlesource.com/10484 TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Adam Langley <agl@golang.org>
2015-06-09crypto/cipher: Support unusual GCM nonce lengthsCarl Jackson
GCM is traditionally used with a 96-bit nonce, but the standard allows for nonces of any size. Non-standard nonce sizes are required in some protocols, so add support for them in crypto/cipher's GCM implementation. Change-Id: I7feca7e903eeba557dcce370412b6ffabf1207ab Reviewed-on: https://go-review.googlesource.com/8946 Reviewed-by: Adam Langley <agl@golang.org> Run-TryBot: Adam Langley <agl@golang.org>
2014-12-26crypto/cipher: update docs for the Stream interfaceShenghou Ma
Specify what will happen if len(dst) != len(src). Change-Id: I66afa3730f637753b825189687418f14ddec3629 Reviewed-on: https://go-review.googlesource.com/1754 Reviewed-by: Adam Langley <agl@golang.org>
2014-09-08build: move package sources from src/pkg to srcRuss Cox
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.