Граф коммитов

31 Коммитов

Автор SHA1 Сообщение Дата
Michael Munday 5d647ca157 sha3: fix SHA-3 on s390x when using KIMD instruction
An illegal instruction would occur due to a bug in the way input
slices were rounded down in size to a multiple of the rate for a
given hash type. This would only occur when the Write function
was called with more than ~3KiB of data and the length of the data
was not a multiple of the rate.

Fixes golang/go#36459.

Change-Id: I621ef8d75602bcd59bb44491e17f721050001e6d
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/213857
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-01-08 21:55:11 +00:00
Bryan C. Mills c7e5f84aec sha3: align (*state).storage
Even on platforms that allow unaligned reads, the Go runtime assumes
that a pointer to a given type has the alignment required by that
type.

Fixes golang/go#35173
Updates golang/go#34972
Updates golang/go#34964

Change-Id: I90361e096e59162e42ebde2914985af92f777ece
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/203837
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2019-11-05 03:41:35 +00:00
Tobias Klauser 71b5226ff7 sha3: add a space before +build in build tag comments
Add a space before build tag comments so it corresponds to the format
documented at https://golang.org/pkg/go/build/.

Change-Id: Ic29df4660a0968f58f721ec61943c0b277d4aaad
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/193777
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-09-07 12:14:10 +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
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
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
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
Igor Zhilianin 45a5f77698 all: fix typos
Change-Id: I62cbcfcd0be5f6a74d93b85b24ff7607533bb239
GitHub-Last-Rev: 9967869e70
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
Leon Klingele 4ec37c66ab sha3: add NewLegacyKeccak256
Keccak uses a different domain separation byte as the NIST-
standardized SHA-3 hashing function.

Fixes golang/go#19709

Change-Id: I1b45afce9b7719241b24bbdc9b67718d73b457d3
GitHub-Last-Rev: 4f2a701c5f
GitHub-Pull-Request: golang/crypto#41
Reviewed-on: https://go-review.googlesource.com/106462
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2018-05-05 02:55:34 +00:00
Kris Kwiatkowski 76a954637d sha3: enable TestUnalignedWrites
Changes function name from "testUnalignedWrites" to "TestUnalignedWrites"
which makes "go test" actually run this test.

Change-Id: Ie46f11ee1fd5c8780d5704d2fabe6ddb229262f9
Reviewed-on: https://go-review.googlesource.com/111282
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-05-03 15:31:09 +00:00
Michael Munday dccd99e89d sha3: add optimized implementation for s390x
Message-security-assist extension 6 adds support for the SHA-3 and
SHAKE algorithms. This CL allows the sha3 package to use these new
features.

name                 old speed     new speed      delta
PermutationFunction  328MB/s ± 0%   385MB/s ± 0%    +17.28%  (p=0.000 n=9+10)
Sha3_512_MTU         108MB/s ± 0%  2011MB/s ± 0%  +1768.56%  (p=0.000 n=10+10)
Sha3_384_MTU         149MB/s ± 0%  2437MB/s ± 0%  +1534.22%  (p=0.000 n=10+10)
Sha3_256_MTU         185MB/s ± 0%  2739MB/s ± 0%  +1379.93%  (p=0.000 n=10+10)
Sha3_224_MTU         195MB/s ± 0%  2782MB/s ± 0%  +1326.05%  (p=0.000 n=10+10)
Shake128_MTU         225MB/s ± 0%  4436MB/s ± 0%  +1873.18%  (p=0.000 n=9+9)
Shake256_MTU         209MB/s ± 0%  4521MB/s ± 0%  +2059.86%  (p=0.000 n=8+10)
Shake256_16x         188MB/s ± 0%  1366MB/s ± 0%   +624.70%  (p=0.000 n=9+10)
Shake256_1MiB        212MB/s ± 0%  5861MB/s ± 0%  +2666.67%  (p=0.000 n=10+10)
Sha3_512_1MiB        116MB/s ± 0%  4328MB/s ± 0%  +3628.33%  (p=0.000 n=10+10)

