blake3-0.2: BLAKE3 hashing algorithm

Safe HaskellNone
LanguageHaskell2010

BLAKE3.IO

Contents

Description

IO and low level tools.

Synopsis

Hashing

hash Source #

Arguments

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

Data to hash.

-> IO (Digest len)

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

BLAKE3 hashing.

init Source #

Arguments

:: Ptr Hasher

Obtain with alloc or similar. It will be mutated.

-> IO () 

Initialize a Hasher.

update Source #

Arguments

:: ByteArrayAccess bin 
=> Ptr Hasher

Obtain with modifyHasher. It will be mutated.

-> [bin] 
-> IO () 

Update Hasher state with new data.

finalize Source #

Arguments

:: KnownNat len 
=> Ptr Hasher

Obtain with modifyHasher. It will be mutated.

-> IO (Digest len)

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

Finalize incremental hashin and obtain a Digest.

finalizeSeek Source #

Arguments

:: KnownNat len 
=> Ptr Hasher

Obtain with modifyHasher. It will be mutated.

-> Word64

Number of bytes to skip before obtaning the digest output.

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

Digest

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

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.

initKeyed Source #

Arguments

:: Ptr Hasher

Obtain with alloc or similar. It will be mutated.

-> Key 
-> IO () 

Initialize a Hasher 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 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

initDerive Source #

Arguments

:: Ptr Hasher

Obtain with alloc or similar. It will be mutated.

-> Context 
-> IO () 

Initialize a Hasher in derivation mode.

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

Hasher

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

modifyHasher Source #

Arguments

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

HASHER_SIZE bytes.

-> IO a 

Obtain a Ptr Hasher to use with functions like initDerive, etc.

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.

type CHUNK_LEN = 1024 Source #

type MAX_DEPTH = 54 Source #

Low-level C bindings

c_init Source #

Arguments

:: Ptr Hasher

You can obtain with alloc. Otherwise, any chunk of HASHER_SIZE bytes aligned to HASHER_ALIGNMENT will do.

-> IO () 
void blake3_hasher_init(blake3_hasher *self)

c_init_keyed Source #

Arguments

:: Ptr Hasher

You can obtain with alloc. Otherwise, any chunk of HASHER_SIZE bytes aligned to HASHER_ALIGNMENT will do.

-> Ptr Word8

You can obtain with alloc. Otherwise, any chunk of length KEY_LEN will do.

-> IO () 
void blake3_hasher_init_keyed(blake3_hasher *self, const uint8_t key[KEY_LEN])

c_init_derive_key Source #

Arguments

:: Ptr Hasher

You can obtain with alloc. Otherwise, any chunk of HASHER_SIZE bytes aligned to HASHER_ALIGNMENT will do.

-> CString

Context.

-> IO () 
void blake3_hasher_init_derive_key(blake3_hasher *self, const char *context)

c_update Source #

Arguments

:: Ptr Hasher

Must have been previously initializedi. See c_init, c_init_keyed, c_init_derive_key.

-> Ptr Word8

Data.

-> CSize

Data length.

-> IO () 
void blake3_hasher_update(blake3_hasher *self, const void *input, size_t input_len)

c_finalize Source #

Arguments

:: Ptr Hasher

Must have been previously initializedi. See c_init, c_init_keyed, c_init_derive_key.

-> Ptr Word8

Out.

-> CSize

Out length.

-> IO () 
void blake3_hasher_finalize(const blake3_hasher *self, uint8_t *out, size_t out_len)

c_finalize_seek Source #

Arguments

:: Ptr Hasher

Must have been previously initializedi. See c_init, c_init_keyed, c_init_derive_key.

-> Word64

Seek position.

-> Ptr Word8

Out.

-> CSize

Out length.

-> IO () 
void blake3_hasher_finalize_seek(const blake3_hasher *self, uint64_t seek, uint8_t *out, size_t out_len)