An incremental hash state that can accept any number of writes.
More...
|
void | Dispose () |
| Dispose this instance.
|
|
void | Reset () |
| Reset the Hasher to its initial state.
|
|
void | Update (ReadOnlySpan< byte > data) |
| Add input bytes to the hash state. You can call this any number of times.
|
|
void | Update< T > (ReadOnlySpan< T > data) |
| Add input data to the hash state. You can call this any number of times.
|
|
void | UpdateWithJoin (ReadOnlySpan< byte > data) |
| Add input bytes to the hash state, as with update, but potentially using multi-threading.
|
|
void | UpdateWithJoin< T > (ReadOnlySpan< T > data) |
| Add input data span to the hash state, as with update, but potentially using multi-threading.
|
|
void | Finalize (Span< byte > hash) |
| Finalize the hash state to the output span, which can supply any number of output bytes.
|
|
void | Finalize (ulong offset, Span< byte > hash) |
| Finalize the hash state to the output span, which can supply any number of output bytes.
|
|
void | Finalize (long offset, Span< byte > hash) |
| Finalize the hash state to the output span, which can supply any number of output bytes.
|
|
|
static void | Hash (ReadOnlySpan< byte > input, Span< byte > output) |
| The default hash function.
|
|
static Hasher | New () |
| Construct a new Hasher for the regular hash function.
|
|
static Hasher | NewKeyed (ReadOnlySpan< byte > key) |
| Construct a new Hasher for the keyed hash function.
|
|
static Hasher | NewDeriveKey (string text) |
| Construct a new Hasher for the key derivation function.
|
|
static Hasher | NewDeriveKey (ReadOnlySpan< byte > str) |
| Construct a new Hasher for the key derivation function.
|
|
|
delegate void * | blake3_new_del () |
|
delegate void * | blake3_new_keyed_del (void *ptr32Bytes) |
|
delegate void * | blake3_new_derive_key_del (void *ptr, void *size) |
|
delegate void | blake3_hash_del (void *ptr, void *size, void *ptrOut) |
|
delegate void | blake3_hash_preemptive_del (void *ptr, void *size, void *ptrOut) |
|
delegate void | blake3_delete_del (void *hasher) |
|
delegate void | blake3_reset_del (void *hasher) |
|
delegate void | blake3_update_del (void *hasher, void *ptr, void *size) |
|
delegate void | blake3_update_preemptive_del (void *hasher, void *ptr, void *size) |
|
delegate void | blake3_update_rayon_del (void *hasher, void *ptr, void *size) |
|
delegate void | blake3_finalize_del (void *hasher, void *ptr) |
|
delegate void | blake3_finalize_xof_del (void *hasher, void *ptr, void *size) |
|
delegate void | blake3_finalize_seek_xof_del (void *hasher, ulong offset, void *ptr, void *size) |
|
| Hasher (void *hasher) |
|
An incremental hash state that can accept any number of writes.
Performance note: The Update<T> and UpdateWithJoin<T> methods perform poorly when the caller's input buffer is small. See their method docs below. A 16 KiB buffer is large enough to leverage all currently supported SIMD instruction sets.
◆ Hasher() [1/2]
static Data.HashFunction.Blake3.Hasher.Hasher |
( |
| ) |
|
|
staticprivate |
◆ Hasher() [2/2]
Data.HashFunction.Blake3.Hasher.Hasher |
( |
void * | hasher | ) |
|
|
private |
◆ blake3_delete_del()
delegate void Data.HashFunction.Blake3.Hasher.blake3_delete_del |
( |
void * | hasher | ) |
|
|
private |
◆ blake3_finalize_del()
delegate void Data.HashFunction.Blake3.Hasher.blake3_finalize_del |
( |
void * | hasher, |
|
|
void * | ptr ) |
|
private |
◆ blake3_finalize_seek_xof_del()
delegate void Data.HashFunction.Blake3.Hasher.blake3_finalize_seek_xof_del |
( |
void * | hasher, |
|
|
ulong | offset, |
|
|
void * | ptr, |
|
|
void * | size ) |
|
private |
◆ blake3_finalize_xof_del()
delegate void Data.HashFunction.Blake3.Hasher.blake3_finalize_xof_del |
( |
void * | hasher, |
|
|
void * | ptr, |
|
|
void * | size ) |
|
private |
◆ blake3_hash_del()
delegate void Data.HashFunction.Blake3.Hasher.blake3_hash_del |
( |
void * | ptr, |
|
|
void * | size, |
|
|
void * | ptrOut ) |
|
private |
◆ blake3_hash_preemptive_del()
delegate void Data.HashFunction.Blake3.Hasher.blake3_hash_preemptive_del |
( |
void * | ptr, |
|
|
void * | size, |
|
|
void * | ptrOut ) |
|
private |
◆ blake3_new_del()
delegate void * Data.HashFunction.Blake3.Hasher.blake3_new_del |
( |
| ) |
|
|
private |
◆ blake3_new_derive_key_del()
delegate void * Data.HashFunction.Blake3.Hasher.blake3_new_derive_key_del |
( |
void * | ptr, |
|
|
void * | size ) |
|
private |
◆ blake3_new_keyed_del()
delegate void * Data.HashFunction.Blake3.Hasher.blake3_new_keyed_del |
( |
void * | ptr32Bytes | ) |
|
|
private |
◆ blake3_reset_del()
delegate void Data.HashFunction.Blake3.Hasher.blake3_reset_del |
( |
void * | hasher | ) |
|
|
private |
◆ blake3_update_del()
delegate void Data.HashFunction.Blake3.Hasher.blake3_update_del |
( |
void * | hasher, |
|
|
void * | ptr, |
|
|
void * | size ) |
|
private |
◆ blake3_update_preemptive_del()
delegate void Data.HashFunction.Blake3.Hasher.blake3_update_preemptive_del |
( |
void * | hasher, |
|
|
void * | ptr, |
|
|
void * | size ) |
|
private |
◆ blake3_update_rayon_del()
delegate void Data.HashFunction.Blake3.Hasher.blake3_update_rayon_del |
( |
void * | hasher, |
|
|
void * | ptr, |
|
|
void * | size ) |
|
private |
◆ Dispose()
void Data.HashFunction.Blake3.Hasher.Dispose |
( |
| ) |
|
◆ FastUpdate()
static void Data.HashFunction.Blake3.Hasher.FastUpdate |
( |
void * | hasher, |
|
|
void * | ptr, |
|
|
long | size ) |
|
staticprivate |
◆ Finalize() [1/3]
void Data.HashFunction.Blake3.Hasher.Finalize |
( |
long | offset, |
|
|
Span< byte > | hash ) |
Finalize the hash state to the output span, which can supply any number of output bytes.
- Parameters
-
offset | The offset to seek to in the output stream, relative to the start. |
hash | The output hash, which can supply any number of output bytes. |
This method is idempotent. Calling it twice will give the same result. You can also add more input and finalize again.
◆ Finalize() [2/3]
void Data.HashFunction.Blake3.Hasher.Finalize |
( |
Span< byte > | hash | ) |
|
Finalize the hash state to the output span, which can supply any number of output bytes.
- Parameters
-
hash | The output hash, which can supply any number of output bytes. |
This method is idempotent. Calling it twice will give the same result. You can also add more input and finalize again.
◆ Finalize() [3/3]
void Data.HashFunction.Blake3.Hasher.Finalize |
( |
ulong | offset, |
|
|
Span< byte > | hash ) |
Finalize the hash state to the output span, which can supply any number of output bytes.
- Parameters
-
offset | The offset to seek to in the output stream, relative to the start. |
hash | The output hash, which can supply any number of output bytes. |
This method is idempotent. Calling it twice will give the same result. You can also add more input and finalize again.
◆ Hash()
static void Data.HashFunction.Blake3.Hasher.Hash |
( |
ReadOnlySpan< byte > | input, |
|
|
Span< byte > | output ) |
|
static |
The default hash function.
- Parameters
-
input | The input data to hash. |
output | The output hash. |
For an incremental version that accepts multiple writes Update<T> This function is always single-threaded. For multi-threading support UpdateWithJoin
◆ New()
static Hasher Data.HashFunction.Blake3.Hasher.New |
( |
| ) |
|
|
static |
Construct a new Hasher for the regular hash function.
- Returns
- A new instance of the hasher
The struct returned needs to be disposed explicitly.
◆ NewDeriveKey() [1/2]
static Hasher Data.HashFunction.Blake3.Hasher.NewDeriveKey |
( |
ReadOnlySpan< byte > | str | ) |
|
|
static |
Construct a new Hasher for the key derivation function.
- Returns
- A new instance of the hasher
The struct returned needs to be disposed explicitly.
◆ NewDeriveKey() [2/2]
static Hasher Data.HashFunction.Blake3.Hasher.NewDeriveKey |
( |
string | text | ) |
|
|
static |
Construct a new Hasher for the key derivation function.
- Returns
- A new instance of the hasher
The struct returned needs to be disposed explicitly.
◆ NewKeyed()
static Hasher Data.HashFunction.Blake3.Hasher.NewKeyed |
( |
ReadOnlySpan< byte > | key | ) |
|
|
static |
Construct a new Hasher for the keyed hash function.
- Parameters
-
- Returns
- A new instance of the hasher
The struct returned needs to be disposed explicitly.
◆ Reset()
void Data.HashFunction.Blake3.Hasher.Reset |
( |
| ) |
|
Reset the Hasher to its initial state.
This is functionally the same as overwriting the Hasher with a new one, using the same key or context string if any. However, depending on how much inlining the optimizer does, moving a Hasher might copy its entire CV stack, most of which is useless uninitialized bytes. This methods avoids that copy.
◆ ThrowArgumentNullException()
static void Data.HashFunction.Blake3.Hasher.ThrowArgumentNullException |
( |
| ) |
|
|
staticprivate |
◆ ThrowArgumentOutOfRange()
static void Data.HashFunction.Blake3.Hasher.ThrowArgumentOutOfRange |
( |
int | size | ) |
|
|
staticprivate |
◆ ThrowNullReferenceException()
static void Data.HashFunction.Blake3.Hasher.ThrowNullReferenceException |
( |
| ) |
|
|
staticprivate |
◆ Update()
void Data.HashFunction.Blake3.Hasher.Update |
( |
ReadOnlySpan< byte > | data | ) |
|
Add input bytes to the hash state. You can call this any number of times.
- Parameters
-
data | The input data byte buffer to hash. |
This method is always single-threaded. For multi-threading support, see UpdateWithJoin below.
Note that the degree of SIMD parallelism that update can use is limited by the size of this input buffer. The 8 KiB buffer currently used by std::io::copy is enough to leverage AVX2, for example, but not enough to leverage AVX-512. A 16 KiB buffer is large enough to leverage all currently supported SIMD instruction sets.
◆ Update< T >()
Add input data to the hash state. You can call this any number of times.
- Template Parameters
-
- Parameters
-
data | The data span to hash. |
This method is always single-threaded. For multi-threading support, see UpdateWithJoin below.
Note that the degree of SIMD parallelism that update can use is limited by the size of this input buffer. The 8 KiB buffer currently used by std::io::copy is enough to leverage AVX2, for example, but not enough to leverage AVX-512. A 16 KiB buffer is large enough to leverage all currently supported SIMD instruction sets.
◆ UpdateWithJoin()
void Data.HashFunction.Blake3.Hasher.UpdateWithJoin |
( |
ReadOnlySpan< byte > | data | ) |
|
Add input bytes to the hash state, as with update, but potentially using multi-threading.
- Parameters
-
data | The input byte buffer. |
To get any performance benefit from multi-threading, the input buffer size needs to be very large. As a rule of thumb on x86_64, there is no benefit to multi-threading inputs less than 128 KiB. Other platforms have different thresholds, and in general you need to benchmark your specific use case. Where possible, memory mapping an entire input file is recommended, to take maximum advantage of multi-threading without needing to tune a specific buffer size. Where memory mapping is not possible, good multi-threading performance requires doing IO on a background thread, to avoid sleeping all your worker threads while the input buffer is (serially) refilled. This is quite complicated compared to memory mapping.
◆ UpdateWithJoin< T >()
Add input data span to the hash state, as with update, but potentially using multi-threading.
- Parameters
-
data | The input data buffer. |
To get any performance benefit from multi-threading, the input buffer size needs to be very large. As a rule of thumb on x86_64, there is no benefit to multi-threading inputs less than 128 KiB. Other platforms have different thresholds, and in general you need to benchmark your specific use case. Where possible, memory mapping an entire input file is recommended, to take maximum advantage of multi-threading without needing to tune a specific buffer size. Where memory mapping is not possible, good multi-threading performance requires doing IO on a background thread, to avoid sleeping all your worker threads while the input buffer is (serially) refilled. This is quite complicated compared to memory mapping.
◆ _hasher
void* Data.HashFunction.Blake3.Hasher._hasher |
|
private |
◆ blake3_delete
◆ blake3_finalize
◆ blake3_finalize_seek_xof
◆ blake3_finalize_xof
◆ blake3_hash
◆ blake3_hash_preemptive
◆ blake3_new
◆ blake3_new_derive_key
◆ blake3_new_keyed
◆ blake3_reset
◆ blake3_update
◆ blake3_update_preemptive
◆ blake3_update_rayon
◆ lib_loader
◆ LimitPreemptive
const int Data.HashFunction.Blake3.Hasher.LimitPreemptive = 1024 |
|
staticprivate |
We are taking a limit of 1024 bytes to switch to a preemptive version, as it takes around 1μs on a x64 very recent CPU to complete, which is better aligned with the documentation of SuppressGCTransitionAttribute: Native function always executes for a trivial amount of time (less than 1 microsecond).
The documentation for this class was generated from the following file: