Commit Graph
770 Commits
Author SHA1 Message Date
Alex Vaghin a4c6cb3142 acme: try to fetch nonce from directory first
The change should reduce resource quota consumed by the client overall.

Instead of sending HEAD to an ACME resource URL to get a new nonce,
the Client will now try to fetch it from the Directory URL first
and only then from the ACME resource URL if the former fails.

This builds up on an abandoned https://golang.org/cl/34623,
only this time with a fallback to the original behaviour.

Change-Id: I6e75c0e524c4bc751f3a651b290c0ac2493e0628
Reviewed-on: https://go-review.googlesource.com/c/162057
Run-TryBot: Alex Vaghin <ddos@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-02-19 17:22:22 +00:00
Meng Zhuo 74369b46fc internal/chacha20: add SIMD implementation on arm64
Inspired by Vectorization of ChaCha Stream Cipher
https://eprint.iacr.org/2013/759.pdf

name            old time/op    new time/op    delta
ChaCha20/32        690ns ± 0%     872ns ± 0%   +26.38%  (p=0.000 n=10+10)
ChaCha20/63        750ns ± 0%     987ns ± 0%   +31.53%  (p=0.000 n=10+10)
ChaCha20/64        674ns ± 0%     879ns ± 0%   +30.42%  (p=0.000 n=8+10)
ChaCha20/256      2.28µs ± 0%    0.82µs ± 0%   -64.13%  (p=0.000 n=10+10)
ChaCha20/1024     8.64µs ± 0%    2.92µs ± 0%   -66.15%  (p=0.000 n=9+9)
ChaCha20/1350     11.9µs ± 0%     4.5µs ± 0%   -62.51%  (p=0.000 n=10+8)
ChaCha20/65536     554µs ± 0%     181µs ± 0%   -67.33%  (p=0.000 n=10+10)

name            old speed      new speed      delta
ChaCha20/32     46.3MB/s ± 0%  36.7MB/s ± 0%   -20.87%  (p=0.000 n=10+9)
ChaCha20/63     83.9MB/s ± 0%  63.8MB/s ± 0%   -23.97%  (p=0.000 n=10+10)
ChaCha20/64     94.9MB/s ± 0%  72.8MB/s ± 0%   -23.31%  (p=0.000 n=10+10)
ChaCha20/256     112MB/s ± 0%   312MB/s ± 0%  +178.74%  (p=0.000 n=10+10)
ChaCha20/1024    119MB/s ± 0%   350MB/s ± 0%  +195.31%  (p=0.000 n=10+9)
ChaCha20/1350    114MB/s ± 0%   303MB/s ± 0%  +166.73%  (p=0.000 n=8+8)
ChaCha20/65536   118MB/s ± 0%   362MB/s ± 0%  +206.12%  (p=0.000 n=10+10)

Updates golang/go#22809
Change-Id: I487487faa2ae4ff29de6fd8eb1317740c2939c10
Reviewed-on: https://go-review.googlesource.com/c/107628
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2019-02-11 18:28:17 +00:00
Michael McLoughlin 193df9c0f0 curve25519: mask high bit when loading group point
Comparison against BoringSSL-generated test vectors showed mismatches
with the pure Go implementation of curve25519. The problem was narrowed
down to a missing mask in feFromBytes(). This diff adds the mask,
bringing this back in line with the reference implementation and
RFC 7748:

    When receiving such an array, implementations of X25519 (but not
    X448) MUST mask the most significant bit in the final byte.  This is
    done to preserve compatibility with point formats that reserve the
    sign bit for use in other protocols and to increase resistance to
    implementation fingerprinting.

Fixes golang/go#30095

Change-Id: If7efc0e2acd6efb761d6e3cb89cec359d7d81cb1
Reviewed-on: https://go-review.googlesource.com/c/161257
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2019-02-08 16:22:36 +00:00
Michael Cook b8fe1690c6 all: fix ineffectual assignments
audited using ineffassign tool from
github.com/gordonklaus/ineffassign
go generate does not generate any changes

