Switched to faster minio/sha256-simd implementation (#2320)
parent
dcc3463e48
commit
f239fcac67
@ -0,0 +1,202 @@ |
||||
|
||||
Apache License |
||||
Version 2.0, January 2004 |
||||
http://www.apache.org/licenses/ |
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION |
||||
|
||||
1. Definitions. |
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, |
||||
and distribution as defined by Sections 1 through 9 of this document. |
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by |
||||
the copyright owner that is granting the License. |
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all |
||||
other entities that control, are controlled by, or are under common |
||||
control with that entity. For the purposes of this definition, |
||||
"control" means (i) the power, direct or indirect, to cause the |
||||
direction or management of such entity, whether by contract or |
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the |
||||
outstanding shares, or (iii) beneficial ownership of such entity. |
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity |
||||
exercising permissions granted by this License. |
||||
|
||||
"Source" form shall mean the preferred form for making modifications, |
||||
including but not limited to software source code, documentation |
||||
source, and configuration files. |
||||
|
||||
"Object" form shall mean any form resulting from mechanical |
||||
transformation or translation of a Source form, including but |
||||
not limited to compiled object code, generated documentation, |
||||
and conversions to other media types. |
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or |
||||
Object form, made available under the License, as indicated by a |
||||
copyright notice that is included in or attached to the work |
||||
(an example is provided in the Appendix below). |
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object |
||||
form, that is based on (or derived from) the Work and for which the |
||||
editorial revisions, annotations, elaborations, or other modifications |
||||
represent, as a whole, an original work of authorship. For the purposes |
||||
of this License, Derivative Works shall not include works that remain |
||||
separable from, or merely link (or bind by name) to the interfaces of, |
||||
the Work and Derivative Works thereof. |
||||
|
||||
"Contribution" shall mean any work of authorship, including |
||||
the original version of the Work and any modifications or additions |
||||
to that Work or Derivative Works thereof, that is intentionally |
||||
submitted to Licensor for inclusion in the Work by the copyright owner |
||||
or by an individual or Legal Entity authorized to submit on behalf of |
||||
the copyright owner. For the purposes of this definition, "submitted" |
||||
means any form of electronic, verbal, or written communication sent |
||||
to the Licensor or its representatives, including but not limited to |
||||
communication on electronic mailing lists, source code control systems, |
||||
and issue tracking systems that are managed by, or on behalf of, the |
||||
Licensor for the purpose of discussing and improving the Work, but |
||||
excluding communication that is conspicuously marked or otherwise |
||||
designated in writing by the copyright owner as "Not a Contribution." |
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity |
||||
on behalf of whom a Contribution has been received by Licensor and |
||||
subsequently incorporated within the Work. |
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of |
||||
this License, each Contributor hereby grants to You a perpetual, |
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable |
||||
copyright license to reproduce, prepare Derivative Works of, |
||||
publicly display, publicly perform, sublicense, and distribute the |
||||
Work and such Derivative Works in Source or Object form. |
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of |
||||
this License, each Contributor hereby grants to You a perpetual, |
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable |
||||
(except as stated in this section) patent license to make, have made, |
||||
use, offer to sell, sell, import, and otherwise transfer the Work, |
||||
where such license applies only to those patent claims licensable |
||||
by such Contributor that are necessarily infringed by their |
||||
Contribution(s) alone or by combination of their Contribution(s) |
||||
with the Work to which such Contribution(s) was submitted. If You |
||||
institute patent litigation against any entity (including a |
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work |
||||
or a Contribution incorporated within the Work constitutes direct |
||||
or contributory patent infringement, then any patent licenses |
||||
granted to You under this License for that Work shall terminate |
||||
as of the date such litigation is filed. |
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the |
||||
Work or Derivative Works thereof in any medium, with or without |
||||
modifications, and in Source or Object form, provided that You |
||||
meet the following conditions: |
||||
|
||||
(a) You must give any other recipients of the Work or |
||||
Derivative Works a copy of this License; and |
||||
|
||||
(b) You must cause any modified files to carry prominent notices |
||||
stating that You changed the files; and |
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works |
||||
that You distribute, all copyright, patent, trademark, and |
||||
attribution notices from the Source form of the Work, |
||||
excluding those notices that do not pertain to any part of |
||||
the Derivative Works; and |
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its |
||||
distribution, then any Derivative Works that You distribute must |
||||
include a readable copy of the attribution notices contained |
||||
within such NOTICE file, excluding those notices that do not |
||||
pertain to any part of the Derivative Works, in at least one |
||||
of the following places: within a NOTICE text file distributed |
||||
as part of the Derivative Works; within the Source form or |
||||
documentation, if provided along with the Derivative Works; or, |
||||
within a display generated by the Derivative Works, if and |
||||
wherever such third-party notices normally appear. The contents |
||||
of the NOTICE file are for informational purposes only and |
||||
do not modify the License. You may add Your own attribution |
||||
notices within Derivative Works that You distribute, alongside |
||||
or as an addendum to the NOTICE text from the Work, provided |
||||
that such additional attribution notices cannot be construed |
||||
as modifying the License. |
||||
|
||||
You may add Your own copyright statement to Your modifications and |
||||
may provide additional or different license terms and conditions |
||||
for use, reproduction, or distribution of Your modifications, or |
||||
for any such Derivative Works as a whole, provided Your use, |
||||
reproduction, and distribution of the Work otherwise complies with |
||||
the conditions stated in this License. |
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise, |
||||
any Contribution intentionally submitted for inclusion in the Work |
||||
by You to the Licensor shall be under the terms and conditions of |
||||
this License, without any additional terms or conditions. |
||||
Notwithstanding the above, nothing herein shall supersede or modify |
||||
the terms of any separate license agreement you may have executed |
||||
with Licensor regarding such Contributions. |
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade |
||||
names, trademarks, service marks, or product names of the Licensor, |
||||
except as required for reasonable and customary use in describing the |
||||
origin of the Work and reproducing the content of the NOTICE file. |
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or |
||||
agreed to in writing, Licensor provides the Work (and each |
||||
Contributor provides its Contributions) on an "AS IS" BASIS, |
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
||||
implied, including, without limitation, any warranties or conditions |
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A |
||||
PARTICULAR PURPOSE. You are solely responsible for determining the |
||||
appropriateness of using or redistributing the Work and assume any |
||||
risks associated with Your exercise of permissions under this License. |
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory, |
||||
whether in tort (including negligence), contract, or otherwise, |
||||
unless required by applicable law (such as deliberate and grossly |
||||
negligent acts) or agreed to in writing, shall any Contributor be |
||||
liable to You for damages, including any direct, indirect, special, |
||||
incidental, or consequential damages of any character arising as a |
||||
result of this License or out of the use or inability to use the |
||||
Work (including but not limited to damages for loss of goodwill, |
||||
work stoppage, computer failure or malfunction, or any and all |
||||
other commercial damages or losses), even if such Contributor |
||||
has been advised of the possibility of such damages. |
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing |
||||
the Work or Derivative Works thereof, You may choose to offer, |
||||
and charge a fee for, acceptance of support, warranty, indemnity, |
||||
or other liability obligations and/or rights consistent with this |
||||
License. However, in accepting such obligations, You may act only |
||||
on Your own behalf and on Your sole responsibility, not on behalf |
||||
of any other Contributor, and only if You agree to indemnify, |
||||
defend, and hold each Contributor harmless for any liability |
||||
incurred by, or claims asserted against, such Contributor by reason |
||||
of your accepting any such warranty or additional liability. |
||||
|
||||
END OF TERMS AND CONDITIONS |
||||
|
||||
APPENDIX: How to apply the Apache License to your work. |
||||
|
||||
To apply the Apache License to your work, attach the following |
||||
boilerplate notice, with the fields enclosed by brackets "[]" |
||||
replaced with your own identifying information. (Don't include |
||||
the brackets!) The text should be enclosed in the appropriate |
||||
comment syntax for the file format. We also recommend that a |
||||
file or class name and description of purpose be included on the |
||||
same "printed page" as the copyright notice for easier |
||||
identification within third-party archives. |
||||
|
||||
Copyright [yyyy] [name of copyright owner] |
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
you may not use this file except in compliance with the License. |
||||
You may obtain a copy of the License at |
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
||||
Unless required by applicable law or agreed to in writing, software |
||||
distributed under the License is distributed on an "AS IS" BASIS, |
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
See the License for the specific language governing permissions and |
||||
limitations under the License. |
@ -0,0 +1,153 @@ |
||||
# sha256-simd |
||||
|
||||
Accelerate SHA256 computations in pure Go for both Intel (AVX2, AVX, SSE) as well as ARM (arm64) platforms. |
||||
|
||||
## Introduction |
||||
|
||||
This package is designed as a drop-in replacement for `crypto/sha256`. For Intel CPUs it has three flavors for AVX2, AVX and SSE whereby the fastest method is automatically chosen depending on CPU capabilities. For ARM CPUs with the Cryptography Extensions advantage is taken of the SHA2 instructions resulting in a massive performance improvement. |
||||
|
||||
This package uses Golang assembly and as such does not depend on cgo. The Intel versions are based on the implementations as described in "Fast SHA-256 Implementations on Intel Architecture Processors" by J. Guilford et al. |
||||
|
||||
## Performance |
||||
|
||||
Below is the speed in MB/s for a single core (ranked fast to slow) as well as the factor of improvement over `crypto/sha256` (when applicable). |
||||
|
||||
| Processor | Package | Speed | Improvement | |
||||
| --------------------------------- | ---------------------------- | -----------:| -----------:| |
||||
| 1.2 GHz ARM Cortex-A53 | minio/sha256-simd (ARM64) | 638.2 MB/s | 105x | |
||||
| 2.4 GHz Intel Xeon CPU E5-2620 v3 | minio/sha256-simd (AVX2) (*) | 355.0 MB/s | 1.88x | |
||||
| 2.4 GHz Intel Xeon CPU E5-2620 v3 | minio/sha256-simd (AVX) | 306.0 MB/s | 1.62x | |
||||
| 2.4 GHz Intel Xeon CPU E5-2620 v3 | minio/sha256-simd (SSE) | 298.7 MB/s | 1.58x | |
||||
| 2.4 GHz Intel Xeon CPU E5-2620 v3 | crypto/sha256 | 189.2 MB/s | | |
||||
| 1.2 GHz ARM Cortex-A53 | crypto/sha256 | 6.1 MB/s | | |
||||
|
||||
(*) Measured with the "unrolled"/"demacro-ed" AVX2 version. Due to some Golang assembly restrictions the AVX2 version that uses `defines` loses about 15% performance. The optimized version is contained in the git history so for maximum speed you want to do this after getting: `git cat-file blob 586b6e > sha256blockAvx2_amd64.s` (or vendor it for your project; see [here](https://github.com/minio/sha256-simd/blob/13b11bdf9b0580a756a111492d2ae382bab7ec79/sha256blockAvx2_amd64.s) to view it in its full glory). |
||||
|
||||
See further down for detailed performance. |
||||
|
||||
## Comparison to other hashing techniques |
||||
|
||||
As measured on Intel Xeon (same as above) with AVX2 version: |
||||
|
||||
| Method | Package | Speed | |
||||
| ------- | -------------------| --------:| |
||||
| BLAKE2B | [minio/blake2b-simd](https://github.com/minio/blake2b-simd) | 851 MB/s | |
||||
| MD5 | crypto/md5 | 607 MB/s | |
||||
| SHA1 | crypto/sha1 | 522 MB/s | |
||||
| SHA256 | minio/sha256-simd | 355 MB/s | |
||||
| SHA512 | crypto/sha512 | 306 MB/s | |
||||
|
||||
asm2plan9s |
||||
---------- |
||||
|
||||
In order to be able to work more easily with AVX2/AVX instructions, a separate tool was developed to convert AVX2/AVX instructions into the corresponding BYTE sequence as accepted by Go assembly. See [asm2plan9s](https://github.com/minio/asm2plan9s) for more information. |
||||
|
||||
Why and benefits |
||||
---------------- |
||||
|
||||
One of the most performance sensitive parts of [Minio](https://minio.io) server (object storage [server](https://github.com/minio/minio) compatible with Amazon S3) is related to SHA256 hash sums calculations. For instance during multi part uploads each part that is uploaded needs to be verified for data integrity by the server. Likewise in order to generated pre-signed URLs check sums must be calculated to ensure their validity. |
||||
|
||||
Other applications that can benefit from enhanced SHA256 performance are deduplication in storage systems, intrusion detection, version control systems, integrity checking, etc. |
||||
|
||||
ARM SHA Extensions |
||||
------------------ |
||||
|
||||
The 64-bit ARMv8 core has introduced new instructions for SHA1 and SHA2 acceleration as part of the [Cryptography Extensions](http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0501f/CHDFJBCJ.html). Below you can see a small excerpt highlighting one of the rounds as is done for the SHA256 calculation process (for full code see [sha256block_arm64.s](https://github.com/minio/sha256-simd/blob/master/sha256block_arm64.s)). |
||||
|
||||
``` |
||||
sha256h q2, q3, v9.4s |
||||
sha256h2 q3, q4, v9.4s |
||||
sha256su0 v5.4s, v6.4s |
||||
rev32 v8.16b, v8.16b |
||||
add v9.4s, v7.4s, v18.4s |
||||
mov v4.16b, v2.16b |
||||
sha256h q2, q3, v10.4s |
||||
sha256h2 q3, q4, v10.4s |
||||
sha256su0 v6.4s, v7.4s |
||||
sha256su1 v5.4s, v7.4s, v8.4s |
||||
``` |
||||
|
||||
Detailed benchmarks |
||||
------------------- |
||||
|
||||
### ARM64 |
||||
|
||||
Benchmarks generated on a 1.2 Ghz Quad-Core ARM Cortex A53 equipped [Pine64](https://www.pine64.com/). |
||||
|
||||
``` |
||||
minio@minio-arm:~/gopath/src/github.com/sha256-simd$ benchcmp golang.txt arm64.txt |
||||
benchmark old ns/op new ns/op delta |
||||
BenchmarkHash8Bytes-4 11836 1403 -88.15% |
||||
BenchmarkHash1K-4 181143 3138 -98.27% |
||||
BenchmarkHash8K-4 1365652 14356 -98.95% |
||||
BenchmarkHash1M-4 173192200 1642954 -99.05% |
||||
|
||||
benchmark old MB/s new MB/s speedup |
||||
BenchmarkHash8Bytes-4 0.68 5.70 8.38x |
||||
BenchmarkHash1K-4 5.65 326.30 57.75x |
||||
BenchmarkHash8K-4 6.00 570.63 95.11x |
||||
BenchmarkHash1M-4 6.05 638.23 105.49x |
||||
``` |
||||
|
||||
Example performance metrics were generated on Intel(R) Xeon(R) CPU E5-2620 v3 @ 2.40GHz - 6 physical cores, 12 logical cores running Ubuntu GNU/Linux with kernel version 4.4.0-24-generic (vanilla with no optimizations). |
||||
|
||||
### AVX2 |
||||
|
||||
``` |
||||
$ benchcmp go.txt avx2.txt |
||||
benchmark old ns/op new ns/op delta |
||||
BenchmarkHash8Bytes-12 446 364 -18.39% |
||||
BenchmarkHash1K-12 5919 3279 -44.60% |
||||
BenchmarkHash8K-12 43791 23655 -45.98% |
||||
BenchmarkHash1M-12 5544989 2969305 -46.45% |
||||
|
||||
benchmark old MB/s new MB/s speedup |
||||
BenchmarkHash8Bytes-12 17.93 21.96 1.22x |
||||
BenchmarkHash1K-12 172.98 312.27 1.81x |
||||
BenchmarkHash8K-12 187.07 346.31 1.85x |
||||
BenchmarkHash1M-12 189.10 353.14 1.87x |
||||
``` |
||||
|
||||
### AVX |
||||
|
||||
``` |
||||
$ benchcmp go.txt avx.txt |
||||
benchmark old ns/op new ns/op delta |
||||
BenchmarkHash8Bytes-12 446 346 -22.42% |
||||
BenchmarkHash1K-12 5919 3701 -37.47% |
||||
BenchmarkHash8K-12 43791 27222 -37.84% |
||||
BenchmarkHash1M-12 5544989 3426938 -38.20% |
||||
|
||||
benchmark old MB/s new MB/s speedup |
||||
BenchmarkHash8Bytes-12 17.93 23.06 1.29x |
||||
BenchmarkHash1K-12 172.98 276.64 1.60x |
||||
BenchmarkHash8K-12 187.07 300.93 1.61x |
||||
BenchmarkHash1M-12 189.10 305.98 1.62x |
||||
``` |
||||
|
||||
### SSE |
||||
|
||||
``` |
||||
$ benchcmp go.txt sse.txt |
||||
benchmark old ns/op new ns/op delta |
||||
BenchmarkHash8Bytes-12 446 362 -18.83% |
||||
BenchmarkHash1K-12 5919 3751 -36.63% |
||||
BenchmarkHash8K-12 43791 27396 -37.44% |
||||
BenchmarkHash1M-12 5544989 3444623 -37.88% |
||||
|
||||
benchmark old MB/s new MB/s speedup |
||||
BenchmarkHash8Bytes-12 17.93 22.05 1.23x |
||||
BenchmarkHash1K-12 172.98 272.92 1.58x |
||||
BenchmarkHash8K-12 187.07 299.01 1.60x |
||||
BenchmarkHash1M-12 189.10 304.41 1.61x |
||||
``` |
||||
|
||||
License |
||||
------- |
||||
|
||||
Released under the Apache License v2.0. You can find the complete text in the file LICENSE. |
||||
|
||||
Contributing |
||||
------------ |
||||
|
||||
Contributions are welcome, please send PRs for any enhancements. |
@ -0,0 +1,32 @@ |
||||
# version format |
||||
version: "{build}" |
||||
|
||||
# Operating system (build VM template) |
||||
os: Windows Server 2012 R2 |
||||
|
||||
# Platform. |
||||
platform: x64 |
||||
|
||||
clone_folder: c:\gopath\src\github.com\minio\sha256-simd |
||||
|
||||
# environment variables |
||||
environment: |
||||
GOPATH: c:\gopath |
||||
GO15VENDOREXPERIMENT: 1 |
||||
|
||||
# scripts that run after cloning repository |
||||
install: |
||||
- set PATH=%GOPATH%\bin;c:\go\bin;%PATH% |
||||
- go version |
||||
- go env |
||||
|
||||
# to run your custom scripts instead of automatic MSBuild |
||||
build_script: |
||||
- go test . |
||||
- go test -race . |
||||
|
||||
# to disable automatic tests |
||||
test: off |
||||
|
||||
# to disable deployment |
||||
deploy: off |
@ -0,0 +1,55 @@ |
||||
// Minio Cloud Storage, (C) 2016 Minio, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
package sha256 |
||||
|
||||
// True when SIMD instructions are available.
|
||||
var avx2 = haveAVX2() |
||||
var avx = haveAVX() |
||||
var ssse3 = haveSSSE3() |
||||
var armSha = haveArmSha() |
||||
|
||||
// haveAVX returns true when there is AVX support
|
||||
func haveAVX() bool { |
||||
_, _, c, _ := cpuid(1) |
||||
|
||||
// Check XGETBV, OXSAVE and AVX bits
|
||||
if c&(1<<26) != 0 && c&(1<<27) != 0 && c&(1<<28) != 0 { |
||||
// Check for OS support
|
||||
eax, _ := xgetbv(0) |
||||
return (eax & 0x6) == 0x6 |
||||
} |
||||
return false |
||||
} |
||||
|
||||
// haveAVX2 returns true when there is AVX2 support
|
||||
func haveAVX2() bool { |
||||
mfi, _, _, _ := cpuid(0) |
||||
|
||||
// Check AVX2, AVX2 requires OS support, but BMI1/2 don't.
|
||||
if mfi >= 7 && haveAVX() { |
||||
_, ebx, _, _ := cpuidex(7, 0) |
||||
return (ebx & 0x00000020) != 0 |
||||
} |
||||
return false |
||||
} |
||||
|
||||
// haveSSSE3 returns true when there is SSSE3 support
|
||||
func haveSSSE3() bool { |
||||
|
||||
_, _, c, _ := cpuid(1) |
||||
|
||||
return (c & 0x00000200) != 0 |
||||
} |
@ -0,0 +1,24 @@ |
||||
// Minio Cloud Storage, (C) 2016 Minio, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
package sha256 |
||||
|
||||
func cpuid(op uint32) (eax, ebx, ecx, edx uint32) |
||||
func cpuidex(op, op2 uint32) (eax, ebx, ecx, edx uint32) |
||||
func xgetbv(index uint32) (eax, edx uint32) |
||||
|
||||
func haveArmSha() bool { |
||||
return false |
||||
} |
@ -0,0 +1,33 @@ |
||||
// Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file. |
||||
|
||||
// +build 386,!gccgo |
||||
|
||||
// func cpuid(op uint32) (eax, ebx, ecx, edx uint32) |
||||
TEXT ·cpuid(SB), 7, $0 |
||||
XORL CX, CX |
||||
MOVL op+0(FP), AX |
||||
CPUID |
||||
MOVL AX, eax+4(FP) |
||||
MOVL BX, ebx+8(FP) |
||||
MOVL CX, ecx+12(FP) |
||||
MOVL DX, edx+16(FP) |
||||
RET |
||||
|
||||
// func cpuidex(op, op2 uint32) (eax, ebx, ecx, edx uint32) |
||||
TEXT ·cpuidex(SB), 7, $0 |
||||
MOVL op+0(FP), AX |
||||
MOVL op2+4(FP), CX |
||||
CPUID |
||||
MOVL AX, eax+8(FP) |
||||
MOVL BX, ebx+12(FP) |
||||
MOVL CX, ecx+16(FP) |
||||
MOVL DX, edx+20(FP) |
||||
RET |
||||
|
||||
// func xgetbv(index uint32) (eax, edx uint32) |
||||
TEXT ·xgetbv(SB), 7, $0 |
||||
MOVL index+0(FP), CX |
||||
BYTE $0x0f; BYTE $0x01; BYTE $0xd0 // XGETBV
|
||||
MOVL AX, eax+4(FP) |
||||
MOVL DX, edx+8(FP) |
||||
RET |
@ -0,0 +1,24 @@ |
||||
// Minio Cloud Storage, (C) 2016 Minio, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
package sha256 |
||||
|
||||
func cpuid(op uint32) (eax, ebx, ecx, edx uint32) |
||||
func cpuidex(op, op2 uint32) (eax, ebx, ecx, edx uint32) |
||||
func xgetbv(index uint32) (eax, edx uint32) |
||||
|
||||
func haveArmSha() bool { |
||||
return false |
||||
} |
@ -0,0 +1,34 @@ |
||||
// Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file. |
||||
|
||||
// +build amd64,!gccgo |
||||
|
||||
// func cpuid(op uint32) (eax, ebx, ecx, edx uint32) |
||||
TEXT ·cpuid(SB), 7, $0 |
||||
XORQ CX, CX |
||||
MOVL op+0(FP), AX |
||||
CPUID |
||||
MOVL AX, eax+8(FP) |
||||
MOVL BX, ebx+12(FP) |
||||
MOVL CX, ecx+16(FP) |
||||
MOVL DX, edx+20(FP) |
||||
RET |
||||
|
||||
|
||||
// func cpuidex(op, op2 uint32) (eax, ebx, ecx, edx uint32) |
||||
TEXT ·cpuidex(SB), 7, $0 |
||||
MOVL op+0(FP), AX |
||||
MOVL op2+4(FP), CX |
||||
CPUID |
||||
MOVL AX, eax+8(FP) |
||||
MOVL BX, ebx+12(FP) |
||||
MOVL CX, ecx+16(FP) |
||||
MOVL DX, edx+20(FP) |
||||
RET |
||||
|
||||
// func xgetbv(index uint32) (eax, edx uint32) |
||||
TEXT ·xgetbv(SB), 7, $0 |
||||
MOVL index+0(FP), CX |
||||
BYTE $0x0f; BYTE $0x01; BYTE $0xd0 // XGETBV
|
||||
MOVL AX, eax+8(FP) |
||||
MOVL DX, edx+12(FP) |
||||
RET |
@ -0,0 +1,33 @@ |
||||
// Minio Cloud Storage, (C) 2016 Minio, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
package sha256 |
||||
|
||||
func cpuid(op uint32) (eax, ebx, ecx, edx uint32) { |
||||
return 0, 0, 0, 0 |
||||
} |
||||
|
||||
func cpuidex(op, op2 uint32) (eax, ebx, ecx, edx uint32) { |
||||
return 0, 0, 0, 0 |
||||
} |
||||
|
||||
func xgetbv(index uint32) (eax, edx uint32) { |
||||
return 0, 0 |
||||
} |
||||
|
||||
func haveArmSha() bool { |
||||
// TODO: Implement feature detection for ARM
|
||||
return true |
||||
} |
@ -0,0 +1,171 @@ |
||||
/* |
||||
* Minio Cloud Storage, (C) 2016 Minio, Inc. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package sha256 |
||||
|
||||
import ( |
||||
"crypto/sha256" |
||||
"hash" |
||||
) |
||||
|
||||
// Size - The size of a SHA256 checksum in bytes.
|
||||
const Size = 32 |
||||
|
||||
// BlockSize - The blocksize of SHA256 in bytes.
|
||||
const BlockSize = 64 |
||||
|
||||
const ( |
||||
chunk = 64 |
||||
init0 = 0x6A09E667 |
||||
init1 = 0xBB67AE85 |
||||
init2 = 0x3C6EF372 |
||||
init3 = 0xA54FF53A |
||||
init4 = 0x510E527F |
||||
init5 = 0x9B05688C |
||||
init6 = 0x1F83D9AB |
||||
init7 = 0x5BE0CD19 |
||||
) |
||||
|
||||
// digest represents the partial evaluation of a checksum.
|
||||
type digest struct { |
||||
h [8]uint32 |
||||
x [chunk]byte |
||||
nx int |
||||
len uint64 |
||||
} |
||||
|
||||
// Reset digest back to default
|
||||
func (d *digest) Reset() { |
||||
d.h[0] = init0 |
||||
d.h[1] = init1 |
||||
d.h[2] = init2 |
||||
d.h[3] = init3 |
||||
d.h[4] = init4 |
||||
d.h[5] = init5 |
||||
d.h[6] = init6 |
||||
d.h[7] = init7 |
||||
d.nx = 0 |
||||
d.len = 0 |
||||
} |
||||
|
||||
func block(dig *digest, p []byte) { |
||||
switch true { |
||||
case avx2: |
||||
blockAvx2Go(dig, p) |
||||
case avx: |
||||
blockAvxGo(dig, p) |
||||
case ssse3: |
||||
blockSsseGo(dig, p) |
||||
case armSha: |
||||
blockArmGo(dig, p) |
||||
default: |
||||
blockGeneric(dig, p) |
||||
} |
||||
} |
||||
|
||||
// New returns a new hash.Hash computing the SHA256 checksum.
|
||||
func New() hash.Hash { |
||||
if avx2 || avx || ssse3 || armSha { |
||||
d := new(digest) |
||||
d.Reset() |
||||
return d |
||||
} else { |
||||
// default back to the standard golang implementation
|
||||
return sha256.New() |
||||
} |
||||
} |
||||
|
||||
// Sum256 - single caller sha256 helper
|
||||
func Sum256(data []byte) [Size]byte { |
||||
var d digest |
||||
d.Reset() |
||||
d.Write(data) |
||||
return d.checkSum() |
||||
} |
||||
|
||||
// Return size of checksum
|
||||
func (d *digest) Size() int { return Size } |
||||
|
||||
// Return blocksize of checksum
|
||||
func (d *digest) BlockSize() int { return BlockSize } |
||||
|
||||
// Write to digest
|
||||
func (d *digest) Write(p []byte) (nn int, err error) { |
||||
nn = len(p) |
||||
d.len += uint64(nn) |
||||
if d.nx > 0 { |
||||
n := copy(d.x[d.nx:], p) |
||||
d.nx += n |
||||
if d.nx == chunk { |
||||
block(d, d.x[:]) |
||||
d.nx = 0 |
||||
} |
||||
p = p[n:] |
||||
} |
||||
if len(p) >= chunk { |
||||
n := len(p) &^ (chunk - 1) |
||||
block(d, p[:n]) |
||||
p = p[n:] |
||||
} |
||||
if len(p) > 0 { |
||||
d.nx = copy(d.x[:], p) |
||||
} |
||||
return |
||||
} |
||||
|
||||
// Return sha256 sum in bytes
|
||||
func (d *digest) Sum(in []byte) []byte { |
||||
// Make a copy of d0 so that caller can keep writing and summing.
|
||||
d0 := *d |
||||
hash := d0.checkSum() |
||||
return append(in, hash[:]...) |
||||
} |
||||
|
||||
// Intermediate checksum function
|
||||
func (d *digest) checkSum() [Size]byte { |
||||
len := d.len |
||||
// Padding. Add a 1 bit and 0 bits until 56 bytes mod 64.
|
||||
var tmp [64]byte |
||||
tmp[0] = 0x80 |
||||
if len%64 < 56 { |
||||
d.Write(tmp[0 : 56-len%64]) |
||||
} else { |
||||
d.Write(tmp[0 : 64+56-len%64]) |
||||
} |
||||
|
||||
// Length in bits.
|
||||
len <<= 3 |
||||
for i := uint(0); i < 8; i++ { |
||||
tmp[i] = byte(len >> (56 - 8*i)) |
||||
} |
||||
d.Write(tmp[0:8]) |
||||
|
||||
if d.nx != 0 { |
||||
panic("d.nx != 0") |
||||
} |
||||
|
||||
h := d.h[:] |
||||
|
||||
var digest [Size]byte |
||||
for i, s := range h { |
||||
digest[i*4] = byte(s >> 24) |
||||
digest[i*4+1] = byte(s >> 16) |
||||
digest[i*4+2] = byte(s >> 8) |
||||
digest[i*4+3] = byte(s) |
||||
} |
||||
|
||||
return digest |
||||
} |
@ -0,0 +1,31 @@ |
||||
//+build !noasm
|
||||
|
||||
/* |
||||
* Minio Cloud Storage, (C) 2016 Minio, Inc. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package sha256 |
||||
|
||||
//go:noescape
|
||||
func blockAvx2(h []uint32, message []uint8) |
||||
|
||||
func blockAvx2Go(dig *digest, p []byte) { |
||||
|
||||
h := []uint32{dig.h[0], dig.h[1], dig.h[2], dig.h[3], dig.h[4], dig.h[5], dig.h[6], dig.h[7]} |
||||
|
||||
blockAvx2(h[:], p[:]) |
||||
|
||||
dig.h[0], dig.h[1], dig.h[2], dig.h[3], dig.h[4], dig.h[5], dig.h[6], dig.h[7] = h[0], h[1], h[2], h[3], h[4], h[5], h[6], h[7] |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,31 @@ |
||||
//+build !noasm
|
||||
|
||||
/* |
||||
* Minio Cloud Storage, (C) 2016 Minio, Inc. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package sha256 |
||||
|
||||
//go:noescape
|
||||
func blockAvx(h []uint32, message []uint8, reserved0, reserved1, reserved2, reserved3 uint64) |
||||
|
||||
func blockAvxGo(dig *digest, p []byte) { |
||||
|
||||
h := []uint32{dig.h[0], dig.h[1], dig.h[2], dig.h[3], dig.h[4], dig.h[5], dig.h[6], dig.h[7]} |
||||
|
||||
blockAvx(h[:], p[:], 0, 0, 0, 0) |
||||
|
||||
dig.h[0], dig.h[1], dig.h[2], dig.h[3], dig.h[4], dig.h[5], dig.h[6], dig.h[7] = h[0], h[1], h[2], h[3], h[4], h[5], h[6], h[7] |
||||
} |
@ -0,0 +1,409 @@ |
||||
//+build !noasm !appengine |
||||
|
||||
// SHA256 implementation for AVX |
||||
|
||||
// |
||||
// Minio Cloud Storage, (C) 2016 Minio, Inc. |
||||
// |
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License. |
||||
// You may obtain a copy of the License at |
||||
// |
||||
// http://www.apache.org/licenses/LICENSE-2.0 |
||||
// |
||||
// Unless required by applicable law or agreed to in writing, software |
||||
// distributed under the License is distributed on an "AS IS" BASIS, |
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
// See the License for the specific language governing permissions and |
||||
// limitations under the License. |
||||
// |
||||
|
||||
// |
||||
// This code is based on an Intel White-Paper: |
||||
// "Fast SHA-256 Implementations on Intel Architecture Processors" |
||||
// |
||||
// together with the reference implementation from the following authors: |
||||
// James Guilford <james.guilford@intel.com>
|
||||
// Kirk Yap <kirk.s.yap@intel.com>
|
||||
// Tim Chen <tim.c.chen@linux.intel.com>
|
||||
// |
||||
// For Golang it has been converted to Plan 9 assembly with the help of |
||||
// github.com/minio/asm2plan9s to assemble Intel instructions to their Plan9 |
||||
// equivalents |
||||
// |
||||
|
||||
#include "textflag.h" |
||||
|
||||
#define ROTATE_XS \ |
||||
MOVOU X4, X15 \ |
||||
MOVOU X5, X4 \ |
||||
MOVOU X6, X5 \ |
||||
MOVOU X7, X6 \ |
||||
MOVOU X15, X7 |
||||
|
||||
// compute s0 four at a time and s1 two at a time |
||||
// compute W[-16] + W[-7] 4 at a time |
||||
#define FOUR_ROUNDS_AND_SCHED(a, b, c, d, e, f, g, h) \ |
||||
MOVL e, R13 \ /* y0 = e */ |
||||
ROLL $18, R13 \ /* y0 = e >> (25-11) */ |
||||
MOVL a, R14 \ /* y1 = a */ |
||||
LONG $0x0f41e3c4; WORD $0x04c6 \ // VPALIGNR XMM0,XMM7,XMM6,0x4 /* XTMP0 = W[-7] */
|
||||
ROLL $23, R14 \ /* y1 = a >> (22-13) */ |
||||
XORL e, R13 \ /* y0 = e ^ (e >> (25-11)) */ |
||||
MOVL f, R15 \ /* y2 = f */ |
||||
ROLL $27, R13 \ /* y0 = (e >> (11-6)) ^ (e >> (25-6)) */ |
||||
XORL a, R14 \ /* y1 = a ^ (a >> (22-13) */ |
||||
XORL g, R15 \ /* y2 = f^g */ |
||||
LONG $0xc4fef9c5 \ // VPADDD XMM0,XMM0,XMM4 /* XTMP0 = W[-7] + W[-16] */ |
||||
XORL e, R13 \ /* y0 = e ^ (e >> (11-6)) ^ (e >> (25-6) ) */ |
||||
ANDL e, R15 \ /* y2 = (f^g)&e */ |
||||
ROLL $21, R14 \ /* y1 = (a >> (13-2)) ^ (a >> (22-2)) */ |
||||
\ /* */ |
||||
\ /* compute s0 */ |
||||
\ /* */ |
||||
LONG $0x0f51e3c4; WORD $0x04cc \ // VPALIGNR XMM1,XMM5,XMM4,0x4 /* XTMP1 = W[-15] */
|
||||
XORL a, R14 \ /* y1 = a ^ (a >> (13-2)) ^ (a >> (22-2)) */ |
||||
ROLL $26, R13 \ /* y0 = S1 = (e>>6) & (e>>11) ^ (e>>25) */ |
||||
XORL g, R15 \ /* y2 = CH = ((f^g)&e)^g */ |
||||
ROLL $30, R14 \ /* y1 = S0 = (a>>2) ^ (a>>13) ^ (a>>22) */ |
||||
ADDL R13, R15 \ /* y2 = S1 + CH */ |
||||
ADDL _xfer+48(FP), R15 \ /* y2 = k + w + S1 + CH */ |
||||
MOVL a, R13 \ /* y0 = a */ |
||||
ADDL R15, h \ /* h = h + S1 + CH + k + w */ |
||||
\ /* ROTATE_ARGS */ |
||||
MOVL a, R15 \ /* y2 = a */ |
||||
LONG $0xd172e9c5; BYTE $0x07 \ // VPSRLD XMM2,XMM1,0x7 /* */
|
||||
ORL c, R13 \ /* y0 = a|c */ |
||||
ADDL h, d \ /* d = d + h + S1 + CH + k + w */ |
||||
ANDL c, R15 \ /* y2 = a&c */ |
||||
LONG $0xf172e1c5; BYTE $0x19 \ // VPSLLD XMM3,XMM1,0x19 /* */
|
||||
ANDL b, R13 \ /* y0 = (a|c)&b */ |
||||
ADDL R14, h \ /* h = h + S1 + CH + k + w + S0 */ |
||||
LONG $0xdaebe1c5 \ // VPOR XMM3,XMM3,XMM2 /* XTMP1 = W[-15] MY_ROR 7 */ |
||||
ORL R15, R13 \ /* y0 = MAJ = (a|c)&b)|(a&c) */ |
||||
ADDL R13, h \ /* h = h + S1 + CH + k + w + S0 + MAJ */ |
||||
\ /* ROTATE_ARGS */ |
||||
MOVL d, R13 \ /* y0 = e */ |
||||
MOVL h, R14 \ /* y1 = a */ |
||||
ROLL $18, R13 \ /* y0 = e >> (25-11) */ |
||||
XORL d, R13 \ /* y0 = e ^ (e >> (25-11)) */ |
||||
MOVL e, R15 \ /* y2 = f */ |
||||
ROLL $23, R14 \ /* y1 = a >> (22-13) */ |
||||
LONG $0xd172e9c5; BYTE $0x12 \ // VPSRLD XMM2,XMM1,0x12 /* */
|
||||
XORL h, R14 \ /* y1 = a ^ (a >> (22-13) */ |
||||
ROLL $27, R13 \ /* y0 = (e >> (11-6)) ^ (e >> (25-6)) */ |
||||
XORL f, R15 \ /* y2 = f^g */ |
||||
LONG $0xd172b9c5; BYTE $0x03 \ // VPSRLD XMM8,XMM1,0x3 /* XTMP4 = W[-15] >> 3 */
|
||||
ROLL $21, R14 \ /* y1 = (a >> (13-2)) ^ (a >> (22-2)) */ |
||||
XORL d, R13 \ /* y0 = e ^ (e >> (11-6)) ^ (e >> (25-6)) */ |
||||
ANDL d, R15 \ /* y2 = (f^g)&e */ |
||||
ROLL $26, R13 \ /* y0 = S1 = (e>>6) & (e>>11) ^ (e>>25) */ |
||||
LONG $0xf172f1c5; BYTE $0x0e \ // VPSLLD XMM1,XMM1,0xe /* */
|
||||
XORL h, R14 \ /* y1 = a ^ (a >> (13-2)) ^ (a >> (22-2)) */ |
||||
XORL f, R15 \ /* y2 = CH = ((f^g)&e)^g */ |
||||
LONG $0xd9efe1c5 \ // VPXOR XMM3,XMM3,XMM1 /* */ |
||||
ADDL R13, R15 \ /* y2 = S1 + CH */ |
||||
ADDL _xfer+52(FP), R15 \ /* y2 = k + w + S1 + CH */ |
||||
ROLL $30, R14 \ /* y1 = S0 = (a>>2) ^ (a>>13) ^ (a>>22) */ |
||||
LONG $0xdaefe1c5 \ // VPXOR XMM3,XMM3,XMM2 /* XTMP1 = W[-15] MY_ROR 7 ^ W[-15] MY_ROR */ |
||||
MOVL h, R13 \ /* y0 = a */ |
||||
ADDL R15, g \ /* h = h + S1 + CH + k + w */ |
||||
MOVL h, R15 \ /* y2 = a */ |
||||
LONG $0xef61c1c4; BYTE $0xc8 \ // VPXOR XMM1,XMM3,XMM8 /* XTMP1 = s0 */
|
||||
ORL b, R13 \ /* y0 = a|c */ |
||||
ADDL g, c \ /* d = d + h + S1 + CH + k + w */ |
||||
ANDL b, R15 \ /* y2 = a&c */ |
||||
\ /* */ |
||||
\ /* compute low s1 */ |
||||
\ /* */ |
||||
LONG $0xd770f9c5; BYTE $0xfa \ // VPSHUFD XMM2,XMM7,0xfa /* XTMP2 = W[-2] {BBAA} */
|
||||
ANDL a, R13 \ /* y0 = (a|c)&b */ |
||||
ADDL R14, g \ /* h = h + S1 + CH + k + w + S0 */ |
||||
LONG $0xc1fef9c5 \ // VPADDD XMM0,XMM0,XMM1 /* XTMP0 = W[-16] + W[-7] + s0 */ |
||||
ORL R15, R13 \ /* y0 = MAJ = (a|c)&b)|(a&c) */ |
||||
ADDL R13, g \ /* h = h + S1 + CH + k + w + S0 + MAJ */ |
||||
\ /* ROTATE_ARGS */ |
||||
MOVL c, R13 \ /* y0 = e */ |
||||
MOVL g, R14 \ /* y1 = a */ |
||||
ROLL $18, R13 \ /* y0 = e >> (25-11) */ |
||||
XORL c, R13 \ /* y0 = e ^ (e >> (25-11)) */ |
||||
ROLL $23, R14 \ /* y1 = a >> (22-13) */ |
||||
MOVL d, R15 \ /* y2 = f */ |
||||
XORL g, R14 \ /* y1 = a ^ (a >> (22-13) */ |
||||
ROLL $27, R13 \ /* y0 = (e >> (11-6)) ^ (e >> (25-6)) */ |
||||
LONG $0xd272b9c5; BYTE $0x0a \ // VPSRLD XMM8,XMM2,0xa /* XTMP4 = W[-2] >> 10 {BBAA} */
|
||||
XORL e, R15 \ /* y2 = f^g */ |
||||
LONG $0xd273e1c5; BYTE $0x13 \ // VPSRLQ XMM3,XMM2,0x13 /* XTMP3 = W[-2] MY_ROR 19 {xBxA} */
|
||||
XORL c, R13 \ /* y0 = e ^ (e >> (11-6)) ^ (e >> (25-6)) */ |
||||
ANDL c, R15 \ /* y2 = (f^g)&e */ |
||||
LONG $0xd273e9c5; BYTE $0x11 \ // VPSRLQ XMM2,XMM2,0x11 /* XTMP2 = W[-2] MY_ROR 17 {xBxA} */
|
||||
ROLL $21, R14 \ /* y1 = (a >> (13-2)) ^ (a >> (22-2)) */ |
||||
XORL g, R14 \ /* y1 = a ^ (a >> (13-2)) ^ (a >> (22-2)) */ |
||||
XORL e, R15 \ /* y2 = CH = ((f^g)&e)^g */ |
||||
ROLL $26, R13 \ /* y0 = S1 = (e>>6) & (e>>11) ^ (e>>25) */ |
||||
LONG $0xd3efe9c5 \ // VPXOR XMM2,XMM2,XMM3 /* */ |
||||
ADDL R13, R15 \ /* y2 = S1 + CH */ |
||||
ROLL $30, R14 \ /* y1 = S0 = (a>>2) ^ (a>>13) ^ (a>>22) */ |
||||
ADDL _xfer+56(FP), R15 \ /* y2 = k + w + S1 + CH */ |
||||
LONG $0xc2ef39c5 \ // VPXOR XMM8,XMM8,XMM2 /* XTMP4 = s1 {xBxA} */ |
||||
MOVL g, R13 \ /* y0 = a */ |
||||
ADDL R15, f \ /* h = h + S1 + CH + k + w */ |
||||
MOVL g, R15 \ /* y2 = a */ |
||||
LONG $0x003942c4; BYTE $0xc2 \ // VPSHUFB XMM8,XMM8,XMM10 /* XTMP4 = s1 {00BA} */
|
||||
ORL a, R13 \ /* y0 = a|c */ |
||||
ADDL f, b \ /* d = d + h + S1 + CH + k + w */ |
||||
ANDL a, R15 \ /* y2 = a&c */ |
||||
LONG $0xfe79c1c4; BYTE $0xc0 \ // VPADDD XMM0,XMM0,XMM8 /* XTMP0 = {..., ..., W[1], W[0]} */
|
||||
ANDL h, R13 \ /* y0 = (a|c)&b */ |
||||
ADDL R14, f \ /* h = h + S1 + CH + k + w + S0 */ |
||||
\ /* */ |
||||
\ /* compute high s1 */ |
||||
\ /* */ |
||||
LONG $0xd070f9c5; BYTE $0x50 \ // VPSHUFD XMM2,XMM0,0x50 /* XTMP2 = W[-2] {DDCC} */
|
||||
ORL R15, R13 \ /* y0 = MAJ = (a|c)&b)|(a&c) */ |
||||
ADDL R13, f \ /* h = h + S1 + CH + k + w + S0 + MAJ */ |
||||
\ /* ROTATE_ARGS */ |
||||
MOVL b, R13 \ /* y0 = e */ |
||||
ROLL $18, R13 \ /* y0 = e >> (25-11) */ |
||||
MOVL f, R14 \ /* y1 = a */ |
||||
ROLL $23, R14 \ /* y1 = a >> (22-13) */ |
||||
XORL b, R13 \ /* y0 = e ^ (e >> (25-11)) */ |
||||
MOVL c, R15 \ /* y2 = f */ |
||||
ROLL $27, R13 \ /* y0 = (e >> (11-6)) ^ (e >> (25-6)) */ |
||||
LONG $0xd272a1c5; BYTE $0x0a \ // VPSRLD XMM11,XMM2,0xa /* XTMP5 = W[-2] >> 10 {DDCC} */
|
||||
XORL f, R14 \ /* y1 = a ^ (a >> (22-13) */ |
||||
XORL d, R15 \ /* y2 = f^g */ |
||||
LONG $0xd273e1c5; BYTE $0x13 \ // VPSRLQ XMM3,XMM2,0x13 /* XTMP3 = W[-2] MY_ROR 19 {xDxC} */
|
||||
XORL b, R13 \ /* y0 = e ^ (e >> (11-6)) ^ (e >> (25-6)) */ |
||||
ANDL b, R15 \ /* y2 = (f^g)&e */ |
||||
ROLL $21, R14 \ /* y1 = (a >> (13-2)) ^ (a >> (22-2)) */ |
||||
LONG $0xd273e9c5; BYTE $0x11 \ // VPSRLQ XMM2,XMM2,0x11 /* XTMP2 = W[-2] MY_ROR 17 {xDxC} */
|
||||
XORL f, R14 \ /* y1 = a ^ (a >> (13-2)) ^ (a >> (22-2)) */ |
||||
ROLL $26, R13 \ /* y0 = S1 = (e>>6) & (e>>11) ^ (e>>25) */ |
||||
XORL d, R15 \ /* y2 = CH = ((f^g)&e)^g */ |
||||
LONG $0xd3efe9c5 \ // VPXOR XMM2,XMM2,XMM3 /* */ |
||||
ROLL $30, R14 \ /* y1 = S0 = (a>>2) ^ (a>>13) ^ (a>>22) */ |
||||
ADDL R13, R15 \ /* y2 = S1 + CH */ |
||||
ADDL _xfer+60(FP), R15 \ /* y2 = k + w + S1 + CH */ |
||||
LONG $0xdaef21c5 \ // VPXOR XMM11,XMM11,XMM2 /* XTMP5 = s1 {xDxC} */ |
||||
MOVL f, R13 \ /* y0 = a */ |
||||
ADDL R15, e \ /* h = h + S1 + CH + k + w */ |
||||
MOVL f, R15 \ /* y2 = a */ |
||||
LONG $0x002142c4; BYTE $0xdc \ // VPSHUFB XMM11,XMM11,XMM12 /* XTMP5 = s1 {DC00} */
|
||||
ORL h, R13 \ /* y0 = a|c */ |
||||
ADDL e, a \ /* d = d + h + S1 + CH + k + w */ |
||||
ANDL h, R15 \ /* y2 = a&c */ |
||||
LONG $0xe0fea1c5 \ // VPADDD XMM4,XMM11,XMM0 /* X0 = {W[3], W[2], W[1], W[0]} */ |
||||
ANDL g, R13 \ /* y0 = (a|c)&b */ |
||||
ADDL R14, e \ /* h = h + S1 + CH + k + w + S0 */ |
||||
ORL R15, R13 \ /* y0 = MAJ = (a|c)&b)|(a&c) */ |
||||
ADDL R13, e \ /* h = h + S1 + CH + k + w + S0 + MAJ */ |
||||
\ /* ROTATE_ARGS */ |
||||
ROTATE_XS |
||||
|
||||
|
||||
#define DO_ROUND(a, b, c, d, e, f, g, h, offset) \ |
||||
MOVL e, R13 \ /* y0 = e */ |
||||
ROLL $18, R13 \ /* y0 = e >> (25-11) */ |
||||
MOVL a, R14 \ /* y1 = a */ |
||||
XORL e, R13 \ /* y0 = e ^ (e >> (25-11)) */ |
||||
ROLL $23, R14 \ /* y1 = a >> (22-13) */ |
||||
MOVL f, R15 \ /* y2 = f */ |
||||
XORL a, R14 \ /* y1 = a ^ (a >> (22-13) */ |
||||
ROLL $27, R13 \ /* y0 = (e >> (11-6)) ^ (e >> (25-6)) */ |
||||
XORL g, R15 \ /* y2 = f^g */ |
||||
XORL e, R13 \ /* y0 = e ^ (e >> (11-6)) ^ (e >> (25-6)) */ |
||||
ROLL $21, R14 \ /* y1 = (a >> (13-2)) ^ (a >> (22-2)) */ |
||||
ANDL e, R15 \ /* y2 = (f^g)&e */ |
||||
XORL a, R14 \ /* y1 = a ^ (a >> (13-2)) ^ (a >> (22-2)) */ |
||||
ROLL $26, R13 \ /* y0 = S1 = (e>>6) & (e>>11) ^ (e>>25) */ |
||||
XORL g, R15 \ /* y2 = CH = ((f^g)&e)^g */ |
||||
ADDL R13, R15 \ /* y2 = S1 + CH */ |
||||
ROLL $30, R14 \ /* y1 = S0 = (a>>2) ^ (a>>13) ^ (a>>22) */ |
||||
ADDL _xfer+offset(FP), R15 \ /* y2 = k + w + S1 + CH */ |
||||
MOVL a, R13 \ /* y0 = a */ |
||||
ADDL R15, h \ /* h = h + S1 + CH + k + w */ |
||||
MOVL a, R15 \ /* y2 = a */ |
||||
ORL c, R13 \ /* y0 = a|c */ |
||||
ADDL h, d \ /* d = d + h + S1 + CH + k + w */ |
||||
ANDL c, R15 \ /* y2 = a&c */ |
||||
ANDL b, R13 \ /* y0 = (a|c)&b */ |
||||
ADDL R14, h \ /* h = h + S1 + CH + k + w + S0 */ |
||||
ORL R15, R13 \ /* y0 = MAJ = (a|c)&b)|(a&c) */ |
||||
ADDL R13, h /* h = h + S1 + CH + k + w + S0 + MAJ */ |
||||
|
||||
|
||||
// func blockAvx(h []uint32, message []uint8, reserved0, reserved1, reserved2, reserved3 uint64) |
||||
TEXT ·blockAvx(SB), 7, $0 |
||||
|
||||
MOVQ h+0(FP), SI // SI: &h |
||||
MOVQ message+24(FP), R8 // &message |
||||
MOVQ lenmessage+32(FP), R9 // length of message |
||||
CMPQ R9, $0 |
||||
JEQ done_hash |
||||
ADDQ R8, R9 |
||||
MOVQ R9, _inp_end+64(FP) // store end of message |
||||
|
||||
// Register definition |
||||
// a --> eax |
||||
// b --> ebx |
||||
// c --> ecx |
||||
// d --> r8d |
||||
// e --> edx |
||||
// f --> r9d |
||||
// g --> r10d |
||||
// h --> r11d |
||||
// |
||||
// y0 --> r13d |
||||
// y1 --> r14d |
||||
// y2 --> r15d |
||||
|
||||
MOVL (0*4)(SI), AX // a = H0 |
||||
MOVL (1*4)(SI), BX // b = H1 |
||||
MOVL (2*4)(SI), CX // c = H2 |
||||
MOVL (3*4)(SI), R8 // d = H3 |
||||
MOVL (4*4)(SI), DX // e = H4 |
||||
MOVL (5*4)(SI), R9 // f = H5 |
||||
MOVL (6*4)(SI), R10 // g = H6 |
||||
MOVL (7*4)(SI), R11 // h = H7 |
||||
|
||||
MOVOU bflipMask<>(SB), X13 |
||||
MOVOU shuf00BA<>(SB), X10 // shuffle xBxA -> 00BA |
||||
MOVOU shufDC00<>(SB), X12 // shuffle xDxC -> DC00 |
||||
|
||||
MOVQ message+24(FP), SI // SI: &message |
||||
|
||||
loop0: |
||||
LEAQ constants<>(SB), BP |
||||
|
||||
// byte swap first 16 dwords |
||||
MOVOU 0*16(SI), X4 |
||||
LONG $0x0059c2c4; BYTE $0xe5 // VPSHUFB XMM4, XMM4, XMM13
|
||||
MOVOU 1*16(SI), X5 |
||||
LONG $0x0051c2c4; BYTE $0xed // VPSHUFB XMM5, XMM5, XMM13
|
||||
MOVOU 2*16(SI), X6 |
||||
LONG $0x0049c2c4; BYTE $0xf5 // VPSHUFB XMM6, XMM6, XMM13
|
||||
MOVOU 3*16(SI), X7 |
||||
LONG $0x0041c2c4; BYTE $0xfd // VPSHUFB XMM7, XMM7, XMM13
|
||||
|
||||
MOVQ SI, _inp+72(FP) |
||||
MOVD $0x3, DI |
||||
|
||||
// schedule 48 input dwords, by doing 3 rounds of 16 each |
||||
loop1: |
||||
LONG $0x4dfe59c5; BYTE $0x00 // VPADDD XMM9, XMM4, 0[RBP] /* Add 1st constant to first part of message */
|
||||
MOVOU X9, _xfer+48(FP) |
||||
FOUR_ROUNDS_AND_SCHED(AX, BX, CX, R8, DX, R9, R10, R11) |
||||
|
||||
LONG $0x4dfe59c5; BYTE $0x10 // VPADDD XMM9, XMM4, 16[RBP] /* Add 2nd constant to message */
|
||||
MOVOU X9, _xfer+48(FP) |
||||
FOUR_ROUNDS_AND_SCHED(DX, R9, R10, R11, AX, BX, CX, R8) |
||||
|
||||
LONG $0x4dfe59c5; BYTE $0x20 // VPADDD XMM9, XMM4, 32[RBP] /* Add 3rd constant to message */
|
||||
MOVOU X9, _xfer+48(FP) |
||||
FOUR_ROUNDS_AND_SCHED(AX, BX, CX, R8, DX, R9, R10, R11) |
||||
|
||||
LONG $0x4dfe59c5; BYTE $0x30 // VPADDD XMM9, XMM4, 48[RBP] /* Add 4th constant to message */
|
||||
MOVOU X9, _xfer+48(FP) |
||||
ADDQ $64, BP |
||||
FOUR_ROUNDS_AND_SCHED(DX, R9, R10, R11, AX, BX, CX, R8) |
||||
|
||||
SUBQ $1, DI |
||||
JNE loop1 |
||||
|
||||
MOVD $0x2, DI |
||||
loop2: |
||||
LONG $0x4dfe59c5; BYTE $0x00 // VPADDD XMM9, XMM4, 0[RBP] /* Add 1st constant to first part of message */
|
||||
MOVOU X9, _xfer+48(FP) |
||||
DO_ROUND( AX, BX, CX, R8, DX, R9, R10, R11, 48) |
||||
DO_ROUND(R11, AX, BX, CX, R8, DX, R9, R10, 52) |
||||
DO_ROUND(R10, R11, AX, BX, CX, R8, DX, R9, 56) |
||||
DO_ROUND( R9, R10, R11, AX, BX, CX, R8, DX, 60) |
||||
|
||||
LONG $0x4dfe51c5; BYTE $0x10 // VPADDD XMM9, XMM5, 16[RBP] /* Add 2nd constant to message */
|
||||
MOVOU X9, _xfer+48(FP) |
||||
ADDQ $32, BP |
||||
DO_ROUND( DX, R9, R10, R11, AX, BX, CX, R8, 48) |
||||
DO_ROUND( R8, DX, R9, R10, R11, AX, BX, CX, 52) |
||||
DO_ROUND( CX, R8, DX, R9, R10, R11, AX, BX, 56) |
||||
DO_ROUND( BX, CX, R8, DX, R9, R10, R11, AX, 60) |
||||
|
||||
MOVOU X6, X4 |
||||
MOVOU X7, X5 |
||||
|
||||
SUBQ $1, DI |
||||
JNE loop2 |
||||
|
||||
MOVQ h+0(FP), SI // SI: &h |
||||
ADDL (0*4)(SI), AX // H0 = a + H0 |
||||
MOVL AX, (0*4)(SI) |
||||
ADDL (1*4)(SI), BX // H1 = b + H1 |
||||
MOVL BX, (1*4)(SI) |
||||
ADDL (2*4)(SI), CX // H2 = c + H2 |
||||
MOVL CX, (2*4)(SI) |
||||
ADDL (3*4)(SI), R8 // H3 = d + H3 |
||||
MOVL R8, (3*4)(SI) |
||||
ADDL (4*4)(SI), DX // H4 = e + H4 |
||||
MOVL DX, (4*4)(SI) |
||||
ADDL (5*4)(SI), R9 // H5 = f + H5 |
||||
MOVL R9, (5*4)(SI) |
||||
ADDL (6*4)(SI), R10 // H6 = g + H6 |
||||
MOVL R10, (6*4)(SI) |
||||
ADDL (7*4)(SI), R11 // H7 = h + H7 |
||||
MOVL R11, (7*4)(SI) |
||||
|
||||
MOVQ _inp+72(FP), SI |
||||
ADDQ $64, SI |
||||
CMPQ _inp_end+64(FP), SI |
||||
JNE loop0 |
||||
|
||||
done_hash: |
||||
RET |
||||
|
||||
// Constants table |
||||
DATA constants<>+0x0(SB)/8, $0x71374491428a2f98 |
||||
DATA constants<>+0x8(SB)/8, $0xe9b5dba5b5c0fbcf |
||||
DATA constants<>+0x10(SB)/8, $0x59f111f13956c25b |
||||
DATA constants<>+0x18(SB)/8, $0xab1c5ed5923f82a4 |
||||
DATA constants<>+0x20(SB)/8, $0x12835b01d807aa98 |
||||
DATA constants<>+0x28(SB)/8, $0x550c7dc3243185be |
||||
DATA constants<>+0x30(SB)/8, $0x80deb1fe72be5d74 |
||||
DATA constants<>+0x38(SB)/8, $0xc19bf1749bdc06a7 |
||||
DATA constants<>+0x40(SB)/8, $0xefbe4786e49b69c1 |
||||
DATA constants<>+0x48(SB)/8, $0x240ca1cc0fc19dc6 |
||||
DATA constants<>+0x50(SB)/8, $0x4a7484aa2de92c6f |
||||
DATA constants<>+0x58(SB)/8, $0x76f988da5cb0a9dc |
||||
DATA constants<>+0x60(SB)/8, $0xa831c66d983e5152 |
||||
DATA constants<>+0x68(SB)/8, $0xbf597fc7b00327c8 |
||||
DATA constants<>+0x70(SB)/8, $0xd5a79147c6e00bf3 |
||||
DATA constants<>+0x78(SB)/8, $0x1429296706ca6351 |
||||
DATA constants<>+0x80(SB)/8, $0x2e1b213827b70a85 |
||||
DATA constants<>+0x88(SB)/8, $0x53380d134d2c6dfc |
||||
DATA constants<>+0x90(SB)/8, $0x766a0abb650a7354 |
||||
DATA constants<>+0x98(SB)/8, $0x92722c8581c2c92e |
||||
DATA constants<>+0xa0(SB)/8, $0xa81a664ba2bfe8a1 |
||||
DATA constants<>+0xa8(SB)/8, $0xc76c51a3c24b8b70 |
||||
DATA constants<>+0xb0(SB)/8, $0xd6990624d192e819 |
||||
DATA constants<>+0xb8(SB)/8, $0x106aa070f40e3585 |
||||
DATA constants<>+0xc0(SB)/8, $0x1e376c0819a4c116 |
||||
DATA constants<>+0xc8(SB)/8, $0x34b0bcb52748774c |
||||
DATA constants<>+0xd0(SB)/8, $0x4ed8aa4a391c0cb3 |
||||
DATA constants<>+0xd8(SB)/8, $0x682e6ff35b9cca4f |
||||
DATA constants<>+0xe0(SB)/8, $0x78a5636f748f82ee |
||||
DATA constants<>+0xe8(SB)/8, $0x8cc7020884c87814 |
||||
DATA constants<>+0xf0(SB)/8, $0xa4506ceb90befffa |
||||
DATA constants<>+0xf8(SB)/8, $0xc67178f2bef9a3f7 |
||||
|
||||
DATA bflipMask<>+0x00(SB)/8, $0x0405060700010203 |
||||
DATA bflipMask<>+0x08(SB)/8, $0x0c0d0e0f08090a0b |
||||
|
||||
DATA shuf00BA<>+0x00(SB)/8, $0x0b0a090803020100 |
||||
DATA shuf00BA<>+0x08(SB)/8, $0xFFFFFFFFFFFFFFFF |
||||
|
||||
DATA shufDC00<>+0x00(SB)/8, $0xFFFFFFFFFFFFFFFF |
||||
DATA shufDC00<>+0x08(SB)/8, $0x0b0a090803020100 |
||||
|
||||
GLOBL constants<>(SB), 8, $256 |
||||
GLOBL bflipMask<>(SB), (NOPTR+RODATA), $16 |
||||
GLOBL shuf00BA<>(SB), (NOPTR+RODATA), $16 |
||||
GLOBL shufDC00<>(SB), (NOPTR+RODATA), $16 |
@ -0,0 +1,31 @@ |
||||
//+build !noasm
|
||||
|
||||
/* |
||||
* Minio Cloud Storage, (C) 2016 Minio, Inc. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package sha256 |
||||
|
||||
//go:noescape
|
||||
func blockSsse(h []uint32, message []uint8, reserved0, reserved1, reserved2, reserved3 uint64) |
||||
|
||||
func blockSsseGo(dig *digest, p []byte) { |
||||
|
||||
h := []uint32{dig.h[0], dig.h[1], dig.h[2], dig.h[3], dig.h[4], dig.h[5], dig.h[6], dig.h[7]} |
||||
|
||||
blockSsse(h[:], p[:], 0, 0, 0, 0) |
||||
|
||||
dig.h[0], dig.h[1], dig.h[2], dig.h[3], dig.h[4], dig.h[5], dig.h[6], dig.h[7] = h[0], h[1], h[2], h[3], h[4], h[5], h[6], h[7] |
||||
} |
@ -0,0 +1,430 @@ |
||||
//+build !noasm !appengine |
||||
|
||||
// SHA256 implementation for SSSE3 |
||||
|
||||
// |
||||
// Minio Cloud Storage, (C) 2016 Minio, Inc. |
||||
// |
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License. |
||||
// You may obtain a copy of the License at |
||||
// |
||||
// http://www.apache.org/licenses/LICENSE-2.0 |
||||
// |
||||
// Unless required by applicable law or agreed to in writing, software |
||||
// distributed under the License is distributed on an "AS IS" BASIS, |
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
// See the License for the specific language governing permissions and |
||||
// limitations under the License. |
||||
// |
||||
|
||||
// |
||||
// This code is based on an Intel White-Paper: |
||||
// "Fast SHA-256 Implementations on Intel Architecture Processors" |
||||
// |
||||
// together with the reference implementation from the following authors: |
||||
// James Guilford <james.guilford@intel.com>
|
||||
// Kirk Yap <kirk.s.yap@intel.com>
|
||||
// Tim Chen <tim.c.chen@linux.intel.com>
|
||||
// |
||||
// For Golang it has been converted to Plan 9 assembly with the help of |
||||
// github.com/minio/asm2plan9s to assemble Intel instructions to their Plan9 |
||||
// equivalents |
||||
// |
||||
|
||||
#include "textflag.h" |
||||
|
||||
#define ROTATE_XS \ |
||||
MOVOU X4, X15 \ |
||||
MOVOU X5, X4 \ |
||||
MOVOU X6, X5 \ |
||||
MOVOU X7, X6 \ |
||||
MOVOU X15, X7 |
||||
|
||||
// compute s0 four at a time and s1 two at a time |
||||
// compute W[-16] + W[-7] 4 at a time |
||||
#define FOUR_ROUNDS_AND_SCHED(a, b, c, d, e, f, g, h) \ |
||||
MOVL e, R13 \ /* y0 = e */ |
||||
ROLL $18, R13 \ /* y0 = e >> (25-11) */ |
||||
MOVL a, R14 \ /* y1 = a */ |
||||
MOVOU X7, X0 \ |
||||
LONG $0x0f3a0f66; WORD $0x04c6 \ // PALIGNR XMM0,XMM6,0x4 /* XTMP0 = W[-7] */
|
||||
ROLL $23, R14 \ /* y1 = a >> (22-13) */ |
||||
XORL e, R13 \ /* y0 = e ^ (e >> (25-11)) */ |
||||
MOVL f, R15 \ /* y2 = f */ |
||||
ROLL $27, R13 \ /* y0 = (e >> (11-6)) ^ (e >> (25-6)) */ |
||||
XORL a, R14 \ /* y1 = a ^ (a >> (22-13) */ |
||||
XORL g, R15 \ /* y2 = f^g */ |
||||
LONG $0xc4fe0f66 \ // PADDD XMM0,XMM4 /* XTMP0 = W[-7] + W[-16] */ |
||||
XORL e, R13 \ /* y0 = e ^ (e >> (11-6)) ^ (e >> (25-6) ) */ |
||||
ANDL e, R15 \ /* y2 = (f^g)&e */ |
||||
ROLL $21, R14 \ /* y1 = (a >> (13-2)) ^ (a >> (22-2)) */ |
||||
\ /* */ |
||||
\ /* compute s0 */ |
||||
\ /* */ |
||||
MOVOU X5, X1 \ |
||||
LONG $0x0f3a0f66; WORD $0x04cc \ // PALIGNR XMM1,XMM4,0x4 /* XTMP1 = W[-15] */
|
||||
XORL a, R14 \ /* y1 = a ^ (a >> (13-2)) ^ (a >> (22-2)) */ |
||||
ROLL $26, R13 \ /* y0 = S1 = (e>>6) & (e>>11) ^ (e>>25) */ |
||||
XORL g, R15 \ /* y2 = CH = ((f^g)&e)^g */ |
||||
ROLL $30, R14 \ /* y1 = S0 = (a>>2) ^ (a>>13) ^ (a>>22) */ |
||||
ADDL R13, R15 \ /* y2 = S1 + CH */ |
||||
ADDL _xfer+48(FP), R15 \ /* y2 = k + w + S1 + CH */ |
||||
MOVL a, R13 \ /* y0 = a */ |
||||
ADDL R15, h \ /* h = h + S1 + CH + k + w */ |
||||
\ /* ROTATE_ARGS */ |
||||
MOVL a, R15 \ /* y2 = a */ |
||||
MOVOU X1, X2 \ |
||||
LONG $0xd2720f66; BYTE $0x07 \ // PSRLD XMM2,0x7 /* */
|
||||
ORL c, R13 \ /* y0 = a|c */ |
||||
ADDL h, d \ /* d = d + h + S1 + CH + k + w */ |
||||
ANDL c, R15 \ /* y2 = a&c */ |
||||
MOVOU X1, X3 \ |
||||
LONG $0xf3720f66; BYTE $0x19 \ // PSLLD XMM3,0x19 /* */
|
||||
ANDL b, R13 \ /* y0 = (a|c)&b */ |
||||
ADDL R14, h \ /* h = h + S1 + CH + k + w + S0 */ |
||||
LONG $0xdaeb0f66 \ // POR XMM3,XMM2 /* XTMP1 = W[-15] MY_ROR 7 */ |
||||
ORL R15, R13 \ /* y0 = MAJ = (a|c)&b)|(a&c) */ |
||||
ADDL R13, h \ /* h = h + S1 + CH + k + w + S0 + MAJ */ |
||||
\ /* ROTATE_ARGS */ |
||||
MOVL d, R13 \ /* y0 = e */ |
||||
MOVL h, R14 \ /* y1 = a */ |
||||
ROLL $18, R13 \ /* y0 = e >> (25-11) */ |
||||
XORL d, R13 \ /* y0 = e ^ (e >> (25-11)) */ |
||||
MOVL e, R15 \ /* y2 = f */ |
||||
ROLL $23, R14 \ /* y1 = a >> (22-13) */ |
||||
MOVOU X1, X2 \ |
||||
LONG $0xd2720f66; BYTE $0x12 \ // PSRLD XMM2,0x12 /* */
|
||||
XORL h, R14 \ /* y1 = a ^ (a >> (22-13) */ |
||||
ROLL $27, R13 \ /* y0 = (e >> (11-6)) ^ (e >> (25-6)) */ |
||||
XORL f, R15 \ /* y2 = f^g */ |
||||
MOVOU X1, X8 \ |
||||
LONG $0x720f4166; WORD $0x03d0 \ // PSRLD XMM8,0x3 /* XTMP4 = W[-15] >> 3 */
|
||||
ROLL $21, R14 \ /* y1 = (a >> (13-2)) ^ (a >> (22-2)) */ |
||||
XORL d, R13 \ /* y0 = e ^ (e >> (11-6)) ^ (e >> (25-6)) */ |
||||
ANDL d, R15 \ /* y2 = (f^g)&e */ |
||||
ROLL $26, R13 \ /* y0 = S1 = (e>>6) & (e>>11) ^ (e>>25) */ |
||||
LONG $0xf1720f66; BYTE $0x0e \ // PSLLD XMM1,0xe /* */
|
||||
XORL h, R14 \ /* y1 = a ^ (a >> (13-2)) ^ (a >> (22-2)) */ |
||||
XORL f, R15 \ /* y2 = CH = ((f^g)&e)^g */ |
||||
LONG $0xd9ef0f66 \ // PXOR XMM3,XMM1 /* */ |
||||
ADDL R13, R15 \ /* y2 = S1 + CH */ |
||||
ADDL _xfer+52(FP), R15 \ /* y2 = k + w + S1 + CH */ |
||||
ROLL $30, R14 \ /* y1 = S0 = (a>>2) ^ (a>>13) ^ (a>>22) */ |
||||
LONG $0xdaef0f66 \ // PXOR XMM3,XMM2 /* XTMP1 = W[-15] MY_ROR 7 ^ W[-15] MY_ROR */ |
||||
MOVL h, R13 \ /* y0 = a */ |
||||
ADDL R15, g \ /* h = h + S1 + CH + k + w */ |
||||
MOVL h, R15 \ /* y2 = a */ |
||||
MOVOU X3, X1 \ |
||||
LONG $0xef0f4166; BYTE $0xc8 \ // PXOR XMM1,XMM8 /* XTMP1 = s0 */
|
||||
ORL b, R13 \ /* y0 = a|c */ |
||||
ADDL g, c \ /* d = d + h + S1 + CH + k + w */ |
||||
ANDL b, R15 \ /* y2 = a&c */ |
||||
\ /* */ |
||||
\ /* compute low s1 */ |
||||
\ /* */ |
||||
LONG $0xd7700f66; BYTE $0xfa \ // PSHUFD XMM2,XMM7,0xfa /* XTMP2 = W[-2] {BBAA} */
|
||||
ANDL a, R13 \ /* y0 = (a|c)&b */ |
||||
ADDL R14, g \ /* h = h + S1 + CH + k + w + S0 */ |
||||
LONG $0xc1fe0f66 \ // PADDD XMM0,XMM1 /* XTMP0 = W[-16] + W[-7] + s0 */ |
||||
ORL R15, R13 \ /* y0 = MAJ = (a|c)&b)|(a&c) */ |
||||
ADDL R13, g \ /* h = h + S1 + CH + k + w + S0 + MAJ */ |
||||
\ /* ROTATE_ARGS */ |
||||
MOVL c, R13 \ /* y0 = e */ |
||||
MOVL g, R14 \ /* y1 = a */ |
||||
ROLL $18, R13 \ /* y0 = e >> (25-11) */ |
||||
XORL c, R13 \ /* y0 = e ^ (e >> (25-11)) */ |
||||
ROLL $23, R14 \ /* y1 = a >> (22-13) */ |
||||
MOVL d, R15 \ /* y2 = f */ |
||||
XORL g, R14 \ /* y1 = a ^ (a >> (22-13) */ |
||||
ROLL $27, R13 \ /* y0 = (e >> (11-6)) ^ (e >> (25-6)) */ |
||||
MOVOU X2, X8 \ |
||||
LONG $0x720f4166; WORD $0x0ad0 \ // PSRLD XMM8,0xa /* XTMP4 = W[-2] >> 10 {BBAA} */
|
||||
XORL e, R15 \ /* y2 = f^g */ |
||||
MOVOU X2, X3 \ |
||||
LONG $0xd3730f66; BYTE $0x13 \ // PSRLQ XMM3,0x13 /* XTMP3 = W[-2] MY_ROR 19 {xBxA} */
|
||||
XORL c, R13 \ /* y0 = e ^ (e >> (11-6)) ^ (e >> (25-6)) */ |
||||
ANDL c, R15 \ /* y2 = (f^g)&e */ |
||||
LONG $0xd2730f66; BYTE $0x11 \ // PSRLQ XMM2,0x11 /* XTMP2 = W[-2] MY_ROR 17 {xBxA} */
|
||||
ROLL $21, R14 \ /* y1 = (a >> (13-2)) ^ (a >> (22-2)) */ |
||||
XORL g, R14 \ /* y1 = a ^ (a >> (13-2)) ^ (a >> (22-2)) */ |
||||
XORL e, R15 \ /* y2 = CH = ((f^g)&e)^g */ |
||||
ROLL $26, R13 \ /* y0 = S1 = (e>>6) & (e>>11) ^ (e>>25) */ |
||||
LONG $0xd3ef0f66 \ // PXOR XMM2,XMM3 /* */ |
||||
ADDL R13, R15 \ /* y2 = S1 + CH */ |
||||
ROLL $30, R14 \ /* y1 = S0 = (a>>2) ^ (a>>13) ^ (a>>22) */ |
||||
ADDL _xfer+56(FP), R15 \ /* y2 = k + w + S1 + CH */ |
||||
LONG $0xef0f4466; BYTE $0xc2 \ // PXOR XMM8,XMM2 /* XTMP4 = s1 {xBxA} */
|
||||
MOVL g, R13 \ /* y0 = a */ |
||||
ADDL R15, f \ /* h = h + S1 + CH + k + w */ |
||||
MOVL g, R15 \ /* y2 = a */ |
||||
LONG $0x380f4566; WORD $0xc200 \ // PSHUFB XMM8,XMM10 /* XTMP4 = s1 {00BA} */
|
||||
ORL a, R13 \ /* y0 = a|c */ |
||||
ADDL f, b \ /* d = d + h + S1 + CH + k + w */ |
||||
ANDL a, R15 \ /* y2 = a&c */ |
||||
LONG $0xfe0f4166; BYTE $0xc0 \ // PADDD XMM0,XMM8 /* XTMP0 = {..., ..., W[1], W[0]} */
|
||||
ANDL h, R13 \ /* y0 = (a|c)&b */ |
||||
ADDL R14, f \ /* h = h + S1 + CH + k + w + S0 */ |
||||
\ /* */ |
||||
\ /* compute high s1 */ |
||||
\ /* */ |
||||
LONG $0xd0700f66; BYTE $0x50 \ // PSHUFD XMM2,XMM0,0x50 /* XTMP2 = W[-2] {DDCC} */
|
||||
ORL R15, R13 \ /* y0 = MAJ = (a|c)&b)|(a&c) */ |
||||
ADDL R13, f \ /* h = h + S1 + CH + k + w + S0 + MAJ */ |
||||
\ /* ROTATE_ARGS */ |
||||
MOVL b, R13 \ /* y0 = e */ |
||||
ROLL $18, R13 \ /* y0 = e >> (25-11) */ |
||||
MOVL f, R14 \ /* y1 = a */ |
||||
ROLL $23, R14 \ /* y1 = a >> (22-13) */ |
||||
XORL b, R13 \ /* y0 = e ^ (e >> (25-11)) */ |
||||
MOVL c, R15 \ /* y2 = f */ |
||||
ROLL $27, R13 \ /* y0 = (e >> (11-6)) ^ (e >> (25-6)) */ |
||||
MOVOU X2, X11 \ |
||||
LONG $0x720f4166; WORD $0x0ad3 \ // PSRLD XMM11,0xa /* XTMP5 = W[-2] >> 10 {DDCC} */
|
||||
XORL f, R14 \ /* y1 = a ^ (a >> (22-13) */ |
||||
XORL d, R15 \ /* y2 = f^g */ |
||||
MOVOU X2, X3 \ |
||||
LONG $0xd3730f66; BYTE $0x13 \ // PSRLQ XMM3,0x13 /* XTMP3 = W[-2] MY_ROR 19 {xDxC} */
|
||||
XORL b, R13 \ /* y0 = e ^ (e >> (11-6)) ^ (e >> (25-6)) */ |
||||
ANDL b, R15 \ /* y2 = (f^g)&e */ |
||||
ROLL $21, R14 \ /* y1 = (a >> (13-2)) ^ (a >> (22-2)) */ |
||||
LONG $0xd2730f66; BYTE $0x11 \ // PSRLQ XMM2,0x11 /* XTMP2 = W[-2] MY_ROR 17 {xDxC} */
|
||||
XORL f, R14 \ /* y1 = a ^ (a >> (13-2)) ^ (a >> (22-2)) */ |
||||
ROLL $26, R13 \ /* y0 = S1 = (e>>6) & (e>>11) ^ (e>>25) */ |
||||
XORL d, R15 \ /* y2 = CH = ((f^g)&e)^g */ |
||||
LONG $0xd3ef0f66 \ // PXOR XMM2,XMM3 /* */ |
||||
ROLL $30, R14 \ /* y1 = S0 = (a>>2) ^ (a>>13) ^ (a>>22) */ |
||||
ADDL R13, R15 \ /* y2 = S1 + CH */ |
||||
ADDL _xfer+60(FP), R15 \ /* y2 = k + w + S1 + CH */ |
||||
LONG $0xef0f4466; BYTE $0xda \ // PXOR XMM11,XMM2 /* XTMP5 = s1 {xDxC} */
|
||||
MOVL f, R13 \ /* y0 = a */ |
||||
ADDL R15, e \ /* h = h + S1 + CH + k + w */ |
||||
MOVL f, R15 \ /* y2 = a */ |
||||
LONG $0x380f4566; WORD $0xdc00 \ // PSHUFB XMM11,XMM12 /* XTMP5 = s1 {DC00} */
|
||||
ORL h, R13 \ /* y0 = a|c */ |
||||
ADDL e, a \ /* d = d + h + S1 + CH + k + w */ |
||||
ANDL h, R15 \ /* y2 = a&c */ |
||||
MOVOU X11, X4 \ |
||||
LONG $0xe0fe0f66 \ // PADDD XMM4,XMM0 /* X0 = {W[3], W[2], W[1], W[0]} */ |
||||
ANDL g, R13 \ /* y0 = (a|c)&b */ |
||||
ADDL R14, e \ /* h = h + S1 + CH + k + w + S0 */ |
||||
ORL R15, R13 \ /* y0 = MAJ = (a|c)&b)|(a&c) */ |
||||
ADDL R13, e \ /* h = h + S1 + CH + k + w + S0 + MAJ */ |
||||
\ /* ROTATE_ARGS */ |
||||
ROTATE_XS |
||||
|
||||
|
||||
#define DO_ROUND(a, b, c, d, e, f, g, h, offset) \ |
||||
MOVL e, R13 \ /* y0 = e */ |
||||
ROLL $18, R13 \ /* y0 = e >> (25-11) */ |
||||
MOVL a, R14 \ /* y1 = a */ |
||||
XORL e, R13 \ /* y0 = e ^ (e >> (25-11)) */ |
||||
ROLL $23, R14 \ /* y1 = a >> (22-13) */ |
||||
MOVL f, R15 \ /* y2 = f */ |
||||
XORL a, R14 \ /* y1 = a ^ (a >> (22-13) */ |
||||
ROLL $27, R13 \ /* y0 = (e >> (11-6)) ^ (e >> (25-6)) */ |
||||
XORL g, R15 \ /* y2 = f^g */ |
||||
XORL e, R13 \ /* y0 = e ^ (e >> (11-6)) ^ (e >> (25-6)) */ |
||||
ROLL $21, R14 \ /* y1 = (a >> (13-2)) ^ (a >> (22-2)) */ |
||||
ANDL e, R15 \ /* y2 = (f^g)&e */ |
||||
XORL a, R14 \ /* y1 = a ^ (a >> (13-2)) ^ (a >> (22-2)) */ |
||||
ROLL $26, R13 \ /* y0 = S1 = (e>>6) & (e>>11) ^ (e>>25) */ |
||||
XORL g, R15 \ /* y2 = CH = ((f^g)&e)^g */ |
||||
ADDL R13, R15 \ /* y2 = S1 + CH */ |
||||
ROLL $30, R14 \ /* y1 = S0 = (a>>2) ^ (a>>13) ^ (a>>22) */ |
||||
ADDL _xfer+offset(FP), R15 \ /* y2 = k + w + S1 + CH */ |
||||
MOVL a, R13 \ /* y0 = a */ |
||||
ADDL R15, h \ /* h = h + S1 + CH + k + w */ |
||||
MOVL a, R15 \ /* y2 = a */ |
||||
ORL c, R13 \ /* y0 = a|c */ |
||||
ADDL h, d \ /* d = d + h + S1 + CH + k + w */ |
||||
ANDL c, R15 \ /* y2 = a&c */ |
||||
ANDL b, R13 \ /* y0 = (a|c)&b */ |
||||
ADDL R14, h \ /* h = h + S1 + CH + k + w + S0 */ |
||||
ORL R15, R13 \ /* y0 = MAJ = (a|c)&b)|(a&c) */ |
||||
ADDL R13, h /* h = h + S1 + CH + k + w + S0 + MAJ */ |
||||
|
||||
|
||||
// func blockSsse(h []uint32, message []uint8, reserved0, reserved1, reserved2, reserved3 uint64) |
||||
TEXT ·blockSsse(SB), 7, $0 |
||||
|
||||
MOVQ h+0(FP), SI // SI: &h |
||||
MOVQ message+24(FP), R8 // &message |
||||
MOVQ lenmessage+32(FP), R9 // length of message |
||||
CMPQ R9, $0 |
||||
JEQ done_hash |
||||
ADDQ R8, R9 |
||||
MOVQ R9, _inp_end+64(FP) // store end of message |
||||
|
||||
// Register definition |
||||
// a --> eax |
||||
// b --> ebx |
||||
// c --> ecx |
||||
// d --> r8d |
||||
// e --> edx |
||||
// f --> r9d |
||||
// g --> r10d |
||||
// h --> r11d |
||||
// |
||||
// y0 --> r13d |
||||
// y1 --> r14d |
||||
// y2 --> r15d |
||||
|
||||
MOVL (0*4)(SI), AX // a = H0 |
||||
MOVL (1*4)(SI), BX // b = H1 |
||||
MOVL (2*4)(SI), CX // c = H2 |
||||
MOVL (3*4)(SI), R8 // d = H3 |
||||
MOVL (4*4)(SI), DX // e = H4 |
||||
MOVL (5*4)(SI), R9 // f = H5 |
||||
MOVL (6*4)(SI), R10 // g = H6 |
||||
MOVL (7*4)(SI), R11 // h = H7 |
||||
|
||||
MOVOU bflipMask<>(SB), X13 |
||||
MOVOU shuf00BA<>(SB), X10 // shuffle xBxA -> 00BA |
||||
MOVOU shufDC00<>(SB), X12 // shuffle xDxC -> DC00 |
||||
|
||||
MOVQ message+24(FP), SI // SI: &message |
||||
|
||||
loop0: |
||||
LEAQ constants<>(SB), BP |
||||
|
||||
// byte swap first 16 dwords |
||||
MOVOU 0*16(SI), X4 |
||||
LONG $0x380f4166; WORD $0xe500 // PSHUFB XMM4, XMM13
|
||||
MOVOU 1*16(SI), X5 |
||||
LONG $0x380f4166; WORD $0xed00 // PSHUFB XMM5, XMM13
|
||||
MOVOU 2*16(SI), X6 |
||||
LONG $0x380f4166; WORD $0xf500 // PSHUFB XMM6, XMM13
|
||||
MOVOU 3*16(SI), X7 |
||||
LONG $0x380f4166; WORD $0xfd00 // PSHUFB XMM7, XMM13
|
||||
|
||||
MOVQ SI, _inp+72(FP) |
||||
MOVD $0x3, DI |
||||
|
||||
// Align |
||||
// nop WORD PTR [rax+rax*1+0x0] |
||||
|
||||
// schedule 48 input dwords, by doing 3 rounds of 16 each |
||||
loop1: |
||||
MOVOU X4, X9 |
||||
LONG $0xfe0f4466; WORD $0x004d // PADDD XMM9, 0[RBP] /* Add 1st constant to first part of message */
|
||||
MOVOU X9, _xfer+48(FP) |
||||
FOUR_ROUNDS_AND_SCHED(AX, BX, CX, R8, DX, R9, R10, R11) |
||||
|
||||
MOVOU X4, X9 |
||||
LONG $0xfe0f4466; WORD $0x104d // PADDD XMM9, 16[RBP] /* Add 2nd constant to message */
|
||||
MOVOU X9, _xfer+48(FP) |
||||
FOUR_ROUNDS_AND_SCHED(DX, R9, R10, R11, AX, BX, CX, R8) |
||||
|
||||
MOVOU X4, X9 |
||||
LONG $0xfe0f4466; WORD $0x204d // PADDD XMM9, 32[RBP] /* Add 3rd constant to message */
|
||||
MOVOU X9, _xfer+48(FP) |
||||
FOUR_ROUNDS_AND_SCHED(AX, BX, CX, R8, DX, R9, R10, R11) |
||||
|
||||
MOVOU X4, X9 |
||||
LONG $0xfe0f4466; WORD $0x304d // PADDD XMM9, 48[RBP] /* Add 4th constant to message */
|
||||
MOVOU X9, _xfer+48(FP) |
||||
ADDQ $64, BP |
||||
FOUR_ROUNDS_AND_SCHED(DX, R9, R10, R11, AX, BX, CX, R8) |
||||
|
||||
SUBQ $1, DI |
||||
JNE loop1 |
||||
|
||||
MOVD $0x2, DI |
||||
loop2: |
||||
MOVOU X4, X9 |
||||
LONG $0xfe0f4466; WORD $0x004d // PADDD XMM9, 0[RBP] /* Add 1st constant to first part of message */
|
||||
MOVOU X9, _xfer+48(FP) |
||||
DO_ROUND( AX, BX, CX, R8, DX, R9, R10, R11, 48) |
||||
DO_ROUND(R11, AX, BX, CX, R8, DX, R9, R10, 52) |
||||
DO_ROUND(R10, R11, AX, BX, CX, R8, DX, R9, 56) |
||||
DO_ROUND( R9, R10, R11, AX, BX, CX, R8, DX, 60) |
||||
|
||||
MOVOU X5, X9 |
||||
LONG $0xfe0f4466; WORD $0x104d // PADDD XMM9, 16[RBP] /* Add 2nd constant to message */
|
||||
MOVOU X9, _xfer+48(FP) |
||||
ADDQ $32, BP |
||||
DO_ROUND( DX, R9, R10, R11, AX, BX, CX, R8, 48) |
||||
DO_ROUND( R8, DX, R9, R10, R11, AX, BX, CX, 52) |
||||
DO_ROUND( CX, R8, DX, R9, R10, R11, AX, BX, 56) |
||||
DO_ROUND( BX, CX, R8, DX, R9, R10, R11, AX, 60) |
||||
|
||||
MOVOU X6, X4 |
||||
MOVOU X7, X5 |
||||
|
||||
SUBQ $1, DI |
||||
JNE loop2 |
||||
|
||||
MOVQ h+0(FP), SI // SI: &h |
||||
ADDL (0*4)(SI), AX // H0 = a + H0 |
||||
MOVL AX, (0*4)(SI) |
||||
ADDL (1*4)(SI), BX // H1 = b + H1 |
||||
MOVL BX, (1*4)(SI) |
||||
ADDL (2*4)(SI), CX // H2 = c + H2 |
||||
MOVL CX, (2*4)(SI) |
||||
ADDL (3*4)(SI), R8 // H3 = d + H3 |
||||
MOVL R8, (3*4)(SI) |
||||
ADDL (4*4)(SI), DX // H4 = e + H4 |
||||
MOVL DX, (4*4)(SI) |
||||
ADDL (5*4)(SI), R9 // H5 = f + H5 |
||||
MOVL R9, (5*4)(SI) |
||||
ADDL (6*4)(SI), R10 // H6 = g + H6 |
||||
MOVL R10, (6*4)(SI) |
||||
ADDL (7*4)(SI), R11 // H7 = h + H7 |
||||
MOVL R11, (7*4)(SI) |
||||
|
||||
MOVQ _inp+72(FP), SI |
||||
ADDQ $64, SI |
||||
CMPQ _inp_end+64(FP), SI |
||||
JNE loop0 |
||||
|
||||
done_hash: |
||||
RET |
||||
|
||||
// Constants table |
||||
DATA constants<>+0x0(SB)/8, $0x71374491428a2f98 |
||||
DATA constants<>+0x8(SB)/8, $0xe9b5dba5b5c0fbcf |
||||
DATA constants<>+0x10(SB)/8, $0x59f111f13956c25b |
||||
DATA constants<>+0x18(SB)/8, $0xab1c5ed5923f82a4 |
||||
DATA constants<>+0x20(SB)/8, $0x12835b01d807aa98 |
||||
DATA constants<>+0x28(SB)/8, $0x550c7dc3243185be |
||||
DATA constants<>+0x30(SB)/8, $0x80deb1fe72be5d74 |
||||
DATA constants<>+0x38(SB)/8, $0xc19bf1749bdc06a7 |
||||
DATA constants<>+0x40(SB)/8, $0xefbe4786e49b69c1 |
||||
DATA constants<>+0x48(SB)/8, $0x240ca1cc0fc19dc6 |
||||
DATA constants<>+0x50(SB)/8, $0x4a7484aa2de92c6f |
||||
DATA constants<>+0x58(SB)/8, $0x76f988da5cb0a9dc |
||||
DATA constants<>+0x60(SB)/8, $0xa831c66d983e5152 |
||||
DATA constants<>+0x68(SB)/8, $0xbf597fc7b00327c8 |
||||
DATA constants<>+0x70(SB)/8, $0xd5a79147c6e00bf3 |
||||
DATA constants<>+0x78(SB)/8, $0x1429296706ca6351 |
||||
DATA constants<>+0x80(SB)/8, $0x2e1b213827b70a85 |
||||
DATA constants<>+0x88(SB)/8, $0x53380d134d2c6dfc |
||||
DATA constants<>+0x90(SB)/8, $0x766a0abb650a7354 |
||||
DATA constants<>+0x98(SB)/8, $0x92722c8581c2c92e |
||||
DATA constants<>+0xa0(SB)/8, $0xa81a664ba2bfe8a1 |
||||
DATA constants<>+0xa8(SB)/8, $0xc76c51a3c24b8b70 |
||||
DATA constants<>+0xb0(SB)/8, $0xd6990624d192e819 |
||||
DATA constants<>+0xb8(SB)/8, $0x106aa070f40e3585 |
||||
DATA constants<>+0xc0(SB)/8, $0x1e376c0819a4c116 |
||||
DATA constants<>+0xc8(SB)/8, $0x34b0bcb52748774c |
||||
DATA constants<>+0xd0(SB)/8, $0x4ed8aa4a391c0cb3 |
||||
DATA constants<>+0xd8(SB)/8, $0x682e6ff35b9cca4f |
||||
DATA constants<>+0xe0(SB)/8, $0x78a5636f748f82ee |
||||
DATA constants<>+0xe8(SB)/8, $0x8cc7020884c87814 |
||||
DATA constants<>+0xf0(SB)/8, $0xa4506ceb90befffa |
||||
DATA constants<>+0xf8(SB)/8, $0xc67178f2bef9a3f7 |
||||
|
||||
DATA bflipMask<>+0x00(SB)/8, $0x0405060700010203 |
||||
DATA bflipMask<>+0x08(SB)/8, $0x0c0d0e0f08090a0b |
||||
|
||||
DATA shuf00BA<>+0x00(SB)/8, $0x0b0a090803020100 |
||||
DATA shuf00BA<>+0x08(SB)/8, $0xFFFFFFFFFFFFFFFF |
||||
|
||||
DATA shufDC00<>+0x00(SB)/8, $0xFFFFFFFFFFFFFFFF |
||||
DATA shufDC00<>+0x08(SB)/8, $0x0b0a090803020100 |
||||
|
||||
GLOBL constants<>(SB), 8, $256 |
||||
GLOBL bflipMask<>(SB), (NOPTR+RODATA), $16 |
||||
GLOBL shuf00BA<>(SB), (NOPTR+RODATA), $16 |
||||
GLOBL shufDC00<>(SB), (NOPTR+RODATA), $16 |
@ -0,0 +1,21 @@ |
||||
//+build !noasm
|
||||
|
||||
/* |
||||
* Minio Cloud Storage, (C) 2016 Minio, Inc. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package sha256 |
||||
|
||||
func blockArmGo(dig *digest, p []byte) {} |
@ -0,0 +1,36 @@ |
||||
//+build !noasm
|
||||
|
||||
/* |
||||
* Minio Cloud Storage, (C) 2016 Minio, Inc. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package sha256 |
||||
|
||||
func blockAvx2Go(dig *digest, p []byte) {} |
||||
func blockAvxGo(dig *digest, p []byte) {} |
||||
func blockSsseGo(dig *digest, p []byte) {} |
||||
|
||||
//go:noescape
|
||||
func blockArm(h []uint32, message []uint8) |
||||
|
||||
func blockArmGo(dig *digest, p []byte) { |
||||
|
||||
h := []uint32{dig.h[0], dig.h[1], dig.h[2], dig.h[3], dig.h[4], dig.h[5], dig.h[6], dig.h[7]} |
||||
|
||||
blockArm(h[:], p[:]) |
||||
|
||||
dig.h[0], dig.h[1], dig.h[2], dig.h[3], dig.h[4], dig.h[5], dig.h[6], dig.h[7] = h[0], h[1], h[2], h[3], h[4], |
||||
h[5], h[6], h[7] |
||||
} |
@ -0,0 +1,193 @@ |
||||
//+build !noasm !appengine |
||||
|
||||
// ARM64 version of SHA256 |
||||
|
||||
// |
||||
// Minio Cloud Storage, (C) 2016 Minio, Inc. |
||||
// |
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License. |
||||
// You may obtain a copy of the License at |
||||
// |
||||
// http://www.apache.org/licenses/LICENSE-2.0 |
||||
// |
||||
// Unless required by applicable law or agreed to in writing, software |
||||
// distributed under the License is distributed on an "AS IS" BASIS, |
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
// See the License for the specific language governing permissions and |
||||
// limitations under the License. |
||||
// |
||||
|
||||
// |
||||
// Based on implementaion as found in https://github.com/jocover/sha256-armv8 |
||||
// |
||||
// Use github.com/minio/asm2plan9s on this file to assemble ARM instructions to |
||||
// their Plan9 equivalents |
||||
// |
||||
|
||||
TEXT ·blockArm(SB), 7, $0 |
||||
MOVD h+0(FP), R0 |
||||
MOVD message+24(FP), R1 |
||||
MOVD lenmessage+32(FP), R2 // length of message |
||||
SUBS $64, R2 |
||||
BMI complete |
||||
|
||||
// Load constants table pointer |
||||
MOVD $·constants(SB), R3 |
||||
|
||||
// Cache constants table in registers v16 - v31 |
||||
WORD $0x4cdf2870 // ld1 {v16.4s-v19.4s}, [x3], #64 |
||||
WORD $0x4cdf7800 // ld1 {v0.4s}, [x0], #16 |
||||
WORD $0x4cdf2874 // ld1 {v20.4s-v23.4s}, [x3], #64 |
||||
|
||||
WORD $0x4c407801 // ld1 {v1.4s}, [x0] |
||||
WORD $0x4cdf2878 // ld1 {v24.4s-v27.4s}, [x3], #64 |
||||
WORD $0xd1004000 // sub x0, x0, #0x10 |
||||
WORD $0x4cdf287c // ld1 {v28.4s-v31.4s}, [x3], #64 |
||||
|
||||
loop: |
||||
// Main loop |
||||
WORD $0x4cdf2025 // ld1 {v5.16b-v8.16b}, [x1], #64 |
||||
WORD $0x4ea01c02 // mov v2.16b, v0.16b |
||||
WORD $0x4ea11c23 // mov v3.16b, v1.16b |
||||
WORD $0x6e2008a5 // rev32 v5.16b, v5.16b |
||||
WORD $0x6e2008c6 // rev32 v6.16b, v6.16b |
||||
WORD $0x4eb084a9 // add v9.4s, v5.4s, v16.4s |
||||
WORD $0x6e2008e7 // rev32 v7.16b, v7.16b |
||||
WORD $0x4eb184ca // add v10.4s, v6.4s, v17.4s |
||||
WORD $0x4ea21c44 // mov v4.16b, v2.16b |
||||
WORD $0x5e094062 // sha256h q2, q3, v9.4s |
||||
WORD $0x5e095083 // sha256h2 q3, q4, v9.4s |
||||
WORD $0x5e2828c5 // sha256su0 v5.4s, v6.4s |
||||
WORD $0x6e200908 // rev32 v8.16b, v8.16b |
||||
WORD $0x4eb284e9 // add v9.4s, v7.4s, v18.4s |
||||
WORD $0x4ea21c44 // mov v4.16b, v2.16b |
||||
WORD $0x5e0a4062 // sha256h q2, q3, v10.4s |
||||
WORD $0x5e0a5083 // sha256h2 q3, q4, v10.4s |
||||
WORD $0x5e2828e6 // sha256su0 v6.4s, v7.4s |
||||
WORD $0x5e0860e5 // sha256su1 v5.4s, v7.4s, v8.4s |
||||
WORD $0x4eb3850a // add v10.4s, v8.4s, v19.4s |
||||
WORD $0x4ea21c44 // mov v4.16b, v2.16b |
||||
WORD $0x5e094062 // sha256h q2, q3, v9.4s |
||||
WORD $0x5e095083 // sha256h2 q3, q4, v9.4s |
||||
WORD $0x5e282907 // sha256su0 v7.4s, v8.4s |
||||
WORD $0x5e056106 // sha256su1 v6.4s, v8.4s, v5.4s |
||||
WORD $0x4eb484a9 // add v9.4s, v5.4s, v20.4s |
||||
WORD $0x4ea21c44 // mov v4.16b, v2.16b |
||||
WORD $0x5e0a4062 // sha256h q2, q3, v10.4s |
||||
WORD $0x5e0a5083 // sha256h2 q3, q4, v10.4s |
||||
WORD $0x5e2828a8 // sha256su0 v8.4s, v5.4s |
||||
WORD $0x5e0660a7 // sha256su1 v7.4s, v5.4s, v6.4s |
||||
WORD $0x4eb584ca // add v10.4s, v6.4s, v21.4s |
||||
WORD $0x4ea21c44 // mov v4.16b, v2.16b |
||||
WORD $0x5e094062 // sha256h q2, q3, v9.4s |
||||
WORD $0x5e095083 // sha256h2 q3, q4, v9.4s |
||||
WORD $0x5e2828c5 // sha256su0 v5.4s, v6.4s |
||||
WORD $0x5e0760c8 // sha256su1 v8.4s, v6.4s, v7.4s |
||||
WORD $0x4eb684e9 // add v9.4s, v7.4s, v22.4s |
||||
WORD $0x4ea21c44 // mov v4.16b, v2.16b |
||||
WORD $0x5e0a4062 // sha256h q2, q3, v10.4s |
||||
WORD $0x5e0a5083 // sha256h2 q3, q4, v10.4s |
||||
WORD $0x5e2828e6 // sha256su0 v6.4s, v7.4s |
||||
WORD $0x5e0860e5 // sha256su1 v5.4s, v7.4s, v8.4s |
||||
WORD $0x4eb7850a // add v10.4s, v8.4s, v23.4s |
||||
WORD $0x4ea21c44 // mov v4.16b, v2.16b |
||||
WORD $0x5e094062 // sha256h q2, q3, v9.4s |
||||
WORD $0x5e095083 // sha256h2 q3, q4, v9.4s |
||||
WORD $0x5e282907 // sha256su0 v7.4s, v8.4s |
||||
WORD $0x5e056106 // sha256su1 v6.4s, v8.4s, v5.4s |
||||
WORD $0x4eb884a9 // add v9.4s, v5.4s, v24.4s |
||||
WORD $0x4ea21c44 // mov v4.16b, v2.16b |
||||
WORD $0x5e0a4062 // sha256h q2, q3, v10.4s |
||||
WORD $0x5e0a5083 // sha256h2 q3, q4, v10.4s |
||||
WORD $0x5e2828a8 // sha256su0 v8.4s, v5.4s |
||||
WORD $0x5e0660a7 // sha256su1 v7.4s, v5.4s, v6.4s |
||||
WORD $0x4eb984ca // add v10.4s, v6.4s, v25.4s |
||||
WORD $0x4ea21c44 // mov v4.16b, v2.16b |
||||
WORD $0x5e094062 // sha256h q2, q3, v9.4s |
||||
WORD $0x5e095083 // sha256h2 q3, q4, v9.4s |
||||
WORD $0x5e2828c5 // sha256su0 v5.4s, v6.4s |
||||
WORD $0x5e0760c8 // sha256su1 v8.4s, v6.4s, v7.4s |
||||
WORD $0x4eba84e9 // add v9.4s, v7.4s, v26.4s |
||||
WORD $0x4ea21c44 // mov v4.16b, v2.16b |
||||
WORD $0x5e0a4062 // sha256h q2, q3, v10.4s |
||||
WORD $0x5e0a5083 // sha256h2 q3, q4, v10.4s |
||||
WORD $0x5e2828e6 // sha256su0 v6.4s, v7.4s |
||||
WORD $0x5e0860e5 // sha256su1 v5.4s, v7.4s, v8.4s |
||||
WORD $0x4ebb850a // add v10.4s, v8.4s, v27.4s |
||||
WORD $0x4ea21c44 // mov v4.16b, v2.16b |
||||
WORD $0x5e094062 // sha256h q2, q3, v9.4s |
||||
WORD $0x5e095083 // sha256h2 q3, q4, v9.4s |
||||
WORD $0x5e282907 // sha256su0 v7.4s, v8.4s |
||||
WORD $0x5e056106 // sha256su1 v6.4s, v8.4s, v5.4s |
||||
WORD $0x4ebc84a9 // add v9.4s, v5.4s, v28.4s |
||||
WORD $0x4ea21c44 // mov v4.16b, v2.16b |
||||
WORD $0x5e0a4062 // sha256h q2, q3, v10.4s |
||||
WORD $0x5e0a5083 // sha256h2 q3, q4, v10.4s |
||||
WORD $0x5e2828a8 // sha256su0 v8.4s, v5.4s |
||||
WORD $0x5e0660a7 // sha256su1 v7.4s, v5.4s, v6.4s |
||||
WORD $0x4ebd84ca // add v10.4s, v6.4s, v29.4s |
||||
WORD $0x4ea21c44 // mov v4.16b, v2.16b |
||||
WORD $0x5e094062 // sha256h q2, q3, v9.4s |
||||
WORD $0x5e095083 // sha256h2 q3, q4, v9.4s |
||||
WORD $0x5e0760c8 // sha256su1 v8.4s, v6.4s, v7.4s |
||||
WORD $0x4ebe84e9 // add v9.4s, v7.4s, v30.4s |
||||
WORD $0x4ea21c44 // mov v4.16b, v2.16b |
||||
WORD $0x5e0a4062 // sha256h q2, q3, v10.4s |
||||
WORD $0x5e0a5083 // sha256h2 q3, q4, v10.4s |
||||
WORD $0x4ebf850a // add v10.4s, v8.4s, v31.4s |
||||
WORD $0x4ea21c44 // mov v4.16b, v2.16b |
||||
WORD $0x5e094062 // sha256h q2, q3, v9.4s |
||||
WORD $0x5e095083 // sha256h2 q3, q4, v9.4s |
||||
WORD $0x4ea21c44 // mov v4.16b, v2.16b |
||||
WORD $0x5e0a4062 // sha256h q2, q3, v10.4s |
||||
WORD $0x5e0a5083 // sha256h2 q3, q4, v10.4s |
||||
WORD $0x4ea38421 // add v1.4s, v1.4s, v3.4s |
||||
WORD $0x4ea28400 // add v0.4s, v0.4s, v2.4s |
||||
|
||||
SUBS $64, R2 |
||||
BPL loop |
||||
|
||||
// Store result |
||||
WORD $0x4c00a800 // st1 {v0.4s, v1.4s}, [x0] |
||||
|
||||
complete: |
||||
RET |
||||
|
||||
|
||||
// Constants table |
||||
DATA ·constants+0x0(SB)/8, $0x71374491428a2f98 |
||||
DATA ·constants+0x8(SB)/8, $0xe9b5dba5b5c0fbcf |
||||
DATA ·constants+0x10(SB)/8, $0x59f111f13956c25b |
||||
DATA ·constants+0x18(SB)/8, $0xab1c5ed5923f82a4 |
||||
DATA ·constants+0x20(SB)/8, $0x12835b01d807aa98 |
||||
DATA ·constants+0x28(SB)/8, $0x550c7dc3243185be |
||||
DATA ·constants+0x30(SB)/8, $0x80deb1fe72be5d74 |
||||
DATA ·constants+0x38(SB)/8, $0xc19bf1749bdc06a7 |
||||
DATA ·constants+0x40(SB)/8, $0xefbe4786e49b69c1 |
||||
DATA ·constants+0x48(SB)/8, $0x240ca1cc0fc19dc6 |
||||
DATA ·constants+0x50(SB)/8, $0x4a7484aa2de92c6f |
||||
DATA ·constants+0x58(SB)/8, $0x76f988da5cb0a9dc |
||||
DATA ·constants+0x60(SB)/8, $0xa831c66d983e5152 |
||||
DATA ·constants+0x68(SB)/8, $0xbf597fc7b00327c8 |
||||
DATA ·constants+0x70(SB)/8, $0xd5a79147c6e00bf3 |
||||
DATA ·constants+0x78(SB)/8, $0x1429296706ca6351 |
||||
DATA ·constants+0x80(SB)/8, $0x2e1b213827b70a85 |
||||
DATA ·constants+0x88(SB)/8, $0x53380d134d2c6dfc |
||||
DATA ·constants+0x90(SB)/8, $0x766a0abb650a7354 |
||||
DATA ·constants+0x98(SB)/8, $0x92722c8581c2c92e |
||||
DATA ·constants+0xa0(SB)/8, $0xa81a664ba2bfe8a1 |
||||
DATA ·constants+0xa8(SB)/8, $0xc76c51a3c24b8b70 |
||||
DATA ·constants+0xb0(SB)/8, $0xd6990624d192e819 |
||||
DATA ·constants+0xb8(SB)/8, $0x106aa070f40e3585 |
||||
DATA ·constants+0xc0(SB)/8, $0x1e376c0819a4c116 |
||||
DATA ·constants+0xc8(SB)/8, $0x34b0bcb52748774c |
||||
DATA ·constants+0xd0(SB)/8, $0x4ed8aa4a391c0cb3 |
||||
DATA ·constants+0xd8(SB)/8, $0x682e6ff35b9cca4f |
||||
DATA ·constants+0xe0(SB)/8, $0x78a5636f748f82ee |
||||
DATA ·constants+0xe8(SB)/8, $0x8cc7020884c87814 |
||||
DATA ·constants+0xf0(SB)/8, $0xa4506ceb90befffa |
||||
DATA ·constants+0xf8(SB)/8, $0xc67178f2bef9a3f7 |
||||
|
||||
GLOBL ·constants(SB), 8, $256 |
||||
|
@ -0,0 +1,136 @@ |
||||
//+build !arm64 !amd64 noasm appengine
|
||||
|
||||
/* |
||||
* Minio Cloud Storage, (C) 2016 Minio, Inc. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package sha256 |
||||
|
||||
func blockGeneric(dig *digest, p []byte) { |
||||
var w [64]uint32 |
||||
h0, h1, h2, h3, h4, h5, h6, h7 := dig.h[0], dig.h[1], dig.h[2], dig.h[3], dig.h[4], dig.h[5], dig.h[6], dig.h[7] |
||||
for len(p) >= chunk { |
||||
// Can interlace the computation of w with the
|
||||
// rounds below if needed for speed.
|
||||
for i := 0; i < 16; i++ { |
||||
j := i * 4 |
||||
w[i] = uint32(p[j])<<24 | uint32(p[j+1])<<16 | uint32(p[j+2])<<8 | uint32(p[j+3]) |
||||
} |
||||
for i := 16; i < 64; i++ { |
||||
v1 := w[i-2] |
||||
t1 := (v1>>17 | v1<<(32-17)) ^ (v1>>19 | v1<<(32-19)) ^ (v1 >> 10) |
||||
v2 := w[i-15] |
||||
t2 := (v2>>7 | v2<<(32-7)) ^ (v2>>18 | v2<<(32-18)) ^ (v2 >> 3) |
||||
w[i] = t1 + w[i-7] + t2 + w[i-16] |
||||
} |
||||
|
||||
a, b, c, d, e, f, g, h := h0, h1, h2, h3, h4, h5, h6, h7 |
||||
|
||||
for i := 0; i < 64; i++ { |
||||
t1 := h + ((e>>6 | e<<(32-6)) ^ (e>>11 | e<<(32-11)) ^ (e>>25 | e<<(32-25))) + ((e & f) ^ (^e & g)) + _K[i] + w[i] |
||||
|
||||
t2 := ((a>>2 | a<<(32-2)) ^ (a>>13 | a<<(32-13)) ^ (a>>22 | a<<(32-22))) + ((a & b) ^ (a & c) ^ (b & c)) |
||||
|
||||
h = g |
||||
g = f |
||||
f = e |
||||
e = d + t1 |
||||
d = c |
||||
c = b |
||||
b = a |
||||
a = t1 + t2 |
||||
} |
||||
|
||||
h0 += a |
||||
h1 += b |
||||
h2 += c |
||||
h3 += d |
||||
h4 += e |
||||
h5 += f |
||||
h6 += g |
||||
h7 += h |
||||
|
||||
p = p[chunk:] |
||||
} |
||||
|
||||
dig.h[0], dig.h[1], dig.h[2], dig.h[3], dig.h[4], dig.h[5], dig.h[6], dig.h[7] = h0, h1, h2, h3, h4, h5, h6, h7 |
||||
} |
||||
|
||||
var _K = []uint32{ |
||||
0x428a2f98, |
||||
0x71374491, |
||||
0xb5c0fbcf, |
||||
0xe9b5dba5, |
||||
0x3956c25b, |
||||
0x59f111f1, |
||||
0x923f82a4, |
||||
0xab1c5ed5, |
||||
0xd807aa98, |
||||
0x12835b01, |
||||
0x243185be, |
||||
0x550c7dc3, |
||||
0x72be5d74, |
||||
0x80deb1fe, |
||||
0x9bdc06a7, |
||||
0xc19bf174, |
||||
0xe49b69c1, |
||||
0xefbe4786, |
||||
0x0fc19dc6, |
||||
0x240ca1cc, |
||||
0x2de92c6f, |
||||
0x4a7484aa, |
||||
0x5cb0a9dc, |
||||
0x76f988da, |
||||
0x983e5152, |
||||
0xa831c66d, |
||||
0xb00327c8, |
||||
0xbf597fc7, |
||||
0xc6e00bf3, |
||||
0xd5a79147, |
||||
0x06ca6351, |
||||
0x14292967, |
||||
0x27b70a85, |
||||
0x2e1b2138, |
||||
0x4d2c6dfc, |
||||
0x53380d13, |
||||
0x650a7354, |
||||
0x766a0abb, |
||||
0x81c2c92e, |
||||
0x92722c85, |
||||
0xa2bfe8a1, |
||||
0xa81a664b, |
||||
0xc24b8b70, |
||||
0xc76c51a3, |
||||
0xd192e819, |
||||
0xd6990624, |
||||
0xf40e3585, |
||||
0x106aa070, |
||||
0x19a4c116, |
||||
0x1e376c08, |
||||
0x2748774c, |
||||
0x34b0bcb5, |
||||
0x391c0cb3, |
||||
0x4ed8aa4a, |
||||
0x5b9cca4f, |
||||
0x682e6ff3, |
||||
0x748f82ee, |
||||
0x78a5636f, |
||||
0x84c87814, |
||||
0x8cc70208, |
||||
0x90befffa, |
||||
0xa4506ceb, |
||||
0xbef9a3f7, |
||||
0xc67178f2, |
||||
} |
Loading…
Reference in new issue