# std.crypto.hash.sha2: cleanup add add more docs \(\#19744\) · gitcafe/zig

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

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

Visibility: public

Requested revision: 8a36a1f913c729993d53786486b542c0501dc27d

Requested commit: 8a36a1f913c729993d53786486b542c0501dc27d

Commit: 8a36a1f913c729993d53786486b542c0501dc27d

Tree: b648a1b375e543737e019ba238d56a5d1a6e13d9

Author: clickingbuttons

Committer: GitHub

## Message

```
std.crypto.hash.sha2: cleanup add add more docs (#19744)

* std.crypto.hash.sha2: generalize sha512 truncation

Replace `Sha512224`, `Sha512256`, and `Sha512T224` with
`fn Sha512Truncated(digest_bits: comptime_int)`.

This required refactoring `Sha2x64(comptime params)` to
`Sha2x64(comptime iv: [8]u64, digest_bits: comptime_int)`
for user-specified `digest_bits`.

I left #19697 alone but added a compile-time check that digest_bits is
divisible by 8.

Remove docs which restate type name. Add module docs and reference where
IVs come from.

* std.crypto.sha2: make Sha512_224 and Sha512_256 pub

* make generic type implementation detail, add comments

* fix iv

* address @jedisct1 feedback

* fix typo

* renaming

* add truncation clarifying comment and Sha259T192 tests
```

## Parents

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

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