Change-Id: Iabbec9ec1aae39081289d503d79fd7b4caadf17b
GitHub-Last-Rev: acd17cce410e9c68ce3c87b5546261be9153e3ea
GitHub-Pull-Request: golang/crypto#70
Reviewed-on: https://go-review.googlesource.com/c/155942
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2019-01-31 18:25:04 +00:00
Filippo Valsorda 9c16a0384b pkcs12: add a note suggesting ToPEM for multiple certificates/keys
Updates golang/go#14015

Change-Id: Iffe73540c5d74e4b3d0664035a1bdce5b47663ee
Reviewed-on: https://go-review.googlesource.com/c/160258
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2019-01-31 18:23:23 +00:00
Alex Vaghin b01c7a7256 acme: support IP address authorization type
This change extends the Client to allow users request
certificate issuance for IP addresses.

See the ACME spec extension for details about IP address
identifiers: https://tools.ietf.org/html/draft-ietf-acme-ip.

Change-Id: I92a8d8fae048487168906c14892c6dd33af10c07
Reviewed-on: https://go-review.googlesource.com/c/160197
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-30 09:05:50 +00:00
Filippo Valsorda ccddf3741a pkcs12: note that this package is frozen and point to an alternative
Change-Id: Ia4d87b816f176194cd9e37efb42e273d678a84b7
Reviewed-on: https://go-review.googlesource.com/c/160259
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-29 21:01:02 +00:00
Filippo Valsorda 54b0dbbbf4 Revert "pkcs12: add a DecodeAll method"
This reverts commit bf88e3f4ba.

Reason for revert: https://go-review.googlesource.com/c/crypto/+/105876/12#message-0dad31af2b487e895ee6926ded82f85ac81c74f8

Updates golang/go#14015

Change-Id: I8eb3ed73f78ac11841ad73435bba00a330d59b58
Reviewed-on: https://go-review.googlesource.com/c/160257
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-29 20:08:51 +00:00
Julien Kauffmann bf88e3f4ba pkcs12: add a DecodeAll method
Addition of a DecodeAll function as it was mentioned in #14015.

This solves a need many people seem to have, where there is no effective
way loading PKCS12 files that contain more than one certificate and one
private key.

The utility functions used by Decode are all internal, which makes
implementing this on the user-side tedious, hence the suggestion of
providing a more liberal version of the function: DecodeAll.

Fixes golang/go#14015

Change-Id: I03c541553b6cb488c2c59d39575342a43136e592
GitHub-Last-Rev: 05f6847ff80ca34c92a01a688c7b81e874af3009
GitHub-Pull-Request: golang/crypto#38
Reviewed-on: https://go-review.googlesource.com/c/105876
Reviewed-by: Adam Shannon <adamkshannon@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-29 17:05:51 +00:00
Michal Bohuslávek c7b33c32a3 ssh/terminal: support ^N and ^P
This makes it possible to navigate the history without leaving
the home row on the keyboard.

Change-Id: Id24c43f8eb6090520ab37bf8126264901b70c489
Reviewed-on: https://go-review.googlesource.com/c/33618
Run-TryBot: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-28 19:33:16 +00:00
Jay Taylor 057139ce5d crypto/ssh/knownhosts: fix out-of-date documentation for checkAddr
Change-Id: I03e9cf1ee82b38f15232a48992bae0234bd51f1a
GitHub-Last-Rev: fd7b92d97c7b52ae00821bad099cf45ff9836cd1
GitHub-Pull-Request: golang/crypto#71
Reviewed-on: https://go-review.googlesource.com/c/156878
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-01-23 08:56:48 +00:00
Ross Smith II 6407268620 blake2b: fix comments in grammar
Change-Id: Idacdbf5ee847be6e21ecce0c9d41818e643c4835
GitHub-Last-Rev: bf1a719b62167d294319f23576302ef567894cc3
GitHub-Pull-Request: golang/crypto#73
Reviewed-on: https://go-review.googlesource.com/c/158837
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-22 01:37:13 +00:00
Péter Szilágyi ff983b9c42 sha3: add support for Keccak-512
Keccak uses a different domain separation byte as the NIST-
standardized SHA-3 hashing function. A previous commit to
this package added support for Keccak-256, but did not do
so for Keccak-512. The reasoning was to support use cases
like Ethereum, however Ethereum also uses Keccak-512 for
the Ethash PoW, so this second method is also needed.

