[mirror] Go supplementary cryptography libraries
Перейти к файлу
Filippo Valsorda c17aa50fbd sha3: avoid buffer copy
Previously, the package worked by copying the input (or the output) into
a buffer, and then XOR'ing (or copying) it into (or out of) the state.
(Except for an input fast path.) There's no need for that! We can XOR
straight into the state, and copy straight out of it, at least on little
endian machines. This is a bit faster, almost halves the state size, and
will make it easier to implement marshaling, but most importantly look
at how much simpler it makes the code!

go: go1.23.0
goos: linux
goarch: amd64
pkg: golang.org/x/crypto/sha3
cpu: AMD Ryzen 7 PRO 8700GE w/ Radeon 780M Graphics
                      │ v0.27.0-2-g42ee18b9637 │    v0.27.0-2-g42ee18b9637-dirty    │
                      │         sec/op         │   sec/op     vs base               │
PermutationFunction-8              270.8n ± 0%   270.4n ± 0%       ~ (p=0.099 n=10)
Sha3_512_MTU-8                     5.762µ ± 0%   5.658µ ± 0%  -1.80% (p=0.000 n=10)
Sha3_384_MTU-8                     4.179µ ± 0%   4.070µ ± 0%  -2.60% (p=0.000 n=10)
Sha3_256_MTU-8                     3.316µ ± 0%   3.214µ ± 0%  -3.08% (p=0.000 n=10)
Sha3_224_MTU-8                     3.175µ ± 0%   3.061µ ± 0%  -3.61% (p=0.000 n=10)
Shake128_MTU-8                     2.779µ ± 0%   2.681µ ± 0%  -3.51% (p=0.000 n=10)
Shake256_MTU-8                     2.947µ ± 0%   2.957µ ± 0%  +0.32% (p=0.000 n=10)
Shake256_16x-8                     44.15µ ± 0%   44.45µ ± 0%  +0.67% (p=0.000 n=10)
Shake256_1MiB-8                    2.319m ± 0%   2.274m ± 0%  -1.93% (p=0.000 n=10)
Sha3_512_1MiB-8                    4.204m ± 0%   4.219m ± 0%  +0.34% (p=0.000 n=10)
geomean                            13.75µ        13.54µ       -1.55%

                      │ v0.27.0-2-g42ee18b9637 │    v0.27.0-2-g42ee18b9637-dirty     │
                      │          B/s           │     B/s       vs base               │
PermutationFunction-8             704.3Mi ± 0%   705.4Mi ± 0%       ~ (p=0.105 n=10)
Sha3_512_MTU-8                    223.5Mi ± 0%   227.6Mi ± 0%  +1.83% (p=0.000 n=10)
Sha3_384_MTU-8                    308.1Mi ± 0%   316.4Mi ± 0%  +2.67% (p=0.000 n=10)
Sha3_256_MTU-8                    388.2Mi ± 0%   400.5Mi ± 0%  +3.17% (p=0.000 n=10)
Sha3_224_MTU-8                    405.5Mi ± 0%   420.7Mi ± 0%  +3.73% (p=0.000 n=10)
Shake128_MTU-8                    463.4Mi ± 0%   480.2Mi ± 0%  +3.64% (p=0.000 n=10)
Shake256_MTU-8                    436.9Mi ± 0%   435.5Mi ± 0%  -0.32% (p=0.000 n=10)
Shake256_16x-8                    353.9Mi ± 0%   351.5Mi ± 0%  -0.66% (p=0.000 n=10)
Shake256_1MiB-8                   431.2Mi ± 0%   439.7Mi ± 0%  +1.97% (p=0.000 n=10)
Sha3_512_1MiB-8                   237.8Mi ± 0%   237.1Mi ± 0%  -0.33% (p=0.000 n=10)
geomean                           375.7Mi        381.6Mi       +1.57%

Even stronger effect when patched on top of CL 616555 (forced on).

go: go1.23.0
goos: darwin
goarch: arm64
pkg: golang.org/x/crypto/sha3
cpu: Apple M2
                      │    old    │               new                   │
                      │   sec/op  │     sec/op     vs base              │
