Commit Graph
808 Commits
Author SHA1 Message Date
Filippo Valsorda 8b5121be2f [release-branch.go1.13] cryptobyte: fix panic due to malformed ASN.1 inputs on 32-bit archs
When int is 32 bits wide (on 32-bit architectures like 386 and arm), an
overflow could occur, causing a panic, due to malformed ASN.1 being
passed to any of the ASN1 methods of String.

Tested on linux/386 and darwin/amd64.

This fixes CVE-2020-7919 and was found thanks to the Project Wycheproof
test vectors.

Change-Id: I8c9696a8bfad1b40ec877cd740dba3467d66ab54
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/645211
Reviewed-by: Katie Hockman <katiehockman@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/647740
2020-01-24 22:56:46 +00:00
Carlos Eduardo Seo 5c40567a22 internal/chacha20: fix variable naming
Wrong variable naming was causing 'go vet' to fail. This change fixes that.

Change-Id: I71e1842ece098198773fb326a725b57fad02f82f
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/181720
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
2019-06-11 18:44:40 +00:00
Lynn Boger f99c8df09e poly1305: improve performance with asm for ppc64le
This adds an asm implementation for poly1305 on ppc64le, based on
the amd64 asm implementation using the mac interface.

The improvements on a power8 based on the poly1305 benchmarks are:

    name              old time/op   new time/op    delta
    64                  172ns ± 0%      78ns ± 0%   -54.77%  (p=1.000 n=1+1)
    1K                 1.47µs ± 0%    0.59µs ± 0%   -59.69%  (p=1.000 n=1+1)
    2M                 2.84ms ± 0%    1.12ms ± 0%   -60.47%  (p=1.000 n=1+1)
    64Unaligned         172ns ± 0%      78ns ± 0%   -54.59%  (p=1.000 n=1+1)
    1KUnaligned        1.47µs ± 0%    0.59µs ± 0%   -59.69%  (p=1.000 n=1+1)
    2MUnaligned        2.84ms ± 0%    1.13ms ± 0%   -60.23%  (p=1.000 n=1+1)
    Write64             100ns ± 0%      46ns ± 0%   -53.80%  (p=1.000 n=1+1)
    Write1K            1.40µs ± 0%    0.56µs ± 0%   -59.90%  (p=1.000 n=1+1)
    Write2M            2.84ms ± 0%    1.12ms ± 0%   -60.46%  (p=1.000 n=1+1)
    Write64Unaligned    100ns ± 0%      46ns ± 0%   -53.60%  (p=1.000 n=1+1)
    Write1KUnaligned   1.40µs ± 0%    0.56µs ± 0%   -59.90%  (p=1.000 n=1+1)
    Write2MUnaligned   2.84ms ± 0%    1.13ms ± 0%   -60.22%  (p=1.000 n=1+1)

Change-Id: I77cc9bb3645a6b1a6edc414b5651dc37ae4a7410
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/173421
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Munday <mike.munday@ibm.com>
2019-06-05 12:30:33 +00:00
Carlos Eduardo Seo 20be4c3c3e internal/chacha20: improve performance for ppc64le
Add asm implementation for chacha20 using vector instructions on ppc64le.
Below, the difference using the new code:

name               old speed     new speed      delta
ChaCha20/32-16     167MB/s ± 0%   129MB/s ± 0%   -22.60%  (p=0.008 n=5+5)
ChaCha20/63-16     308MB/s ± 0%   249MB/s ± 0%   -19.00%  (p=0.008 n=5+5)
ChaCha20/64-16     357MB/s ± 0%   251MB/s ± 0%   -29.57%  (p=0.008 n=5+5)
ChaCha20/256-16    398MB/s ± 0%  1199MB/s ± 0%  +201.20%  (p=0.008 n=5+5)
ChaCha20/1024-16   413MB/s ± 0%  1398MB/s ± 0%  +238.67%  (p=0.008 n=5+5)
ChaCha20/1350-16   395MB/s ± 0%  1189MB/s ± 0%  +200.71%  (p=0.008 n=5+5)
ChaCha20/65536-16  420MB/s ± 0%  1489MB/s ± 0%  +254.10%  (p=0.008 n=5+5)

