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
Copy file name to clipboardExpand all lines: readme.md
+32-10Lines changed: 32 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
Blake2Fast
2
2
==========
3
3
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 build supports the new X86 SIMD Intrinsics for even greater speed and `Span<T>` for even lower memory usage.
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 build supports the new X86 SIMD Intrinsics for even greater speed and `Span<T>` for even lower memory usage.
5
5
6
6
Sample benchmark results comparing with built-in .NET algorithms, 10MiB input, .NET Core 2.1 x64 and x86 runtimes:
7
7
@@ -19,7 +19,7 @@ MD5 | X86 | 20.06 ms | 0.0996 ms | 0.0931 ms | 0 B |
19
19
SHA256 | X86 | 52.47 ms | 0.3252 ms | 0.3042 ms | 0 B |
20
20
SHA512 | X86 | 44.07 ms | 0.1643 ms | 0.1372 ms | 0 B |
21
21
22
-
You can find more detailed comparison between Blake2Fast and other .NET Blake2 implementations starting [here](https://photosauce.net/blog/post/fast-hashing-with-blake2-part-1-nuget-is-a-minefield)
22
+
You can find more detailed comparison between Blake2Fast and other .NET BLAKE2 implementations starting [here](https://photosauce.net/blog/post/fast-hashing-with-blake2-part-1-nuget-is-a-minefield)
23
23
24
24
Installation
25
25
------------
@@ -36,26 +36,29 @@ Usage
36
36
### All-at-Once Hashing
37
37
38
38
The simplest and lightest-weight way to calculate a hash is the all-at-once `ComputeHash` method.
39
+
39
40
```C#
40
-
Blake2b.ComputeHash(data);
41
+
varhash=Blake2b.ComputeHash(data);
41
42
```
42
43
43
-
Blake2 supports variable digest lengths from 1 to 32 bytes for `Blake2s` or 1 to 64 bytes for `Blake2b`.
44
+
BLAKE2 supports variable digest lengths from 1 to 32 bytes for BLAKE2s or 1 to 64 bytes for BLAKE2b.
45
+
44
46
```C#
45
-
Blake2b.ComputeHash(48, data);
47
+
varhash=Blake2b.ComputeHash(42, data);
46
48
```
47
49
48
-
Blake2 also natively supports keyed hashing.
50
+
BLAKE2 also natively supports keyed hashing.
51
+
49
52
```C#
50
-
Blake2b.ComputeHash(key, data);
53
+
varhash=Blake2b.ComputeHash(key, data);
51
54
```
52
55
53
56
### Incremental Hashing
54
57
55
-
Blake2 hashes can be incrementally updated if you do not have the data available all at once.
58
+
BLAKE2 hashes can be incrementally updated if you do not have the data available all at once.
The output hash digest can be written to an existing buffer to avoid allocating a new array each time. This is especially useful when performing an iterative hash, as might be used in a [key derivation function](https://en.wikipedia.org/wiki/Key_derivation_function).
80
+
81
+
```C#
82
+
byte[] DeriveBytes(stringpassword, byte[] salt)
83
+
{
84
+
// Create key from password, then hash the salt using the key
// Hash the hash lots of times, re-using the same buffer
89
+
for (inti=0; i<1_000_000; i++)
90
+
Blake2b.ComputeAndWriteHash(pwkey, hbuff, hbuff);
91
+
92
+
returnhbuff;
93
+
}
94
+
```
95
+
74
96
### System.Security.Cryptography Interop
75
97
76
98
For interoperating with code that uses `System.Security.Cryptography` primitives, Blake2Fast can create a `HashAlgorithm` wrapper. The wrapper inherits from `HMAC` in case keyed hashing is required.
77
99
78
-
`HashAlgorithm` is less efficient than the above methods, so use it only when necessary.
100
+
`HashAlgorithm` is less efficient than the above methods, so use it only when necessary for compatibility.
<Description>Optimized implementations of the Blake2b and Blake2s hashing algorithms. Uses SSE2-SSE4.1 intrinsics support on .NET Core 2.1</Description>
13
+
<Description>Optimized implementations of the BLAKE2b and BLAKE2s hashing algorithms. Uses SSE2-SSE4.1 Intrinsics support on .NET Core 2.1</Description>
<DefineConstantsCondition="'$(TargetFramework)'=='netcoreapp2.0' Or '$(TargetFramework)'=='netcoreapp2.1'">$(DefineConstants);IMPLICIT_BYTESPAN</DefineConstants>
/// <summary>Perform an all-at-once BLAKE2b hash computation and write the hash digest to <paramref name="output" />.</summary>
53
+
/// <remarks>If you have all the input available at once, this is the most efficient way to calculate the hash.</remarks>
54
+
/// <param name="key">0 to 64 bytes of input for initializing a keyed hash.</param>
55
+
/// <param name="input">The message bytes to hash.</param>
56
+
/// <param name="output">Destination buffer into which the hash digest is written. The buffer must have a capacity of at least <see cref="DefaultDigestLength"/>(64) /> bytes.</param>
/// <summary>Perform an all-at-once BLAKE2b hash computation and write the hash digest to <paramref name="output" />.</summary>
60
+
/// <remarks>If you have all the input available at once, this is the most efficient way to calculate the hash.</remarks>
61
+
/// <param name="digestLength">The hash digest length in bytes. Valid values are 1 to 64.</param>
62
+
/// <param name="key">0 to 64 bytes of input for initializing a keyed hash.</param>
63
+
/// <param name="input">The message bytes to hash.</param>
64
+
/// <param name="output">Destination buffer into which the hash digest is written. The buffer must have a capacity of at least <paramref name="digestLength" /> bytes.</param>
/// <summary>Creates and initializes an <see cref="HMAC" /> instance that implements Blake2b keyed hashing.</summary>
146
+
/// <summary>Creates and initializes an <see cref="HMAC" /> instance that implements BLAKE2b keyed hashing. Uses BLAKE2's built-in support for keyed hashing rather than the normal 2-pass approach.</summary>
94
147
/// <remarks>Use this only if you require an implementation of <see cref="HMAC" />. It is less efficient than the direct methods.</remarks>
95
148
/// <param name="digestLength">The hash digest length in bytes. Valid values are 1 to 64.</param>
96
149
/// <param name="key">0 to 64 bytes of input for initializing the keyed hash.</param>
0 commit comments