Prev CL: https://go-review.googlesource.com/c/crypto/+/106462

Fixes golang/go#29533

Change-Id: I9d92b1f121657f631c157e5e309771db1cd91c82
Reviewed-on: https://go-review.googlesource.com/c/125795
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-03 21:31:33 +00:00
kc1212 8d7daa0c54 bn256: fix gfp12 MulScalar
Previously MulScalar was ignoring the first parameter, which was inconsistent with gfp6 and gfp2.

Change-Id: I4f4a4ca2f07a25176ab159be684a02696f1580ba
GitHub-Last-Rev: ec40c0403614ed56cf329102eb274dc776fa3be8
GitHub-Pull-Request: golang/crypto#67
Reviewed-on: https://go-review.googlesource.com/c/154457
Reviewed-by: Adam Langley <agl@golang.org>
Run-TryBot: Adam Langley <agl@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-01-02 17:18:10 +00:00
Axel Wagner 505ab145d0 openpgp: support SHA384
SHA384 is a natural hashing choice for P-384 ECDSA. The only thing
needed to make it usable, is adding it to the list of candidates.

Change-Id: I61f66f371774f95dfc1de30d10fab66f92c21b6b
Reviewed-on: https://go-review.googlesource.com/c/137956
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-12-03 04:23:31 +00:00
Tobias Klauser eb0de9b17e ssh/terminal: enable tests for aix
Enable the tests on aix after support was added in CL 151077.

Change-Id: I2dcdaaa54d7c27b7697224e0f3cfab3cf0b52b6a
Reviewed-on: https://go-review.googlesource.com/c/151437
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Clément Chigot <clement.chigot@atos.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-11-27 14:34:15 +00:00
Tobias Klauser e657309f52 ssh/terminal: use "reports whether" in IsTerminal doc
Go documentation style for boolean funcs is to say:

    // Foo reports whether ...
    func Foo() bool

(rather than "returns true if")

Change-Id: I6972d123ba99bbf3dbf95e876b45b2ecd98dd07c
Reviewed-on: https://go-review.googlesource.com/c/151257
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-26 16:34:21 +00:00
Philipp c05539cddb cryptobyte: fix typo in test
Change-Id: I03178eca962c29ad03fd9b2fb57ad35c53c99860
GitHub-Last-Rev: 21a7a751920a5d3e650d1f91d17177f33e477ff1
GitHub-Pull-Request: golang/crypto#66
Reviewed-on: https://go-review.googlesource.com/c/151277
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-26 14:41:56 +00:00
chigotc 9eb0be3963 ssh/terminal: add AIX operating system
This commit adds AIX operation system to ssh/terminal package.

Change-Id: I31ccec5512dbf476eaf22ff79951b5fab434d5fd
Reviewed-on: https://go-review.googlesource.com/c/151077
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2018-11-26 09:39:34 +00:00
Filippo Valsorda 3d3f9f4138 cryptobyte: don't ignore bytes added to BuilderContinuations of fixed-size Builders
Builders created with NewFixedBuilder were broken when used with
BuilderContinuations. The length of the bytes written to the
continuation would get added correctly to the parent, but the actual
content would be discarded.

For example, the BytesOrPanic() in TestFixedBuilderLengthPrefixed would
return [00 08] instead of [00 08 ff ff ff ff ff ff ff ff].

