sha512.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* Declarations of functions and data types used for SHA512 and SHA384 sum
  2. library functions.
  3. Copyright (C) 2005-2006, 2008-2011 Free Software Foundation, Inc.
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #ifndef SHA512_H
  15. # define SHA512_H 1
  16. # include <stdio.h>
  17. # include "u64.h"
  18. # ifdef __cplusplus
  19. extern "C" {
  20. # endif
  21. /* Structure to save state of computation between the single steps. */
  22. struct sha512_ctx
  23. {
  24. u64 state[8];
  25. u64 total[2];
  26. size_t buflen;
  27. u64 buffer[32];
  28. };
  29. enum { SHA384_DIGEST_SIZE = 384 / 8 };
  30. enum { SHA512_DIGEST_SIZE = 512 / 8 };
  31. /* Initialize structure containing state of computation. */
  32. extern void sha512_init_ctx (struct sha512_ctx *ctx);
  33. extern void sha384_init_ctx (struct sha512_ctx *ctx);
  34. /* Starting with the result of former calls of this function (or the
  35. initialization function update the context for the next LEN bytes
  36. starting at BUFFER.
  37. It is necessary that LEN is a multiple of 128!!! */
  38. extern void sha512_process_block (const void *buffer, size_t len,
  39. struct sha512_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 128. */
  44. extern void sha512_process_bytes (const void *buffer, size_t len,
  45. struct sha512_ctx *ctx);
  46. /* Process the remaining bytes in the buffer and put result from CTX
  47. in first 64 (48) bytes following RESBUF. The result is always in little
  48. endian byte order, so that a byte-wise output yields to the wanted
  49. ASCII representation of the message digest. */
  50. extern void *sha512_finish_ctx (struct sha512_ctx *ctx, void *resbuf);
  51. extern void *sha384_finish_ctx (struct sha512_ctx *ctx, void *resbuf);
  52. /* Put result from CTX in first 64 (48) bytes following RESBUF. The result is
  53. always in little endian byte order, so that a byte-wise output yields
  54. to the wanted ASCII representation of the message digest.
  55. IMPORTANT: On some systems it is required that RESBUF is correctly
  56. aligned for a 32 bits value. */
  57. extern void *sha512_read_ctx (const struct sha512_ctx *ctx, void *resbuf);
  58. extern void *sha384_read_ctx (const struct sha512_ctx *ctx, void *resbuf);
  59. /* Compute SHA512 (SHA384) message digest for bytes read from STREAM. The
  60. resulting message digest number will be written into the 64 (48) bytes
  61. beginning at RESBLOCK. */
  62. extern int sha512_stream (FILE *stream, void *resblock);
  63. extern int sha384_stream (FILE *stream, void *resblock);
  64. /* Compute SHA512 (SHA384) message digest for LEN bytes beginning at BUFFER. The
  65. result is always in little endian byte order, so that a byte-wise
  66. output yields to the wanted ASCII representation of the message
  67. digest. */
  68. extern void *sha512_buffer (const char *buffer, size_t len, void *resblock);
  69. extern void *sha384_buffer (const char *buffer, size_t len, void *resblock);
  70. # ifdef __cplusplus
  71. }
  72. # endif
  73. #endif