blake3-0.3: BLAKE3 hashing algorithm
Safe HaskellSafe-Inferred
LanguageHaskell2010

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

Hashing

hash Source #

Arguments

:: 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 digest type could be Digest len.

BLAKE3 hashing.

For incremental hashing, see init, update and finalize:

hash yk = finalize . update (init yk)

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

Instances details
KnownNat len => ByteArrayN len (Digest len) Source # 
Instance details

Defined in BLAKE3.IO

Methods

allocRet :: Proxy len -> (Ptr p -> IO a) -> IO (a, Digest len) #

KnownNat len => Storable (Digest len) Source #

When allocating a Digest, prefer to use alloc, which wipes and releases the memory as soon it becomes unused.

Instance details

Defined in BLAKE3.IO

Methods

sizeOf :: Digest len -> Int #

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 () #

peek :: Ptr (Digest len) -> IO (Digest len) #

poke :: Ptr (Digest len) -> Digest len -> IO () #

Show (Digest len) Source #

Base 16 (hexadecimal).

Instance details

Defined in BLAKE3.IO

Methods

showsPrec :: Int -> Digest len -> ShowS #

show :: Digest len -> String #

showList :: [Digest len] -> ShowS #

Eq (Digest len) Source #

Constant time.

Instance details

Defined in BLAKE3.IO

Methods

(==) :: Digest len -> Digest len -> Bool #

(/=) :: Digest len -> Digest len -> Bool #

Ord (Digest len) Source # 
Instance details

Defined in BLAKE3.IO

Methods

compare :: Digest len -> Digest len -> Ordering #

(<) :: Digest len -> Digest len -> Bool #

(<=) :: Digest len -> Digest len -> Bool #

(>) :: Digest len -> Digest len -> Bool #

(>=) :: Digest len -> Digest len -> Bool #

max :: Digest len -> Digest len -> Digest len #

min :: Digest len -> Digest len -> Digest len #

KnownNat len => ByteArrayAccess (Digest len) Source # 
Instance details

Defined in BLAKE3.IO

Methods

length :: Digest len -> Int #

withByteArray :: Digest len -> (Ptr p -> IO a) -> IO a #

copyByteArrayToPtr :: Digest len -> Ptr p -> IO () #

Keyed hashing

data Key Source #

Key used for keyed hashing mode.

Obtain with key.

See hashKeyed.

Instances

Instances details
Storable Key Source #

When allocating a Key, prefer to use alloc, which wipes and releases the memory as soon it becomes unused.

Instance details

Defined in BLAKE3.IO

Methods

sizeOf :: Key -> Int #

alignment :: Key -> Int #

peekElemOff :: Ptr Key -> Int -> IO Key #

pokeElemOff :: Ptr Key -> Int -> Key -> IO () #

peekByteOff :: Ptr b -> Int -> IO Key #

pokeByteOff :: Ptr b -> Int -> Key -> IO () #

peek :: Ptr Key -> IO Key #

poke :: Ptr Key -> Key -> IO () #

Show Key Source #

Base 16 (hexadecimal).

Instance details

Defined in BLAKE3.IO

Methods

showsPrec :: Int -> Key -> ShowS #

show :: Key -> String #

showList :: [Key] -> ShowS #

Eq Key Source #

Constant time.

Instance details

Defined in BLAKE3.IO

Methods

(==) :: Key -> Key -> Bool #

(/=) :: Key -> Key -> Bool #

ByteArrayAccess Key Source #

Length is KEY_LEN.

Instance details

Defined in BLAKE3.IO

Methods

length :: Key -> Int #

withByteArray :: Key -> (Ptr p -> IO a) -> IO a #

copyByteArrayToPtr :: Key -> Ptr p -> IO () #

ByteArrayN KEY_LEN Key Source #

Allocate a Key.

The memory is wiped and freed as soon as the Key becomes unused.

Instance details

Defined in BLAKE3.IO

Methods

allocRet :: Proxy KEY_LEN -> (Ptr p -> IO a) -> IO (a, Key) #

key Source #

Arguments

:: ByteArrayAccess bin 
=> bin

Key bytes. Must have length KEY_LEN.

-> Maybe Key 

Obtain a Key for use in BLAKE3 keyed hashing.

See hashKeyed.

Key derivation

derive Source #

Arguments

:: 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 lenght.

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

data Hasher Source #

BLAKE3 internal state.

Obtain with hasher, hasherKeyed.

Instances

Instances details
Storable Hasher Source #

When allocating a Hasher, prefer to use alloc, which wipes and releases the memory as soon it becomes unused.

Instance details

Defined in BLAKE3.IO

Show Hasher Source #

Base 16 (hexadecimal).

Instance details

Defined in BLAKE3.IO

Eq Hasher Source #

Constant time.

Instance details

Defined in BLAKE3.IO

Methods

(==) :: Hasher -> Hasher -> Bool #

(/=) :: Hasher -> Hasher -> Bool #

ByteArrayAccess Hasher Source #

Length is HASHER_SIZE.

Instance details

Defined in BLAKE3.IO

Methods

length :: Hasher -> Int #

withByteArray :: Hasher -> (Ptr p -> IO a) -> IO a #

copyByteArrayToPtr :: Hasher -> Ptr p -> IO () #

ByteArrayN HASHER_SIZE Hasher Source #

Allocate a Hasher. The memory is wiped and freed as soon as the Hasher becomes unused.

Instance details

Defined in BLAKE3.IO

Methods

allocRet :: Proxy HASHER_SIZE -> (Ptr p -> IO a) -> IO (a, Hasher) #

init Source #

Arguments

:: Maybe Key

Whether to use keyed hashing mode (for MAC, PRF).

-> Hasher 

Initial Hasher for incremental hashing.

update Source #

Arguments

:: forall bin. ByteArrayAccess bin 
=> Hasher 
-> [bin]

New data to hash.

-> Hasher 

Update Hasher with new data.

finalize Source #

Arguments

:: forall len output. ByteArrayN len output 
=> Hasher 
-> output

The output type could be Digest len.

Finalize incremental hashing and obtain a the BLAKE3 output of the specified length.

finalizeSeek Source #

Arguments

:: forall len output. ByteArrayN len output 
=> Hasher 
-> Word64

BLAKE3 output offset.

-> output

The output type could be Digest len.

Finalize incremental hashing and obtain the specified length of BLAKE3 output starting at the specified offset.

finalize h = finalizeSeek h 0

Constants

type KEY_LEN = 32 Source #

In bytes.

type BLOCK_SIZE = 64 Source #

In bytes.

type DEFAULT_DIGEST_LEN = 32 Source #

In bytes.