Change-Id: I80837a9bf3562751addcb827274649d9f52fc79a
Reviewed-on: https://go-review.googlesource.com/c/148882
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Adam Langley <agl@golang.org>
2018-11-12 20:29:54 +00:00
Han-Wen Nienhuys e4dc69e5b2 ssh: return specific error for invalid signature algorithm
Previously, this would return the default error "no auth passed yet".

Not only is the new error more specific, it makes it easier to verify
the control flow of server authentication code.

Change-Id: I6c8de4e3f91da74274acbe9d87ec4f6158b4a94f
Reviewed-on: https://go-review.googlesource.com/c/142897
Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-06 17:15:34 +00:00
Alex Vaghin bfa7d42eb5 acme: support custom crypto.Signer implementations
Currently, only rsa.PrivateKey and ecdsa.PrivateKey are supported
when creating JWS signatures. However, it is unnecessarily limiting
because any crypto.Signer implementation can sign a digest
in the appropriate format.

This change uses key.Public() instead of type-asserting the private
key which allows for a custom crypto.Signer implementation.
For instance, a key stored in a hardware module where the latter
does the actual signing without the key ever leaving its boundaries.

Change-Id: Ie7930ea2ba8c49dde7107ff074ae34abec05bdb9
Reviewed-on: https://go-review.googlesource.com/c/145137
Run-TryBot: Alex Vaghin <ddos@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2018-11-06 15:23:44 +00:00
Ian Haken 4d3f4d9ffa ssh/agent: Fix error returned from agent responses that are too big.
Make sure a meaningful error is returned when the SSH agent client receives
a response that is too big.

Change-Id: Ied68b2c559a61dede2f3112c4c8143babd385f48
GitHub-Last-Rev: ad65e1b423bb00f2501dfde84040469aef4ee2df
GitHub-Pull-Request: golang/crypto#61
Reviewed-on: https://go-review.googlesource.com/c/143058
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-10-30 10:24:18 +00:00
Kevin Burke bc7917b19d bcrypt: benchmark defaults
Currently the benchmarks hard code "10" for the cost but maybe a
better benchmark would be to use the DefaultCost, since this is the
most common use mode for the bcrypt package.

Change-Id: Ie89853fcbe4a3a2830fff812ae5cfe908df145fe
Reviewed-on: https://go-review.googlesource.com/c/144338
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2018-10-30 02:28:21 +00:00
Filippo Valsorda b078efbc80 cryptobyte: add (*Builder).Unwrite and (*Builder).SetError
Unwrite allows programs to rollback builders more reliably and
efficiently than by copying a Builder (which might waste an allocation
and depends on internal behavior). This is useful for example to remove
a length-prefixed field if it ends up being empty.

SetError allows simple Builder extensions to set errors without making
MarshalingValue wrappers.

Based on the experience of CL 144115.

Change-Id: I9a785b81b51b15af49418b5bdb71c4ef222ccc46
Reviewed-on: https://go-review.googlesource.com/c/145317
Reviewed-by: Adam Langley <agl@golang.org>
2018-10-29 21:22:43 +00:00
Axel Wagner 7e6ffbd038 openpgp: pass hash to Signer.Sign for ECDSA
Change-Id: Iabb601d9d7f3394c2a20cacd042c00bd05457500
Reviewed-on: https://go-review.googlesource.com/c/137897
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-10-29 17:52:32 +00:00
Ian Haken dab2b1051b ssh: support SSH agent signature flags and custom extensions
This commit implements two new features. To preserve backwards
compatibility the new methods are added to an `ExtendedAgent` interface
which extends `Agent`. The client code implements `ExtendedAgent`
(which extends Agent) so you can call these additional methods against
SSH agents such as the OpenSSH agent. The ServeAgent method still
accepts Agent but will attempt to upcast the agent to `ExtendedAgent`
as needed, so if you supply an ExtendedAgent implementation you can
implement these additional methods (which keyring does).

The first feature is supporting the standard flags that can be passed to
SSH Sign requests, requesting that RSA signatures use SHA-256 or
SHA-512. See section 4.5.1 of the SSH agent protocol draft:
https://tools.ietf.org/html/draft-miller-ssh-agent-02

