blake3-0.1: BLAKE3 hashing algorithm

Safe HaskellNone
LanguageHaskell2010

BLAKE3.IO

Contents

Synopsis

Hashing

init Source #

Arguments

:: Ptr HasherInternal

Will be mutated.

-> IO () 

Initialize a HasherInternal.

update Source #

Arguments

:: ByteArrayAccess bin 
=> Ptr HasherInternal

Will be mutated.

-> [bin] 
-> IO () 

Update HasherInternal state with new data.

finalize Source #

Arguments

:: KnownNat len 
=> Ptr HasherInternal

Will be mutated.

-> IO (Digest len) 

Finalize HasherInternal state and obtain a digest.

The HasherInternal is mutated.

data Hasher Source #

Immutable BLAKE3 hashing state.

Obtain with hasher or hasherKeyed.

allocRetHasher Source #

Arguments

:: (Ptr HasherInternal -> IO a)

Initialize HASHER_SIZE bytes.

-> IO (a, Hasher) 

Allocate Hasher.

The Hasher is wiped and freed as soon as it becomes unused.

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

allocRetDigest Source #

Arguments

:: KnownNat len 
=> (Ptr Word8 -> IO a)

Initialize len bytes.

-> IO (a, Digest len) 

Allocate a Digest.

The Digest is wiped and freed as soon as it becomes unused.

Memory

data HasherInternal Source #

Opaque datatype of size HASHER_SIZE and alignment HASHER_ALIGNMENT.

Obtain with withHasherInternal.

copyHasher Source #

Arguments

:: Hasher 
-> IO Hasher 

Copy an inmutable Hasher.

withHasherInternal Source #

Arguments

:: Hasher 
-> (Ptr HasherInternal -> IO a)

Read or write.

-> IO a 

Mutate the given Hasher.

Keyed hashing

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.

allocRetKey Source #

Arguments

:: (Ptr Word8 -> IO a)

Initialize KEY_LEN bytes.

-> IO (a, Key) 

Allocate a Key.

The Key is wiped and freed as soon as it becomes unused.

initKeyed Source #

Arguments

:: Ptr HasherInternal

Will be mutated.

-> Key 
-> IO () 

Initialize a HasherInternal in keyed mode.

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

initDerive Source #

Arguments

:: Ptr HasherInternal

Will be mutated.

-> Context 
-> IO () 

Initialize a HasherInternal in derivation mode.

The input key material must be provided afterwards, using update.

Constants

type HASHER_SIZE = 1912 Source #

In bytes.

type KEY_LEN = 32 Source #

In bytes.

type BLOCK_SIZE = 64 Source #

In bytes.

type DEFAULT_DIGEST_LEN = 32 Source #

In bytes.