# std/crypto/blake2b: allow the initial output length to be set · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/26793453a7cf2016ae6fa7ad3d649dca150b53f5)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 26793453a7cf2016ae6fa7ad3d649dca150b53f5

Requested commit: 26793453a7cf2016ae6fa7ad3d649dca150b53f5

Commit: 26793453a7cf2016ae6fa7ad3d649dca150b53f5

Tree: cb174c663085e6908335350622e39de1bd4f181d

Author: Frank Denis

Committer: Andrew Kelley

## Message

```
std/crypto/blake2b: allow the initial output length to be set

BLAKE2 includes the expected output length in the initial state.

This length is actually distinct from the actual output length
used at finalization.

BLAKE2b-256/128 is thus not the same as BLAKE2b-128.

This behavior can be a little bit surprising, and has been "fixed"
in BLAKE3.

In order to support this, we may want to provide an option to set the
length used for domain separation.

In Zig, there is another reason to allow this: we assume that the
output length is defined at comptime.

But BLAKE2 doesn't have a fixed output length. For an output length that
is not known at comptime, we can't take the full block size and
truncate it due to the reason above.

What we can do now is set that length as an option to get the correct
initial state, and truncate the output if necessary.

```

## Parents

- [32e65c3f96b5418acf4d444714facbba98790a91](https://git.cafe/gitcafe/zig/commit/32e65c3f96b5418acf4d444714facbba98790a91?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/26793453a7cf2016ae6fa7ad3d649dca150b53f5?format=markdown)