The second feature is supporting calling custom extensions from clients
and implementing custom extensions from servers. See section 4.7 of the
SSH agent protocol draft:
https://tools.ietf.org/html/draft-miller-ssh-agent-02

Change-Id: I0f74feb893762c27e921ec37604d3a46434ee6ef
GitHub-Last-Rev: 2e23fd01c0e95b664e8507682f0bd5bd61d4c146
GitHub-Pull-Request: golang/crypto#53
Reviewed-on: https://go-review.googlesource.com/c/123955
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-10-29 10:30:14 +00:00
Igor Zhilianin 45a5f77698 all: fix typos
Change-Id: I62cbcfcd0be5f6a74d93b85b24ff7607533bb239
GitHub-Last-Rev: 9967869e706e9fe7d13964bb32b30a44ba640869
GitHub-Pull-Request: golang/crypto#64
Reviewed-on: https://go-review.googlesource.com/c/145240
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-10-29 02:12:03 +00:00
Filippo Valsorda e84da03127 hkdf: add Extract and Expand
RFC 5869, Section 3.3 suggests it might be sometimes appropriate to use
Expand without Extract, and it is reasonable to reuse (secret, salt)
with different info values, in which case the Extract can be performed
once as an optimization.

TLS 1.3 also needs direct access to both Extract and Expand.

pseudorandomKey is ugly to look at, but that's intentional, as it
signals that this should have non-obvious properties to the user. The
docs will make it clear it's not the thing you should use in most cases.

Fixes golang/go#28237

Change-Id: Ib43ae8cdde0663aa4752172c39aadfb0e1c35f10
Reviewed-on: https://go-review.googlesource.com/c/144398
Reviewed-by: Adam Langley <agl@golang.org>
2018-10-25 21:37:31 +00:00
Filippo Valsorda d2c3f1d8b9 hkdf: improve example
Change-Id: I540c699baf1f7cbf27da458961d581773f442864
Reviewed-on: https://go-review.googlesource.com/c/144397
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Adam Langley <agl@golang.org>
2018-10-25 21:28:55 +00:00
Axel Wagner 85e1b3f913 openpgp: don't generate PubKeyAlgoRSASignOnly keys
These are deprecated according to RFC4880 and should no longer be
generated: https://tools.ietf.org/html/rfc4880#section-13.5
With that, the notion of a "sign-only" private key doesn't make sense
(as that is a signature property, not a private key property), so remove
it from the comment.

Fixes golang/go#27888

Change-Id: I7d41acd0793b2caf3c0897e580f42375c72d82a8
Reviewed-on: https://go-review.googlesource.com/c/137896
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-10-25 11:38:41 +00:00
David Jones 74cb1d3d52 acme/autocert: include rejected hostname in TLS handshake error when host not configured
More informative error message enables HTTPS server configuration mistakes to be corrected quickly, since log files will now include the rejected hostname.  If the hostname should be accepted, it can be added to the HostWhitelist Policy.

Fixes golang/go#28345

Change-Id: I801c82f0d3b19bc34592c9cd0bce77f1b284d19d
GitHub-Last-Rev: 5dfe731d732d693f9bdd79c8a74efd30a2f56d0b
GitHub-Pull-Request: golang/crypto#63
Reviewed-on: https://go-review.googlesource.com/c/144337
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-10-24 17:11:44 +00:00
Andres Lowrie 0c41d7ab0a ssh/testdata: correct typo
Change-Id: I93275a7aa048bab63bcf5dafe8582a0fcd7802ae
GitHub-Last-Rev: d56c40c905351af5d9555b2966ea793328655ee4
GitHub-Pull-Request: golang/crypto#60
Reviewed-on: https://go-review.googlesource.com/c/142077
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-10-15 02:39:09 +00:00
mkishere a92615f3c4 ssh: fix typo in error message
Fix typo in error message when keyboard-interactive auth not supported by server and client requests it

