sha1.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Declarations of functions and data types used for SHA1 sum
  2. library functions.
  3. Copyright (C) 2000-2001, 2003, 2005-2006, 2008-2022 Free Software
  4. Foundation, Inc.
  5. This file is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU Lesser General Public License as
  7. published by the Free Software Foundation; either version 2.1 of the
  8. License, or (at your option) any later version.
  9. This file is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License
  14. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  15. #pragma once
  16. #include <stdio.h>
  17. #include <stdint.h>
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #define SHA1_DIGEST_SIZE 20
  22. /* Structure to save state of computation between the single steps. */
  23. struct sha1_ctx {
  24. uint32_t A;
  25. uint32_t B;
  26. uint32_t C;
  27. uint32_t D;
  28. uint32_t E;
  29. uint32_t total[2];
  30. uint32_t buflen; /* ≥ 0, ≤ 128 */
  31. uint32_t buffer[32]; /* 128 bytes; the first buflen bytes are in use */
  32. };
  33. /* Initialize structure containing state of computation. */
  34. extern void sha1_init_ctx(struct sha1_ctx* ctx);
  35. /* Starting with the result of former calls of this function (or the
  36. initialization function update the context for the next LEN bytes
  37. starting at BUFFER.
  38. It is necessary that LEN is a multiple of 64!!! */
  39. extern void sha1_process_block(const void* buffer, size_t len, struct sha1_ctx* ctx);
  40. /* Starting with the result of former calls of this function (or the
  41. initialization function update the context for the next LEN bytes
  42. starting at BUFFER.
  43. It is NOT required that LEN is a multiple of 64. */
  44. extern void sha1_process_bytes(const void* buffer, size_t len, struct sha1_ctx* ctx);
  45. /* Process the remaining bytes in the buffer and put result from CTX
  46. in first 20 bytes following RESBUF. The result is always in little
  47. endian byte order, so that a byte-wise output yields to the wanted
  48. ASCII representation of the message digest. */
  49. extern void* sha1_finish_ctx(struct sha1_ctx* ctx, void* restrict resbuf);
  50. /* Put result from CTX in first 20 bytes following RESBUF. The result is
  51. always in little endian byte order, so that a byte-wise output yields
  52. to the wanted ASCII representation of the message digest. */
  53. extern void* sha1_read_ctx(const struct sha1_ctx* ctx, void* restrict resbuf);
  54. /* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The
  55. result is always in little endian byte order, so that a byte-wise
  56. output yields to the wanted ASCII representation of the message
  57. digest. */
  58. extern void* sha1_buffer(const char* buffer, size_t len, void* restrict resblock);
  59. #ifdef __cplusplus
  60. }
  61. #endif
  62. /*
  63. * Hey Emacs!
  64. * Local Variables:
  65. * coding: utf-8
  66. * End:
  67. */