md4.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. #define MBEDTLS_ERR_MD4_HW_ACCEL_FAILED -0x002D /**< MD4 hardware accelerator failed */
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. #if !defined(MBEDTLS_MD4_ALT)
  43. // Regular implementation
  44. //
  45. /**
  46. * \brief MD4 context structure
  47. *
  48. * \warning MD4 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
  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_md4_context;
  60. #else /* MBEDTLS_MD4_ALT */
  61. #include "md4_alt.h"
  62. #endif /* MBEDTLS_MD4_ALT */
  63. /**
  64. * \brief Initialize MD4 context
  65. *
  66. * \param ctx MD4 context to be initialized
  67. *
  68. * \warning MD4 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_md4_init( mbedtls_md4_context *ctx );
  74. /**
  75. * \brief Clear MD4 context
  76. *
  77. * \param ctx MD4 context to be cleared
  78. *
  79. * \warning MD4 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_md4_free( mbedtls_md4_context *ctx );
  85. /**
  86. * \brief Clone (the state of) an MD4 context
  87. *
  88. * \param dst The destination context
  89. * \param src The context to be cloned
  90. *
  91. * \warning MD4 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_md4_clone( mbedtls_md4_context *dst,
  97. const mbedtls_md4_context *src );
  98. /**
  99. * \brief MD4 context setup
  100. *
  101. * \param ctx context to be initialized
  102. *
  103. * \return 0 if successful
  104. *
  105. * \warning MD4 is considered a weak message digest and its use
  106. * constitutes a security risk. We recommend considering
  107. * stronger message digests instead.
  108. */
  109. int mbedtls_md4_starts_ret( mbedtls_md4_context *ctx );
  110. /**
  111. * \brief MD4 process buffer
  112. *
  113. * \param ctx MD4 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 MD4 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_md4_update_ret( mbedtls_md4_context *ctx,
  125. const unsigned char *input,
  126. size_t ilen );
  127. /**
  128. * \brief MD4 final digest
  129. *
  130. * \param ctx MD4 context
  131. * \param output MD4 checksum result
  132. *
  133. * \return 0 if successful
  134. *
  135. * \warning MD4 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_md4_finish_ret( mbedtls_md4_context *ctx,
  141. unsigned char output[16] );
  142. /**
  143. * \brief MD4 process data block (internal use only)
  144. *
  145. * \param ctx MD4 context
  146. * \param data buffer holding one block of data
  147. *
  148. * \return 0 if successful
  149. *
  150. * \warning MD4 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_md4_process( mbedtls_md4_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 MD4 context setup
  165. *
  166. * \deprecated Superseded by mbedtls_md4_starts_ret() in 2.7.0
  167. *
  168. * \param ctx context to be initialized
  169. *
  170. * \warning MD4 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_md4_starts( mbedtls_md4_context *ctx );
  176. /**
  177. * \brief MD4 process buffer
  178. *
  179. * \deprecated Superseded by mbedtls_md4_update_ret() in 2.7.0
  180. *
  181. * \param ctx MD4 context
  182. * \param input buffer holding the data
  183. * \param ilen length of the input data
  184. *
  185. * \warning MD4 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_md4_update( mbedtls_md4_context *ctx,
  191. const unsigned char *input,
  192. size_t ilen );
  193. /**
  194. * \brief MD4 final digest
  195. *
  196. * \deprecated Superseded by mbedtls_md4_finish_ret() in 2.7.0
  197. *
  198. * \param ctx MD4 context
  199. * \param output MD4 checksum result
  200. *
  201. * \warning MD4 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_md4_finish( mbedtls_md4_context *ctx,
  207. unsigned char output[16] );
  208. /**
  209. * \brief MD4 process data block (internal use only)
  210. *
  211. * \deprecated Superseded by mbedtls_internal_md4_process() in 2.7.0
  212. *
  213. * \param ctx MD4 context
  214. * \param data buffer holding one block of data
  215. *
  216. * \warning MD4 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_md4_process( mbedtls_md4_context *ctx,
  222. const unsigned char data[64] );
  223. #undef MBEDTLS_DEPRECATED
  224. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  225. /**
  226. * \brief Output = MD4( input buffer )
  227. *
  228. * \param input buffer holding the data
  229. * \param ilen length of the input data
  230. * \param output MD4 checksum result
  231. *
  232. * \return 0 if successful
  233. *
  234. * \warning MD4 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_md4_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 = MD4( input buffer )
  250. *
  251. * \deprecated Superseded by mbedtls_md4_ret() in 2.7.0
  252. *
  253. * \param input buffer holding the data
  254. * \param ilen length of the input data
  255. * \param output MD4 checksum result
  256. *
  257. * \warning MD4 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_md4( 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 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. #ifdef __cplusplus
  279. }
  280. #endif
  281. #endif /* mbedtls_md4.h */