sha512.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /**
  2. * \file sha512.h
  3. *
  4. * \brief SHA-384 and SHA-512 cryptographic hash function
  5. *
  6. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  7. * SPDX-License-Identifier: GPL-2.0
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. *
  23. * This file is part of mbed TLS (https://tls.mbed.org)
  24. */
  25. #ifndef MBEDTLS_SHA512_H
  26. #define MBEDTLS_SHA512_H
  27. #if !defined(MBEDTLS_CONFIG_FILE)
  28. #include "config.h"
  29. #else
  30. #include MBEDTLS_CONFIG_FILE
  31. #endif
  32. #include <stddef.h>
  33. #include <stdint.h>
  34. #if !defined(MBEDTLS_SHA512_ALT)
  35. // Regular implementation
  36. //
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. /**
  41. * \brief SHA-512 context structure
  42. */
  43. typedef struct
  44. {
  45. uint64_t total[2]; /*!< number of bytes processed */
  46. uint64_t state[8]; /*!< intermediate digest state */
  47. unsigned char buffer[128]; /*!< data block being processed */
  48. int is384; /*!< 0 => SHA-512, else SHA-384 */
  49. }
  50. mbedtls_sha512_context;
  51. /**
  52. * \brief Initialize SHA-512 context
  53. *
  54. * \param ctx SHA-512 context to be initialized
  55. */
  56. void mbedtls_sha512_init( mbedtls_sha512_context *ctx );
  57. /**
  58. * \brief Clear SHA-512 context
  59. *
  60. * \param ctx SHA-512 context to be cleared
  61. */
  62. void mbedtls_sha512_free( mbedtls_sha512_context *ctx );
  63. /**
  64. * \brief Clone (the state of) a SHA-512 context
  65. *
  66. * \param dst The destination context
  67. * \param src The context to be cloned
  68. */
  69. void mbedtls_sha512_clone( mbedtls_sha512_context *dst,
  70. const mbedtls_sha512_context *src );
  71. /**
  72. * \brief SHA-512 context setup
  73. *
  74. * \param ctx context to be initialized
  75. * \param is384 0 = use SHA512, 1 = use SHA384
  76. */
  77. void mbedtls_sha512_starts( mbedtls_sha512_context *ctx, int is384 );
  78. /**
  79. * \brief SHA-512 process buffer
  80. *
  81. * \param ctx SHA-512 context
  82. * \param input buffer holding the data
  83. * \param ilen length of the input data
  84. */
  85. void mbedtls_sha512_update( mbedtls_sha512_context *ctx, const unsigned char *input,
  86. size_t ilen );
  87. /**
  88. * \brief SHA-512 final digest
  89. *
  90. * \param ctx SHA-512 context
  91. * \param output SHA-384/512 checksum result
  92. */
  93. void mbedtls_sha512_finish( mbedtls_sha512_context *ctx, unsigned char output[64] );
  94. #ifdef __cplusplus
  95. }
  96. #endif
  97. #else /* MBEDTLS_SHA512_ALT */
  98. #include "sha512_alt.h"
  99. #endif /* MBEDTLS_SHA512_ALT */
  100. #ifdef __cplusplus
  101. extern "C" {
  102. #endif
  103. /**
  104. * \brief Output = SHA-512( input buffer )
  105. *
  106. * \param input buffer holding the data
  107. * \param ilen length of the input data
  108. * \param output SHA-384/512 checksum result
  109. * \param is384 0 = use SHA512, 1 = use SHA384
  110. */
  111. void mbedtls_sha512( const unsigned char *input, size_t ilen,
  112. unsigned char output[64], int is384 );
  113. /**
  114. * \brief Checkup routine
  115. *
  116. * \return 0 if successful, or 1 if the test failed
  117. */
  118. int mbedtls_sha512_self_test( int verbose );
  119. /* Internal use */
  120. void mbedtls_sha512_process( mbedtls_sha512_context *ctx, const unsigned char data[128] );
  121. #ifdef __cplusplus
  122. }
  123. #endif
  124. #endif /* mbedtls_sha512.h */