md4.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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 (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. */
  29. #ifndef MBEDTLS_MD4_H
  30. #define MBEDTLS_MD4_H
  31. #if !defined(MBEDTLS_CONFIG_FILE)
  32. #include "config.h"
  33. #else
  34. #include MBEDTLS_CONFIG_FILE
  35. #endif
  36. #include <stddef.h>
  37. #include <stdint.h>
  38. /* MBEDTLS_ERR_MD4_HW_ACCEL_FAILED is deprecated and should not be used. */
  39. #define MBEDTLS_ERR_MD4_HW_ACCEL_FAILED -0x002D /**< MD4 hardware accelerator failed */
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. #if !defined(MBEDTLS_MD4_ALT)
  44. // Regular implementation
  45. //
  46. /**
  47. * \brief MD4 context structure
  48. *
  49. * \warning MD4 is considered a weak message digest and its use
  50. * constitutes a security risk. We recommend considering
  51. * stronger message digests instead.
  52. *
  53. */
  54. typedef struct mbedtls_md4_context
  55. {
  56. uint32_t total[2]; /*!< number of bytes processed */
  57. uint32_t state[4]; /*!< intermediate digest state */
  58. unsigned char buffer[64]; /*!< data block being processed */
  59. }
  60. mbedtls_md4_context;
  61. #else /* MBEDTLS_MD4_ALT */
  62. #include "md4_alt.h"
  63. #endif /* MBEDTLS_MD4_ALT */
  64. /**
  65. * \brief Initialize MD4 context
  66. *
  67. * \param ctx MD4 context to be initialized
  68. *
  69. * \warning MD4 is considered a weak message digest and its use
  70. * constitutes a security risk. We recommend considering
  71. * stronger message digests instead.
  72. *
  73. */
  74. void mbedtls_md4_init( mbedtls_md4_context *ctx );
  75. /**
  76. * \brief Clear MD4 context
  77. *
  78. * \param ctx MD4 context to be cleared
  79. *
  80. * \warning MD4 is considered a weak message digest and its use
  81. * constitutes a security risk. We recommend considering
  82. * stronger message digests instead.
  83. *
  84. */
  85. void mbedtls_md4_free( mbedtls_md4_context *ctx );
  86. /**
  87. * \brief Clone (the state of) an MD4 context
  88. *
  89. * \param dst The destination context
  90. * \param src The context to be cloned
  91. *
  92. * \warning MD4 is considered a weak message digest and its use
  93. * constitutes a security risk. We recommend considering
  94. * stronger message digests instead.
  95. *
  96. */
  97. void mbedtls_md4_clone( mbedtls_md4_context *dst,
  98. const mbedtls_md4_context *src );
  99. /**
  100. * \brief MD4 context setup
  101. *
  102. * \param ctx context to be initialized
  103. *
  104. * \return 0 if successful
  105. *
  106. * \warning MD4 is considered a weak message digest and its use
  107. * constitutes a security risk. We recommend considering
  108. * stronger message digests instead.
  109. */
  110. int mbedtls_md4_starts_ret( mbedtls_md4_context *ctx );
  111. /**
  112. * \brief MD4 process buffer
  113. *
  114. * \param ctx MD4 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 MD4 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_md4_update_ret( mbedtls_md4_context *ctx,
  126. const unsigned char *input,
  127. size_t ilen );
  128. /**
  129. * \brief MD4 final digest
  130. *
  131. * \param ctx MD4 context
  132. * \param output MD4 checksum result
  133. *
  134. * \return 0 if successful
  135. *
  136. * \warning MD4 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_md4_finish_ret( mbedtls_md4_context *ctx,
  142. unsigned char output[16] );
  143. /**
  144. * \brief MD4 process data block (internal use only)
  145. *
  146. * \param ctx MD4 context
  147. * \param data buffer holding one block of data
  148. *
  149. * \return 0 if successful
  150. *
  151. * \warning MD4 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_md4_process( mbedtls_md4_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 MD4 context setup
  166. *
  167. * \deprecated Superseded by mbedtls_md4_starts_ret() in 2.7.0
  168. *
  169. * \param ctx context to be initialized
  170. *
  171. * \warning MD4 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_md4_starts( mbedtls_md4_context *ctx );
  177. /**
  178. * \brief MD4 process buffer
  179. *
  180. * \deprecated Superseded by mbedtls_md4_update_ret() in 2.7.0
  181. *
  182. * \param ctx MD4 context
  183. * \param input buffer holding the data
  184. * \param ilen length of the input data
  185. *
  186. * \warning MD4 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_md4_update( mbedtls_md4_context *ctx,
  192. const unsigned char *input,
  193. size_t ilen );
  194. /**
  195. * \brief MD4 final digest
  196. *
  197. * \deprecated Superseded by mbedtls_md4_finish_ret() in 2.7.0
  198. *
  199. * \param ctx MD4 context
  200. * \param output MD4 checksum result
  201. *
  202. * \warning MD4 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_md4_finish( mbedtls_md4_context *ctx,
  208. unsigned char output[16] );
  209. /**
  210. * \brief MD4 process data block (internal use only)
  211. *
  212. * \deprecated Superseded by mbedtls_internal_md4_process() in 2.7.0
  213. *
  214. * \param ctx MD4 context
  215. * \param data buffer holding one block of data
  216. *
  217. * \warning MD4 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_md4_process( mbedtls_md4_context *ctx,
  223. const unsigned char data[64] );
  224. #undef MBEDTLS_DEPRECATED
  225. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  226. /**
  227. * \brief Output = MD4( input buffer )
  228. *
  229. * \param input buffer holding the data
  230. * \param ilen length of the input data
  231. * \param output MD4 checksum result
  232. *
  233. * \return 0 if successful
  234. *
  235. * \warning MD4 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_md4_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 = MD4( input buffer )
  251. *
  252. * \deprecated Superseded by mbedtls_md4_ret() in 2.7.0
  253. *
  254. * \param input buffer holding the data
  255. * \param ilen length of the input data
  256. * \param output MD4 checksum result
  257. *
  258. * \warning MD4 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_md4( 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 MD4 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_md4_self_test( int verbose );
  280. #endif /* MBEDTLS_SELF_TEST */
  281. #ifdef __cplusplus
  282. }
  283. #endif
  284. #endif /* mbedtls_md4.h */