blake3-0.1: BLAKE3 hashing algorithm

Safe HaskellNone
LanguageHaskell2010

BLAKE3

Contents

Description

Haskell bindings to the official BLAKE3 hashing implementation in C.

The original 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.

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

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

hashKeyed Source #

Arguments

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

Data to hash.

-> Digest len

Default digest length is DEFAULT_DIGEST_LEN.

BLAKE3 hashing with a Key.

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 #

ByteArrayAccess Key Source # 
Instance details

Defined in BLAKE3.IO

Methods

length :: Key -> Int #

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

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

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.

BLAKE3 key derivation.

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 0 .. toEnum 255]. See context.

Instance details

Defined in BLAKE3.IO

Methods

fromString :: String -> Context #

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 #

Immutable BLAKE3 hashing state.

Obtain with hasher or hasherKeyed.

hasher Source #

Arguments

:: Hasher 

Initial Hasher for incremental hashing.

hasherKeyed Source #

Arguments

:: Key 
-> Hasher 

Initial Hasher for incremental keyed hashing.

update :: forall bin. ByteArrayAccess bin => Hasher -> [bin] -> Hasher Source #

Update Hasher with new data.

finalize :: forall len. KnownNat len => Hasher -> Digest len Source #

Update Hasher with new data.

Constants

type KEY_LEN = 32 Source #

In bytes.

type BLOCK_SIZE = 64 Source #

In bytes.

type DEFAULT_DIGEST_LEN = 32 Source #

In bytes.