Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Haskell bindings to the fast official BLAKE3 hashing implementation in assembly and C. With support for AVX-512, AVX2, SSE 2, and SSE 4.1.
The original assembly and C implementation is released into the public domain with CC0 1.0. Alternatively, it is licensed under the Apache License 2.0, copyright of Jack O'Connor and Samuel Neves. See its LICENSE for details.
This Haskell library is the copyright of Renzo Carbonara, licensed under the terms of the Apache License 2.0.
Synopsis
- hash :: forall len digest bin. (ByteArrayN len digest, ByteArrayAccess bin) => Maybe Key -> [bin] -> digest
- newtype Digest (len :: Nat) = Digest (SizedByteArray len ScrubbedBytes)
- data Key
- key :: ByteArrayAccess bin => bin -> Maybe Key
- derive :: forall len okm ikm context. (ByteArrayN len okm, ByteArrayAccess ikm, ByteArrayAccess context) => context -> [ikm] -> okm
- data Hasher
- init :: Maybe Key -> Hasher
- update :: forall bin. ByteArrayAccess bin => Hasher -> [bin] -> Hasher
- finalize :: forall len output. ByteArrayN len output => Hasher -> output
- finalizeSeek :: forall len output. ByteArrayN len output => Hasher -> Word64 -> output
- type KEY_LEN = 32
- type BLOCK_SIZE = 64
- type DEFAULT_DIGEST_LEN = 32
Hashing
:: forall len digest bin. (ByteArrayN len digest, ByteArrayAccess bin) | |
=> Maybe Key | Whether to use keyed hashing mode (for MAC, PRF). |
-> [bin] | Data to hash. |
-> digest | The |
newtype Digest (len :: Nat) Source #
Output from BLAKE3 algorithm, of len
bytes.
The default digest length for BLAKE3 is DEFAULT_DIGEST_LEN
.
Instances
KnownNat len => ByteArrayN len (Digest len) Source # | |
KnownNat len => Storable (Digest len) Source # | When allocating a |
Defined in BLAKE3.IO | |
Show (Digest len) Source # | Base 16 (hexadecimal). |
Eq (Digest len) Source # | Constant time. |
Ord (Digest len) Source # | |
KnownNat len => ByteArrayAccess (Digest len) Source # | |
Keyed hashing
Instances
Storable Key Source # | When allocating a |
Defined in BLAKE3.IO | |
Show Key Source # | Base 16 (hexadecimal). |
Eq Key Source # | Constant time. |
ByteArrayAccess Key Source # | Length is |
ByteArrayN KEY_LEN Key Source # | Allocate a The memory is wiped and freed as soon as the |
:: ByteArrayAccess bin | |
=> bin | Key bytes. Must have length |
-> Maybe Key |
Key derivation
:: forall len okm ikm context. (ByteArrayN len okm, ByteArrayAccess ikm, ByteArrayAccess context) | |
=> context | Key derivation context. |
-> [ikm] | Input key material. |
-> okm | Output key material of the specified |
BLAKE3 key derivation.
This can be used for KDF (key derivation function) purposes.
The key derivation context
should be hardcoded, globally unique,
application-specific well-known string.
A good format for the context string is:
[application] [commit timestamp] [purpose]
For example:
example.com 2019-12-25 16:18:03 session tokens v1
Incremental hashing
BLAKE3 internal state.
Obtain with hasher
, hasherKeyed
.
Instances
Storable Hasher Source # | When allocating a |
Show Hasher Source # | Base 16 (hexadecimal). |
Eq Hasher Source # | Constant time. |
ByteArrayAccess Hasher Source # | Length is |
ByteArrayN HASHER_SIZE Hasher Source # | Allocate a |
Initial Hasher
for incremental hashing.
:: forall bin. ByteArrayAccess bin | |
=> Hasher | |
-> [bin] | New data to hash. |
-> Hasher |
Update Hasher
with new data.
:: forall len output. ByteArrayN len output | |
=> Hasher | |
-> output | The |
Finalize incremental hashing and obtain a the BLAKE3 output of the
specified len
gth.
:: forall len output. ByteArrayN len output | |
=> Hasher | |
-> Word64 | BLAKE3 output offset. |
-> output | The |
Finalize incremental hashing and obtain the specified len
gth of BLAKE3
output starting at the specified offset.
finalize
h =finalizeSeek
h 0
Constants
type BLOCK_SIZE = 64 Source #
In bytes.
type DEFAULT_DIGEST_LEN = 32 Source #
In bytes.