sha1.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* Declarations of functions and data types used for SHA1 sum
  2. library functions.
  3. Copyright (C) 2000-2001, 2003, 2005-2006, 2008-2013 Free Software
  4. Foundation, Inc.
  5. This program is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU General Public License as published by the
  7. Free Software Foundation; either version 3, or (at your option) any
  8. later version.
  9. This program 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 General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, see <http://www.gnu.org/licenses/>. */
  15. #ifndef SHA1_H
  16. # define SHA1_H 1
  17. # include <stdio.h>
  18. # include <stdint.h>
  19. # ifdef __cplusplus
  20. extern "C" {
  21. # endif
  22. #define SHA1_DIGEST_SIZE 20
  23. /* Structure to save state of computation between the single steps. */
  24. struct sha1_ctx
  25. {
  26. uint32_t A;
  27. uint32_t B;
  28. uint32_t C;
  29. uint32_t D;
  30. uint32_t E;
  31. uint32_t total[2];
  32. uint32_t buflen;
  33. uint32_t buffer[32];
  34. };
  35. /* Initialize structure containing state of computation. */
  36. extern void sha1_init_ctx (struct sha1_ctx *ctx);
  37. /* Starting with the result of former calls of this function (or the
  38. initialization function update the context for the next LEN bytes
  39. starting at BUFFER.
  40. It is necessary that LEN is a multiple of 64!!! */
  41. extern void sha1_process_block (const void *buffer, size_t len,
  42. struct sha1_ctx *ctx);
  43. /* Starting with the result of former calls of this function (or the
  44. initialization function update the context for the next LEN bytes
  45. starting at BUFFER.
  46. It is NOT required that LEN is a multiple of 64. */
  47. extern void sha1_process_bytes (const void *buffer, size_t len,
  48. struct sha1_ctx *ctx);
  49. /* Process the remaining bytes in the buffer and put result from CTX
  50. in first 20 bytes following RESBUF. The result is always in little
  51. endian byte order, so that a byte-wise output yields to the wanted
  52. ASCII representation of the message digest. */
  53. extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf);
  54. /* Put result from CTX in first 20 bytes following RESBUF. The result is
  55. always in little endian byte order, so that a byte-wise output yields
  56. to the wanted ASCII representation of the message digest. */
  57. extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf);
  58. /* Compute SHA1 message digest for bytes read from STREAM. The
  59. resulting message digest number will be written into the 20 bytes
  60. beginning at RESBLOCK. */
  61. extern int sha1_stream (FILE *stream, void *resblock);
  62. /* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The
  63. result is always in little endian byte order, so that a byte-wise
  64. output yields to the wanted ASCII representation of the message
  65. digest. */
  66. extern void *sha1_buffer (const char *buffer, size_t len, void *resblock);
  67. # ifdef __cplusplus
  68. }
  69. # endif
  70. #endif