aboutsummaryrefslogtreecommitdiff
path: root/src/crypto
AgeCommit message (Collapse)Author
2021-07-12[release-branch.go1.16] crypto/tls: test key type when castingRoland Shoemaker
When casting the certificate public key in generateClientKeyExchange, check the type is appropriate. This prevents a panic when a server agrees to a RSA based key exchange, but then sends an ECDSA (or other) certificate. Updates #47143 Fixes #47145 Fixes CVE-2021-34558 Thanks to Imre Rad for reporting this issue. Change-Id: Iabccacca6052769a605cccefa1216a9f7b7f6aea Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1116723 Reviewed-by: Filippo Valsorda <valsorda@google.com> Reviewed-by: Katie Hockman <katiehockman@google.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/334029 Trust: Filippo Valsorda <filippo@golang.org> Run-TryBot: Filippo Valsorda <filippo@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
2021-01-27crypto/x509: remove leftover CertificateRequest fieldRoland Shoemaker
Removes the KeyUsage field that was missed in the rollback in CL 281235. Also updates CreateCertificateRequest to reflect that these fields were removed. For #43407. Updates #43477. Updates #37172. Change-Id: I6244aed4a3ef3c2460c38af5511e5c2e82546179 Reviewed-on: https://go-review.googlesource.com/c/go/+/287392 Trust: Alexander Rakoczy <alex@golang.org> Trust: Roland Shoemaker <roland@golang.org> Trust: Dmitri Shuralyov <dmitshur@golang.org> Run-TryBot: Alexander Rakoczy <alex@golang.org> Reviewed-by: Alexander Rakoczy <alex@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
2021-01-21crypto/elliptic: fix P-224 field reductionFilippo Valsorda
This patch fixes two independent bugs in p224Contract, the function that performs the final complete reduction in the P-224 field. Incorrect outputs due to these bugs were observable from a high-level P224().ScalarMult() call. The first bug was in the calculation of out3GT. That mask was supposed to be all ones if the third limb of the value is greater than the third limb of P (out[3] > 0xffff000). Instead, it was also set if they are equal. That meant that if the third limb was equal, the value was always considered greater than or equal to P, even when the three bottom limbs were all zero. There is exactly one affected value, P - 1, which would trigger the subtraction by P even if it's lower than P already. The second bug was more easily hit, and is the one that caused the known high-level incorrect output: after the conditional subtraction by P, a potential underflow of the lowest limb was not handled. Any values that trigger the subtraction by P (values between P and 2^224-1, and P - 1 due to the bug above) but have a zero lowest limb would produce invalid outputs. Those conditions apply to the intermediate representation before the subtraction, so they are hard to trace to precise inputs. This patch also adds a test suite for the P-224 field arithmetic, including a custom fuzzer that automatically explores potential edge cases by combining limb values that have various meanings in the code. contractMatchesBigInt in TestP224Contract finds the second bug in less than a second without being tailored to it, and could eventually find the first one too by combining 0, (1 << 28) - 1, and the difference of (1 << 28) and (1 << 12). The incorrect P224().ScalarMult() output was found by the elliptic-curve-differential-fuzzer project running on OSS-Fuzz and reported by Philippe Antoine (Catena cyber). Fixes CVE-2021-3114 Fixes #43786 Change-Id: I50176602d544de3da854270d66a293bcaca57ad7 Reviewed-on: https://go-review.googlesource.com/c/go/+/284779 Run-TryBot: Roland Shoemaker <roland@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Ian Lance Taylor <iant@golang.org> Trust: Roland Shoemaker <roland@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
2021-01-15syscall: remove RtlGenRandom and move it into internal/syscallJason A. Donenfeld
There's on need to expose this to the frozen syscall package, and it also doesn't need to be unsafe. So we move it into internal/syscall and have the generator make a safer function signature. Fixes #43704. Change-Id: Iccae69dc273a0aa97ee6846eb537f1dc1412f2de Reviewed-on: https://go-review.googlesource.com/c/go/+/283992 Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Trust: Jason A. Donenfeld <Jason@zx2c4.com>
2021-01-15crypto/x509: update iOS bundled roots to version 55188.40.9Filippo Valsorda
Updates #38843 Change-Id: If76844e1caf23f98d814de89f77610de59d96a34 Reviewed-on: https://go-review.googlesource.com/c/go/+/284134 Trust: Filippo Valsorda <filippo@golang.org> Run-TryBot: Filippo Valsorda <filippo@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2021-01-06crypto/x509: rollback new CertificateRequest fieldsFilippo Valsorda
In general, we don't want to encourage reading them from CSRs, and applications that really want to can parse the Extensions field. Note that this also fixes a bug where the error of parseKeyUsageExtension was not handled in parseCertificateRequest. Fixes #43477 Updates #37172 Change-Id: Ia5707b0e23cecc0aed57e419a1ca25e26eea6bbe Reviewed-on: https://go-review.googlesource.com/c/go/+/281235 Trust: Filippo Valsorda <filippo@golang.org> Run-TryBot: Filippo Valsorda <filippo@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org>
2020-12-17crypto/tls: revert "add HandshakeContext method to Conn"Johan Brandhorst
This reverts CL 246338. Reason for revert: waiting for 1.17 release cycle Updates #32406 Change-Id: I074379039041e086c62271d689b4b7f442281663 Reviewed-on: https://go-review.googlesource.com/c/go/+/269697 Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Run-TryBot: Katie Hockman <katie@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Katie Hockman <katie@golang.org> Trust: Katie Hockman <katie@golang.org> Trust: Roland Shoemaker <roland@golang.org>
2020-12-09all: update to use os.ReadDir where appropriateRuss Cox
os.ReadDir is a replacement for ioutil.ReadDir that returns a slice of fs.DirEntry instead of fs.FileInfo, meaning it is the more efficient form. This CL updates call sites throughout the Go source tree wherever possible. As usual, code built using the Go 1.4 bootstrap toolchain is not included. There is also a use in go/build that appears in the public API and can't be changed, at least not without additional changes. Fixes #42026. Change-Id: Icfc9dd52c6045020f6830e22c72128499462d561 Reviewed-on: https://go-review.googlesource.com/c/go/+/266366 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-12-09all: update to use os.ReadFile, os.WriteFile, os.CreateTemp, os.MkdirTempRuss Cox
As part of #42026, these helpers from io/ioutil were moved to os. (ioutil.TempFile and TempDir became os.CreateTemp and MkdirTemp.) Update the Go tree to use the preferred names. As usual, code compiled with the Go 1.4 bootstrap toolchain and code vendored from other sources is excluded. ReadDir changes are in a separate CL, because they are not a simple search and replace. For #42026. Change-Id: If318df0216d57e95ea0c4093b89f65e5b0ababb3 Reviewed-on: https://go-review.googlesource.com/c/go/+/266365 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-12-02crypto/ed25519/internal/edwards25519: fix typo in commentsFilippo Valsorda
Change-Id: I8133762d53d9e5d3cc13e0f97b9679a3248a7f0f Reviewed-on: https://go-review.googlesource.com/c/go/+/273087 Trust: Filippo Valsorda <filippo@golang.org> Reviewed-by: Katie Hockman <katie@golang.org>
2020-11-10crypto/tls: de-prioritize AES-GCM ciphers when lacking hardware supportRoland Shoemaker
When either the server or client are lacking hardware support for AES-GCM ciphers, indicated by the server lacking the relevant instructions and by the client not putting AES-GCM ciphers at the top of its preference list, reorder the preference list to de-prioritize AES-GCM based ciphers when they are adjacent to other AEAD ciphers. Also updates a number of recorded openssl TLS tests which previously only specified TLS 1.2 cipher preferences (using -cipher), but not TLS 1.3 cipher preferences (using -ciphersuites), to specify both preferences, making these tests more predictable. Fixes #41181. Change-Id: Ied896c96c095481e755aaff9ff0746fb4cb9568e Reviewed-on: https://go-review.googlesource.com/c/go/+/262857 Run-TryBot: Roland Shoemaker <roland@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org> Trust: Roland Shoemaker <roland@golang.org> Trust: Katie Hockman <katie@golang.org>
2020-11-09crypto/x509: drop the cgo implementation of root_darwin_amd64.goFilippo Valsorda
This code was preserved just to do side-by-side testing while transitioning to the Go implementation. There haven't been mismatch issues, so drop the cgo code, which was making it hard to improve the Go code without diverging. Change-Id: I2a23039c31a46e88b94250aafbc98d4ea8daf22f Reviewed-on: https://go-review.googlesource.com/c/go/+/232397 Run-TryBot: Filippo Valsorda <filippo@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Filippo Valsorda <filippo@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-11-09crypto/tls: ensure the server picked an advertised ALPN protocolFilippo Valsorda
This is a SHALL in RFC 7301, Section 3.2. Also some more cleanup after NPN, which worked the other way around (with the possibility that the client could pick a protocol the server did not suggest). Change-Id: I83cc43ca1b3c686dfece8315436441c077065d82 Reviewed-on: https://go-review.googlesource.com/c/go/+/239748 Run-TryBot: Filippo Valsorda <filippo@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Filippo Valsorda <filippo@golang.org> Trust: Roland Shoemaker <roland@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org>
2020-11-09crypto/tls: drop macFunction abstractionFilippo Valsorda
Since we dropped SSLv3, there is only one MAC scheme, and it doesn't need any state beyond a keyed HMAC, so we can replace the macFunction with the hash.Hash it wraps. Pointed out by mtp@. Change-Id: I5545be0e6ccb34a3055fad7f6cb5f628ff748e9f Reviewed-on: https://go-review.googlesource.com/c/go/+/251859 Run-TryBot: Filippo Valsorda <filippo@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org> Trust: Roland Shoemaker <roland@golang.org> Trust: Filippo Valsorda <filippo@golang.org>
2020-11-09crypto/tls: add HandshakeContext method to ConnJohan Brandhorst
Adds the (*tls.Conn).HandshakeContext method. This allows us to pass the context provided down the call stack to eventually reach the tls.ClientHelloInfo and tls.CertificateRequestInfo structs. These contexts are exposed to the user as read-only via Context() methods. This allows users of (*tls.Config).GetCertificate and (*tls.Config).GetClientCertificate to use the context for request scoped parameters and cancellation. Replace uses of (*tls.Conn).Handshake with (*tls.Conn).HandshakeContext where appropriate, to propagate existing contexts. Fixes #32406 Change-Id: I33c228904fe82dcf57683b63627497d3eb841ff2 Reviewed-on: https://go-review.googlesource.com/c/go/+/246338 Run-TryBot: Filippo Valsorda <filippo@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Roland Shoemaker <roland@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-11-09crypto/x509: return additional chains from Verify on WindowsKoen
Previously windows only returned the certificate-chain with the highest quality. This change makes it so chains with a potentially lower quality originating from other root certificates are also returned by verify. Tests in verify_test flagged with systemLax are now allowed to pass if the system returns additional chains Fixes #40604 Change-Id: I66edc233219f581039d47a15f2200ff627154691 Reviewed-on: https://go-review.googlesource.com/c/go/+/257257 Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Filippo Valsorda <filippo@golang.org> Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org>
2020-11-09crypto/x509: add additional convenience fields to CertificateRequestRoland Shoemaker
Adds the following additional convenience fields to CertificateRequest: * KeyUsage * ExtKeyUsage * UnknownExtKeyUsage * IsCA * MaxPathLen * BasicConstraintsValid * MaxPathLenZero * SubjectKeyId * PolicyIdentifier These fields are parsed during ParseCertificateRequest and marshalled during CreateCertificateRequest. The parsing/marshalling code is factored out of parseCertificate and buildExtensions (which is renamed buildCertExtensions). This has the side effect of making these methods somewhat easier to read. Documentation for the fields is copied from Certificate. Example CSR created with all of these fields parsed with openssl: $ openssl req -in ~/test-csr.pem -noout -text Certificate Request: Data: Version: 0 (0x0) Subject: Subject Public Key Info: Public Key Algorithm: id-ecPublicKey Public-Key: (256 bit) pub: 04:a4:cb:64:35:8e:dd:8c:2b:a6:f1:aa:39:d1:be: d0:b9:95:1e:59:19:82:76:28:d3:85:1b:c6:88:62: e1:15:33:be:26:18:80:14:fe:f4:d4:91:66:4e:a4: a4:47:bd:53:db:f7:2e:e3:31:ce:5f:86:cb:92:59: 93:bb:d0:7f:a2 ASN1 OID: prime256v1 NIST CURVE: P-256 Attributes: Requested Extensions: X509v3 Key Usage: critical Certificate Sign X509v3 Extended Key Usage: Any Extended Key Usage, 1.2.3 X509v3 Basic Constraints: critical CA:TRUE, pathlen:0 X509v3 Subject Key Identifier: 01:02:03 X509v3 Certificate Policies: Policy: 1.2.3 Signature Algorithm: ecdsa-with-SHA256 30:45:02:21:00:a7:88:e5:96:d4:ad:ae:24:26:ab:5f:15:6a: 3f:22:6d:0e:a6:ba:15:64:8d:78:34:f4:c4:7d:ac:37:b0:2a: 84:02:20:68:44:f0:8e:8a:1b:c1:68:be:14:a6:e3:83:41:fd: 2d:cc:00:aa:bc:50:f6:50:56:12:9e:a4:09:84:5c:bf:c1 Fixes #37172 Change-Id: Ife79d01e203827ef0ac3c787aa13c00d0751a1ec Reviewed-on: https://go-review.googlesource.com/c/go/+/233163 Run-TryBot: Roland Shoemaker <roland@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org> Trust: Katie Hockman <katie@golang.org> Trust: Roland Shoemaker <roland@golang.org>
2020-11-09crypto/x509: update iOS bundled roots to version 55161.140.3Filippo Valsorda
Extended the sorting logic to be stable even when there are two roots with the same name and notBefore timestamp, like the GlobalSign ones. Updates #38843 Change-Id: Ie4db0bb8b6a8b5ffbb7390b6bd527fc0c3badaca Reviewed-on: https://go-review.googlesource.com/c/go/+/266677 Reviewed-by: Katie Hockman <katie@golang.org> Trust: Filippo Valsorda <filippo@golang.org>
2020-11-09crypto/tls: don't use CN in BuildNameToCertificate if SANs are presentFilippo Valsorda
Change-Id: I18d5b9fc392a6a52fbdd240254d6d9db838073a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/266540 Trust: Filippo Valsorda <filippo@golang.org> Run-TryBot: Filippo Valsorda <filippo@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Katie Hockman <katie@golang.org>
2020-11-09crypto/x509: use fingerprint map for (*CertPool).containsFilippo Valsorda
This fell through the cracks from the CL 229917 comments. Change-Id: I22584107f1e8111f9c523f45307dd50e1e5f4b8f Reviewed-on: https://go-review.googlesource.com/c/go/+/268339 Trust: Filippo Valsorda <filippo@golang.org> Run-TryBot: Filippo Valsorda <filippo@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-11-09crypto/tls: pool Conn's outBuf to reduce memory cost of idle connectionscch123
Derived from CL 263277, which includes benchmarks. Fixes #42035 Co-authored-by: Filippo Valsorda <filippo@golang.org> Change-Id: I5f28673f95d4568b7d13dbc20e9d4b48d481a93d Reviewed-on: https://go-review.googlesource.com/c/go/+/267957 Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Filippo Valsorda <filippo@golang.org> Trust: Roland Shoemaker <roland@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org> Reviewed-by: Roberto Clapis <roberto@golang.org>
2020-11-07crypto/x509: keep smaller root cert representation in memory until neededBrad Fitzpatrick
Instead of parsing the PEM files and then storing the *Certificate values forever, still parse them to see if they're valid and pick out some fields, but then only store the decoded pem.Block.Bytes until that cert is first needed. Saves about 500K of memory on my (Debian stable) machine after doing a tls.Dial or calling x509.SystemCertPool. A more aggressive version of this is still possible: we can not keep the pem.Block.Bytes in memory either, and re-read them from disk when necessary. But dealing with files disappearing and even large multi-cert PEM files changing (with offsets sliding around) made this conservative version attractive. It doesn't change the slurp-roots-on-startup semantics. It just does so with less memory retained. Change-Id: I3aea333f4749ae3b0026042ec3ff7ac015c72204 Reviewed-on: https://go-review.googlesource.com/c/go/+/230025 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Roland Shoemaker <roland@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-11-07crypto/x509: add support for CertPool to load certs lazilyBrad Fitzpatrick
This will allow building CertPools that consume less memory. (Most certs are never accessed. Different users/programs access different ones, but not many.) This CL only adds the new internal mechanism (and uses it for the old AddCert) but does not modify any existing root pool behavior. (That is, the default Unix roots are still all slurped into memory as of this CL) Change-Id: Ib3a42e4050627b5e34413c595d8ced839c7bfa14 Reviewed-on: https://go-review.googlesource.com/c/go/+/229917 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Brad Fitzpatrick <bradfitz@golang.org> Trust: Roland Shoemaker <roland@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org>
2020-11-07crypto/cipher: use Neon for xor on arm64Meng Zhuo
cpu: HiSilicon(R) Kirin 970 2.4GHz name old time/op new time/op delta XORBytes/8Bytes 39.8ns ± 0% 17.3ns ± 0% -56.53% (p=0.000 n=10+10) XORBytes/128Bytes 376ns ± 0% 28ns ± 0% -92.63% (p=0.000 n=10+8) XORBytes/2048Bytes 5.67µs ± 0% 0.22µs ± 0% -96.03% (p=0.000 n=10+10) XORBytes/32768Bytes 90.3µs ± 0% 3.5µs ± 0% -96.12% (p=0.000 n=10+10) AESGCMSeal1K 853ns ± 0% 853ns ± 0% ~ (all equal) AESGCMOpen1K 876ns ± 0% 874ns ± 0% -0.23% (p=0.000 n=10+10) AESGCMSign8K 3.09µs ± 0% 3.08µs ± 0% -0.34% (p=0.000 n=10+9) AESGCMSeal8K 5.87µs ± 0% 5.87µs ± 0% +0.01% (p=0.008 n=10+8) AESGCMOpen8K 5.82µs ± 0% 5.82µs ± 0% +0.02% (p=0.037 n=10+10) AESCFBEncrypt1K 7.05µs ± 0% 4.27µs ± 0% -39.38% (p=0.000 n=10+10) AESCFBDecrypt1K 7.12µs ± 0% 4.30µs ± 0% -39.54% (p=0.000 n=10+9) AESCFBDecrypt8K 56.7µs ± 0% 34.1µs ± 0% -39.82% (p=0.000 n=10+10) AESOFB1K 5.20µs ± 0% 2.54µs ± 0% -51.07% (p=0.000 n=10+10) AESCTR1K 4.96µs ± 0% 2.30µs ± 0% -53.62% (p=0.000 n=9+10) AESCTR8K 39.5µs ± 0% 18.2µs ± 0% -53.98% (p=0.000 n=8+10) AESCBCEncrypt1K 5.81µs ± 0% 3.07µs ± 0% -47.13% (p=0.000 n=10+8) AESCBCDecrypt1K 5.83µs ± 0% 3.10µs ± 0% -46.84% (p=0.000 n=10+8) name old speed new speed delta XORBytes/8Bytes 201MB/s ± 0% 461MB/s ± 0% +129.80% (p=0.000 n=6+10) XORBytes/128Bytes 340MB/s ± 0% 4625MB/s ± 0% +1259.91% (p=0.000 n=8+10) XORBytes/2048Bytes 361MB/s ± 0% 9088MB/s ± 0% +2414.23% (p=0.000 n=8+10) XORBytes/32768Bytes 363MB/s ± 0% 9350MB/s ± 0% +2477.44% (p=0.000 n=10+10) AESGCMSeal1K 1.20GB/s ± 0% 1.20GB/s ± 0% -0.02% (p=0.041 n=10+10) AESGCMOpen1K 1.17GB/s ± 0% 1.17GB/s ± 0% +0.20% (p=0.000 n=10+10) AESGCMSign8K 2.65GB/s ± 0% 2.66GB/s ± 0% +0.35% (p=0.000 n=10+9) AESGCMSeal8K 1.40GB/s ± 0% 1.40GB/s ± 0% -0.01% (p=0.000 n=10+7) AESGCMOpen8K 1.41GB/s ± 0% 1.41GB/s ± 0% -0.03% (p=0.022 n=10+10) AESCFBEncrypt1K 145MB/s ± 0% 238MB/s ± 0% +64.95% (p=0.000 n=10+10) AESCFBDecrypt1K 143MB/s ± 0% 237MB/s ± 0% +65.39% (p=0.000 n=10+9) AESCFBDecrypt8K 144MB/s ± 0% 240MB/s ± 0% +66.15% (p=0.000 n=10+10) AESOFB1K 196MB/s ± 0% 401MB/s ± 0% +104.35% (p=0.000 n=9+10) AESCTR1K 205MB/s ± 0% 443MB/s ± 0% +115.57% (p=0.000 n=7+10) AESCTR8K 207MB/s ± 0% 450MB/s ± 0% +117.27% (p=0.000 n=10+10) AESCBCEncrypt1K 176MB/s ± 0% 334MB/s ± 0% +89.15% (p=0.000 n=10+8) AESCBCDecrypt1K 176MB/s ± 0% 330MB/s ± 0% +88.08% (p=0.000 n=10+9) Updates #42010 Change-Id: I75e6d66fd0070e184d93b020c55a7580c713647c Reviewed-on: https://go-review.googlesource.com/c/go/+/142537 Reviewed-by: Meng Zhuo <mzh@golangcn.org> Reviewed-by: Filippo Valsorda <filippo@golang.org> Run-TryBot: Meng Zhuo <mzh@golangcn.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Meng Zhuo <mzh@golangcn.org>
2020-11-07crypto/tls: set Deadline before sending close notify alertKatie Hockman
This change also documents the need to set a Deadline before calling Read or Write. Fixes #31224 Change-Id: I89d6fe3ecb0a0076b4c61765f61c88056f951406 Reviewed-on: https://go-review.googlesource.com/c/go/+/266037 Trust: Katie Hockman <katie@golang.org> Run-TryBot: Katie Hockman <katie@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-11-06crypto/x509: add Unwrap to SystemRootsErrorPantelis Sampaziotis
This change modifies Go to add the Unwrap method to SystemRootsError Updates #30322 Change-Id: Ibe63d1d0bc832fc0607f09053908d55275a6f350 GitHub-Last-Rev: 9a95bc66019d25f02a0a5f92a87e9405a52802e4 GitHub-Pull-Request: golang/go#41981 Reviewed-on: https://go-review.googlesource.com/c/go/+/262343 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Filippo Valsorda <filippo@golang.org> Trust: Damien Neil <dneil@google.com> Run-TryBot: Filippo Valsorda <filippo@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
2020-10-29crypto/x509: add comment to blank imports done for init side effectsBrad Fitzpatrick
To educate future readers. Change-Id: I1ef79178b6997cc96ca066c91b9fec822478674b Reviewed-on: https://go-review.googlesource.com/c/go/+/266301 Reviewed-by: Katie Hockman <katie@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Katie Hockman <katie@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2020-10-29Revert "crypto/x509: fix duplicate import"Katie Hockman
This reverts CL 250497. It also moves all blank identifier imports below the rest of the imports for clarity. Reason for revert: The blank identifier import was intentional to show that it's needed for its registration side effect. The duplicate import should stay since it communicates that the side-effect is important to tools and to future developers updating this file. Change-Id: I626e6329db50f47453aa71085a05d21bf6efe0ac Reviewed-on: https://go-review.googlesource.com/c/go/+/265078 Run-TryBot: Katie Hockman <katie@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com> Trust: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-10-27crypto/tls: document the ClientAuthType constsRoland Shoemaker
Fixes #34023 Change-Id: Ib7552a8873a79a91e8d971f906c6d7283da7a80c Reviewed-on: https://go-review.googlesource.com/c/go/+/264027 Trust: Roland Shoemaker <roland@golang.org> Reviewed-by: Katie Hockman <katie@golang.org>
2020-10-27crypto/rand: generate random numbers using RtlGenRandom on WindowsJason A. Donenfeld
CryptGenRandom appears to be unfavorable these days, whereas the classic RtlGenRandom is still going strong. This commit also moves the warnBlocked function into rand_unix, rather than rand, because it's now only used on unix. Fixes #33542 Change-Id: I5c02a5917572f54079d627972401efb6e1ce4057 Reviewed-on: https://go-review.googlesource.com/c/go/+/210057 Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org> Trust: Jason A. Donenfeld <Jason@zx2c4.com>
2020-10-24crypto/x509: deprecate legacy PEM encryptionFilippo Valsorda
It's unfortunate that we don't implement PKCS#8 encryption (#8860) so we can't recommend an alternative but PEM encryption is so broken that it's worth deprecating outright. Fixes #41949 Fixes #32777 Change-Id: Ieb46444662adec108d0de3550b693a50545c2344 Reviewed-on: https://go-review.googlesource.com/c/go/+/264159 Trust: Filippo Valsorda <filippo@golang.org> Trust: Roland Shoemaker <roland@golang.org> Run-TryBot: Filippo Valsorda <filippo@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org>
2020-10-24crypto/tls: add no-shared to openssl build instructionsThom Wiggers
This prevents the custom-built version of openssl prefering the system libraries over the ones compiled with the specified (weak crypto) options necessary to generate the updates. This difference can lead to confusing failures when updating the tests. Fixes #31809 Change-Id: I2dd257f3121d6c6c62c6aeba52e1c74046b3c584 GitHub-Last-Rev: 6d4eeafadf0b4671b7e17c6810f1a66a9fda7d3c GitHub-Pull-Request: golang/go#41630 Reviewed-on: https://go-review.googlesource.com/c/go/+/257517 Trust: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-10-21crypto/x509: bypass signature verification in CreateCertificate when using ↵Roland Shoemaker
MD5WithRSA Bypasses the signature verification check we previously added if the signature algorithm is MD5WithRSA, as we only support this algorithm for signing and not verification. Change-Id: Idba6dbba8b365d6199d467526746b88a5f734af1 Reviewed-on: https://go-review.googlesource.com/c/go/+/264019 Run-TryBot: Roland Shoemaker <roland@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org> Trust: Roland Shoemaker <roland@golang.org>
2020-10-20all: update references to symbols moved from io/ioutil to ioRuss Cox
The old ioutil references are still valid, but update our code to reflect best practices and get used to the new locations. Code compiled with the bootstrap toolchain (cmd/asm, cmd/dist, cmd/compile, debug/elf) must remain Go 1.4-compatible and is excluded. Also excluded vendored code. For #41190. Change-Id: I6d86f2bf7bc37a9d904b6cee3fe0c7af6d94d5b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/263142 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-10-20all: update references to symbols moved from os to io/fsRuss Cox
The old os references are still valid, but update our code to reflect best practices and get used to the new locations. Code compiled with the bootstrap toolchain (cmd/asm, cmd/dist, cmd/compile, debug/elf) must remain Go 1.4-compatible and is excluded. For #41190. Change-Id: I8f9526977867c10a221e2f392f78d7dec073f1bd Reviewed-on: https://go-review.googlesource.com/c/go/+/243907 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-10-19crypto/hmac: panic if reusing hash.Hash valuesKatie Hockman
Also put Reset in the correct place for the other benchmarks. name old time/op new time/op delta NewWriteSum-8 1.01µs ± 0% 1.01µs ± 1% ~ (p=0.945 n=9+9) name old speed new speed delta NewWriteSum-8 31.7MB/s ± 0% 31.6MB/s ± 1% ~ (p=0.948 n=9+9) name old alloc/op new alloc/op delta NewWriteSum-8 544B ± 0% 544B ± 0% ~ (all equal) name old allocs/op new allocs/op delta NewWriteSum-8 7.00 ± 0% 7.00 ± 0% ~ (all equal) Fixes #41089 Change-Id: I3dae660adbe4993963130bf3c2636bd53899164b Reviewed-on: https://go-review.googlesource.com/c/go/+/261960 Trust: Katie Hockman <katie@golang.org> Trust: Roland Shoemaker <roland@golang.org> Run-TryBot: Katie Hockman <katie@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org>
2020-10-14crypto/x509: add signature verification to CreateCertificateRoland Shoemaker
This changes checks the signature generated during CreateCertificate and returns an error if the verification fails. A benchmark is also added. For RSA keys the delta looks to be insignificant, but for ECDSA keys it introduces a much larger delta which is not ideal. name old time/op new time/op delta RSA_2048-8 1.38ms ± 6% 1.41ms ± 2% ~ (p=0.182 n=10) ECDSA_P256-8 42.6µs ± 4% 116.8µs ± 4% +174.00% (p=0.000 n=1 Fixes #40458 Change-Id: I22827795bb9bb6868b4fa47391927db1d3bc19a1 Reviewed-on: https://go-review.googlesource.com/c/go/+/259697 Run-TryBot: Roland Shoemaker <roland@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org> Trust: Emmanuel Odeke <emm.odeke@gmail.com> Trust: Roland Shoemaker <roland@golang.org>
2020-10-07crypto/x509: use macOS/AMD64 implementation on macOS/ARM64Cherry Zhang
Updates #38485. Change-Id: I0582a53171ce803ca1b0237cfa9bc022fc1da6f9 Reviewed-on: https://go-review.googlesource.com/c/go/+/260340 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-10-06crypto/tls: fix typo in spelling of permanentErrorLuca Spiller
Change-Id: I819c121ff388460ec348af773ef94b44416a2ea9 GitHub-Last-Rev: 98dd8fb25cecb73e88d107e0a35e3e63a53dfd09 GitHub-Pull-Request: golang/go#41785 Reviewed-on: https://go-review.googlesource.com/c/go/+/259517 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Filippo Valsorda <filippo@golang.org> Trust: Emmanuel Odeke <emm.odeke@gmail.com>
2020-10-02crypto/dsa,crypto/x509: deprecate DSA and remove crypto/x509 supportFilippo Valsorda
Updates #40337 Change-Id: I5c1218df3ae7e13144a1d9f7d4a4b456e4475c0a Reviewed-on: https://go-review.googlesource.com/c/go/+/257939 Trust: Filippo Valsorda <filippo@golang.org> Trust: Roland Shoemaker <roland@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org> Reviewed-by: Katie Hockman <katie@golang.org>
2020-09-30crypto/x509: enforce SAN IA5String encoding restrictionsRoland Shoemaker
Extends the IA5String encoding restrictions that are currently applied to name constraints to dNSName, rfc822Name, and uniformResourceIdentifier elements of the SAN. The utility function isIA5String is updated to use unicode.MaxASCII rather than utf8.RuneSelf as it is somewhat more readable. Certificates that include these badly encoded names do exist, but are exceedingly rare. zlint and other linters enforce this encoding and searching censys.io reveals only three currently trusted certificates with this particular encoding issue. Fixes #26362 Change-Id: I7a4f3e165a1754e5b4bfaeabc03e01eb7367f3c9 Reviewed-on: https://go-review.googlesource.com/c/go/+/235078 Run-TryBot: Roland Shoemaker <roland@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Roland Shoemaker <roland@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-09-30crypto/x509: return errors instead of panickingPaschalis Tsilias
Eliminate a panic in x509.CreateCertificate when passing templates with unknown ExtKeyUsage; return an error instead. Fixes #41169 Change-Id: Ia229d3b0d4a1bdeef05928439d97dab228687b3c Reviewed-on: https://go-review.googlesource.com/c/go/+/252557 Reviewed-by: Roland Shoemaker <roland@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org> Run-TryBot: Roland Shoemaker <roland@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
2020-09-30crypto/ecdsa: use FillBytes on s390xRuixin Bao
Originally, zeroExtendAndCopy is used to pad src with leading zeros and copy the padded src into the destination. It is no longer needed after CL 230397 introduced FillBytes. We can simply use that and remove the zeroExtendAndCopy function. It is cleaner and reduces some allocation. In addition, this patch tries to avoid calling hashToInt function in both Sign and Verify function so some allocation is reduced. Benchmarks: name old alloc/op new alloc/op delta SignP256-8 1.60kB ± 0% 1.49kB ± 0% -7.23% (p=0.000 n=20+20) SignP384-8 1.74kB ± 0% 1.59kB ± 0% -8.50% (p=0.000 n=20+18) VerifyP256-8 176B ± 0% 0B -100.00% (p=0.000 n=20+20) KeyGeneration-8 640B ± 0% 640B ± 0% ~ (all equal) name old allocs/op new allocs/op delta SignP256-8 22.0 ± 0% 17.0 ± 0% -22.73% (p=0.000 n=20+20) SignP384-8 22.0 ± 0% 17.0 ± 0% -22.73% (p=0.000 n=20+20) VerifyP256-8 7.00 ± 0% 0.00 -100.00% (p=0.000 n=20+20) KeyGeneration-8 13.0 ± 0% 13.0 ± 0% ~ (all equal) Change-Id: Ic4c95191eded55deb3420d97db501689f3b173c9 Reviewed-on: https://go-review.googlesource.com/c/go/+/232297 Reviewed-by: Michael Munday <mike.munday@ibm.com> Run-TryBot: Michael Munday <mike.munday@ibm.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Filippo Valsorda <filippo@golang.org>
2020-09-29crypto/x509: prioritize potential parents in chain buildingRoland Shoemaker
When building a x509 chain the algorithm currently looks for parents that have a subject key identifier (SKID) that matches the child authority key identifier (AKID), if it is present, and returns all matches. If the child doesn't have an AKID, or there are no parents with matching SKID it will instead return all parents that have a subject DN matching the child's issuer DN. Prioritizing AKID/SKID matches over issuer/subject matches means that later in buildChains we have to throw away any pairs where these DNs do not match. This also prevents validation when a child has a SKID with two possible parents, one with matching AKID but mismatching subject DN, and one with a matching subject but missing AKID. In this case the former will be chosen and the latter ignored, meaning a valid chain cannot be built. This change alters how possible parents are chosen. Instead of doing a two step search it instead only consults the CertPool.byName subject DN map, avoiding issues where possible parents may be shadowed by parents that have SKID but bad subject DNs. Additionally it orders the list of possible parents by the likelihood that they are in fact a match. This ordering follows this pattern: * AKID and SKID match * AKID present, SKID missing / AKID missing, SKID present * AKID and SKID don't match In an ideal world this should save a handful of cycles when there are multiple possible matching parents by prioritizing parents that have the highest likelihood. This does diverge from past behavior in that it also means there are cases where _more_ parents will be considered than in the past. Another version of this change could just retain the past behavior, and only consider parents where both the subject and issuer DNs match, and if both parent and child have SKID and AKID also compare those, without any prioritization of the candidate parents. This change removes an existing test case as it assumes that the CertPool will return a possible candidate where the issuer/subject DNs do not match. Fixes #30079 Change-Id: I629f579cabb0b3d0c8cae5ad0429cc5a536b3e58 Reviewed-on: https://go-review.googlesource.com/c/go/+/232993 Trust: Roland Shoemaker <roland@golang.org> Run-TryBot: Roland Shoemaker <roland@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-09-29crypto/tls: fix TestLinkerGC testCherry Zhang
A test that checks if "tls.(*Conn)" appears in any symbol's name. tls.Conn is a type, so the string "tls.(*Conn)" can only appear in the name of a method of Conn. But the test code doesn't use any of the methods. Not sure why this needs to be live. In particular, the linker is now able to prune all methods of Conn. Remove this requirement. In fact, just drop the only_conn test case, as simply allocating a type doesn't necessarily bring anything live. Change-Id: I754291b75d38e1465b5291b4dea20806615d21b3 Reviewed-on: https://go-review.googlesource.com/c/go/+/257973 Trust: Cherry Zhang <cherryyz@google.com> Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Jeremy Faller <jeremy@golang.org>
2020-09-29crypto/tls: make config.Clone return nil if the source is nilChen.Zhidong
Fixes #40565 Change-Id: I13a67be193f8cd68df02b8729529e627a73d364b GitHub-Last-Rev: b03d2c04fd88db909b40dfd7bd08fe13d8994ab9 GitHub-Pull-Request: golang/go#40566 Reviewed-on: https://go-review.googlesource.com/c/go/+/246637 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Trust: Emmanuel Odeke <emm.odeke@gmail.com>
2020-09-29crypto/x509: define certDirectories per GOOSTobias Klauser
Split the list of CA certificate directory locations in root_unix.go by GOOS (aix, *bsd, js, linux, solaris). On solaris, also include /etc/certs/CA as documented here: https://docs.oracle.com/cd/E37838_01/html/E61024/kmf-cacerts.html Same as CL 2208 did for certFiles. Change-Id: Id24822d6a674bbbbf4088ebb8fe8437edad232b7 Reviewed-on: https://go-review.googlesource.com/c/go/+/248762 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-09-28crypto/x509: hardcode RSA PSS parameters rather than generating themRoland Shoemaker
Rather than generating the three possible RSA PSS parameters each time they are needed just hardcode them and pick the required one based on the hash function. Fixes #41407 Change-Id: Id43bdaf40b3ca82c4c04c6588e3b643f63107657 Reviewed-on: https://go-review.googlesource.com/c/go/+/258037 Run-TryBot: Roland Shoemaker <roland@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Roland Shoemaker <roland@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-09-24crypto/tls: replace errClosed with net.ErrClosedAinar Garipov
CL 250357 exported net.ErrClosed to allow more reliable detection of closed network connection errors. Use that error in crypto/tls as well. The error message is changed from "tls: use of closed connection" to "use of closed network connection", so the code that detected such errors by looking for that text in the error message will need to be updated to use errors.Is(err, net.ErrClosed) instead. Fixes #41066 Change-Id: Ic05c0ed6a4f57af2a0302d53b00851a59200be2e Reviewed-on: https://go-review.googlesource.com/c/go/+/256897 Reviewed-by: Katie Hockman <katie@golang.org> Trust: Katie Hockman <katie@golang.org> Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Katie Hockman <katie@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
2020-09-23all: add GOOS=iosCherry Zhang
Introduce GOOS=ios for iOS systems. GOOS=ios matches "darwin" build tag, like GOOS=android matches "linux" and GOOS=illumos matches "solaris". Only ios/arm64 is supported (ios/amd64 is not). GOOS=ios and GOOS=darwin remain essentially the same at this point. They will diverge at later time, to differentiate macOS and iOS. Uses of GOOS=="darwin" are changed to (GOOS=="darwin" || GOOS=="ios"), except if it clearly means macOS (e.g. GOOS=="darwin" && GOARCH=="amd64"), it remains GOOS=="darwin". Updates #38485. Change-Id: I4faacdc1008f42434599efb3c3ad90763a83b67c Reviewed-on: https://go-review.googlesource.com/c/go/+/254740 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>