Small sizes are slower due the fact that it always calculates using
256 bytes of key stream.

This change was originally from Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com>
and started as CL 108999 (https://go-review.googlesource.com/c/crypto/+/108999).

Fixes golang/go#25051

Change-Id: Ie510494249b227379e23d993467256b3d4088035
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/172177
Run-TryBot: Carlos Eduardo Seo <cseo@linux.vnet.ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
2019-05-30 12:26:14 +00:00
Conrado P. L. Gouvea 22d7a77e9e sha3: fix bug in cSHAKE Clone()
Clone() made a copy of the Keccak state after invoking clone(), which is not
supported, since the "buf" slice in the Keccak state must point to the "storage"
array, and if the state is copied directly it will keep pointing to the storage
returned by clone().

Fix it by embedding a pointer to the Keccak state instead of the state itself.

Change-Id: I7d392963ec65d784a360f6c12a7935a9a9a788b5
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/173018
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-05-13 17:29:03 +00:00
yanweizhi cbcb750295 ssh/gss: support kerberos authentication for ssh server and client
Change-Id: I20e3356476dc50402dd34d2b39ad030c1e63a9ef
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/170919
Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
2019-05-10 10:41:15 +00:00
Matthew Dempsky e1dfcc5662 openpgp: replace "currentTime" with "creationTime" as appropriate
RFC 4880 uses the term "creation time" to refer to when keys and
signatures are created, and this is partially followed already. This
CL applies it to the rest of places that were using "currentTime"
instead.

Change-Id: I8a83604b53a240689327defd89e22ddbebe3b679
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/175446
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-05-06 20:42:51 +00:00
Udalov Max a29dc8fdc7 scrypt: use math.bits rotate functions instead of ad-hoc implementation
This makes code more readable and idiomatic. No change in benchmarks.

Updates golang/go#31456

Change-Id: I010bbff33580350019ce2b0ff13847261905d32f
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/174137
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-04-26 14:53:43 +00:00
chigotc f162ad860c ssh/test: add port for aix/ppc64
Fixes golang/go#31413

Change-Id: I52105280a2237f23cd91b8ec92fd89cf62564572
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/171917
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-04-26 14:52:10 +00:00
Filippo Valsorda c05e17bb3b openpgp/clearsign: reject potentially misleading headers and messages
Aida Mynzhasova of SEC Consult Vulnerability Lab reported that the
clearsign package accepts some malformed messages, which can make it
possible for an attacker to trick a human user (but not a Go program)
into thinking unverified text is part of the message.

For example, if in the following message the vertical tab character is
printed as a new line, a human observer could believe that the
unverified header text is part of the signed message.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1\x0b\x0bThis text is part of the header.

Hello world!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iJwEAQECAAYFAk8kMuEACgkQO9o98PRieSpMsAQAhmY/vwmNpflrPgmfWsYhk5O8
[...]
MyTpno24AjIAGb+mH1U=
=hIJ6
-----END PGP SIGNATURE-----

The OpenPGP specs are delightfully vague about purpose and validation of
these headers. RFC 4880, Section 7 says

    The cleartext signed message consists of:

        - The cleartext header '-----BEGIN PGP SIGNED MESSAGE-----' on a
        single line,

        - One or more "Hash" Armor Headers,

        - Exactly one empty line not included into the message digest,
        [...]

but also

    If MD5 is the only hash used, then an
    implementation MAY omit this header for improved V2.x compatibility.

and

    If more than one message digest is used in the signature, the "Hash"
    armor header contains a comma-delimited list of used message digests.

which seems to suggest that there can be zero or more Hash headers, each
with one or more algorithms, and no other header types.

Anyway, it's entirely unclear what security purpose, if any, the Hash
header accomplishes. If the hash is too weak to be secure or
unsupported, the verification will fail. Otherwise, the user shouldn't
care. Given its dubious function, avoid breaking abstractions to check
that it matches the signature, and just document it as unverified.

As for valid characters, RFC 4880 is silent, except reluctantly
mentioning that the Comment header can be UTF-8, but I am going to
assume that all hash algorithms will have ASCII names, because come on.

Even more importantly, reject non-Hash SIGNED MESSAGE headers (as opposed
to the SIGNATURE headers), to prevent a "Thank you!" message turning into

-----BEGIN PGP SIGNED MESSAGE-----
Reminder: I need you to wire $100k to 12345566 as soon as possible.

Thank you!
-----BEGIN PGP SIGNATURE-----
[...]

While at it, also check for trailing characters after the signed message
delimiter, as they are invalid and can be similarly used to confuse humans.

The Decode API is also unfortunate in that it doesn't return an error,
so we can't tell the user what's wrong with the message, but that's what
we've got.

Change-Id: I8a72c4851075337443d7a27e0b49a6b6e39f5a41
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/453011
Reviewed-by: Adam Langley <agl@google.com>
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/173778
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Adam Langley <agl@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-04-24 20:35:55 +00:00
Udalov Max d864b10871 blake2s: use math.bits rotate functions instead of ad-hoc implementation
This makes code more readable and idiomatic.

Updates golang/go#31456

Benchstat:
name       old time/op   new time/op   delta
Write64-8    211ns ± 6%    205ns ± 2%    ~     (p=0.243 n=10+9)
Write1K-8   3.26µs ± 3%   3.12µs ± 2%  -4.44%  (p=0.000 n=9+9)
Sum64-8      227ns ± 5%    217ns ± 6%  -4.58%  (p=0.009 n=10+10)
Sum1K-8     3.28µs ± 2%   3.31µs ± 4%    ~     (p=0.412 n=10+9)

name       old speed     new speed     delta
Write64-8  303MB/s ± 6%  312MB/s ± 1%    ~     (p=0.203 n=10+8)
Write1K-8  314MB/s ± 3%  329MB/s ± 2%  +4.64%  (p=0.000 n=9+9)
Sum64-8    281MB/s ± 5%  295MB/s ± 5%  +4.93%  (p=0.009 n=10+10)
Sum1K-8    313MB/s ± 2%  310MB/s ± 4%    ~     (p=0.447 n=10+9)

Change-Id: Iee0e88f4405d4da1feacddaf24835e86d8ddeff7
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/173278
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-04-22 18:39:09 +00:00
Aofei Sheng f8560614ba acme/autocert: make host of TLS certificate to be obtained always Punycode
According to the [RFC 5280, section 4.2.1.6](https://tools.ietf.org/html/rfc5280#section-4.2.1.6):

> ...
> When the subjectAltName extension contains a domain name system
> label, the domain name MUST be stored in the dNSName (an IA5String).
> The name MUST be in the "preferred name syntax", as specified by
> Section 3.5 of [RFC1034] and as modified by Section 2.1 of
> [RFC1123].  Note that while uppercase and lowercase letters are
> allowed in domain names, no significance is attached to the case.
> ...

And the [RFC 1034, section 3.5](https://tools.ietf.org/html/rfc1034#section-3.5):

> ...
> Note that while upper and lower case letters are allowed in domain
> names, no significance is attached to the case.  That is, two names with
> the same spelling but different case are to be treated as if identical.
> ...

We should return the same TLS certificate for both `example.com` and `EXAMPLE.COM`. But the `autocert.Manager.GetCertificate` treats the two as totally different, it signs and returns two different TLS certificates.

Moreover, now the `autocert.Manager.GetCertificate` and the `autocert.HostWhitelist` can only handle Punycode IDN. If the client sends a Unicode IDN to `autocert.Manager.GetCertificate` (cURL is doing this), the "Invalid character in DNS name" error will be triggered.

This PR corrects these problems by converting the host of the TLS certificate to be obtained to Punycode via `idna.Lookup.ToASCII`.

Change-Id: I993821b3a6ae532a53772e2db00524479ef111af
GitHub-Last-Rev: 6c12694574b6ac71a920da8a8bdb130c0b6e0272
GitHub-Pull-Request: golang/crypto#85
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/171997
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-04-22 17:19:13 +00:00
Udalov Max af44ce270e blake2b: use math.bits rotate functions instead of ad-hoc implementations
This makes code more readable and idiomatic and slightly improves performance.

Updates golang/go#31456

Benchstat:
name        old time/op    new time/op    delta
Write128-4     271ns ± 4%     250ns ± 2%  -7.78%  (p=0.000 n=10+9)
Write1K-4     2.01µs ± 6%    1.97µs ± 5%    ~     (p=0.393 n=10+10)
Sum128-4       271ns ± 6%     276ns ± 5%    ~     (p=0.342 n=10+10)
Sum1K-4       1.98µs ±11%    2.03µs ± 4%    ~     (p=0.093 n=10+10)

name        old speed      new speed      delta
Write128-4   471MB/s ± 4%   511MB/s ± 2%  +8.34%  (p=0.000 n=10+9)
Write1K-4    511MB/s ± 6%   521MB/s ± 5%    ~     (p=0.393 n=10+10)
Sum128-4     472MB/s ± 6%   463MB/s ± 6%    ~     (p=0.315 n=10+10)
Sum1K-4      520MB/s ±10%   504MB/s ± 4%    ~     (p=0.105 n=10+10)

Change-Id: I7e18379c02a78c77afcf8195d42307f71bc49fe0
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/173277
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-04-22 16:24:23 +00:00
Han-Wen Nienhuys df01cb2cc4 ssh: invert algorithm choices on the server
At the protocol level, SSH lets client and server specify different
algorithms for the read and write half of the connection. This has
never worked correctly, as Client-to-Server was always interpreted as
the "write" side, even if we were the server.

This has never been a problem because, apparently, there are no
clients that insist on different algorithm choices running against Go
SSH servers.

Since the SSH package does not expose a mechanism to specify
algorithms for read/write separately, there is end-to-end for this
change, so add a unittest instead.

Change-Id: Ie3aa781630a3bb7a3b0e3754cb67b3ce12581544
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/172538
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-04-18 16:56:55 +00:00
Tobias Klauser b43e412143 ssh/test: skip test on js/wasm
This should fix the build on the js/wasm builder.

Change-Id: I02a0ae00dcfd2691fbb4c7cf038b12988f3b4b85
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/172717
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-04-18 16:12:25 +00:00
Kris Kwiatkowski f416ebab96 sha3: add cSHAKE support
This patch implements 128- and 256-bit version of customizable variant
of SHAKE function (cSHAKE).

* Implementation based on NIST FIPS 202
* Test data file has been updated with cSHAKE KATs. I've copied
  examples from NIST document available here:
  https://csrc.nist.gov/csrc/media/projects/cryptographic-standards-and
  -guidelines/documents/examples/cshake_samples.pdf

Fixes #25395

Change-Id: Icbbc4232f3d9a28b3d6ead51937c2e60c00e5d8c
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/111281
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2019-04-17 17:40:47 +00:00
Neven Sajko 92d88b081a all: change the old assembly style AX:CX to CX, AX
Assembly files with "/vendor/" or "testdata" in their paths were
ignored.

Change-Id: I10621751b5eb649d0737025f944d5955c9204376
GitHub-Last-Rev: 005e16566cbfb36ffb4f31e4138e963c5dbcc700
GitHub-Pull-Request: golang/crypto#83
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/170778
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-04-17 17:02:29 +00:00
Han-Wen Nienhuys 88737f569e ssh/test: use t.Run for MAC/kex/pubkey tests
Change-Id: Ic57625964b6d40d63acade476a0f99c00d598267
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/171681
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-04-11 19:13:39 +00:00
Han-Wen Nienhuys e7b772b700 ssh: print server exit reason in tests
This helps debugging protocol violations by the client

Change-Id: I8e5486b49515b719bbe3de44daa489fb7434875a
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/171680
Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-04-11 14:19:40 +00:00
Han-Wen Nienhuys 9732e03de3 ssh: add packetTypeNames map for better debug info
Change-Id: Ie1f58e00982568382e09d8f1dd12bf8a1dc1a9ed
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/171679
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-04-11 14:12:12 +00:00
Han-Wen Nienhuys d99183c9a7 ssh: rename ExampleHostKeyCheck to ExampleClientConfig_HostKeyCallback
Change-Id: I6d0f3396f06871286e3d48ec5af38770663dbed2
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/171678
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-04-11 14:11:56 +00:00
Han-Wen Nienhuys 184a689644 ssh: remove testing.T from ExampleRetryableAuthMethod
Change-Id: I9cb821827b16d60b0a8c4fff9caec78748f3a495
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/171677
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-04-11 14:11:41 +00:00
Han-Wen Nienhuys 457ee04da3 ssh: rename methods in packetCipher interface
The new name readCipherPacket/writeCipherPacket disambiguates method
calls from packetConn.{read,write}Packet, which has a different
signature, and is called in different layers of the stack.

Change-Id: I02ca83e28f74f0a347a1cde665efdfb78f3f51bb
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/171657
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-04-11 14:11:16 +00:00
Brad Fitzpatrick 38d8ce5564 ssh/test: skip test to fix build on solaris and aix
Change-Id: I734bf1f709a259889eeb9243079edb90d6751f67
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/170677
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2019-04-04 16:44:18 +00:00
Brad Fitzpatrick 8e1b8d32e6 crypto: update go.mod for s390x x/sys/cpu changes
To fix broken builds like:
https://build.golang.org/log/4c3d8463f5c2b2478dc2315f6c685b2f77bfcdd1

Change-Id: I4c4866e5928a73856ca8a411ed97588e6f66e490
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/170623
Reviewed-by: Michael Munday <mike.munday@ibm.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-04-03 20:25:08 +00:00
Andrey Petrov a5d413f772 ssh/terminal: Use move-N sequences for >1 cursor moves
Before, we emitted N single-move sequences on a cursor move. For
example, "move 4 left" would emit "^[[D^[[D^[[D^[[D". With this change,
it would emit "^[[4D".

Using variable move sequences when possible reduces the amount of
rendering output that the terminal implementation produces. This can
have some low-level performance benefits, but also helps consumers
reason through the produced output.

Includes a test with a couple of cases.

Note: The old implementation used ^[[D instead of ^[D which is also
valid. This is true in several unrelated places, so this implementation
continues to use ^[[D for consistency.

Change-Id: If38eaaed8fb4075499fdda54c06681dc34c3ad70
GitHub-Last-Rev: 92ef2538d33a9493f3df09984c277dfd8bf0abf4
GitHub-Pull-Request: golang/crypto#82
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/169077
Reviewed-by: Adam Langley <agl@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-25 15:42:30 +00:00
Filippo Valsorda b7391e95e5 salsa20/salsa: fix keystream loop in amd64 assembly when overflowing 32-bit counter
Fixes golang/go#30965

Change-Id: I83a804d555c048e0124c35f95c9e611b2c5bdb01
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/436856
Reviewed-by: Adam Langley <agl@google.com>
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/168406
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-20 22:39:03 +00:00
Michael McLoughlin a1f597ede0 curve25519: add test vectors from BoringSSL
This diff extends the curve25519 test suite with some test vectors
generated from BoringSSL.

Updates golang/go#30095

Change-Id: I4e871378c77b46167d162e9eec75fc412596ff7c
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/161277
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-13 02:43:23 +00:00
Andreas Auernhammer c2843e01d9 poly1305: implement a subset of the hash.Hash interface
This CL adds the poly1305.MAC type which implements a
subset of the hash.Hash interface. With MAC it is possible
to compute an authentication tag of data without copying
it into a single byte slice.

This commit modifies the reference/generic and the
AMD64 assembler but not the ARM/s390x implementation
to support an io.Writer interface.

Updates golang/go#25219

Change-Id: I7ee5a9eadd43387cf3cd887d734c625575eee47d
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/111335
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2019-03-08 22:17:18 +00:00
Michael Munday 8dd112bcdc internal/chacha20: use x/sys/cpu for s390x feature detection
Use the recently added CPU feature detection API rather than custom
assembly. This will need to be updated to use 'internal/cpu' when
the package is revendored into std.

Change-Id: Icf0f28236ca0c351c88035f36e5b9c29d4bc2ba7
Reviewed-on: https://go-review.googlesource.com/c/164383
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-02-28 16:15:10 +00:00
Michael Munday 0091315ad7 poly1305: use x/sys/cpu for s390x feature detection
Use the recently added CPU feature detection API rather than custom
assembly. This will need to be updated to use 'internal/cpu' when
the package is revendored into std.

Change-Id: Ia99c51c7409fe4fabcd88fdf5ff19772c1ca2257
Reviewed-on: https://go-review.googlesource.com/c/164382
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-02-28 16:14:51 +00:00
Michael Munday e37aea1ec3 sha3: use x/sys/cpu for s390x feature detection
Use the recently added CPU feature detection API rather than custom
assembly.

While we are here also make vet happy by renaming params in the asm
file to chain to match the go function declaration.

Change-Id: Ide0171793c9fa5ef6671b394e97a27f2c6e44a9f
Reviewed-on: https://go-review.googlesource.com/c/164381
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-02-28 16:14:30 +00:00
Max Semenik 31a3858548 ssh/terminal: fix GetSize on Windows
Return window size instead of buffer size.

Fixes golang/go#27743

Change-Id: Ib1cd249f5680d86d505032e51d9102c2718ddf6f
Reviewed-on: https://go-review.googlesource.com/c/163538
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-02-28 05:08:51 +00:00
Michael Matloob 215aa809ca all: add a go.mod file
This change adds a go.mod and go.sum file to this repo, following the
requirements stated in bcmills's comment here:
https://golang.org/issue/28136#issuecomment-462971974. It's
important to note that we will not be
adding versions to the repo for now.

The change was generated by running "go mod init" and "go mod tidy" using Go
1.11.5 in the top-level directory of the repository.

Updates golang/go#28136

Change-Id: I17b2ac9eaae028a172a5adc260cffba5e0997619
Reviewed-on: https://go-review.googlesource.com/c/162911
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
2019-02-27 17:51:34 +00:00
Ian Haken 7f87c0fbb8 ssh/agent: add checking for empty SSH requests
Previously empty SSH requests would cause a panic.

Change-Id: I8443fee50891b3d2b3b62ac01fb0b9e96244241f
GitHub-Last-Rev: 64f00d2bf2ee722f53e68b6bd4f70c722d7694bd
GitHub-Pull-Request: golang/crypto#58
Reviewed-on: https://go-review.googlesource.com/c/140237
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-02-25 12:45:18 +00:00
lukechampine ffb98f7385 xts: reduce tweak allocations
The call to k2.Encrypt causes tweak to escape to the heap, resulting
in a 16-byte allocation for each call to Encrypt/Decrypt. Moving
tweak into the Cipher struct would allow it to be reused, but this
is ruled out by the Cipher docstring, which states that it is safe
for concurrent use. Instead, manage tweak arrays with a sync.Pool.
Benchmarks indicate that this amortizes allocation cost without
impacting performance.

benchmark          old ns/op     new ns/op     delta
BenchmarkXTS-4     234           245           +4.70%

benchmark          old allocs    new allocs    delta
BenchmarkXTS-4     2             0             -100.00%

benchmark          old bytes     new bytes     delta
BenchmarkXTS-4     32            0             -100.00%

Change-Id: I5e0dd8c2e1a1078a151bbeb1d0760936b6b56216
GitHub-Last-Rev: 14d81f589f3ada2b19511d592000657af3410a51
GitHub-Pull-Request: golang/crypto#51
Reviewed-on: https://go-review.googlesource.com/c/118535
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-02-22 23:57:06 +00:00
Sad Pencil 6635ad9975 bn256: fix String methods when g.p == nil
Previously, when g.p == nil, String() crashed. In other method like Add(),
a point with g.p == nil is treated as an identity element.

Besides, the following code is the only way to get an identity element
outside the library: g := bn256.G1{}. In this situation, g.p == nil.

For example, the following code will crash:

package main

import (
	"fmt"
	"golang.org/x/crypto/bn256"
)

func main() {
	g := bn256.G1{}
	fmt.Println(g.String())
}

Change-Id: Ied6f7c8197e7b79b0913c000a9cf1cf68f8188a9
GitHub-Last-Rev: 23246486a982ea54d6023726e048c74f02089f25
GitHub-Pull-Request: golang/crypto#75
Reviewed-on: https://go-review.googlesource.com/c/163118
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
2019-02-22 23:45:11 +00:00
Filippo Valsorda a57398324d all: deprecate broken and legacy packages
Fixes golang/go#30141

Change-Id: I76f8eae31cfd6d106440114685cc0d9abba374f8
Reviewed-on: https://go-review.googlesource.com/c/163537
Reviewed-by: Adam Langley <agl@golang.org>
2019-02-22 23:25:34 +00:00
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