Change-Id: I8ebc503ca2b9eda2ebb361dffdbfe79dd97e1975
Reviewed-on: https://go-review.googlesource.com/59391
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-26 18:01:11 +00:00
Kyle Spiers 182114d582 sha3: fix typo in Shake256 docs
Change-Id: I1d8d1016a956bf185d3a5af76188b8287fce6391
Reviewed-on: https://go-review.googlesource.com/100195
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-03-12 19:55:33 +00:00
Kevin Burke 94eea52f7b all: run gofmt -s on source code
Per the description, the "-s" file issues slight simplifications to
the source code.

Change-Id: I77395d763f5eafb48653902dcedfa56b150b2d67
Reviewed-on: https://go-review.googlesource.com/80138
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-11-28 19:40:09 +00:00
Michael Munday 81e90905da sha3: delete unused field
Change-Id: I7dcb8a5ee07cc39e0c503f211f8f77732f006ad6
Reviewed-on: https://go-review.googlesource.com/59170
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-08-25 22:01:21 +00:00
sbuss 7f7c0c2d75 sha3: added example output
Output for sha3.ShakeSum256 and sha3.NewShake256 examples is now
verified.

Change-Id: I31e186a025cbea20d206a253fccea44e1f8a6e49
Reviewed-on: https://go-review.googlesource.com/48870
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-07-15 21:18:42 +00:00
Austin Clements 77e80449e8 sha3: fix SP adjustment
keccakF1600 manually subtracts 200 from SP, but the generated prologue
already does this and the extra subtraction just means keccakF1600 is
defeating the stack growth check.

Remove the unnecessary SP adjustment.

Change-Id: I9450f6b12489bcd20e9ace30f9dd3066025d3a1a
Reviewed-on: https://go-review.googlesource.com/31653
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Adam Langley <agl@golang.org>
2016-10-21 19:51:19 +00:00
Péter Szilágyi 80b25ed484 crypto/sha3: use the assembly optimized KeccakF on amd64
NIST published a Keccak Code Package following the SHA-3 workshop
organized in 2014, containing optimized versions of various Keccak
functions for various architectures. This CL converts the GNU asm
code of the Keccak permutation for the x86_64 architecture into Go
assembly.

The code here is almost an identical copy of KeccakF1600_StatePermute,
with the only modification of converting the input state into the
implementation's internal representation and vice versa before return.
This keeps the algorithm an in-place version and avoids requiring
extra external state inits and data XORs before and after the permute.

The speed difference is:

benchmark                          old ns/op     new ns/op     delta
BenchmarkPermutationFunction-8     476           411           -13.66%
BenchmarkSha3_512_MTU-8            9910          8681          -12.40%
BenchmarkSha3_384_MTU-8            7124          6249          -12.28%
BenchmarkSha3_256_MTU-8            5666          4986          -12.00%
BenchmarkSha3_224_MTU-8            5401          4750          -12.05%
BenchmarkShake128_MTU-8            4614          3980          -13.74%
BenchmarkShake256_MTU-8            4935          4295          -12.97%
BenchmarkShake256_16x-8            71850         63798         -11.21%
BenchmarkShake256_1MiB-8           3784244       3285733       -13.17%
BenchmarkSha3_512_1MiB-8           7098875       6163359       -13.18%

benchmark                          old MB/s     new MB/s     speedup
BenchmarkPermutationFunction-8     420.11       486.35       1.16x
BenchmarkSha3_512_MTU-8            136.22       155.51       1.14x
BenchmarkSha3_384_MTU-8            189.49       216.03       1.14x
BenchmarkSha3_256_MTU-8            238.23       270.71       1.14x
BenchmarkSha3_224_MTU-8            249.91       284.19       1.14x
BenchmarkShake128_MTU-8            292.58       339.15       1.16x
BenchmarkShake256_MTU-8            273.53       314.28       1.15x
BenchmarkShake256_16x-8            228.03       256.81       1.13x
BenchmarkShake256_1MiB-8           277.09       319.13       1.15x
BenchmarkSha3_512_1MiB-8           147.71       170.13       1.15x

