aboutsummaryrefslogtreecommitdiff
path: root/src/crypto/ecdsa/ecdsa.go
AgeCommit message (Collapse)Author
2022-04-29[dev.boringcrypto] crypto/ecdsa, crypto/rsa: use boring.CacheRuss Cox
In the original BoringCrypto port, ecdsa and rsa's public and private keys added a 'boring unsafe.Pointer' field to cache the BoringCrypto form of the key. This led to problems with code that “knew” the layout of those structs and in particular that they had no unexported fields. In response, as an awful kludge, I changed the compiler to pretend that field did not exist when laying out reflect data. Because we want to merge BoringCrypto in the main tree, we need a different solution. Using boring.Cache is that solution. For #51940. Change-Id: Ideb2b40b599a1dc223082eda35a5ea9abcc01e30 Reviewed-on: https://go-review.googlesource.com/c/go/+/395883 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org>
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-27[dev.boringcrypto] all: merge master into dev.boringcryptoChressie Himpel
Change-Id: Ic5f71c04f08c03319c043f35be501875adb0a3b0
2022-04-27crypto/elliptic: refactor package structureFilippo Valsorda
Not quite golang.org/wiki/TargetSpecific compliant, but almost. The only substantial code change is in randFieldElement: it used to use Params().BitSize instead of Params().N.BitLen(), which is semantically incorrect, even if the two values are the same for all named curves. For #52182 Change-Id: Ibc47450552afe23ea74fcf55d1d799d5d7e5487c Reviewed-on: https://go-review.googlesource.com/c/go/+/315273 Run-TryBot: Filippo Valsorda <filippo@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Roland Shoemaker <roland@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2022-02-03[dev.boringcrypto] all: merge master into dev.boringcryptoChressie Himpel
Change-Id: I18dbf4f9fa7e2334fccedd862a523126cf38164e
2022-02-03crypto/ecdsa,crypto/elliptic: update docs and spec referencesFilippo Valsorda
crypto/ecdsa was long overdue a cleanup. Bump the FIPS 186 version, and make sure we consistently reference that and SEC 1, not the paywalled ANSI standard. Change-Id: Idd90bd6c14b334941fdcd829d89b796a60a8b174 Reviewed-on: https://go-review.googlesource.com/c/go/+/352529 Run-TryBot: Filippo Valsorda <filippo@golang.org> Trust: Filippo Valsorda <filippo@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org>
2021-11-05[dev.boringcrypto] all: merge master into dev.boringcryptoRoland Shoemaker
Change-Id: I1aa33cabd0c55fe64994b08f8a3f7b6bbfb3282c
2021-11-05crypto/ecdsa: draw a fixed amount of entropy while signingFilippo Valsorda
The current code, introduced in CL 2422, mixes K bits of entropy with the private key and message digest to generate the signature nonce, where K is half the bit size of the curve. While the ECDLP complexity (and hence security level) of a curve is half its bit size, the birthday bound on K bits is only K/2. For P-224, this means we should expect a collision after 2^56 signatures over the same message with the same key. A collision, which is unlikely, would still not be a major practical concern, because the scheme would fall back to a secure deterministic signature scheme, and simply leak the fact that the two signed messages are the same (which is presumably already public). Still, we can simplify the code and remove the eventuality by always drawing 256 bits of entropy. Change-Id: I58097bd3cfc9283503e38751c924c53d271af92b Reviewed-on: https://go-review.googlesource.com/c/go/+/352530 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>
2021-05-13[dev.boringcrypto] all: merge commit 9d0819b27c (CL 314609) into ↵Filippo Valsorda
dev.boringcrypto There used to be two BoringCrypto-specific behaviors related to cipher suites in crypto/tls: 1. in FIPS-only mode, only a restricted set of AES ciphers is allowed 2. NOT in FIPS-only mode, AES would be prioritized over ChaCha20 even if AES hardware was not available The motivation of (2) is unclear, and BoringSSL doesn't have equivalent logic. This merge drops (2), and keeps (1). Note that the list of FIPS-only ciphers does not have priority semantics anymore, but the default logic still sorts them the same way as they used to be. Change-Id: I50544011085cfa2b087f323aebf5338c0bd2dd33
2021-03-13crypto/ecdsa: fix dead reference linkMostyn Bramley-Moore
The previous link broke, but it's available on the internet archive. Fixes #39808 Change-Id: Ic2be74a1f0591600ca1acbe08e1bab8ba1e21abe GitHub-Last-Rev: 6d6de5d2f451c6d53a1e55b62fb5a1fab0d49f10 GitHub-Pull-Request: golang/go#40165 Reviewed-on: https://go-review.googlesource.com/c/go/+/242103 Trust: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-05-07[dev.boringcrypto] all: merge master into dev.boringcryptoDmitri Shuralyov
Change-Id: I083d1e4e997b30d9fab10940401eaf160e36f6c1
2020-05-07[dev.boringcrypto] all: merge master into dev.boringcryptoDmitri Shuralyov
Change-Id: Idd59c37d2fd759b0f73d2ee01b30f72ef4e9aee8
2020-05-05crypto/rsa,crypto/ecdsa,crypto/ed25519: implement PrivateKey.EqualFilippo Valsorda
Fixes #38190 Change-Id: I10766068ee18974e81b3bd78ee0b4d83cc9d1a8c Reviewed-on: https://go-review.googlesource.com/c/go/+/231417 Run-TryBot: Filippo Valsorda <filippo@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Katie Hockman <katie@golang.org>
2020-04-27crypto/ecdsa: implement ecdsa on s390x for P256/P384/P521 using KDSA instructionRuixin Bao
This CL revives CL 174437(also IBM CLA) and adds benchmarks and some simplifications. The original commit message is as follows: Utilize KDSA when available. This guarantees constant time operation on all three curves mentioned, and is faster than conventional assembly. Benchmarks: name old time/op new time/op delta SignP256-8 15.2µs ±14% 14.1µs ±18% ~ (p=0.356 n=9+10) SignP384-8 4.28ms ±26% 0.02ms ±30% -99.43% (p=0.000 n=10+10) VerifyP256-8 33.6µs ±13% 13.3µs ±38% -60.32% (p=0.000 n=9+10) name old alloc/op new alloc/op delta SignP256-8 2.16kB ± 0% 1.60kB ± 0% -25.63% (p=0.000 n=9+10) SignP384-8 1.75MB ± 0% 0.00MB ± 0% -99.90% (p=0.000 n=9+10) VerifyP256-8 1.08kB ± 0% 0.18kB ± 0% -83.70% (p=0.000 n=9+10) name old allocs/op new allocs/op delta SignP256-8 29.0 ± 0% 22.0 ± 0% -24.14% (p=0.000 n=10+10) SignP384-8 14.4k ± 0% 0.0k ± 0% -99.85% (p=0.000 n=9+10) VerifyP256-8 23.0 ± 0% 7.0 ± 0% -69.57% (p=0.000 n=10+10) Change-Id: Ifa1fc5917fa7592dd592affa7549147dbc9b4169 Reviewed-on: https://go-review.googlesource.com/c/go/+/228580 Run-TryBot: Michael Munday <mike.munday@ibm.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Munday <mike.munday@ibm.com>
2020-04-08[dev.boringcrypto] all: merge master into dev.boringcryptoFilippo Valsorda
Change-Id: I2dcec316fd08d91db4183fb9d3b9afde65cc248f
2020-03-26crypto/rsa,crypto/ecdsa,crypto/ed25519: implement PublicKey.EqualFilippo Valsorda
This makes all modern public keys in the standard library implement a common interface (below) that can be used by applications for better type safety and allows for checking that public (and private keys via Public()) are equivalent. interface { Equal(crypto.PublicKey) bool } Equality for ECDSA keys is complicated, we take a strict interpretation that works for all secure applications (the ones not using the unfortunate non-constant time CurveParams implementation) and fails closed otherwise. Tests in separate files to make them x_tests and avoid an import loop with crypto/x509. Re-landing of CL 223754. Dropped the test that was assuming named curves are not implemented by CurveParams, because it's not true for all curves, and anyway is not a property we need to test. There is still a test to check that different curves make keys not Equal. Fixes #21704 Fixes #38035 Reviewed-on: https://go-review.googlesource.com/c/go/+/223754 Reviewed-by: Katie Hockman <katie@golang.org> Change-Id: I736759b145bfb4f7f8eecd78c324315d5a05385c Reviewed-on: https://go-review.googlesource.com/c/go/+/225460 Run-TryBot: Filippo Valsorda <filippo@golang.org> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-03-23Revert "crypto/rsa,crypto/ecdsa,crypto/ed25519: implement PublicKey.Equal"Bryan C. Mills
This reverts CL 223754. Reason for revert: new tests are failing on all longtest builders. Change-Id: I2257d106c132f3a02c0af6b20061d4f9a8093c4f Reviewed-on: https://go-review.googlesource.com/c/go/+/225077 Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Katie Hockman <katie@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-03-23crypto/rsa,crypto/ecdsa,crypto/ed25519: implement PublicKey.EqualFilippo Valsorda
This makes all modern public keys in the standard library implement a common interface (below) that can be used by applications for better type safety and allows for checking that public (and private keys via Public()) are equivalent. interface { Equal(crypto.PublicKey) bool } Equality for ECDSA keys is complicated, we take a strict interpretation that works for all secure applications (the ones not using the unfortunate non-constant time CurveParams implementation) and fails closed otherwise. Tests in separate files to make them x_tests and avoid an import loop with crypto/x509. Fixes #21704 Change-Id: Id5379c96384a11c5afde0614955360e7470bb1c4 Reviewed-on: https://go-review.googlesource.com/c/go/+/223754 Reviewed-by: Katie Hockman <katie@golang.org>
2020-02-21crypto/ecdsa: add SignASN1, VerifyASN1Katie Hockman
Update the Example in the crypto/ecdsa package for signing and verifying signatures to use these new functions. This also changes (*PrivateKey).Sign to use x/crypto/cryptobyte/asn1 instead of encoding/asn1 to marshal the signature. Fixes #20544 Change-Id: I3423cfc4d7f9e1748fbed5a631438c8a3b280df4 Reviewed-on: https://go-review.googlesource.com/c/go/+/217940 TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
2019-11-19[dev.boringcrypto] all: merge master into dev.boringcryptoFilippo Valsorda
Signing-side signature algorithm selection moved to selectSignatureScheme, so add FIPS logic there. Change-Id: I827e7296d01ecfd36072e2139e74603ef42c6b24
2019-10-16crypto/ecdsa: remove s390x assemblyMichael Munday
This a revert of CL 174437 and follow up fix CL 201317. The s390x assembly in this package makes use of an instruction (specifically KDSA) which is not supported by the current build machine. Remove this assembly for now, we can revisit this functionality once we have a newer build machine and can ensure that this assembly is well tested. Updates #34927. Change-Id: I779286fa7d9530a254b53a515ee76b1218821f2f Reviewed-on: https://go-review.googlesource.com/c/go/+/201360 Run-TryBot: Michael Munday <mike.munday@ibm.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-08-28crypto/ecdsa: improve documentation readabilityMostyn Bramley-Moore
Include references in the package-level comment block, expand the obscure IRO acronym, and add a reference for "the standard (cryptographic) assumptions". Fixes #33589 Change-Id: I76c3b0a2f7258b3ab4bf1c8e7681c5d159720a20 GitHub-Last-Rev: 30d5a1e2fbbbb577ccc819f5ef80d5238565c9f3 GitHub-Pull-Request: golang/go#33723 Reviewed-on: https://go-review.googlesource.com/c/go/+/190840 Reviewed-by: Filippo Valsorda <filippo@golang.org>
2019-06-27[dev.boringcrypto] all: merge master into dev.boringcryptoFilippo Valsorda
Change-Id: Ic1d89215bb3e37a722d3d3bc7698edea940a83d9
2019-06-09[dev.boringcrypto] crypto: move crypto/internal/boring imports to reduce ↵Filippo Valsorda
merge conflicts As suggested by dmitshur@, move them to their own block so they don't conflict with changes in the upstream imports. Change-Id: Id46fb7c766066c406023b0355f4c3c860166f0fe Reviewed-on: https://go-review.googlesource.com/c/go/+/181277 Run-TryBot: Filippo Valsorda <filippo@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2019-05-24crypto/ecdsa: implement ecdsa on s390x for P256/P384/P521 using KDSA instructionbill_ofarrell
Utilize KDSA when available. This guarantees constant time operation on all three curves mentioned, and is faster than conventional assembly. The IBM Z model(s) that support KDSA as used in this CL are not yet publicly available, and so we are unable to release performance data at this time. Change-Id: I85360dcf90fe42d2bf32afe3f638e282de10a518 Reviewed-on: https://go-review.googlesource.com/c/go/+/174437 Run-TryBot: Michael Munday <mike.munday@ibm.com> Reviewed-by: Michael Munday <mike.munday@ibm.com>
2019-02-08[dev.boringcrypto] all: merge master into dev.boringcryptoFilippo Valsorda
Change-Id: I9246c8228d38559c40e69fa403fa946ac1b31dbe
2018-12-10crypto/ecdsa: fix NSA reference to Suite B implementer's guide to FIPS 186-3Gerasimos (Makis) Maropoulos
Change-Id: I34877ac1d6d7fe9ffa7eabe46b4032af84d33794 Reviewed-on: https://go-review.googlesource.com/c/153337 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-08[dev.boringcrypto] all: merge master into dev.boringcryptoFilippo Valsorda
Conflicts due to randutil.MaybeReadByte (kept at the top for patch maintainability and consistency): src/crypto/ecdsa/ecdsa.go src/crypto/rsa/pkcs1v15.go src/crypto/rsa/rsa.go Change-Id: I03a2de541e68a1bbdc48590ad7c01fbffbbf4a2b
2018-06-07crypto: randomly read an extra byte of randomness in some places.Adam Langley
Code has ended up depending on things like RSA's key generation being deterministic given a fixed random Reader. This was never guaranteed and would prevent us from ever changing anything about it. This change makes certain calls randomly (based on the internal fastrand) read an extra byte from the random Reader. This helps to ensure that code does not depend on internal details. I've not added this call in the key generation of ECDSA and DSA because, in those cases, key generation is so obvious that it probably is acceptable to do the obvious thing and not worry about code that depends on that. This does not affect tests that use a Reader of constant bytes (e.g. a zeroReader) because shifting such a stream is a no-op. The stdlib uses this internally (which is fine because it can be atomically updated if the crypto libraries change). It is possible that external tests could be doing the same and would thus break if we ever, say, tweaked the way RSA key generation worked. I feel that addressing that would be more effort than it's worth. Fixes #21915 Change-Id: I84cff2e249acc921ad6eb5527171e02e6d39c530 Reviewed-on: https://go-review.googlesource.com/64451 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2017-12-06[dev.boringcrypto] all: merge master (nearly Go 1.10 beta 1) into ↵Russ Cox
dev.boringcrypto This is a git merge of master into dev.boringcrypto. The branch was previously based on release-branch.go1.9, so there are a handful of spurious conflicts that would also arise if trying to merge master into release-branch.go1.9 (which we never do). Those have all been resolved by taking the original file from master, discarding any Go 1.9-specific edits. all.bash passes on darwin/amd64, which is to say without actually using BoringCrypto. Go 1.10-related fixes to BoringCrypto itself will be in a followup CL. This CL is just the merge. Change-Id: I4c97711fec0fb86761913dcde28d25c001246c35
2017-10-29crypto/{ecdsa,rsa}: rename argument to PrivateKey.Sign.Adam Langley
The crypto.Signer interface takes pre-hased messages for ECDSA and RSA, but the argument in the implementations was called “msg”, not “digest”, which is confusing. This change renames them to help clarify the intended use. Change-Id: Ie2fb8753ca5280e493810d211c7c66223f94af88 Reviewed-on: https://go-review.googlesource.com/70950 Reviewed-by: Filippo Valsorda <hi@filippo.io>
2017-09-15all: fix article typosKunpei Sakai
a -> an Change-Id: I7362bdc199e83073a712be657f5d9ba16df3077e Reviewed-on: https://go-review.googlesource.com/63850 Reviewed-by: Rob Pike <r@golang.org>
2017-08-19[dev.boringcrypto] crypto/ecdsa: use unsafe.Pointer instead of atomic.ValueRuss Cox
Using atomic.Value causes vet errors in code copying PublicKey or PrivateKey structures. I don't think the errors are accurate, but it's easier to work around them than to change vet or change atomic.Value. See #21504. Change-Id: I3a3435c1fc664cc5166c81674f6f7c58dab35f21 Reviewed-on: https://go-review.googlesource.com/56671 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@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>
2016-10-02crypto/ecdsa: correct code comment.Adam Langley
The code comment mixed up max and min. In this case, min is correct because this entropy is only used to make the signature scheme probabilistic. (I.e. if it were fixed then the scheme would still be secure except that key.Sign(foo) would always give the same result for a fixed key and foo.) For this purpose, 256-bits is plenty. Fixes #16819. Change-Id: I309bb312b775cf0c4b7463c980ba4b19ad412c36 Reviewed-on: https://go-review.googlesource.com/30153 Run-TryBot: Adam Langley <agl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-06-29crypto/ecdsa: Update documentation for SignNick Harper
Change-Id: I2b7a81cb809d109f10d5f0db957c614f466d6bfd Reviewed-on: https://go-review.googlesource.com/24582 Reviewed-by: Adam Langley <agl@golang.org>
2016-05-18crypto/ecdsa: reject negative inputs.Adam Langley
The fact that crypto/ecdsa.Verify didn't reject negative inputs was a mistake on my part: I had unsigned numbers on the brain. However, it doesn't generally cause problems. (ModInverse results in zero, which results in x being zero, which is rejected.) The amd64 P-256 code will crash when given a large, negative input. This fixes both crypto/ecdsa to reject these values and also the P-256 code to ignore the sign of inputs. Change-Id: I6370ed7ca8125e53225866f55b616a4022b818f8 Reviewed-on: https://go-review.googlesource.com/22093 Run-TryBot: Adam Langley <agl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-04-05crypto/rsa, crypto/ecdsa: fail earlier on zero parametersBrad Fitzpatrick
Change-Id: Ia6ed49d5ef3a256a55e6d4eaa1b4d9f0fc447013 Reviewed-on: https://go-review.googlesource.com/21560 Reviewed-by: Robert Griesemer <gri@golang.org>
2016-02-29all: remove public named return values when uselessBrad Fitzpatrick
Named returned values should only be used on public funcs and methods when it contributes to the documentation. Named return values should not be used if they're only saving the programmer a few lines of code inside the body of the function, especially if that means there's stutter in the documentation or it was only there so the programmer could use a naked return statement. (Naked returns should not be used except in very small functions) This change is a manual audit & cleanup of public func signatures. Signatures were not changed if: * the func was private (wouldn't be in public godoc) * the documentation referenced it * the named return value was an interesting name. (i.e. it wasn't simply stutter, repeating the name of the type) There should be no changes in behavior. (At least: none intended) Change-Id: I3472ef49619678fe786e5e0994bdf2d9de76d109 Reviewed-on: https://go-review.googlesource.com/20024 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-11-10crypto/elliptic,crypto/ecdsa: P256 amd64 assemblyVlad Krasnov
This is based on the implementation used in OpenSSL, from a submission by Shay Gueron and myself. Besides using assembly, this implementation employs several optimizations described in: S.Gueron and V.Krasnov, "Fast prime field elliptic-curve cryptography with 256-bit primes" In addition a new and improved modular inverse modulo N is implemented here. The performance measured on a Haswell based Macbook Pro shows 21X speedup for the sign and 9X for the verify operations. The operation BaseMult is 30X faster (and the Diffie-Hellman/ECDSA key generation that use it are sped up as well). The adaptation to Go with the help of Filippo Valsorda Updated the submission for faster verify/ecdh, fixed some asm syntax and API problems and added benchmarks. Change-Id: I86a33636747d5c92f15e0c8344caa2e7e07e0028 Reviewed-on: https://go-review.googlesource.com/8968 Run-TryBot: Adam Langley <agl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Adam Langley <agl@golang.org>
2015-06-26crypto/ecdsa, crypto/x509: update SEC1 ECC link in commentsDmitry Savintsev
Updated the document URL in comments to avoid dead link Old: http://www.secg.org/download/aid-780/sec1-v2.pdf New: http://www.secg.org/sec1-v2.pdf Change-Id: If13d0da4c0e7831b2bd92c45116c2412a2a965f5 Reviewed-on: https://go-review.googlesource.com/11550 Reviewed-by: Russ Cox <rsc@golang.org>
2015-03-18crypto/{ecdsa,rsa}: always use io.ReadFull with crypto/rand.Reader.Adam Langley
crypto/rand.Reader doesn't ensure that short reads don't happen. This change contains a couple of fixups where io.ReadFull wasn't being used with it. Change-Id: I3855b81f5890f2e703112eeea804aeba07b6a6b8 Reviewed-on: https://go-review.googlesource.com/7645 Reviewed-by: Minux Ma <minux@golang.org> Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-01-28crypto/ecdsa: make Sign safe with broken entropy sourcesDavid Leon Gil
ECDSA is unsafe to use if an entropy source produces predictable output for the ephemeral nonces. E.g., [Nguyen]. A simple countermeasure is to hash the secret key, the message, and entropy together to seed a CSPRNG, from which the ephemeral key is derived. Fixes #9452 -- This is a minimalist (in terms of patch size) solution, though not the most parsimonious in its use of primitives: - csprng_key = ChopMD-256(SHA2-512(priv.D||entropy||hash)) - reader = AES-256-CTR(k=csprng_key) This, however, provides at most 128-bit collision-resistance, so that Adv will have a term related to the number of messages signed that is significantly worse than plain ECDSA. This does not seem to be of any practical importance. ChopMD-256(SHA2-512(x)) is used, rather than SHA2-256(x), for two sets of reasons: *Practical:* SHA2-512 has a larger state and 16 more rounds; it is likely non-generically stronger than SHA2-256. And, AFAIK, cryptanalysis backs this up. (E.g., [Biryukov] gives a distinguisher on 47-round SHA2-256 with cost < 2^85.) This is well below a reasonable security-strength target. *Theoretical:* [Coron] and [Chang] show that Chop-MD(F(x)) is indifferentiable from a random oracle for slightly beyond the birthday barrier. It seems likely that this makes a generic security proof that this construction remains UF-CMA is possible in the indifferentiability framework. -- Many thanks to Payman Mohassel for reviewing this construction; any mistakes are mine, however. And, as he notes, reusing the private key in this way means that the generic-group (non-RO) proof of ECDSA's security given in [Brown] no longer directly applies. -- [Brown]: http://www.cacr.math.uwaterloo.ca/techreports/2000/corr2000-54.ps "Brown. The exact security of ECDSA. 2000" [Coron]: https://www.cs.nyu.edu/~puniya/papers/merkle.pdf "Coron et al. Merkle-Damgard revisited. 2005" [Chang]: https://www.iacr.org/archive/fse2008/50860436/50860436.pdf "Chang and Nandi. Improved indifferentiability security analysis of chopMD hash function. 2008" [Biryukov]: http://www.iacr.org/archive/asiacrypt2011/70730269/70730269.pdf "Biryukov et al. Second-order differential collisions for reduced SHA-256. 2011" [Nguyen]: ftp://ftp.di.ens.fr/pub/users/pnguyen/PubECDSA.ps "Nguyen and Shparlinski. The insecurity of the elliptic curve digital signature algorithm with partially known nonces. 2003" New tests: TestNonceSafety: Check that signatures are safe even with a broken entropy source. TestINDCCA: Check that signatures remain non-deterministic with a functional entropy source. Updated "golden" KATs in crypto/tls/testdata that use ECDSA suites. Change-Id: I55337a2fbec2e42a36ce719bd2184793682d678a Reviewed-on: https://go-review.googlesource.com/3340 Reviewed-by: Adam Langley <agl@golang.org>
2015-01-26Revert "crypto/ecdsa: make Sign safe with broken entropy sources"Adam Langley
This reverts commit 8d7bf2291b095d3a2ecaa2609e1101be46d80deb. Change-Id: Iad2c74a504d64bcf7ca707b00bda29bc796a2ae9 Reviewed-on: https://go-review.googlesource.com/3320 Reviewed-by: Adam Langley <agl@golang.org>
2015-01-26crypto/ecdsa: make Sign safe with broken entropy sourcesDavid Leon Gil
ECDSA is unsafe to use if an entropy source produces predictable output for the ephemeral nonces. E.g., [Nguyen]. A simple countermeasure is to hash the secret key, the message, and entropy together to seed a CSPRNG, from which the ephemeral key is derived. -- This is a minimalist (in terms of patch size) solution, though not the most parsimonious in its use of primitives: - csprng_key = ChopMD-256(SHA2-512(priv.D||entropy||hash)) - reader = AES-256-CTR(k=csprng_key) This, however, provides at most 128-bit collision-resistance, so that Adv will have a term related to the number of messages signed that is significantly worse than plain ECDSA. This does not seem to be of any practical importance. ChopMD-256(SHA2-512(x)) is used, rather than SHA2-256(x), for two sets of reasons: *Practical:* SHA2-512 has a larger state and 16 more rounds; it is likely non-generically stronger than SHA2-256. And, AFAIK, cryptanalysis backs this up. (E.g., [Biryukov] gives a distinguisher on 47-round SHA2-256 with cost < 2^85.) This is well below a reasonable security-strength target. *Theoretical:* [Coron] and [Chang] show that Chop-MD(F(x)) is indifferentiable from a random oracle for slightly beyond the birthday barrier. It seems likely that this makes a generic security proof that this construction remains UF-CMA is possible in the indifferentiability framework. -- Many thanks to Payman Mohassel for reviewing this construction; any mistakes are mine, however. And, as he notes, reusing the private key in this way means that the generic-group (non-RO) proof of ECDSA's security given in [Brown] no longer directly applies. -- [Brown]: http://www.cacr.math.uwaterloo.ca/techreports/2000/corr2000-54.ps "Brown. The exact security of ECDSA. 2000" [Coron]: https://www.cs.nyu.edu/~puniya/papers/merkle.pdf "Coron et al. Merkle-Damgard revisited. 2005" [Chang]: https://www.iacr.org/archive/fse2008/50860436/50860436.pdf "Chang and Nandi. Improved indifferentiability security analysis of chopMD hash function. 2008" [Biryukov]: http://www.iacr.org/archive/asiacrypt2011/70730269/70730269.pdf "Biryukov et al. Second-order differential collisions for reduced SHA-256. 2011" [Nguyen]: ftp://ftp.di.ens.fr/pub/users/pnguyen/PubECDSA.ps "Nguyen and Shparlinski. The insecurity of the elliptic curve digital signature algorithm with partially known nonces. 2003" Fixes #9452 Tests: TestNonceSafety: Check that signatures are safe even with a broken entropy source. TestINDCCA: Check that signatures remain non-deterministic with a functional entropy source. Change-Id: Ie7e04057a3a26e6becb80e845ecb5004bb482745 Reviewed-on: https://go-review.googlesource.com/2422 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.