md4.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /**
  2. * \file md4.h
  3. *
  4. * \brief MD4 message digest algorithm (hash function)
  5. *
  6. * \warning MD4 is considered a weak message digest and its use constitutes a
  7. * security risk. We recommend considering stronger message digests
  8. * instead.
  9. */
  10. /*
  11. * Copyright The Mbed TLS Contributors
  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. */
  27. #ifndef MBEDTLS_MD4_H
  28. #define MBEDTLS_MD4_H
  29. #if !defined(MBEDTLS_CONFIG_FILE)
  30. #include "mbedtls/config.h"
  31. #else
  32. #include MBEDTLS_CONFIG_FILE
  33. #endif
  34. #include <stddef.h>
  35. #include <stdint.h>
  36. /* MBEDTLS_ERR_MD4_HW_ACCEL_FAILED is deprecated and should not be used. */
  37. #define MBEDTLS_ERR_MD4_HW_ACCEL_FAILED -0x002D /**< MD4 hardware accelerator failed */
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. #if !defined(MBEDTLS_MD4_ALT)
  42. // Regular implementation
  43. //
  44. /**
  45. * \brief MD4 context structure
  46. *
  47. * \warning MD4 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 mbedtls_md4_context
  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_md4_context;
  59. #else /* MBEDTLS_MD4_ALT */
  60. #include "md4_alt.h"
  61. #endif /* MBEDTLS_MD4_ALT */
  62. /**
  63. * \brief Initialize MD4 context
  64. *
  65. * \param ctx MD4 context to be initialized
  66. *
  67. * \warning MD4 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_md4_init( mbedtls_md4_context *ctx );
  73. /**
  74. * \brief Clear MD4 context
  75. *
  76. * \param ctx MD4 context to be cleared
  77. *
  78. * \warning MD4 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_md4_free( mbedtls_md4_context *ctx );
  84. /**
  85. * \brief Clone (the state of) an MD4 context
  86. *
  87. * \param dst The destination context
  88. * \param src The context to be cloned
  89. *
  90. * \warning MD4 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_md4_clone( mbedtls_md4_context *dst,
  96. const mbedtls_md4_context *src );
  97. /**
  98. * \brief MD4 context setup
  99. *
  100. * \param ctx context to be initialized
  101. *
  102. * \return 0 if successful
  103. *
  104. * \warning MD4 is considered a weak message digest and its use
  105. * constitutes a security risk. We recommend considering
  106. * stronger message digests instead.
  107. */
  108. int mbedtls_md4_starts_ret( mbedtls_md4_context *ctx );
  109. /**
  110. * \brief MD4 process buffer
  111. *
  112. * \param ctx MD4 context
  113. * \param input buffer holding the data
  114. * \param ilen length of the input data
  115. *
  116. * \return 0 if successful
  117. *
  118. * \warning MD4 is considered a weak message digest and its use
  119. * constitutes a security risk. We recommend considering
  120. * stronger message digests instead.
  121. *
  122. */
  123. int mbedtls_md4_update_ret( mbedtls_md4_context *ctx,
  124. const unsigned char *input,
  125. size_t ilen );
  126. /**
  127. * \brief MD4 final digest
  128. *
  129. * \param ctx MD4 context
  130. * \param output MD4 checksum result
  131. *
  132. * \return 0 if successful
  133. *
  134. * \warning MD4 is considered a weak message digest and its use
  135. * constitutes a security risk. We recommend considering
  136. * stronger message digests instead.
  137. *
  138. */
  139. int mbedtls_md4_finish_ret( mbedtls_md4_context *ctx,
  140. unsigned char output[16] );
  141. /**
  142. * \brief MD4 process data block (internal use only)
  143. *
  144. * \param ctx MD4 context
  145. * \param data buffer holding one block of data
  146. *
  147. * \return 0 if successful
  148. *
  149. * \warning MD4 is considered a weak message digest and its use
  150. * constitutes a security risk. We recommend considering
  151. * stronger message digests instead.
  152. *
  153. */
  154. int mbedtls_internal_md4_process( mbedtls_md4_context *ctx,
  155. const unsigned char data[64] );
  156. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  157. #if defined(MBEDTLS_DEPRECATED_WARNING)
  158. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  159. #else
  160. #define MBEDTLS_DEPRECATED
  161. #endif
  162. /**
  163. * \brief MD4 context setup
  164. *
  165. * \deprecated Superseded by mbedtls_md4_starts_ret() in 2.7.0
  166. *
  167. * \param ctx context to be initialized
  168. *
  169. * \warning MD4 is considered a weak message digest and its use
  170. * constitutes a security risk. We recommend considering
  171. * stronger message digests instead.
  172. *
  173. */
  174. MBEDTLS_DEPRECATED void mbedtls_md4_starts( mbedtls_md4_context *ctx );
  175. /**
  176. * \brief MD4 process buffer
  177. *
  178. * \deprecated Superseded by mbedtls_md4_update_ret() in 2.7.0
  179. *
  180. * \param ctx MD4 context
  181. * \param input buffer holding the data
  182. * \param ilen length of the input data
  183. *
  184. * \warning MD4 is considered a weak message digest and its use
  185. * constitutes a security risk. We recommend considering
  186. * stronger message digests instead.
  187. *
  188. */
  189. MBEDTLS_DEPRECATED void mbedtls_md4_update( mbedtls_md4_context *ctx,
  190. const unsigned char *input,
  191. size_t ilen );
  192. /**
  193. * \brief MD4 final digest
  194. *
  195. * \deprecated Superseded by mbedtls_md4_finish_ret() in 2.7.0
  196. *
  197. * \param ctx MD4 context
  198. * \param output MD4 checksum result
  199. *
  200. * \warning MD4 is considered a weak message digest and its use
  201. * constitutes a security risk. We recommend considering
  202. * stronger message digests instead.
  203. *
  204. */
  205. MBEDTLS_DEPRECATED void mbedtls_md4_finish( mbedtls_md4_context *ctx,
  206. unsigned char output[16] );
  207. /**
  208. * \brief MD4 process data block (internal use only)
  209. *
  210. * \deprecated Superseded by mbedtls_internal_md4_process() in 2.7.0
  211. *
  212. * \param ctx MD4 context
  213. * \param data buffer holding one block of data
  214. *
  215. * \warning MD4 is considered a weak message digest and its use
  216. * constitutes a security risk. We recommend considering
  217. * stronger message digests instead.
  218. *
  219. */
  220. MBEDTLS_DEPRECATED void mbedtls_md4_process( mbedtls_md4_context *ctx,
  221. const unsigned char data[64] );
  222. #undef MBEDTLS_DEPRECATED
  223. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  224. /**
  225. * \brief Output = MD4( input buffer )
  226. *
  227. * \param input buffer holding the data
  228. * \param ilen length of the input data
  229. * \param output MD4 checksum result
  230. *
  231. * \return 0 if successful
  232. *
  233. * \warning MD4 is considered a weak message digest and its use
  234. * constitutes a security risk. We recommend considering
  235. * stronger message digests instead.
  236. *
  237. */
  238. int mbedtls_md4_ret( const unsigned char *input,
  239. size_t ilen,
  240. unsigned char output[16] );
  241. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  242. #if defined(MBEDTLS_DEPRECATED_WARNING)
  243. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  244. #else
  245. #define MBEDTLS_DEPRECATED
  246. #endif
  247. /**
  248. * \brief Output = MD4( input buffer )
  249. *
  250. * \deprecated Superseded by mbedtls_md4_ret() in 2.7.0
  251. *
  252. * \param input buffer holding the data
  253. * \param ilen length of the input data
  254. * \param output MD4 checksum result
  255. *
  256. * \warning MD4 is considered a weak message digest and its use
  257. * constitutes a security risk. We recommend considering
  258. * stronger message digests instead.
  259. *
  260. */
  261. MBEDTLS_DEPRECATED void mbedtls_md4( const unsigned char *input,
  262. size_t ilen,
  263. unsigned char output[16] );
  264. #undef MBEDTLS_DEPRECATED
  265. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  266. #if defined(MBEDTLS_SELF_TEST)
  267. /**
  268. * \brief Checkup routine
  269. *
  270. * \return 0 if successful, or 1 if the test failed
  271. *
  272. * \warning MD4 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_md4_self_test( int verbose );
  278. #endif /* MBEDTLS_SELF_TEST */
  279. #ifdef __cplusplus
  280. }
  281. #endif
  282. #endif /* mbedtls_md4.h */