For further details, please see:
 - http://csrc.nist.gov/groups/ST/hash/sha-3/Aug2014/documents/vanassche_keccak_code.pdf
 - https://github.com/gvanas/KeccakCodePackage

Change-Id: I5b0b9395bba7d8c9acfe2b9c79f6e9c2cf858c7c
Reviewed-on: https://go-review.googlesource.com/17962
Reviewed-by: Adam Langley <agl@golang.org>
2016-09-13 20:24:05 +00:00
Martin Hamrle 077efaa604 x/crypto: fix typos
The typos were found by misspell tool.

Change-Id: I120740f12f7ba48330749ebf84050a7b98e01016
Reviewed-on: https://go-review.googlesource.com/24725
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
2016-07-06 16:40:51 +00:00
Lynn Boger fbbbdbdd6f sha3: revert alignment optimization on ppc64
A previous fix to improve performance based on alignment
to sha3 was made in both ppc64le and ppc64, when it should
have only applied to ppc64le.  This changes the build tags
so it is only done for ppc64le.

Fixes golang/go#15392

Change-Id: Idf32a0370f3c76fc2b54a2897a668acbae5d43c5
Reviewed-on: https://go-review.googlesource.com/22323
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-04-20 21:40:36 +00:00
Lynn Boger c197bcf24c golang/x/crypto/sha3: use better alignment
Change the build tags for xor.go and xor_unaligned.go
to perform better on ppc64/ppc64le.

This improves performance for these sha3 benchmarks:

benchmark                        old MB/s     new MB/s     speedup
BenchmarkSha3_512_MTU            68.42        76.03        1.11x
BenchmarkSha3_384_MTU            91.12        105.38       1.16x
BenchmarkSha3_256_MTU            110.19       132.63       1.20x
BenchmarkSha3_224_MTU            114.46       139.12       1.22x
BenchmarkShake128_MTU            129.77       163.14       1.26x
BenchmarkShake256_MTU            125.01       151.93       1.22x
BenchmarkShake256_16x            110.60       129.44       1.17x
BenchmarkShake256_1MiB           128.51       154.23       1.20x
BenchmarkSha3_512_1MiB           74.18        82.39        1.11x

Fixes golang/go#14847

Change-Id: I59ba763b4eaf3e567399b132ad820fb2dcbbf129
Reviewed-on: https://go-review.googlesource.com/20821
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-03-17 20:21:02 +00:00
Glenn Brown bc65b9074c sha3: fix TestAppend to loop twice, to match the comments.
Change-Id: I84713a4173d9de4cd3d14991b8a47c9fbae7dcfd
Reviewed-on: https://go-review.googlesource.com/8976
Reviewed-by: David Symonds <dsymonds@golang.org>
2015-04-16 05:37:58 +00:00
David Leon Gil bfc286917c sha3: move test data to testdata
Change the location of the KAT data for consistency with
other packages.

Change-Id: Ica10ad7d1730603f957fb413e28fe771b3c323bc
Reviewed-on: https://go-review.googlesource.com/3267
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-01-24 22:04:49 +00:00
David Leon Gil 4ed45ec682 sha3: use unaligned reads and xors on x86 and x64
Speedup of about 1.4x on x64. Added benchmarks that use the
ShakeHash interface, which doesn't require copying the state.

Unaligned or generic xorIn and copyOut functions chosen via
buildline, but both are tested.

Substantial contributions from Eric Eisner.

See golang.org/cl/151630044 for the previous CR.

(There are also some minor edits/additions to the documentation.)

