md5.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. #define MBEDTLS_ERR_MD5_HW_ACCEL_FAILED -0x002F /**< MD5 hardware accelerator failed */
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. #if !defined(MBEDTLS_MD5_ALT)
  42. // Regular implementation
  43. //
  44. /**
  45. * \brief MD5 context structure
  46. *
  47. * \warning MD5 is considered a weak message digest and its use
  48. * constitutes a security risk. We recommend considering
  49. * stronger message digests instead.
  50. *
  51. */
  52. typedef struct
  53. {
  54. uint32_t total[2]; /*!< number of bytes processed */
  55. uint32_t state[4]; /*!< intermediate digest state */
  56. unsigned char buffer[64]; /*!< data block being processed */
  57. }
  58. mbedtls_md5_context;
  59. #else /* MBEDTLS_MD5_ALT */
  60. #include "md5_alt.h"
  61. #endif /* MBEDTLS_MD5_ALT */
  62. /**
  63. * \brief Initialize MD5 context
  64. *
  65. * \param ctx MD5 context to be initialized
  66. *
  67. * \warning MD5 is considered a weak message digest and its use
  68. * constitutes a security risk. We recommend considering
  69. * stronger message digests instead.
  70. *
  71. */
  72. void mbedtls_md5_init( mbedtls_md5_context *ctx );
  73. /**
  74. * \brief Clear MD5 context
  75. *
  76. * \param ctx MD5 context to be cleared
  77. *
  78. * \warning MD5 is considered a weak message digest and its use
  79. * constitutes a security risk. We recommend considering
  80. * stronger message digests instead.
  81. *
  82. */
  83. void mbedtls_md5_free( mbedtls_md5_context *ctx );
  84. /**
  85. * \brief Clone (the state of) an MD5 context
  86. *
  87. * \param dst The destination context
  88. * \param src The context to be cloned
  89. *
  90. * \warning MD5 is considered a weak message digest and its use
  91. * constitutes a security risk. We recommend considering
  92. * stronger message digests instead.
  93. *
  94. */
  95. void mbedtls_md5_clone( mbedtls_md5_context *dst,
  96. const mbedtls_md5_context *src );
  97. /**
  98. * \brief MD5 context setup
  99. *
  100. * \param ctx context to be initialized
  101. *
  102. * \return 0 if successful
  103. *
  104. * \warning MD5 is considered a weak message digest and its use
  105. * constitutes a security risk. We recommend considering
  106. * stronger message digests instead.
  107. *
  108. */
  109. int mbedtls_md5_starts_ret( mbedtls_md5_context *ctx );
  110. /**
  111. * \brief MD5 process buffer
  112. *
  113. * \param ctx MD5 context
  114. * \param input buffer holding the data
  115. * \param ilen length of the input data
  116. *
  117. * \return 0 if successful
  118. *
  119. * \warning MD5 is considered a weak message digest and its use
  120. * constitutes a security risk. We recommend considering
  121. * stronger message digests instead.
  122. *
  123. */
  124. int mbedtls_md5_update_ret( mbedtls_md5_context *ctx,
  125. const unsigned char *input,
  126. size_t ilen );
  127. /**
  128. * \brief MD5 final digest
  129. *
  130. * \param ctx MD5 context
  131. * \param output MD5 checksum result
  132. *
  133. * \return 0 if successful
  134. *
  135. * \warning MD5 is considered a weak message digest and its use
  136. * constitutes a security risk. We recommend considering
  137. * stronger message digests instead.
  138. *
  139. */
  140. int mbedtls_md5_finish_ret( mbedtls_md5_context *ctx,
  141. unsigned char output[16] );
  142. /**
  143. * \brief MD5 process data block (internal use only)
  144. *
  145. * \param ctx MD5 context
  146. * \param data buffer holding one block of data
  147. *
  148. * \return 0 if successful
  149. *
  150. * \warning MD5 is considered a weak message digest and its use
  151. * constitutes a security risk. We recommend considering
  152. * stronger message digests instead.
  153. *
  154. */
  155. int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
  156. const unsigned char data[64] );
  157. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  158. #if defined(MBEDTLS_DEPRECATED_WARNING)
  159. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  160. #else
  161. #define MBEDTLS_DEPRECATED
  162. #endif
  163. /**
  164. * \brief MD5 context setup
  165. *
  166. * \deprecated Superseded by mbedtls_md5_starts_ret() in 2.7.0
  167. *
  168. * \param ctx context to be initialized
  169. *
  170. * \warning MD5 is considered a weak message digest and its use
  171. * constitutes a security risk. We recommend considering
  172. * stronger message digests instead.
  173. *
  174. */
  175. MBEDTLS_DEPRECATED void mbedtls_md5_starts( mbedtls_md5_context *ctx );
  176. /**
  177. * \brief MD5 process buffer
  178. *
  179. * \deprecated Superseded by mbedtls_md5_update_ret() in 2.7.0
  180. *
  181. * \param ctx MD5 context
  182. * \param input buffer holding the data
  183. * \param ilen length of the input data
  184. *
  185. * \warning MD5 is considered a weak message digest and its use
  186. * constitutes a security risk. We recommend considering
  187. * stronger message digests instead.
  188. *
  189. */
  190. MBEDTLS_DEPRECATED void mbedtls_md5_update( mbedtls_md5_context *ctx,
  191. const unsigned char *input,
  192. size_t ilen );
  193. /**
  194. * \brief MD5 final digest
  195. *
  196. * \deprecated Superseded by mbedtls_md5_finish_ret() in 2.7.0
  197. *
  198. * \param ctx MD5 context
  199. * \param output MD5 checksum result
  200. *
  201. * \warning MD5 is considered a weak message digest and its use
  202. * constitutes a security risk. We recommend considering
  203. * stronger message digests instead.
  204. *
  205. */
  206. MBEDTLS_DEPRECATED void mbedtls_md5_finish( mbedtls_md5_context *ctx,
  207. unsigned char output[16] );
  208. /**
  209. * \brief MD5 process data block (internal use only)
  210. *
  211. * \deprecated Superseded by mbedtls_internal_md5_process() in 2.7.0
  212. *
  213. * \param ctx MD5 context
  214. * \param data buffer holding one block of data
  215. *
  216. * \warning MD5 is considered a weak message digest and its use
  217. * constitutes a security risk. We recommend considering
  218. * stronger message digests instead.
  219. *
  220. */
  221. MBEDTLS_DEPRECATED void mbedtls_md5_process( mbedtls_md5_context *ctx,
  222. const unsigned char data[64] );
  223. #undef MBEDTLS_DEPRECATED
  224. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  225. /**
  226. * \brief Output = MD5( input buffer )
  227. *
  228. * \param input buffer holding the data
  229. * \param ilen length of the input data
  230. * \param output MD5 checksum result
  231. *
  232. * \return 0 if successful
  233. *
  234. * \warning MD5 is considered a weak message digest and its use
  235. * constitutes a security risk. We recommend considering
  236. * stronger message digests instead.
  237. *
  238. */
  239. int mbedtls_md5_ret( const unsigned char *input,
  240. size_t ilen,
  241. unsigned char output[16] );
  242. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  243. #if defined(MBEDTLS_DEPRECATED_WARNING)
  244. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  245. #else
  246. #define MBEDTLS_DEPRECATED
  247. #endif
  248. /**
  249. * \brief Output = MD5( input buffer )
  250. *
  251. * \deprecated Superseded by mbedtls_md5_ret() in 2.7.0
  252. *
  253. * \param input buffer holding the data
  254. * \param ilen length of the input data
  255. * \param output MD5 checksum result
  256. *
  257. * \warning MD5 is considered a weak message digest and its use
  258. * constitutes a security risk. We recommend considering
  259. * stronger message digests instead.
  260. *
  261. */
  262. MBEDTLS_DEPRECATED void mbedtls_md5( const unsigned char *input,
  263. size_t ilen,
  264. unsigned char output[16] );
  265. #undef MBEDTLS_DEPRECATED
  266. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  267. /**
  268. * \brief Checkup routine
  269. *
  270. * \return 0 if successful, or 1 if the test failed
  271. *
  272. * \warning MD5 is considered a weak message digest and its use
  273. * constitutes a security risk. We recommend considering
  274. * stronger message digests instead.
  275. *
  276. */
  277. int mbedtls_md5_self_test( int verbose );
  278. #ifdef __cplusplus
  279. }
  280. #endif
  281. #endif /* mbedtls_md5.h */