sha1.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* Declarations of functions and data types used for SHA1 sum
  2. library functions.
  3. Copyright (C) 2000-2001, 2003, 2005-2006, 2008-2017 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. # if HAVE_OPENSSL_SHA1
  20. # include <openssl/sha.h>
  21. # endif
  22. # ifdef __cplusplus
  23. extern "C" {
  24. # endif
  25. #define SHA1_DIGEST_SIZE 20
  26. # if HAVE_OPENSSL_SHA1
  27. # define GL_OPENSSL_NAME 1
  28. # include "gl_openssl.h"
  29. # else
  30. /* Structure to save state of computation between the single steps. */
  31. struct sha1_ctx
  32. {
  33. uint32_t A;
  34. uint32_t B;
  35. uint32_t C;
  36. uint32_t D;
  37. uint32_t E;
  38. uint32_t total[2];
  39. uint32_t buflen; /* ≥ 0, ≤ 128 */
  40. uint32_t buffer[32]; /* 128 bytes; the first buflen bytes are in use */
  41. };
  42. /* Initialize structure containing state of computation. */
  43. extern void sha1_init_ctx (struct sha1_ctx *ctx);
  44. /* Starting with the result of former calls of this function (or the
  45. initialization function update the context for the next LEN bytes
  46. starting at BUFFER.
  47. It is necessary that LEN is a multiple of 64!!! */
  48. extern void sha1_process_block (const void *buffer, size_t len,
  49. struct sha1_ctx *ctx);
  50. /* Starting with the result of former calls of this function (or the
  51. initialization function update the context for the next LEN bytes
  52. starting at BUFFER.
  53. It is NOT required that LEN is a multiple of 64. */
  54. extern void sha1_process_bytes (const void *buffer, size_t len,
  55. struct sha1_ctx *ctx);
  56. /* Process the remaining bytes in the buffer and put result from CTX
  57. in first 20 bytes following RESBUF. The result is always in little
  58. endian byte order, so that a byte-wise output yields to the wanted
  59. ASCII representation of the message digest. */
  60. extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf);
  61. /* Put result from CTX in first 20 bytes following RESBUF. The result is
  62. always in little endian byte order, so that a byte-wise output yields
  63. to the wanted ASCII representation of the message digest. */
  64. extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf);
  65. /* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The
  66. result is always in little endian byte order, so that a byte-wise
  67. output yields to the wanted ASCII representation of the message
  68. digest. */
  69. extern void *sha1_buffer (const char *buffer, size_t len, void *resblock);
  70. # endif
  71. /* Compute SHA1 message digest for bytes read from STREAM. The
  72. resulting message digest number will be written into the 20 bytes
  73. beginning at RESBLOCK. */
  74. extern int sha1_stream (FILE *stream, void *resblock);
  75. # ifdef __cplusplus
  76. }
  77. # endif
  78. #endif