sha1.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. #ifndef SHA1_H
  16. # define SHA1_H 1
  17. # include <stdio.h>
  18. # include <stdint.h>
  19. # if HAVE_OPENSSL_SHA1
  20. # ifndef OPENSSL_API_COMPAT
  21. # define OPENSSL_API_COMPAT 0x10101000L /* FIXME: Use OpenSSL 1.1+ API. */
  22. # endif
  23. # include <openssl/sha.h>
  24. # endif
  25. # ifdef __cplusplus
  26. extern "C" {
  27. # endif
  28. # define SHA1_DIGEST_SIZE 20
  29. # if HAVE_OPENSSL_SHA1
  30. # define GL_OPENSSL_NAME 1
  31. # include "gl_openssl.h"
  32. # else
  33. /* Structure to save state of computation between the single steps. */
  34. struct sha1_ctx
  35. {
  36. uint32_t A;
  37. uint32_t B;
  38. uint32_t C;
  39. uint32_t D;
  40. uint32_t E;
  41. uint32_t total[2];
  42. uint32_t buflen; /* ≥ 0, ≤ 128 */
  43. uint32_t buffer[32]; /* 128 bytes; the first buflen bytes are in use */
  44. };
  45. /* Initialize structure containing state of computation. */
  46. extern void sha1_init_ctx (struct sha1_ctx *ctx);
  47. /* Starting with the result of former calls of this function (or the
  48. initialization function update the context for the next LEN bytes
  49. starting at BUFFER.
  50. It is necessary that LEN is a multiple of 64!!! */
  51. extern void sha1_process_block (const void *buffer, size_t len,
  52. struct sha1_ctx *ctx);
  53. /* Starting with the result of former calls of this function (or the
  54. initialization function update the context for the next LEN bytes
  55. starting at BUFFER.
  56. It is NOT required that LEN is a multiple of 64. */
  57. extern void sha1_process_bytes (const void *buffer, size_t len,
  58. struct sha1_ctx *ctx);
  59. /* Process the remaining bytes in the buffer and put result from CTX
  60. in first 20 bytes following RESBUF. The result is always in little
  61. endian byte order, so that a byte-wise output yields to the wanted
  62. ASCII representation of the message digest. */
  63. extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *restrict resbuf);
  64. /* Put result from CTX in first 20 bytes following RESBUF. The result is
  65. always in little endian byte order, so that a byte-wise output yields
  66. to the wanted ASCII representation of the message digest. */
  67. extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *restrict resbuf);
  68. /* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The
  69. result is always in little endian byte order, so that a byte-wise
  70. output yields to the wanted ASCII representation of the message
  71. digest. */
  72. extern void *sha1_buffer (const char *buffer, size_t len,
  73. void *restrict resblock);
  74. # endif
  75. /* Compute SHA1 message digest for bytes read from STREAM.
  76. STREAM is an open file stream. Regular files are handled more efficiently.
  77. The contents of STREAM from its current position to its end will be read.
  78. The case that the last operation on STREAM was an 'ungetc' is not supported.
  79. The resulting message digest number will be written into the 20 bytes
  80. beginning at RESBLOCK. */
  81. extern int sha1_stream (FILE *stream, void *resblock);
  82. # ifdef __cplusplus
  83. }
  84. # endif
  85. #endif
  86. /*
  87. * Hey Emacs!
  88. * Local Variables:
  89. * coding: utf-8
  90. * End:
  91. */