| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
BLAKE3
Description
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 :: Nat) 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 :: Nat) okm ikm context. (ByteArrayN len okm, ByteArrayAccess ikm, ByteArrayAccess context) => context -> [ikm] -> okm
- data Hasher
- init :: Maybe Key -> Hasher
- update :: ByteArrayAccess bin => Hasher -> [bin] -> Hasher
- finalize :: forall (len :: Nat) output. ByteArrayN len output => Hasher -> output
- finalizeSeek :: forall (len :: Nat) output. ByteArrayN len output => Hasher -> Word64 -> output
- type KEY_LEN = 32
- type BLOCK_SIZE = 64
- type DEFAULT_DIGEST_LEN = 32
Hashing
newtype Digest (len :: Nat) Source #
Output from BLAKE3 algorithm, of len bytes.
The default digest length for BLAKE3 is DEFAULT_DIGEST_LEN.
Constructors
| Digest (SizedByteArray len ScrubbedBytes) |
Instances
| KnownNat len => ByteArrayN len (Digest len) Source # | |
| KnownNat len => Storable (Digest len) Source # | When allocating a |
Defined in BLAKE3.IO Methods alignment :: Digest len -> Int peekElemOff :: Ptr (Digest len) -> Int -> IO (Digest len) pokeElemOff :: Ptr (Digest len) -> Int -> Digest len -> IO () peekByteOff :: Ptr b -> Int -> IO (Digest len) pokeByteOff :: Ptr b -> Int -> Digest len -> IO () | |
| Show (Digest len) Source # | Base 16 (hexadecimal). |
| Eq (Digest len) Source # | Constant time. |
| Ord (Digest len) Source # | |
| KnownNat len => ByteArrayAccess (Digest len) Source # | |
Defined in BLAKE3.IO Methods withByteArray :: Digest len -> (Ptr p -> IO a) -> IO a copyByteArrayToPtr :: Digest len -> Ptr p -> IO () | |
Keyed hashing
Instances
| Storable Key Source # | When allocating a |
| Show Key Source # | Base 16 (hexadecimal). |
| Eq Key Source # | Constant time. |
| ByteArrayAccess Key Source # | Length is |
Defined in BLAKE3.IO | |
| ByteArrayN KEY_LEN Key Source # | Allocate a The memory is wiped and freed as soon as the |
Key derivation
Arguments
| :: forall (len :: Nat) 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 |
Defined in BLAKE3.IO Methods peekElemOff :: Ptr Hasher -> Int -> IO Hasher pokeElemOff :: Ptr Hasher -> Int -> Hasher -> IO () peekByteOff :: Ptr b -> Int -> IO Hasher pokeByteOff :: Ptr b -> Int -> Hasher -> IO () | |
| Show Hasher Source # | Base 16 (hexadecimal). |
| Eq Hasher Source # | Constant time. |
| ByteArrayAccess Hasher Source # | Length is |
Defined in BLAKE3.IO Methods withByteArray :: Hasher -> (Ptr p -> IO a) -> IO a copyByteArrayToPtr :: Hasher -> Ptr p -> IO () | |
| ByteArrayN HASHER_SIZE Hasher Source # | Allocate a |
Defined in BLAKE3.IO Methods allocRet :: Proxy HASHER_SIZE -> (Ptr p -> IO a) -> IO (a, Hasher) | |
Initial Hasher for incremental hashing.
Update Hasher with new data.
Arguments
| :: forall (len :: Nat) output. ByteArrayN len output | |
| => Hasher | |
| -> output | The |
Finalize incremental hashing and obtain a the BLAKE3 output of the
specified length.
Arguments
| :: forall (len :: Nat) output. ByteArrayN len output | |
| => Hasher | |
| -> Word64 | BLAKE3 output offset. |
| -> output | The |
Finalize incremental hashing and obtain the specified length of BLAKE3
output starting at the specified offset.
finalizeh =finalizeSeekh 0
Constants
type BLOCK_SIZE = 64 Source #
In bytes.
type DEFAULT_DIGEST_LEN = 32 Source #
In bytes.