Change-Id: Iedb72625852f03552481d85cce2119765cfba320
GitHub-Last-Rev: ee47092daf8c40fe3e0e166e7370556819457af6
GitHub-Pull-Request: golang/crypto#59
Reviewed-on: https://go-review.googlesource.com/c/141658
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-10-12 14:40:02 +00:00
aviau 7c1a557ab9 openpgp: split up tests and keys
keys_test.go was slowing down my editor because it was getting too
large. It helps to remove the keys of the file as they contain extremely
long lines and large strings.

Change-Id: I8d193179ddc32438b7233f0f9ca8c57c928a0436
Reviewed-on: https://go-review.googlesource.com/c/138997
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-10-09 21:39:50 +00:00
Axel Wagner e3636079e1 openpgp: allow RSA/ECDSA signers to return a pointer
Fixes golang/go#27606

Change-Id: I88b2f7c7796b43449a17a6be963c05f741dbf904
Reviewed-on: https://go-review.googlesource.com/137895
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2018-10-01 20:31:47 +00:00
aviau f7f546618e openpgp: test subkeys with sub-optimal signature packet ordering
Test for RFC4880 5.2.3.3:
> An implementation that encounters multiple self-signatures on the
> same object may resolve the ambiguity in any way it sees fit, but it
> is RECOMMENDED that priority be given to the most recent self-
> signature.

Note: Some GPG implementation will reorder the packets for you when
 exporting keys. This makes it complicated to generate a key for this
 test. Should someone have to create a similar key again, look into
 gpgsplit, gpg --dearmor, and gpg --enarmor. These keys exist in the
 wild too.

Change-Id: I5d46054ebbc95407d644e4e462d777aab290794c
Reviewed-on: https://go-review.googlesource.com/138215
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2018-10-01 20:27:00 +00:00
Paul M Furley 0259c3f76d openpgp: use latest subkey binding signature
Rather than using the first subkey binding signature encountered, use
the one with the most recent creation data, as per the recommendation from
RFC 4880:

> An implementation that encounters multiple self-signatures on the
> same object may resolve the ambiguity in any way it sees fit, but it
> is RECOMMENDED that priority be given to the most recent self-
> signature.

This allows subkeys to approach expiry then be re-signed with a new expiry.

This extends the recent commit 0e37d00 by @aviau and @FiloSottile.

Fixes golang/go#26468

Change-Id: I7f12706727373259c188bfee4254306ef9d4e935
GitHub-Last-Rev: 0da814166411a3c3334312576d3f7f8f2bba4ff4
GitHub-Pull-Request: golang/crypto#57
Reviewed-on: https://go-review.googlesource.com/135357
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2018-10-01 20:26:45 +00:00
aviau 5295e83643 openpgp: move addUserID outside of ReadEntity
In change id Id992676ef2363779a7028f4799180efb027fcf47, "current" was
moved into the UserID packet handling scope. This was the only thing
preventing us to move the UserID packet handling code inside its own
function.

This patch moves the UserID packet handling code inside a new addUserID
function. This is consistent with the other existing addSubKey method.

"current" is renamed to "identity" for improved readability.

Change-Id: I5d58eb35ab5fa9fc7d9d111fa186fec6f5e11e79
Reviewed-on: https://go-review.googlesource.com/118959
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-27 16:59:25 +00:00
aviau 0e37d00645 openpgp: don't treat extra subkey selfsigs as uid sigs
Consider the following packet ordering scenario:
    PUBKEY UID SELFSIG SUBKEY REV SELFSIG

In this scenario, addSubkey would only consume the REV signature after
the subkey, leaving SELFSIG to be read by ReadEntity, which in turn
would add the last SELFSIG to the UID's signatures, which is wrong to do
because this is a SUBKEY SELFSIG, not a UID signature.

Remove "current" from the ReadEntity scope, it should only be visible
to the UserId packet handling code.

Keep the warning about signature packets found before user id packets.
Without it, I would not have found this bug.

