aboutsummaryrefslogtreecommitdiff
path: root/src/crypto/internal/boring/boring.go
AgeCommit message (Collapse)Author
2022-04-29[dev.boringcrypto] crypto/..., go/build: align deps test with standard rulesRuss Cox
One annoying difference between dev.boringcrypto and master is that there is not a clear separation between low-level (math/big-free) crypto and high-level crypto, because crypto/internal/boring imports both encoding/asn1 and math/big. This CL removes both those problematic imports and aligns the dependency rules in the go/build test with the ones in the main branch. To remove encoding/asn1, the crypto/internal/boring APIs change to accepting and returning encoded ASN.1, leaving crypto/ecdsa to do the marshaling and unmarshaling, which it already contains code to do. To remove math/big, the crypto/internal/boring package defines type BigInt []uint, which is the same representation as a big.Int's internal storage. The new package crypto/internal/boring/bbig provides conversions between BigInt and *big.Int. The boring package can then be in the low-level crypto set, and any package needing to use bignum APIs (necessarily in the high-level crypto set) can import bbig to convert. To simplify everything we hide from the test the fact that crypto/internal/boring imports cgo. Better to pretend it doesn't and keep the prohibitions that other packages like crypto/aes must not use cgo (outside of BoringCrypto). $ git diff origin/master src/go/build/deps_test.go diff --git a/src/go/build/deps_test.go b/src/go/build/deps_test.go index 6ce872e297..a63979cc93 100644 --- a/src/go/build/deps_test.go +++ b/src/go/build/deps_test.go @@ -402,9 +402,13 @@ var depsRules = ` NET, log < net/mail; + NONE < crypto/internal/boring/sig; + sync/atomic < crypto/internal/boring/fipstls; + crypto/internal/boring/sig, crypto/internal/boring/fipstls < crypto/tls/fipsonly; + # CRYPTO is core crypto algorithms - no cgo, fmt, net. # Unfortunately, stuck with reflect via encoding/binary. - encoding/binary, golang.org/x/sys/cpu, hash + crypto/internal/boring/sig, encoding/binary, golang.org/x/sys/cpu, hash < crypto < crypto/subtle < crypto/internal/subtle @@ -413,6 +417,8 @@ var depsRules = ` < crypto/ed25519/internal/edwards25519/field, golang.org/x/crypto/curve25519/internal/field < crypto/ed25519/internal/edwards25519 < crypto/cipher + < crypto/internal/boring + < crypto/boring < crypto/aes, crypto/des, crypto/hmac, crypto/md5, crypto/rc4, crypto/sha1, crypto/sha256, crypto/sha512 < CRYPTO; @@ -421,6 +427,7 @@ var depsRules = ` # CRYPTO-MATH is core bignum-based crypto - no cgo, net; fmt now ok. CRYPTO, FMT, math/big, embed + < crypto/internal/boring/bbig < crypto/rand < crypto/internal/randutil < crypto/ed25519 @@ -443,7 +450,8 @@ var depsRules = ` < golang.org/x/crypto/hkdf < crypto/x509/internal/macos < crypto/x509/pkix - < crypto/x509 + < crypto/x509; + crypto/internal/boring/fipstls, crypto/x509 < crypto/tls; # crypto-aware packages @@ -653,6 +661,9 @@ func findImports(pkg string) ([]string, error) { } var imports []string var haveImport = map[string]bool{} + if pkg == "crypto/internal/boring" { + haveImport["C"] = true // kludge: prevent C from appearing in crypto/internal/boring imports + } fset := token.NewFileSet() for _, file := range files { name := file.Name() For #51940. Change-Id: I26fc752484310d77d22adb06495120a361568d04 Reviewed-on: https://go-review.googlesource.com/c/go/+/395877 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org> Run-TryBot: Russ Cox <rsc@golang.org>
2022-04-29[dev.boringcrypto] crypto/internal/boring: make SHA calls allocation-freeRuss Cox
The standard Go implementations are allocation-free. Making the BoringCrypto ones the same helps avoid surprises, including in some of our own tests. For #51940. Change-Id: Ic9c5dc46f5e29ca85f571244be2b380ec2cf89c9 Reviewed-on: https://go-review.googlesource.com/c/go/+/395876 Reviewed-by: Roland Shoemaker <roland@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-29[dev.boringcrypto] crypto/internal/boring: avoid allocation in big.Int ↵Russ Cox
conversion The conversion via byte slices is inefficient; we can convert via word slices and avoid the copy entirely. For #51940. Change-Id: I06f747e0acffffae427d9706d43bdacf146c027d Reviewed-on: https://go-review.googlesource.com/c/go/+/395875 Reviewed-by: Roland Shoemaker <roland@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-29[dev.boringcrypto] all: add boringcrypto build tagsRuss Cox
A plain make.bash in this tree will produce a working, standard Go toolchain, not a BoringCrypto-enabled one. The BoringCrypto-enabled one will be created with: GOEXPERIMENT=boringcrypto ./make.bash For #51940. Change-Id: Ia9102ed993242eb1cb7f9b93eca97e81986a27b3 Reviewed-on: https://go-review.googlesource.com/c/go/+/395881 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-12-06[dev.boringcrypto] crypto/internal/boring: add -pthread linker flagCherry Mui
goboringcrypto_linux_amd64.syso references pthread functions, so we need to pass -pthread to the C linker when external linking. Usually it is automatically added when linking with runtime/cgo package. But in shared linkage the runtime/cgo package may be in a separate DSO and not part of this invocation. Fixes #49965. Change-Id: I3a9983e715ee804594a14006f212f76769ad71db Reviewed-on: https://go-review.googlesource.com/c/go/+/369161 Trust: Cherry Mui <cherryyz@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
2021-10-28[dev.boringcrypto] all: convert +build to //go:build lines in ↵Russ Cox
boring-specific files This makes the latest Go 1.18 cmd/dist happier. Change-Id: If1894ce4f60a0b604a2bd889974ddb16c405e0c7 Reviewed-on: https://go-review.googlesource.com/c/go/+/359474 Trust: Russ Cox <rsc@golang.org> Trust: Damien Neil <dneil@google.com> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2017-09-22[dev.boringcrypto] crypto/tls/fipsonly: new package to force FIPS-allowed ↵Russ Cox
TLS settings Change-Id: I3268cab2de8aed9e2424e9c3bc7667083bc5e1ce Reviewed-on: https://go-review.googlesource.com/65250 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Adam Langley <agl@golang.org>
2017-09-18[dev.boringcrypto] crypto/internal/boring: fall back to standard crypto when ↵Russ Cox
using -msan The syso is not compiled with -fsanitize=memory, so don't try to use it. Otherwise the first time it calls out to memcmp, memcmp complains that it is being asked to compare uninitialized memory. Change-Id: I85ab707cfbe64eded8e110d4d6b40d1b75f50541 Reviewed-on: https://go-review.googlesource.com/63916 Reviewed-by: Adam Langley <agl@golang.org>
2017-09-18[dev.boringcrypto] crypto/internal/boring: fix detection of tests to allow ↵Russ Cox
*.test and *_test When using the go command, test binaries end in .test, but when using Bazel, test binaries conventionally end in _test. Change-Id: Ic4cac8722fd93ae316169f87b321f68e0b71f0c3 Reviewed-on: https://go-review.googlesource.com/63913 Reviewed-by: Adam Langley <agl@golang.org>
2017-08-25[dev.boringcrypto] crypto/internal/boring: disable for android & non-cgo buildsRuss Cox
Change-Id: Ia4458090118c4391a73cf1ae65bc8d187f03eca0 Reviewed-on: https://go-review.googlesource.com/59051 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-08-19[dev.boringcrypto] crypto/rsa: use BoringCryptoRuss Cox
Change-Id: Ibb92f0f8cb487f4d179b069e588e1cb266599384 Reviewed-on: https://go-review.googlesource.com/55479 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Adam Langley <agl@golang.org>
2017-08-17[dev.boringcrypto] crypto/ecdsa: use BoringCryptoRuss Cox
Change-Id: I108e0a527bddd673b16582d206e0697341d0a0ea Reviewed-on: https://go-review.googlesource.com/55478 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Adam Langley <agl@golang.org>
2017-08-17[dev.boringcrypto] crypto/rand: use BoringCryptoRuss Cox
Change-Id: Ie630eff90f7fee9b359683930aec2daf96c1bdfe Reviewed-on: https://go-review.googlesource.com/55473 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Adam Langley <agl@golang.org>
2017-08-17[dev.boringcrypto] crypto/internal/boring: add initial BoringCrypto accessRuss Cox
Right now the package doesn't do anything useful, but it will. This CL is about the machinery for building goboringcrypto_linux_amd64.syso and then running the self-test and checking FIPS_mode from Go init. Change-Id: I4ec0f5efaa88ccfb506b9818d24a7f1cbcc5a7d6 Reviewed-on: https://go-review.googlesource.com/55472 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Adam Langley <agl@golang.org>