sha1.h 955 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the License); you may
  5. * not use this file except in compliance with the License.
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. */
  9. #ifndef GMSSL_SHA1_H
  10. #define GMSSL_SHA1_H
  11. #include <string.h>
  12. #include <stdint.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #define SHA1_IS_BIG_ENDIAN 1
  17. #define SHA1_DIGEST_SIZE 20
  18. #define SHA1_BLOCK_SIZE 64
  19. #define SHA1_STATE_WORDS (SHA1_DIGEST_SIZE/sizeof(uint32_t))
  20. typedef struct {
  21. uint32_t state[SHA1_STATE_WORDS];
  22. uint64_t nblocks;
  23. uint8_t block[SHA1_BLOCK_SIZE];
  24. size_t num;
  25. } SHA1_CTX;
  26. void sha1_init(SHA1_CTX *ctx);
  27. void sha1_update(SHA1_CTX *ctx, const uint8_t *data, size_t datalen);
  28. void sha1_finish(SHA1_CTX *ctx, uint8_t dgst[SHA1_DIGEST_SIZE]);
  29. void sha1_digest(const uint8_t *data, size_t datalen, uint8_t dgst[SHA1_DIGEST_SIZE]);
  30. #ifdef __cplusplus
  31. }
  32. #endif
  33. #endif