md5.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /**
  2. * \file md5.h
  3. *
  4. * \brief MD5 message digest algorithm (hash function)
  5. *
  6. * \warning MD5 is considered a weak message digest and its use constitutes a
  7. * security risk. We recommend considering stronger message
  8. * digests instead.
  9. */
  10. /*
  11. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  12. * SPDX-License-Identifier: Apache-2.0
  13. *
  14. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  15. * not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at
  17. *
  18. * http://www.apache.org/licenses/LICENSE-2.0
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  22. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. *
  26. * This file is part of mbed TLS (https://tls.mbed.org)
  27. */
  28. #ifndef MBEDTLS_MD5_H
  29. #define MBEDTLS_MD5_H
  30. #if !defined(MBEDTLS_CONFIG_FILE)
  31. #include "config.h"
  32. #else
  33. #include MBEDTLS_CONFIG_FILE
  34. #endif
  35. #include <stddef.h>
  36. #include <stdint.h>
  37. /* MBEDTLS_ERR_MD5_HW_ACCEL_FAILED is deprecated and should not be used. */
  38. #define MBEDTLS_ERR_MD5_HW_ACCEL_FAILED -0x002F /**< MD5 hardware accelerator failed */
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. #if !defined(MBEDTLS_MD5_ALT)
  43. // Regular implementation
  44. //
  45. /**
  46. * \brief MD5 context structure
  47. *
  48. * \warning MD5 is considered a weak message digest and its use
  49. * constitutes a security risk. We recommend considering
  50. * stronger message digests instead.
  51. *
  52. */
  53. typedef struct mbedtls_md5_context
  54. {
  55. uint32_t total[2]; /*!< number of bytes processed */
  56. uint32_t state[4]; /*!< intermediate digest state */
  57. unsigned char buffer[64]; /*!< data block being processed */
  58. }
  59. mbedtls_md5_context;
  60. #else /* MBEDTLS_MD5_ALT */
  61. #include "md5_alt.h"
  62. #endif /* MBEDTLS_MD5_ALT */
  63. /**
  64. * \brief Initialize MD5 context
  65. *
  66. * \param ctx MD5 context to be initialized
  67. *
  68. * \warning MD5 is considered a weak message digest and its use
  69. * constitutes a security risk. We recommend considering
  70. * stronger message digests instead.
  71. *
  72. */
  73. void mbedtls_md5_init( mbedtls_md5_context *ctx );
  74. /**
  75. * \brief Clear MD5 context
  76. *
  77. * \param ctx MD5 context to be cleared
  78. *
  79. * \warning MD5 is considered a weak message digest and its use
  80. * constitutes a security risk. We recommend considering
  81. * stronger message digests instead.
  82. *
  83. */
  84. void mbedtls_md5_free( mbedtls_md5_context *ctx );
  85. /**
  86. * \brief Clone (the state of) an MD5 context
  87. *
  88. * \param dst The destination context
  89. * \param src The context to be cloned
  90. *
  91. * \warning MD5 is considered a weak message digest and its use
  92. * constitutes a security risk. We recommend considering
  93. * stronger message digests instead.
  94. *
  95. */
  96. void mbedtls_md5_clone( mbedtls_md5_context *dst,
  97. const mbedtls_md5_context *src );
  98. /**
  99. * \brief MD5 context setup
  100. *
  101. * \param ctx context to be initialized
  102. *
  103. * \return 0 if successful
  104. *
  105. * \warning MD5 is considered a weak message digest and its use
  106. * constitutes a security risk. We recommend considering
  107. * stronger message digests instead.
  108. *
  109. */
  110. int mbedtls_md5_starts_ret( mbedtls_md5_context *ctx );
  111. /**
  112. * \brief MD5 process buffer
  113. *
  114. * \param ctx MD5 context
  115. * \param input buffer holding the data
  116. * \param ilen length of the input data
  117. *
  118. * \return 0 if successful
  119. *
  120. * \warning MD5 is considered a weak message digest and its use
  121. * constitutes a security risk. We recommend considering
  122. * stronger message digests instead.
  123. *
  124. */
  125. int mbedtls_md5_update_ret( mbedtls_md5_context *ctx,
  126. const unsigned char *input,
  127. size_t ilen );
  128. /**
  129. * \brief MD5 final digest
  130. *
  131. * \param ctx MD5 context
  132. * \param output MD5 checksum result
  133. *
  134. * \return 0 if successful
  135. *
  136. * \warning MD5 is considered a weak message digest and its use
  137. * constitutes a security risk. We recommend considering
  138. * stronger message digests instead.
  139. *
  140. */
  141. int mbedtls_md5_finish_ret( mbedtls_md5_context *ctx,
  142. unsigned char output[16] );
  143. /**
  144. * \brief MD5 process data block (internal use only)
  145. *
  146. * \param ctx MD5 context
  147. * \param data buffer holding one block of data
  148. *
  149. * \return 0 if successful
  150. *
  151. * \warning MD5 is considered a weak message digest and its use
  152. * constitutes a security risk. We recommend considering
  153. * stronger message digests instead.
  154. *
  155. */
  156. int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
  157. const unsigned char data[64] );
  158. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  159. #if defined(MBEDTLS_DEPRECATED_WARNING)
  160. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  161. #else
  162. #define MBEDTLS_DEPRECATED
  163. #endif
  164. /**
  165. * \brief MD5 context setup
  166. *
  167. * \deprecated Superseded by mbedtls_md5_starts_ret() in 2.7.0
  168. *
  169. * \param ctx context to be initialized
  170. *
  171. * \warning MD5 is considered a weak message digest and its use
  172. * constitutes a security risk. We recommend considering
  173. * stronger message digests instead.
  174. *
  175. */
  176. MBEDTLS_DEPRECATED void mbedtls_md5_starts( mbedtls_md5_context *ctx );
  177. /**
  178. * \brief MD5 process buffer
  179. *
  180. * \deprecated Superseded by mbedtls_md5_update_ret() in 2.7.0
  181. *
  182. * \param ctx MD5 context
  183. * \param input buffer holding the data
  184. * \param ilen length of the input data
  185. *
  186. * \warning MD5 is considered a weak message digest and its use
  187. * constitutes a security risk. We recommend considering
  188. * stronger message digests instead.
  189. *
  190. */
  191. MBEDTLS_DEPRECATED void mbedtls_md5_update( mbedtls_md5_context *ctx,
  192. const unsigned char *input,
  193. size_t ilen );
  194. /**
  195. * \brief MD5 final digest
  196. *
  197. * \deprecated Superseded by mbedtls_md5_finish_ret() in 2.7.0
  198. *
  199. * \param ctx MD5 context
  200. * \param output MD5 checksum result
  201. *
  202. * \warning MD5 is considered a weak message digest and its use
  203. * constitutes a security risk. We recommend considering
  204. * stronger message digests instead.
  205. *
  206. */
  207. MBEDTLS_DEPRECATED void mbedtls_md5_finish( mbedtls_md5_context *ctx,
  208. unsigned char output[16] );
  209. /**
  210. * \brief MD5 process data block (internal use only)
  211. *
  212. * \deprecated Superseded by mbedtls_internal_md5_process() in 2.7.0
  213. *
  214. * \param ctx MD5 context
  215. * \param data buffer holding one block of data
  216. *
  217. * \warning MD5 is considered a weak message digest and its use
  218. * constitutes a security risk. We recommend considering
  219. * stronger message digests instead.
  220. *
  221. */
  222. MBEDTLS_DEPRECATED void mbedtls_md5_process( mbedtls_md5_context *ctx,
  223. const unsigned char data[64] );
  224. #undef MBEDTLS_DEPRECATED
  225. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  226. /**
  227. * \brief Output = MD5( input buffer )
  228. *
  229. * \param input buffer holding the data
  230. * \param ilen length of the input data
  231. * \param output MD5 checksum result
  232. *
  233. * \return 0 if successful
  234. *
  235. * \warning MD5 is considered a weak message digest and its use
  236. * constitutes a security risk. We recommend considering
  237. * stronger message digests instead.
  238. *
  239. */
  240. int mbedtls_md5_ret( const unsigned char *input,
  241. size_t ilen,
  242. unsigned char output[16] );
  243. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  244. #if defined(MBEDTLS_DEPRECATED_WARNING)
  245. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  246. #else
  247. #define MBEDTLS_DEPRECATED
  248. #endif
  249. /**
  250. * \brief Output = MD5( input buffer )
  251. *
  252. * \deprecated Superseded by mbedtls_md5_ret() in 2.7.0
  253. *
  254. * \param input buffer holding the data
  255. * \param ilen length of the input data
  256. * \param output MD5 checksum result
  257. *
  258. * \warning MD5 is considered a weak message digest and its use
  259. * constitutes a security risk. We recommend considering
  260. * stronger message digests instead.
  261. *
  262. */
  263. MBEDTLS_DEPRECATED void mbedtls_md5( const unsigned char *input,
  264. size_t ilen,
  265. unsigned char output[16] );
  266. #undef MBEDTLS_DEPRECATED
  267. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  268. #if defined(MBEDTLS_SELF_TEST)
  269. /**
  270. * \brief Checkup routine
  271. *
  272. * \return 0 if successful, or 1 if the test failed
  273. *
  274. * \warning MD5 is considered a weak message digest and its use
  275. * constitutes a security risk. We recommend considering
  276. * stronger message digests instead.
  277. *
  278. */
  279. int mbedtls_md5_self_test( int verbose );
  280. #endif /* MBEDTLS_SELF_TEST */
  281. #ifdef __cplusplus
  282. }
  283. #endif
  284. #endif /* mbedtls_md5.h */