logo

utils-std

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

sha256.h (690B)


  1. // SPDX-FileCopyrightText: public domain sha256 implementation based on fips180-3
  2. // SPDX-License-Identifier: 0BSD
  3. #include <stdint.h>
  4. struct sha256
  5. {
  6. uint64_t len; /* processed message length */
  7. uint32_t h[8]; /* hash state */
  8. uint8_t buf[64]; /* message block buffer */
  9. };
  10. enum
  11. {
  12. SHA256_DIGEST_LENGTH = 32
  13. };
  14. /* reset state */
  15. void sha256_init(void *ctx);
  16. /* process message */
  17. void sha256_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 sha256_sum(void *ctx, uint8_t md[SHA256_DIGEST_LENGTH]);