ripemd160.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /**
  2. * \file ripemd160.h
  3. *
  4. * \brief RIPE MD-160 message digest
  5. */
  6. /*
  7. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  8. * SPDX-License-Identifier: Apache-2.0
  9. *
  10. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  11. * not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  18. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. *
  22. * This file is part of mbed TLS (https://tls.mbed.org)
  23. */
  24. #ifndef MBEDTLS_RIPEMD160_H
  25. #define MBEDTLS_RIPEMD160_H
  26. #if !defined(MBEDTLS_CONFIG_FILE)
  27. #include "config.h"
  28. #else
  29. #include MBEDTLS_CONFIG_FILE
  30. #endif
  31. #include <stddef.h>
  32. #include <stdint.h>
  33. #define MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED -0x0031 /**< RIPEMD160 hardware accelerator failed */
  34. #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
  35. !defined(inline) && !defined(__cplusplus)
  36. #define inline __inline
  37. #endif
  38. #if !defined(MBEDTLS_RIPEMD160_ALT)
  39. // Regular implementation
  40. //
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. /**
  45. * \brief RIPEMD-160 context structure
  46. */
  47. typedef struct
  48. {
  49. uint32_t total[2]; /*!< number of bytes processed */
  50. uint32_t state[5]; /*!< intermediate digest state */
  51. unsigned char buffer[64]; /*!< data block being processed */
  52. }
  53. mbedtls_ripemd160_context;
  54. /**
  55. * \brief Initialize RIPEMD-160 context
  56. *
  57. * \param ctx RIPEMD-160 context to be initialized
  58. */
  59. void mbedtls_ripemd160_init( mbedtls_ripemd160_context *ctx );
  60. /**
  61. * \brief Clear RIPEMD-160 context
  62. *
  63. * \param ctx RIPEMD-160 context to be cleared
  64. */
  65. void mbedtls_ripemd160_free( mbedtls_ripemd160_context *ctx );
  66. /**
  67. * \brief Clone (the state of) an RIPEMD-160 context
  68. *
  69. * \param dst The destination context
  70. * \param src The context to be cloned
  71. */
  72. void mbedtls_ripemd160_clone( mbedtls_ripemd160_context *dst,
  73. const mbedtls_ripemd160_context *src );
  74. /**
  75. * \brief RIPEMD-160 context setup
  76. *
  77. * \param ctx context to be initialized
  78. *
  79. * \return 0 if successful
  80. */
  81. int mbedtls_ripemd160_starts_ret( mbedtls_ripemd160_context *ctx );
  82. /**
  83. * \brief RIPEMD-160 process buffer
  84. *
  85. * \param ctx RIPEMD-160 context
  86. * \param input buffer holding the data
  87. * \param ilen length of the input data
  88. *
  89. * \return 0 if successful
  90. */
  91. int mbedtls_ripemd160_update_ret( mbedtls_ripemd160_context *ctx,
  92. const unsigned char *input,
  93. size_t ilen );
  94. /**
  95. * \brief RIPEMD-160 final digest
  96. *
  97. * \param ctx RIPEMD-160 context
  98. * \param output RIPEMD-160 checksum result
  99. *
  100. * \return 0 if successful
  101. */
  102. int mbedtls_ripemd160_finish_ret( mbedtls_ripemd160_context *ctx,
  103. unsigned char output[20] );
  104. /**
  105. * \brief RIPEMD-160 process data block (internal use only)
  106. *
  107. * \param ctx RIPEMD-160 context
  108. * \param data buffer holding one block of data
  109. *
  110. * \return 0 if successful
  111. */
  112. int mbedtls_internal_ripemd160_process( mbedtls_ripemd160_context *ctx,
  113. const unsigned char data[64] );
  114. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  115. #if defined(MBEDTLS_DEPRECATED_WARNING)
  116. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  117. #else
  118. #define MBEDTLS_DEPRECATED
  119. #endif
  120. /**
  121. * \brief RIPEMD-160 context setup
  122. *
  123. * \deprecated Superseded by mbedtls_ripemd160_starts_ret() in 2.7.0
  124. *
  125. * \param ctx context to be initialized
  126. */
  127. MBEDTLS_DEPRECATED static inline void mbedtls_ripemd160_starts(
  128. mbedtls_ripemd160_context *ctx )
  129. {
  130. mbedtls_ripemd160_starts_ret( ctx );
  131. }
  132. /**
  133. * \brief RIPEMD-160 process buffer
  134. *
  135. * \deprecated Superseded by mbedtls_ripemd160_update_ret() in 2.7.0
  136. *
  137. * \param ctx RIPEMD-160 context
  138. * \param input buffer holding the data
  139. * \param ilen length of the input data
  140. */
  141. MBEDTLS_DEPRECATED static inline void mbedtls_ripemd160_update(
  142. mbedtls_ripemd160_context *ctx,
  143. const unsigned char *input,
  144. size_t ilen )
  145. {
  146. mbedtls_ripemd160_update_ret( ctx, input, ilen );
  147. }
  148. /**
  149. * \brief RIPEMD-160 final digest
  150. *
  151. * \deprecated Superseded by mbedtls_ripemd160_finish_ret() in 2.7.0
  152. *
  153. * \param ctx RIPEMD-160 context
  154. * \param output RIPEMD-160 checksum result
  155. */
  156. MBEDTLS_DEPRECATED static inline void mbedtls_ripemd160_finish(
  157. mbedtls_ripemd160_context *ctx,
  158. unsigned char output[20] )
  159. {
  160. mbedtls_ripemd160_finish_ret( ctx, output );
  161. }
  162. /**
  163. * \brief RIPEMD-160 process data block (internal use only)
  164. *
  165. * \deprecated Superseded by mbedtls_internal_ripemd160_process() in 2.7.0
  166. *
  167. * \param ctx RIPEMD-160 context
  168. * \param data buffer holding one block of data
  169. */
  170. MBEDTLS_DEPRECATED static inline void mbedtls_ripemd160_process(
  171. mbedtls_ripemd160_context *ctx,
  172. const unsigned char data[64] )
  173. {
  174. mbedtls_internal_ripemd160_process( ctx, data );
  175. }
  176. #undef MBEDTLS_DEPRECATED
  177. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  178. #ifdef __cplusplus
  179. }
  180. #endif
  181. #else /* MBEDTLS_RIPEMD160_ALT */
  182. #include "ripemd160_alt.h"
  183. #endif /* MBEDTLS_RIPEMD160_ALT */
  184. #ifdef __cplusplus
  185. extern "C" {
  186. #endif
  187. /**
  188. * \brief Output = RIPEMD-160( input buffer )
  189. *
  190. * \param input buffer holding the data
  191. * \param ilen length of the input data
  192. * \param output RIPEMD-160 checksum result
  193. *
  194. * \return 0 if successful
  195. */
  196. int mbedtls_ripemd160_ret( const unsigned char *input,
  197. size_t ilen,
  198. unsigned char output[20] );
  199. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  200. #if defined(MBEDTLS_DEPRECATED_WARNING)
  201. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  202. #else
  203. #define MBEDTLS_DEPRECATED
  204. #endif
  205. /**
  206. * \brief Output = RIPEMD-160( input buffer )
  207. *
  208. * \deprecated Superseded by mbedtls_ripemd160_ret() in 2.7.0
  209. *
  210. * \param input buffer holding the data
  211. * \param ilen length of the input data
  212. * \param output RIPEMD-160 checksum result
  213. */
  214. MBEDTLS_DEPRECATED static inline void mbedtls_ripemd160(
  215. const unsigned char *input,
  216. size_t ilen,
  217. unsigned char output[20] )
  218. {
  219. mbedtls_ripemd160_ret( input, ilen, output );
  220. }
  221. #undef MBEDTLS_DEPRECATED
  222. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  223. /**
  224. * \brief Checkup routine
  225. *
  226. * \return 0 if successful, or 1 if the test failed
  227. */
  228. int mbedtls_ripemd160_self_test( int verbose );
  229. #ifdef __cplusplus
  230. }
  231. #endif
  232. #endif /* mbedtls_ripemd160.h */