---
name: "blake2"
section: "3"
platform: "linux"
package: "libb2-dev"
version: "0.98.1-1.1+b2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/blake2"
---

# blake2(3)

BLAKE2 cryptographic hash functions

## NAME

**blake2s**, **blake2b**, **blake2sp**, **blake2bp**, **blake2s\_init**, **blake2s\_init\_key**, **blake2s\_init\_param**, **blake2s\_update**, **blake2s\_final**, **blake2b\_init**, **blake2b\_init\_key**, **blake2b\_init\_param**, **blake2b\_update**, **blake2b\_final**, **blake2sp\_init**, **blake2sp\_init\_key**, **blake2sp\_update**, **blake2sp\_final**, **blake2bp\_init**, **blake2bp\_init\_key**, **blake2bp\_update**, **blake2bp\_final** – BLAKE2 cryptographic hash functions

## SYNOPSIS

**#include \<blake2.h\>**

*int*\

**blake2s**(*uint8\_t \*out*, *const void \*in*, *const void \*key*, *size\_t outlen*, *size\_t inlen*, *size\_t keylen*);

*int*\

**blake2b**(*uint8\_t \*out*, *const void \*in*, *const void \*key*, *size\_t outlen*, *size\_t inlen*, *size\_t keylen*);

*int*\

**blake2sp**(*uint8\_t \*out*, *const void \*in*, *const void \*key*, *size\_t outlen*, *size\_t inlen*, *size\_t keylen*);

*int*\

**blake2bp**(*uint8\_t \*out*, *const void \*in*, *const void \*key*, *size\_t outlen*, *size\_t inlen*, *size\_t keylen*);

*int*\

**blake2s\_init**(*blake2s\_state \*S*, *size\_t outlen*);

*int*\

**blake2s\_init\_key**(*blake2s\_state \*S*, *size\_t outlen*, *const void \*key*, *size\_t keylen*);

*int*\

**blake2s\_init\_param**(*blake2s\_state \*S*, *const blake2s\_param \*P*);

*int*\

**blake2s\_update**(*blake2s\_state \*S*, *const uint8\_t \*in*, *size\_t inlen*);

*int*\

**blake2s\_final**(*blake2s\_state \*S*, *uint8\_t \*out*, *size\_t outlen*);

*int*\

**blake2b\_init**(*blake2b\_state \*S*, *size\_t outlen*);

*int*\

**blake2b\_init\_key**(*blake2b\_state \*S*, *size\_t outlen*, *const void \*key*, *size\_t keylen*);

*int*\

**blake2b\_init\_param**(*blake2b\_state \*S*, *const blake2b\_param \*P*);

*int*\

**blake2b\_update**(*blake2b\_state \*S*, *const uint8\_t \*in*, *size\_t inlen*);

*int*\

**blake2b\_final**(*blake2b\_state \*S*, *uint8\_t \*out*, *size\_t outlen*);

*int*\

**blake2sp\_init**(*blake2sp\_state \*S*, *size\_t outlen*);

*int*\

**blake2sp\_init\_key**(*blake2sp\_state \*S*, *size\_t outlen*, *const void \*key*, *size\_t keylen*);

*int*\

**blake2sp\_update**(*blake2sp\_state \*S*, *const uint8\_t \*in*, *size\_t inlen*);

*int*\

**blake2sp\_final**(*blake2sp\_state \*S*, *uint8\_t \*out*, *size\_t outlen*);

*int*\

**blake2bp\_init**(*blake2bp\_state \*S*, *size\_t outlen*);

*int*\

**blake2bp\_init\_key**(*blake2bp\_state \*S*, *size\_t outlen*, *const void \*key*, *size\_t keylen*);

*int*\

**blake2bp\_update**(*blake2bp\_state \*S*, *const uint8\_t \*in*, *size\_t inlen*);

*int*\

**blake2bp\_final**(*blake2bp\_state \*S*, *uint8\_t \*out*, *size\_t outlen*);

## DESCRIPTION

The BLAKE2 family of cryptographic hash functions is an improved version of the SHA-3 finalist BLAKE.

BLAKE2b is optimized for 64-bit platforms and produces up to 64 bytes of output; BLAKE2s is optimized for 32-bit platforms and produces up to 32 bytes of output.

BLAKE2bp and BLAKE2sp are parallel versions of BLAKE2b and BLAKE2s designed for increased performance on multicore and large-vector SIMD processors.

The **blake2s\_init**(), **blake2b\_init**(), **blake2sp\_init**(), and **blake2bp\_init**() functions initialize a hash state *S* to hash a message to an output of *outlen* bytes, without using a key.

*S* must be allocated by the caller.

The **blake2s\_init\_key**(), **blake2b\_init\_key**(), **blake2sp\_init\_key**(), and **blake2bp\_init\_key**() functions initialize a hash state *S* to hash a message to an output of *outlen* bytes, using the key *key* of length *keylen*.

The **blake2s\_init\_param**() and **blake2b\_init\_param**() initialize a hash state *S* using a custom parameter block *P*, which must have been filled in completely by the caller. See the BLAKE2 paper and the ⟨blake2.h⟩ header file for details.

The **blake2s\_update**(), **blake2b\_update**(), **blake2sp\_update**(), and **blake2bp\_update**() functions hash the input buffer *in* of length *inlen* bytes into the hash state *S*.

The **blake2s\_final**(), **blake2b\_final**(), **blake2sp\_final**(), and **blake2bp\_final**() functions compute the hash value accumulated in *S* and store it into *out*. *outlen* must have the same value that was passed to the corresponding init function.

The **blake2s**(), **blake2b**(), **blake2sp**(), and **blake2bp**() functions hash a single-buffer input in one function call, optionally using a key.

To use the latter functions without a key, set *keylen* to 0 and *key* to NULL.

For all functions, the lengths *outlen*, *inlen*, and *keylen* are specified in bytes.

*outlen* must be positive and no greater than BLAKE2S\_OUTBYTES (32) for the blake2s and blake2sp functions, or positive and no greater than BLAKE2B\_OUTBYTES (64) for the blake2b and blake2bp functions.

*keylen* must be positive and no greater than BLAKE2S\_KEYBYTES (32) for the blake2s and blake2sp functions, or positive and no greater than BLAKE2B\_KEYBYTES (64) for the blake2b and blake2bp functions.

## RETURN VALUES

All of these functions return 0 if successful, or -1 if they detect an error.

All detected, reported errors are caused by invalid pointer arguments or out-of-bounds length arguments.

Not all invalid arguments are detected.

These functions do *not* set *errno* themselves, but do call standard C library functions which might set *errno*.

## BUGS

The library does not include a self-test function.

The library does not attempt to detect or report an error if the caller exceeds the input length limits specified for the BLAKE2 functions, even for BLAKE2s and BLAKE2sp, whose length limits (2\*\*64-1 bytes and 2\*\*67-1 bytes respectively) could theoretically be reached.

**blake2s\_final**(), **blake2b\_final**(), **blake2sp\_final**(), and **blake2bp\_final**() do not erase the state *S*, and do not treat the hash value as sensitive, even if they are used to compute a keyed hash.

**blake2s\_final**(), **blake2b\_final**(), **blake2sp\_final**(), and **blake2bp\_final**() alter the state such that further calls to the \_update or \_final functions will produce poorly-behaved results, and do not mark the state as no longer valid in order to detect and prevent such programmer errors.