Change-Id: I9500c25682457c82487512b9b8c66df7d75bff5d
Reviewed-on: https://go-review.googlesource.com/2132
Reviewed-by: Adam Langley <agl@golang.org>
2015-01-12 22:01:33 +00:00
David Symonds 1fbbd62cfe crypto: add import comments.
Change-Id: I33240faf1b8620d0cd600de661928d8e422ebdbc
Reviewed-on: https://go-review.googlesource.com/1235
Reviewed-by: Andrew Gerrand <adg@golang.org>
2014-12-09 23:26:36 +00:00
Ian Lance Taylor cb7a96fa34 sha3: change range statement in test to work with Go 1.3 and earlier
LGTM=bradfitz
R=agl, bradfitz
CC=golang-codereviews
https://golang.org/cl/157930043
2014-10-13 14:14:22 -07:00
Eric Roshan-Eisner 9b55b542f6 go.crypto/sha3: optimize round function
benchmark                        old ns/op     new ns/op     delta
BenchmarkPermutationFunction     1128          733           -35.02%
BenchmarkShake256_1MiB           10004381      6832715       -31.70%

benchmark                        old MB/s     new MB/s     speedup
BenchmarkPermutationFunction     177.23       272.54       1.54x
BenchmarkShake256_1MiB           104.81       153.46       1.46x

LGTM=agl
R=golang-codereviews, agl
CC=golang-codereviews
https://golang.org/cl/156770043
2014-10-08 10:57:02 -07:00
Adam Langley 82442e0e95 go.crypto/sha3: use the go1.4 tag to register the hash functions.
Prior to Go 1.4, crypto didn't have the consts defined for SHA-3.

LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/133540043
2014-09-03 16:08:25 -07:00
David Leon Gil 1b32d8b50a go.crypto/sha3: update to sync with draft FIPS-202
1. API:

This exposes a minimal API: the SHA-3 functions implement hash.Hash. The
SHAKE functions implement a new "ShakeHash" interface that implements
io.Reader, io.Writer, and Reset().

(The previous Barrier() function has been removed.)

(Alternative proposal: Don't implement io.Reader, but instead provide a
"Digest(d []byte) error" function that performs a hash.Hash style copy.
Somewhat more minimal, but very easy to use incorrectly.)

2. Tests

Added the complete set of ShortMsgKATs from
   https://github.com/gvanas/KeccakCodePackage

3. Correctness

In sync with draft FIPS-202.

4. Documentation

A summary of the security properties of the SHA-3 and SHAKE functions is
provided in doc.go; some concrete recommendations as well.

Fixes 8563.

R=golang-codereviews, agl
CC=golang-codereviews
https://golang.org/cl/130950043
2014-09-03 12:04:00 -07:00
Eric Roshan-Eisner d52ec73510 go.crypto/sha3: change keccakF to stateless function
Taken from my implementation: https://bitbucket.org/ede/sha3
Performance gain from using less memory and more registers.

benchmark                       old ns/op    new ns/op    delta
BenchmarkPermutationFunction         1484         1118  -24.66%
BenchmarkBulkKeccak512             374993       295178  -21.28%
BenchmarkBulkKeccak256             215496       172335  -20.03%

benchmark                        old MB/s     new MB/s  speedup
BenchmarkPermutationFunction       134.76       178.80    1.33x
BenchmarkBulkKeccak512              43.69        55.51    1.27x
BenchmarkBulkKeccak256              76.03        95.07    1.25x

R=jcb, agl
CC=golang-dev, nigeltao
https://golang.org/cl/8088044
2013-04-02 10:41:35 -04:00
Nigel Tao 44f6c2e4a2 go.crypto/sha3: fix typo; remove 4 million map lookups (5% of "go test"
time); delete some comments that didn't add much and were incorrect
anyway (the test specification was tc, not t).

R=jcb
CC=agl, golang-dev
https://golang.org/cl/7665045
2013-03-23 10:10:15 +11:00
Joseph Bonneau 0bc0bccba9 go.crypto/sha3: new package
Added a pure Go implementation of SHA3 (Keccak) which implements the hash.Hash interface.
A test file is included with performance benchmarks and standard test vectors.

R=agl, nigeltao
CC=golang-dev
https://golang.org/cl/7760044
2013-03-22 14:59:59 -04:00