Modify addSubKey so that it consumes all signatures following the SUBKEY
packet, keeping eithier the first valid signature (like we did before)
or any valid revocation.

In a follow-up patch, we can improve this further by keeping the
most recent signature, as suggested by RFC4880:
> An implementation that encounters multiple self-signatures on the
> same object may resolve the ambiguity in any way it sees fit, but it
> is RECOMMENDED that priority be given to the most recent self-
> signature.

Fixes golang/go#26449

Change-Id: Id992676ef2363779a7028f4799180efb027fcf47
Reviewed-on: https://go-review.googlesource.com/118957
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2018-09-10 18:16:07 +00:00
Adam Langley 0709b304e7 ssh: don't panic if a key is too short.
Change-Id: I810eb1c5d4cacc710a427e2ce031db1e9c292454
Reviewed-on: https://go-review.googlesource.com/132656
Run-TryBot: Adam Langley <agl@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-09-04 16:38:35 +00:00
David Ndungu 182538f800 acme/autocert: clarify that multiple names are allowed
Change-Id: Ib5111388859b36c1989aad1a1948bd83ab01b7e0
Reviewed-on: https://go-review.googlesource.com/132328
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-08-30 19:23:47 +00:00
Martin Möhrmann 614d502a4d chacha20poly1305: use x/sys/cpu feature variables directly
Avoid using package specific variables when there is a one to one
correspondance to cpu feature support exported by internal/cpu.

This makes it clearer which cpu feature is referenced.
Another advantage is that internal/cpu variables are padded to avoid
false sharing and memory and cache usage is shared by multiple packages.

Change-Id: Ieadfc2f2f65f83f947aa8a5efc869aa85d89615d
Reviewed-on: https://go-review.googlesource.com/126597
Run-TryBot: Martin Möhrmann <moehrmann@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-20 15:07:26 +00:00
Thomas Bushnell, BSG aabede6cba openpgp/clearsign: add ability to sign with more than one key.
Change-Id: I34036514435d365adb2b9da4ac66673be466a34b
Reviewed-on: https://go-review.googlesource.com/129655
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-08-16 22:57:34 +00:00
Adam Langley de07523181 chacha20poly1305: add some more XChaCha20-Poly1305 test vectors.
These vectors were generated with libsodium to ensure that Go is
compatible with that library:

  #include <stdio.h>
  #include <sodium.h>
  #include <stdlib.h>

  static void hexdump(const uint8_t *in, size_t in_len) {
  	printf("\t\t\"");
  	for (size_t i = 0; i < in_len; i++) {
  		printf("%02x", in[i]);
  	}
  	printf("\",\n");
  }

  int main() {
  	uint8_t nonce[24];
  	uint8_t key[32];
  	uint8_t m[64], c[64+16];
  	uint8_t ad[16];

  	for (size_t ad_len = 0; ad_len < sizeof(ad); ad_len += 4) {
  		for (size_t m_len = 0; m_len < sizeof(m); m_len += 5) {
  			randombytes(nonce, sizeof(nonce));
  			randombytes(key, sizeof(key));
  			randombytes(m, m_len);
  			randombytes(ad, ad_len);

  			unsigned long long c_len = sizeof(c);
  			if (crypto_aead_xchacha20poly1305_ietf_encrypt(c, &c_len, m, m_len, ad, ad_len, NULL, nonce, key)) {
  				abort();
  			}

  			printf("\t{\n");
  			hexdump(m, m_len);
  			hexdump(ad, ad_len);
  			hexdump(key, sizeof(key));
  			hexdump(nonce, sizeof(nonce));
  			hexdump(c, c_len);
  			printf("\t},\n");
  		}
  	}

  	return 0;
  }