PermutationFunction-8   154.7n ± 2%   153.8n ± 1%        ~ (p=0.469 n=10)
Sha3_512_MTU-8          3.260µ ± 2%   3.143µ ± 2%   -3.60% (p=0.000 n=10)
Sha3_384_MTU-8          2.389µ ± 2%   2.244µ ± 2%   -6.07% (p=0.000 n=10)
Sha3_256_MTU-8          1.950µ ± 2%   1.758µ ± 1%   -9.87% (p=0.000 n=10)
Sha3_224_MTU-8          1.874µ ± 2%   1.686µ ± 1%  -10.06% (p=0.000 n=10)
Shake128_MTU-8          1.827µ ± 3%   1.447µ ± 1%  -20.80% (p=0.000 n=10)
Shake256_MTU-8          1.665µ ± 3%   1.604µ ± 3%   -3.63% (p=0.003 n=10)
Shake256_16x-8          25.14µ ± 1%   25.23µ ± 2%        ~ (p=0.912 n=10)
Shake256_1MiB-8         1.236m ± 2%   1.243m ± 2%        ~ (p=0.631 n=10)
Sha3_512_1MiB-8         2.296m ± 2%   2.305m ± 1%        ~ (p=0.315 n=10)
geomean                 7.906µ        7.467µ        -5.56%

                      │    old    │               new                   │
                      │    B/op   │      B/op      vs base              │
PermutationFunction-8   1.204Gi ± 2%   1.212Gi ± 1%        ~ (p=0.529 n=10)
Sha3_512_MTU-8          394.9Mi ± 2%   409.7Mi ± 2%   +3.73% (p=0.000 n=10)
Sha3_384_MTU-8          539.0Mi ± 2%   573.8Mi ± 2%   +6.45% (p=0.000 n=10)
Sha3_256_MTU-8          660.3Mi ± 2%   732.6Mi ± 1%  +10.95% (p=0.000 n=10)
Sha3_224_MTU-8          687.1Mi ± 2%   763.9Mi ± 1%  +11.17% (p=0.000 n=10)
Shake128_MTU-8          704.7Mi ± 2%   889.6Mi ± 2%  +26.24% (p=0.000 n=10)
Shake256_MTU-8          773.4Mi ± 3%   802.5Mi ± 3%   +3.76% (p=0.004 n=10)
Shake256_16x-8          621.6Mi ± 1%   619.3Mi ± 2%        ~ (p=0.912 n=10)
Shake256_1MiB-8         809.1Mi ± 2%   804.7Mi ± 2%        ~ (p=0.631 n=10)
Sha3_512_1MiB-8         435.6Mi ± 2%   433.9Mi ± 1%        ~ (p=0.315 n=10)
geomean                 653.6Mi        692.0Mi        +5.88%

