logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git

sha512.h (693B)


  1. // SPDX-FileCopyrightText: public domain sha512 implementation based on fips180-3
  2. // SPDX-License-Identifier: 0BSD
  3. #include <stdint.h>
  4. struct sha512
  5. {
  6. uint64_t len; /* processed message length */
  7. uint64_t h[8]; /* hash state */
  8. uint8_t buf[128]; /* message block buffer */
  9. };
  10. enum
  11. {
  12. SHA512_DIGEST_LENGTH = 64
  13. };
  14. /* reset state */
  15. void sha512_init(void *ctx);
  16. /* process message */
  17. void sha512_update(void *ctx, const void *m, unsigned long len);
  18. /* get message digest */
  19. /* state is ruined after sum, keep a copy if multiple sum is needed */
  20. /* part of the message might be left in s, zero it if secrecy is needed */
  21. void sha512_sum(void *ctx, uint8_t md[SHA512_DIGEST_LENGTH]);