You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These [RFC 7693](https://tools.ietf.org/html/rfc7693)-compliant BLAKE2 implementations have been tuned for high speed and low memory usage. The .NET Core 2.1 and 3.0 builds support the new X86 SIMD Intrinsics for even greater speed. `Span<byte>` is used throughout for lower memory overhead compared to `byte[]` based APIs.
4
+
These [RFC 7693](https://tools.ietf.org/html/rfc7693)-compliant BLAKE2 implementations have been tuned for high speed and low memory usage. The .NET Core 2.1 and 3.0 builds use the new x86 SIMD Intrinsics for even greater speed. `Span<byte>` is used throughout for lower memory overhead compared to `byte[]` based APIs.
5
5
6
-
Sample benchmark results comparing with built-in .NET algorithms, 10MiB input, .NET Core x64 and x86 runtimes:
6
+
On .NET Core 2.1, Blake2Fast uses an SSE4.1 SIMD-accelerated implementation for both BLAKE2b and BLAKE2s.
7
7
8
-
```ini
9
-
10
-
BenchmarkDotNet=v0.10.14, OS=Windows 10.0.17134
11
-
Intel Core i7-6700K CPU 4.00GHz (Skylake), 1 CPU, 8 logical and 4 physical cores
| Blake2bFast | netcoreapp1.1 | X86 | 68.925 ms | 0.1575 ms | 0.1315 ms | 0 B |
38
-
| Blake2sFast | netcoreapp1.1 | X86 | 67.513 ms | 0.5069 ms | 0.4742 ms | 0 B |
39
-
||||||||
40
-
| Blake2bFast | netcoreapp2.1 | X86 | 14.208 ms | 0.0876 ms | 0.0819 ms | 0 B |
41
-
| Blake2sFast | netcoreapp2.1 | X86 | 13.628 ms | 0.0399 ms | 0.0333 ms | 0 B |
42
-
||||||||
43
-
| Blake2bFast | netcoreapp3.0 | X86 | 8.965 ms | 0.0483 ms | 0.0452 ms | 0 B |
44
-
| Blake2sFast | netcoreapp3.0 | X86 | 13.636 ms | 0.0474 ms | 0.0443 ms | 0 B |
45
-
| MD5 | netcoreapp3.0 | X86 | 16.966 ms | 0.1235 ms | 0.1155 ms | 0 B |
46
-
| SHA256 | netcoreapp3.0 | X86 | 44.138 ms | 0.1181 ms | 0.0986 ms | 0 B |
47
-
| SHA512 | netcoreapp3.0 | X86 | 37.384 ms | 0.3196 ms | 0.2989 ms | 0 B |
48
-
49
-
Duplicate results have been removed from the above tables for the sake of brevity.
50
-
51
-
Note that the built-in cryptographic hash algorithms in .NET forward to platform-native libraries for their implementations. On Windows, this means the implementations are provided by [Windows CNG](https://docs.microsoft.com/en-us/windows/desktop/seccng/cng-portal). Their performance is therefore identical across all .NET Core versions.
52
-
53
-
On .NET Framework and .NET Core 1.1, only scalar implementations are available for both BLAKE2 algorithms. The scalar implementations outperform the built-in .NET algorithms on x64 platforms, but they are significantly slower on x86.
54
-
55
-
On .NET Core 2.1, Blake2Fast uses an SSE4.1 SIMD-accelerated implementation for both BLAKE2b and BLAKE2s. On .NET Core 3.0, an AVX2 implementation of BLAKE2b is available (with SSE4.1 fallback for older processors), while BLAKE2s uses the same SSE4.1 implementation. These are faster than the .NET built-in algorithms on either processor architecture.
8
+
On .NET Core 3.0, a faster AVX2 implementation of BLAKE2b is available (with SSE4.1 fallback for older processors), while BLAKE2s uses the same SSE4.1 implementation.
56
9
57
-
You can find more detailed comparisons between Blake2Fast and other .NET BLAKE2 implementations starting [here](https://photosauce.net/blog/post/fast-hashing-with-blake2-part-1-nuget-is-a-minefield). The short version is that Blake2Fast is the fastest and lowest-memory version of RFC-compliant BLAKE2 available for .NET.
58
10
59
11
Installation
60
12
------------
@@ -95,14 +47,15 @@ BLAKE2 hashes can be incrementally updated if you do not have the data available
95
47
```C#
96
48
asyncTask<byte[]>ComputeHashAsync(Streamdata)
97
49
{
98
-
varincHash=Blake2b.CreateIncrementalHasher();
99
-
varbuffer=newbyte[4096];
100
-
intbytesRead;
50
+
varhasher=Blake2b.CreateIncrementalHasher();
51
+
varbuffer=ArrayPool<byte>.Shared.Rent(4096);
101
52
53
+
intbytesRead;
102
54
while ((bytesRead=awaitdata.ReadAsync(buffer, 0, buffer.Length)) >0)
The X86 SIMD Intrinsics used in the .NET Core 2.1 build are not officially supported by Microsoft. Although the specific SSE Intrinsics used by Blake2Fast have been well-tested, the JIT support for the X86 Intrinsics in general is experimental in .NET Core 2.1.
104
+
**This warning applies only to .NET Core 2.1**; the older build targets use only the scalar code, and SIMD intrinsics are fully supported on .NET Core 3.0.
105
+
106
+
The x86 SIMD Intrinsics used in the .NET Core 2.1 build are not officially supported by Microsoft. Although the specific SSE Intrinsics used by Blake2Fast have been well-tested, the JIT support for the x86 Intrinsics in general is experimental in .NET Core 2.1.
152
107
153
108
If you are uncomfortable using unsupported functionality, you can make a custom build of Blake2Fast by removing the `USE_INTRINSICS` define constant in the [project file](src/Blake2Fast/Blake2Fast.csproj).
154
109
155
-
This warning applies only to .NET Core 2.1; the older build targets use only the scalar code, and SIMD intrinsics will be fully supported on .NET Core 3.0+.
110
+
111
+
Benchmarks
112
+
----------
113
+
114
+
Sample results from the [Blake2.Bench](tests/Blake2.Bench) project. Benchmarks were run on the .NET Core 3.0-preview7 x64 runtime. Configuration below:
115
+
116
+
```ini
117
+
118
+
BenchmarkDotNet=v0.11.5, OS=Windows 10.0.18362
119
+
Intel Core i7-6700K CPU 4.00GHz (Skylake), 1 CPU, 8 logical and 4 physical cores
Note that the built-in cryptographic hash algorithms in .NET Core forward to platform-native libraries for their implementations. On Windows, this means the implementations are provided by [Windows CNG](https://docs.microsoft.com/en-us/windows/desktop/seccng/cng-portal). Performance may differ on Linux.
153
+
154
+
On .NET Framework, only scalar (not SIMD) implementations are available for both BLAKE2 algorithms. The scalar implementations outperform the built-in .NET algorithms in 64-bit applications, but they are slower for large input data on 32-bit. The SIMD implementations available in .NET Core are faster than the built-in algorithms on either processor architecture.
155
+
156
+
### Blake2Fast vs other BLAKE2b implementations available on Nuget
157
+
158
+
```
159
+
| Method | Data Length | Mean | Error | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
(1) `Blake2Sharp` is the reference C# BLAKE2b implementation from the [official BLAKE2 repo](https://github.com/BLAKE2/BLAKE2). This version is not published to Nuget, so the source is included in the benchmark project directly.
190
+
(2) `ByteTerrace.Maths.Cryptography.Blake2` version 0.0.4. This package also includes a BLAKE2s implementation, but it crashed on the 3268 byte and 3KiB inputs, so it is included only in the BLAKE2b benchmark.
191
+
(3) `System.Data.HashFunction.Blake2` version 2.0.0. BLAKE2b only.
192
+
(4) `Konscious.Security.Cryptography.Blake2` version 1.0.9. BLAKE2b only.
193
+
(5) `Isopoh.Cryptography.Blake2b` version 1.1.2.
194
+
(6) `Blake2Core` version 1.0.0. This package contains the reference Blake2Sharp code compiled as a debug (unoptimized) build. BenchmarkDotNet errors in such cases, so the settings were overridden to allow this library to run.
195
+
(7) `NSec.Cryptography` 19.5.0. This implementation of BLAKE2 is not RFC-compliant in that it does not allow digest sizes less than 16 bytes. This library forwards to a referenced native library (libsodium), which contains an AVX2 implementation of BLAKE2b.
196
+
197
+
### Blake2Fast vs other BLAKE2s implementations available on Nuget
198
+
199
+
```
200
+
| Method | Data Length | Mean | Error | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
(1) blake2s-net version 0.1.0. This is a conversion of the reference Blake2Sharp code to support BLAKE2s. It is the only other properly working BLAKE2s implementation I could find on Nuget.
213
+
214
+
You can find more detailed comparisons between Blake2Fast and other .NET BLAKE2 implementations starting [here](https://photosauce.net/blog/post/fast-hashing-with-blake2-part-1-nuget-is-a-minefield). The short version is that Blake2Fast is the fastest and lowest-memory version of RFC-compliant BLAKE2 available for .NET.
0 commit comments