sha512.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Declarations of functions and data types used for SHA512 and SHA384 sum
  2. library functions.
  3. Copyright (C) 2005-2006, 2008-2022 Free Software Foundation, Inc.
  4. This file is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as
  6. published by the Free Software Foundation; either version 2.1 of the
  7. License, or (at your option) any later version.
  8. This file 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 Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  14. #pragma once
  15. #include <stdio.h>
  16. #include "u64.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. enum { SHA512_DIGEST_SIZE = 512 / 8 };
  21. /* Structure to save state of computation between the single steps. */
  22. struct sha512_ctx {
  23. u64 state[8];
  24. u64 total[2];
  25. size_t buflen; /* ≥ 0, ≤ 256 */
  26. u64 buffer[32]; /* 256 bytes; the first buflen bytes are in use */
  27. };
  28. /* Initialize structure containing state of computation. */
  29. extern void sha512_init_ctx(struct sha512_ctx* ctx);
  30. /* Starting with the result of former calls of this function (or the
  31. initialization function update the context for the next LEN bytes
  32. starting at BUFFER.
  33. It is necessary that LEN is a multiple of 128!!! */
  34. extern void sha512_process_block(const void* buffer, size_t len, struct sha512_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 NOT required that LEN is a multiple of 128. */
  39. extern void sha512_process_bytes(const void* buffer, size_t len, struct sha512_ctx* ctx);
  40. /* Process the remaining bytes in the buffer and put result from CTX
  41. in first 64 (48) bytes following RESBUF. The result is always in little
  42. endian byte order, so that a byte-wise output yields to the wanted
  43. ASCII representation of the message digest. */
  44. extern void* sha512_finish_ctx(struct sha512_ctx* ctx, void* restrict resbuf);
  45. /* Put result from CTX in first 64 (48) bytes following RESBUF. The result is
  46. always in little endian byte order, so that a byte-wise output yields
  47. to the wanted ASCII representation of the message digest.
  48. IMPORTANT: On some systems it is required that RESBUF is correctly
  49. aligned for a 32 bits value. */
  50. extern void* sha512_read_ctx(const struct sha512_ctx* ctx, void* restrict resbuf);
  51. /* Compute SHA512 message digest for LEN bytes beginning at BUFFER.
  52. The result is always in little endian byte order, so that a byte-wise
  53. output yields to the wanted ASCII representation of the message
  54. digest. */
  55. extern void* sha512_buffer(const char* buffer, size_t len, void* restrict resblock);
  56. #ifdef __cplusplus
  57. }
  58. #endif
  59. /*
  60. * Hey Emacs!
  61. * Local Variables:
  62. * coding: utf-8
  63. * End:
  64. */