blake3-0.2: BLAKE3 hashing algorithm

Safe HaskellNone
LanguageHaskell2010

BLAKE3

Contents

Description

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

Hashing

hash Source #

Arguments

:: (KnownNat len, ByteArrayAccess bin) 
=> [bin]

Data to hash.

-> Digest len

Default digest length is DEFAULT_DIGEST_LEN. The Digest is wiped from memory as soon as the Digest becomes unused.

BLAKE3 hashing.

For incremental hashing, see hasher, update and finalize:

hash = finalize . update hasher

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 Digest. The memory is wiped and freed as soon the Digest becomes unused.

Instance details

Defined in BLAKE3.IO

Methods

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

Eq (Digest len) Source #

Constant time.

Instance details

Defined in BLAKE3.IO

Methods

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

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

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 #

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

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

digest Source #

Arguments

:: (KnownNat len, ByteArrayAccess bin) 
=> bin

Raw digest bytes. Must have length len.

-> 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

hashKeyed Source #

Arguments

:: (KnownNat len, ByteArrayAccess bin) 
=> Key 
-> [bin]

Data to hash.

-> Digest len

Default digest length is DEFAULT_DIGEST_LEN. The Digest is wiped from memory as soon as the Digest becomes unused.

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)

data Key Source #

Key used for keyed hashing mode.

Obtain with key.

See hashKeyed.

Instances
Eq Key Source #

Constant time.

Instance details

Defined in BLAKE3.IO

Methods

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

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

Show Key Source #

Base 16 (hexadecimal).

Instance details

Defined in BLAKE3.IO

Methods

showsPrec :: Int -> Key -> ShowS #

show :: Key -> String #

showList :: [Key] -> ShowS #

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

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

:: (KnownNat len, ByteArrayAccess ikm) 
=> Context 
-> [ikm]

Input key material.

-> Digest len

Default digest length is DEFAULT_DIGEST_LEN. The Digest is wiped from memory as soon as the Digest becomes unused.

BLAKE3 key derivation.

This can be used for KDF (key derivation function) purposes.

data Context Source #

Context for BLAKE3 key derivation. Obtain with context.

Instances
Eq Context Source # 
Instance details

Defined in BLAKE3.IO

Methods

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

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

Show Context Source #

Base 16 (hexadecimal).

Instance details

Defined in BLAKE3.IO

IsString Context Source #

fromString is a partial function that fails if the given String contains Chars outside the range [toEnum 1 .. toEnum 255]. See context for more details.

Instance details

Defined in BLAKE3.IO

Methods

fromString :: String -> Context #

ByteArrayAccess Context Source # 
Instance details

Defined in BLAKE3.IO

Methods

length :: Context -> Int #

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

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

context Source #

Arguments

:: ByteArrayAccess bin 
=> bin

If bin contains null bytes, this function returns Nothing.

-> 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

data Hasher Source #

BLAKE3 internal state.

Obtain with hasher, hasherKeyed.

Instances
Eq Hasher Source # 
Instance details

Defined in BLAKE3.IO

Methods

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

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

Show Hasher Source #

Base 16 (hexadecimal).

Instance details

Defined in BLAKE3.IO

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

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

hasher Source #

Arguments

:: Hasher 

Initial Hasher for incremental hashing.

hasherKeyed Source #

Arguments

:: Key 
-> Hasher 

Initial Hasher for incremental keyed hashing.

update Source #

Arguments

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

New data to hash.

-> Hasher 

Update Hasher with new data.

finalize Source #

Arguments

:: KnownNat len 
=> Hasher 
-> Digest len

Default digest length is DEFAULT_DIGEST_LEN. The Digest is wiped from memory as soon as the Digest becomes unused.

Finish hashing and obtain a Digest of the specified length.

finalizeSeek Source #

Arguments

:: KnownNat len 
=> Hasher 
-> Word64

Number of bytes to skip before obtaning the digest output.

-> Digest len

Default digest length is DEFAULT_DIGEST_LEN. The Digest is wiped from memory as soon as the Digest becomes unused.

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 KEY_LEN = 32 Source #

In bytes.

type BLOCK_SIZE = 64 Source #

In bytes.

type DEFAULT_DIGEST_LEN = 32 Source #

In bytes.