Change-Id: I33a0a1ddf305c395f99bf17f81473e2f42c5ce42
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/616575
Reviewed-by: Daniel McCarney <daniel@binaryparadox.net>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Andrew Ekstedt <andrew.ekstedt@gmail.com>
2024-10-21 19:02:20 +00:00
acme all: fix printf(var) mistakes detected by latest printf checker 2024-09-04 21:26:08 +00:00
argon2 argon2: Avo port of blamka_amd64.s 2024-09-04 20:33:49 +00:00
bcrypt all: bump go.mod version and drop compatibility shims 2024-06-26 15:12:35 +00:00
blake2b blake2b: port blake2b_amd64.s to Avo 2024-09-04 20:34:46 +00:00
blake2s blake2s: port blake2s_amd64.s to Avo 2024-09-04 20:34:20 +00:00
blowfish all: bump go.mod version and drop compatibility shims 2024-06-26 15:12:35 +00:00
bn256 bn256: add missing symbols in comment 2024-09-10 20:43:33 +00:00
cast5 all: bump go.mod version and drop compatibility shims 2024-06-26 15:12:35 +00:00
chacha20 chacha20: extend ppc64le support to ppc64 2024-10-11 17:09:09 +00:00
chacha20poly1305 chacha20poly1305: Avo port of chacha20poly1305_amd64.s 2024-09-04 20:35:14 +00:00
cryptobyte all: bump go.mod version and drop compatibility shims 2024-06-26 15:12:35 +00:00
curve25519 all: bump go.mod version and drop compatibility shims 2024-06-26 15:12:35 +00:00
ed25519 all: bump go.mod version and drop compatibility shims 2024-06-26 15:12:35 +00:00
hkdf all: bump go.mod version and drop compatibility shims 2024-06-26 15:12:35 +00:00
internal internal/poly1305: extend ppc64le support to ppc64 2024-10-04 20:59:56 +00:00
md4 all: bump go.mod version and drop compatibility shims 2024-06-26 15:12:35 +00:00
nacl all: bump go.mod version and drop compatibility shims 2024-06-26 15:12:35 +00:00
ocsp all: bump go.mod version and drop compatibility shims 2024-06-26 15:12:35 +00:00
openpgp all: bump go.mod version and drop compatibility shims 2024-06-26 15:12:35 +00:00
otr all: bump go.mod version and drop compatibility shims 2024-06-26 15:12:35 +00:00
pbkdf2 all: bump go.mod version and drop compatibility shims 2024-06-26 15:12:35 +00:00
pkcs12 all: use math/bits.RotateLeft 2022-10-24 17:35:37 +00:00
poly1305 all: bump go.mod version and drop compatibility shims 2024-06-26 15:12:35 +00:00
ripemd160 all: bump go.mod version and drop compatibility shims 2024-06-26 15:12:35 +00:00
salsa20 salsa20/salsa: Port salsa20_amd64.s to Avo 2024-09-04 20:34:59 +00:00
scrypt all: bump go.mod version and drop compatibility shims 2024-06-26 15:12:35 +00:00
sha3 sha3: avoid buffer copy 2024-10-21 19:02:20 +00:00
ssh ssh: return unexpected msg error when server fails keyboard-interactive auth early 2024-10-16 07:16:19 +00:00
tea all: deprecate broken and legacy packages 2019-02-22 23:25:34 +00:00
twofish all: bump go.mod version and drop compatibility shims 2024-06-26 15:12:35 +00:00
x509roots x509roots/fallback: update bundle 2024-09-03 18:00:24 +00:00
xtea all: bump go.mod version and drop compatibility shims 2024-06-26 15:12:35 +00:00
xts all: bump go.mod version and drop compatibility shims 2024-06-26 15:12:35 +00:00
.gitattributes crypto: copying .gitattributes to all subrepositories 2014-12-23 06:54:52 +00:00
.gitignore gitignore: remove obsolete reference to .hgignore in comment 2020-03-20 18:11:02 +00:00
CONTRIBUTING.md CONTRIBUTING.md: remove note about not accepting Pull Requests 2018-03-14 18:02:59 +00:00
LICENSE LICENSE: update per Google Legal 2024-07-16 16:09:32 +00:00
PATENTS go.crypto: add PATENTS file to the subrepo. 2012-04-16 11:25:08 +10:00
README.md README.md: add badge to pkg.go.dev 2020-12-08 17:14:46 +00:00
codereview.cfg crypto: add codereview.cfg 2015-03-18 17:04:25 +00:00
go.mod go.mod: update golang.org/x dependencies 2024-10-04 15:35:24 +00:00
go.sum go.mod: update golang.org/x dependencies 2024-10-04 15:35:24 +00:00

README.md

Go Cryptography

Go Reference

This repository holds supplementary Go cryptography libraries.

Download/Install

The easiest way to install is to run go get -u golang.org/x/crypto/.... You can also manually git clone the repository to $GOPATH/src/golang.org/x/crypto.

Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://golang.org/doc/contribute.html.

The main issue tracker for the crypto repository is located at https://github.com/golang/go/issues. Prefix your issue with "x/crypto:" in the subject line, so it is easy to find.

Note that contributions to the cryptography package receive additional scrutiny due to their sensitive nature. Patches may take longer than normal to receive feedback.