Change-Id: I4e9e4dc26e0e842c82319829599dbe48c331726f
Reviewed-on: https://go-review.googlesource.com/128615
Run-TryBot: Adam Langley <agl@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-08-08 21:18:26 +00:00
Adam Langley ff745d0763 acme/autocert: fix race in test.
The timeNow package variable doesn't work well here: since the renewal
functionality spawns goroutines that invoke timeNow, once a test has
caused such goroutines to exist, another test can't fiddle with it
without the race detector triggering.

Instead, have a private member of Manager that the tests can set if they
need.

Change-Id: Iaf1a68d8efb84c9c5e2804aeb9cc6b2d3f3fef43
Reviewed-on: https://go-review.googlesource.com/128655
Run-TryBot: Adam Langley <agl@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-08 21:16:02 +00:00
Noel Georgi f027049dab ssh: RFC5208 support PKCS#8 key
Change-Id: I3d0ea816843c88930af3aa1f613978e0e90fa389
Reviewed-on: https://go-review.googlesource.com/127779
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
2018-08-07 10:46:21 +00:00
Filippo Valsorda 80fca2ff14 chacha20poly1305: add example for NewX
Change-Id: I619e38a2c8629e851435299fa5204f5fd48a1d87
Reviewed-on: https://go-review.googlesource.com/128055
Reviewed-by: Adam Langley <agl@golang.org>
2018-08-06 19:00:21 +00:00
Filippo Valsorda f792edd33d chacha20poly1305: add XChaCha20-Poly1305
The XChaCha20 construction does not have an authoritative spec, but this
implementation is based on the following documents:

https://cr.yp.to/snuffle/xsalsa-20081128.pdf
https://download.libsodium.org/doc/secret-key_cryptography/aead.html
http://loup-vaillant.fr/tutorials/chacha20-design
https://tools.ietf.org/html/draft-paragon-paseto-rfc-00#section-7

Tested against the following implementations:

https://github.com/jedisct1/libsodium/blob/7cdf3f0e841/test/default/aead_xchacha20poly1305.c
https://git.kernel.org/pub/scm/linux/kernel/git/zx2c4/linux.git/diff/lib/zinc/selftest/chacha20poly1305.h?h=zinc
https://git.zx2c4.com/wireguard-go/tree/xchacha20poly1305/xchacha20.go

name                            time/op          speed
Chacha20Poly1305/Open-64-8         225ns ± 1%     283MB/s ± 1%
Chacha20Poly1305/Open-64-X-8       390ns ± 0%     164MB/s ± 0%
Chacha20Poly1305/Seal-64-8         222ns ± 0%     287MB/s ± 0%
Chacha20Poly1305/Seal-64-X-8       386ns ± 0%     165MB/s ± 1%
Chacha20Poly1305/Open-1350-8      1.12µs ± 1%    1.21GB/s ± 1%
Chacha20Poly1305/Open-1350-X-8    1.28µs ± 0%    1.05GB/s ± 0%
Chacha20Poly1305/Seal-1350-8      1.15µs ± 0%    1.17GB/s ± 0%
Chacha20Poly1305/Seal-1350-X-8    1.32µs ± 1%    1.02GB/s ± 0%
Chacha20Poly1305/Open-8192-8      5.53µs ± 0%    1.48GB/s ± 0%
Chacha20Poly1305/Open-8192-X-8    5.71µs ± 1%    1.44GB/s ± 1%
Chacha20Poly1305/Seal-8192-8      5.54µs ± 1%    1.48GB/s ± 1%
Chacha20Poly1305/Seal-8192-X-8    5.74µs ± 1%    1.43GB/s ± 1%

Updates golang/go#24485

Change-Id: Iea6f3b4c2be67f16f56720a200dcc895c0f9d520
Reviewed-on: https://go-review.googlesource.com/127819
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Adam Langley <agl@golang.org>
2018-08-06 17:10:22 +00:00
Filippo Valsorda 56440b844d acme/autocert: expand tls-alpn-01 docs
Change-Id: Ia2fe53e6c85ffe4859248e50ab0e489a3b783ef5
Reviewed-on: https://go-review.googlesource.com/126607
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-02 22:12:40 +00:00