Safe Haskell | None |
---|---|
Language | Haskell2010 |
Haskell bindings to the fast official BLAKE3 hashing implementation in assembly and C. With support for AVX-512, AVX2 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 bin. (KnownNat len, ByteArrayAccess bin) => [bin] -> Digest len
- data Digest (len :: Nat)
- digest :: forall len bin. (KnownNat len, ByteArrayAccess bin) => bin -> Maybe (Digest len)
- hashKeyed :: forall len bin. (KnownNat len, ByteArrayAccess bin) => Key -> [bin] -> Digest len
- data Key
- key :: ByteArrayAccess bin => bin -> Maybe Key
- derive :: forall len ikm. (KnownNat len, ByteArrayAccess ikm) => Context -> [ikm] -> Digest len
- data Context
- context :: ByteArrayAccess bin => bin -> Maybe Context
- data Hasher
- hasher :: Hasher
- hasherKeyed :: Key -> Hasher
- update :: forall bin. ByteArrayAccess bin => Hasher -> [bin] -> Hasher
- finalize :: forall len. KnownNat len => Hasher -> Digest len
- finalizeSeek :: forall len. KnownNat len => Hasher -> Word64 -> Digest len
- type KEY_LEN = 32
- type BLOCK_SIZE = 64
- type DEFAULT_DIGEST_LEN = 32
Hashing
:: (KnownNat len, ByteArrayAccess bin) | |
=> [bin] | Data to hash. |
-> Digest len | Default digest length is |
data 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 # | Allocate a |
Eq (Digest len) Source # | Constant time. |
Show (Digest len) Source # | Base 16 (hexadecimal). |
KnownNat len => Storable (Digest len) Source # | When allocating a |
Defined in BLAKE3.IO | |
ByteArrayAccess (Digest len) Source # | |
:: (KnownNat len, ByteArrayAccess bin) | |
=> bin | Raw digest bytes. Must have length |
-> Maybe (Digest len) |
Obtain a digest containing bytes from a third-party source.
This is useful if you want to use the Digest
datatype in your programs, but
you are loading the pre-calculated digests from a database or similar.
Keyed hashing
:: (KnownNat len, ByteArrayAccess bin) | |
=> Key | |
-> [bin] | Data to hash. |
-> Digest len | Default digest length is |
BLAKE3 hashing with a Key
.
This can be used for MAC (message authentication code), PRF (pseudo random function) and SHO (stateful hash object) purposes.
For incremental hashing, see hasherKeyed
, update
and finalize
:
hashKeyed
key =finalize
.
update
(hasherKeyed
key)
Instances
Eq Key Source # | Constant time. |
Show Key Source # | Base 16 (hexadecimal). |
Storable Key Source # | When allocating a |
Defined in BLAKE3.IO | |
ByteArrayAccess Key Source # | Length is |
ByteArrayN KEY_LEN Key Source # | Allocate a |
:: ByteArrayAccess bin | |
=> bin | Key bytes. Must have length |
-> Maybe Key |
Key derivation
:: (KnownNat len, ByteArrayAccess ikm) | |
=> Context | |
-> [ikm] | Input key material. |
-> Digest len | Default digest length is |
BLAKE3 key derivation.
This can be used for KDF (key derivation function) purposes.
Context for BLAKE3 key derivation. Obtain with context
.
Instances
Eq Context Source # | |
Show Context Source # | Base 16 (hexadecimal). |
IsString Context Source # |
|
Defined in BLAKE3.IO fromString :: String -> Context # | |
ByteArrayAccess Context Source # | |
:: ByteArrayAccess bin | |
=> bin | If |
-> Maybe Context |
Obtain a Context
for BLAKE3 key derivation.
The context should be hardcoded, globally unique, and application-specific.
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
Eq Hasher Source # | |
Show Hasher Source # | Base 16 (hexadecimal). |
Storable Hasher Source # | When allocating a |
ByteArrayAccess Hasher Source # | Length is |
ByteArrayN HASHER_SIZE Hasher Source # | Allocate a |
:: ByteArrayAccess bin | |
=> Hasher | |
-> [bin] | New data to hash. |
-> Hasher |
Update Hasher
with new data.
:: KnownNat len | |
=> Hasher | |
-> Digest len | Default digest length is |
Finish hashing and obtain a Digest
of the specified len
gth.
:: KnownNat len | |
=> Hasher | |
-> Word64 | Number of bytes to skip before obtaning the digest output. |
-> Digest len | Default digest length is |
Finalize incremental hashing and obtain a Digest
of length len
after
the specified number of bytes of BLAKE3 output.
finalize
h =finalizeSeek
h 0
Constants
type BLOCK_SIZE = 64 Source #
In bytes.
type DEFAULT_DIGEST_LEN = 32 Source #
In bytes.