Hash#
Hash algorithms in HACL Packages can be used through two APIs: a (simple) One-shot API, and a (more flexible) Streaming API.
Note: HACL Packages supports MD5 but does not document it here because it should not be used.
One-shot API
If you want to hash a complete messages, i.e., can provide a slice of memory that already contains all the bytes you want to hash, you can use the one-shot API and hash
to easily calculate the digest of that message.
Streaming API
If you need to provide a message chunk-by-chunk, e.g., because you read the message from network or similar, it could be more appropriate to use the streaming API.
The streaming API has roughly three phases: init, update, and finish.
Typically, you create a state element by using malloc
, call update
as often as needed, and then call digest
to obtain the final digest.
Finally, you free
the state element.
Streaming API (with intermediate digests)
It is also possible to obtain all intermediate digests by calling digest
more than once.
You can call update("Hello, ")
, and digest
to obtain the hash of "Hello, "
.
Then you can call update("World!")
, and digest
again to obtain the hash of "Hello, World!"
.
You only need to call malloc
and free
once to obtain both digests.
- Blake2
- Blake2b
- API Reference
- One-Shot
- Streaming (without key)
Hacl_Hash_Blake2b_state_t
Hacl_Hash_Blake2b_malloc()
Hacl_Hash_Blake2b_update()
Hacl_Hash_Blake2b_digest()
Hacl_Hash_Blake2b_reset()
Hacl_Hash_Blake2b_free()
Hacl_Hash_Blake2b_Simd256_state_t
Hacl_Hash_Blake2b_Simd256_malloc()
Hacl_Hash_Blake2b_Simd256_update()
Hacl_Hash_Blake2b_Simd256_digest()
Hacl_Hash_Blake2b_Simd256_reset()
Hacl_Hash_Blake2b_Simd256_free()
- API Reference
- Blake2s
- API Reference
- One-Shot
- Streaming (without key)
Hacl_Hash_Blake2s_state_t
Hacl_Hash_Blake2s_malloc()
Hacl_Hash_Blake2s_update()
Hacl_Hash_Blake2s_digest()
Hacl_Hash_Blake2s_reset()
Hacl_Hash_Blake2s_free()
Hacl_Hash_Blake2s_Simd128_state_t
Hacl_Hash_Blake2s_Simd128_malloc()
Hacl_Hash_Blake2s_Simd128_update()
Hacl_Hash_Blake2s_Simd128_digest()
Hacl_Hash_Blake2s_Simd128_reset()
Hacl_Hash_Blake2s_Simd128_free()
- API Reference
- Blake2b
- SHA-3
- SHA-2
- API Reference
- One-Shot
- Streaming
Hacl_Hash_SHA2_state_t_224
Hacl_Hash_SHA2_malloc_224()
Hacl_Hash_SHA2_update_224()
Hacl_Hash_SHA2_digest_224()
Hacl_Hash_SHA2_reset_224()
Hacl_Hash_SHA2_free_224()
Hacl_Hash_SHA2_state_t_256
Hacl_Hash_SHA2_malloc_256()
Hacl_Hash_SHA2_update_256()
Hacl_Hash_SHA2_digest_256()
Hacl_Hash_SHA2_reset_256()
Hacl_Hash_SHA2_free_256()
Hacl_Hash_SHA2_state_t_384
Hacl_Hash_SHA2_malloc_384()
Hacl_Hash_SHA2_update_384()
Hacl_Hash_SHA2_digest_384()
Hacl_Hash_SHA2_reset_384()
Hacl_Hash_SHA2_free_384()
Hacl_Hash_SHA2_state_t_512
Hacl_Hash_SHA2_malloc_512()
Hacl_Hash_SHA2_update_512()
Hacl_Hash_SHA2_digest_512()
Hacl_Hash_SHA2_reset_512()
Hacl_Hash_SHA2_free_512()
- API Reference
- SHA-1