md2.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /**
  2. * \file md2.h
  3. *
  4. * \brief MD2 message digest algorithm (hash function)
  5. *
  6. * \warning MD2 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_MD2_H
  30. #define MBEDTLS_MD2_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. /* MBEDTLS_ERR_MD2_HW_ACCEL_FAILED is deprecated and should not be used. */
  38. #define MBEDTLS_ERR_MD2_HW_ACCEL_FAILED -0x002B /**< MD2 hardware accelerator failed */
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. #if !defined(MBEDTLS_MD2_ALT)
  43. // Regular implementation
  44. //
  45. /**
  46. * \brief MD2 context structure
  47. *
  48. * \warning MD2 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_md2_context
  54. {
  55. unsigned char cksum[16]; /*!< checksum of the data block */
  56. unsigned char state[48]; /*!< intermediate digest state */
  57. unsigned char buffer[16]; /*!< data block being processed */
  58. size_t left; /*!< amount of data in buffer */
  59. }
  60. mbedtls_md2_context;
  61. #else /* MBEDTLS_MD2_ALT */
  62. #include "md2_alt.h"
  63. #endif /* MBEDTLS_MD2_ALT */
  64. /**
  65. * \brief Initialize MD2 context
  66. *
  67. * \param ctx MD2 context to be initialized
  68. *
  69. * \warning MD2 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_md2_init( mbedtls_md2_context *ctx );
  75. /**
  76. * \brief Clear MD2 context
  77. *
  78. * \param ctx MD2 context to be cleared
  79. *
  80. * \warning MD2 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_md2_free( mbedtls_md2_context *ctx );
  86. /**
  87. * \brief Clone (the state of) an MD2 context
  88. *
  89. * \param dst The destination context
  90. * \param src The context to be cloned
  91. *
  92. * \warning MD2 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_md2_clone( mbedtls_md2_context *dst,
  98. const mbedtls_md2_context *src );
  99. /**
  100. * \brief MD2 context setup
  101. *
  102. * \param ctx context to be initialized
  103. *
  104. * \return 0 if successful
  105. *
  106. * \warning MD2 is considered a weak message digest and its use
  107. * constitutes a security risk. We recommend considering
  108. * stronger message digests instead.
  109. *
  110. */
  111. int mbedtls_md2_starts_ret( mbedtls_md2_context *ctx );
  112. /**
  113. * \brief MD2 process buffer
  114. *
  115. * \param ctx MD2 context
  116. * \param input buffer holding the data
  117. * \param ilen length of the input data
  118. *
  119. * \return 0 if successful
  120. *
  121. * \warning MD2 is considered a weak message digest and its use
  122. * constitutes a security risk. We recommend considering
  123. * stronger message digests instead.
  124. *
  125. */
  126. int mbedtls_md2_update_ret( mbedtls_md2_context *ctx,
  127. const unsigned char *input,
  128. size_t ilen );
  129. /**
  130. * \brief MD2 final digest
  131. *
  132. * \param ctx MD2 context
  133. * \param output MD2 checksum result
  134. *
  135. * \return 0 if successful
  136. *
  137. * \warning MD2 is considered a weak message digest and its use
  138. * constitutes a security risk. We recommend considering
  139. * stronger message digests instead.
  140. *
  141. */
  142. int mbedtls_md2_finish_ret( mbedtls_md2_context *ctx,
  143. unsigned char output[16] );
  144. /**
  145. * \brief MD2 process data block (internal use only)
  146. *
  147. * \param ctx MD2 context
  148. *
  149. * \return 0 if successful
  150. *
  151. * \warning MD2 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_md2_process( mbedtls_md2_context *ctx );
  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 MD2 context setup
  165. *
  166. * \deprecated Superseded by mbedtls_md2_starts_ret() in 2.7.0
  167. *
  168. * \param ctx context to be initialized
  169. *
  170. * \warning MD2 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_md2_starts( mbedtls_md2_context *ctx );
  176. /**
  177. * \brief MD2 process buffer
  178. *
  179. * \deprecated Superseded by mbedtls_md2_update_ret() in 2.7.0
  180. *
  181. * \param ctx MD2 context
  182. * \param input buffer holding the data
  183. * \param ilen length of the input data
  184. *
  185. * \warning MD2 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_md2_update( mbedtls_md2_context *ctx,
  191. const unsigned char *input,
  192. size_t ilen );
  193. /**
  194. * \brief MD2 final digest
  195. *
  196. * \deprecated Superseded by mbedtls_md2_finish_ret() in 2.7.0
  197. *
  198. * \param ctx MD2 context
  199. * \param output MD2 checksum result
  200. *
  201. * \warning MD2 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_md2_finish( mbedtls_md2_context *ctx,
  207. unsigned char output[16] );
  208. /**
  209. * \brief MD2 process data block (internal use only)
  210. *
  211. * \deprecated Superseded by mbedtls_internal_md2_process() in 2.7.0
  212. *
  213. * \param ctx MD2 context
  214. *
  215. * \warning MD2 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_md2_process( mbedtls_md2_context *ctx );
  221. #undef MBEDTLS_DEPRECATED
  222. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  223. /**
  224. * \brief Output = MD2( input buffer )
  225. *
  226. * \param input buffer holding the data
  227. * \param ilen length of the input data
  228. * \param output MD2 checksum result
  229. *
  230. * \warning MD2 is considered a weak message digest and its use
  231. * constitutes a security risk. We recommend considering
  232. * stronger message digests instead.
  233. *
  234. */
  235. int mbedtls_md2_ret( const unsigned char *input,
  236. size_t ilen,
  237. unsigned char output[16] );
  238. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  239. #if defined(MBEDTLS_DEPRECATED_WARNING)
  240. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  241. #else
  242. #define MBEDTLS_DEPRECATED
  243. #endif
  244. /**
  245. * \brief Output = MD2( input buffer )
  246. *
  247. * \deprecated Superseded by mbedtls_md2_ret() in 2.7.0
  248. *
  249. * \param input buffer holding the data
  250. * \param ilen length of the input data
  251. * \param output MD2 checksum result
  252. *
  253. * \warning MD2 is considered a weak message digest and its use
  254. * constitutes a security risk. We recommend considering
  255. * stronger message digests instead.
  256. *
  257. */
  258. MBEDTLS_DEPRECATED void mbedtls_md2( const unsigned char *input,
  259. size_t ilen,
  260. unsigned char output[16] );
  261. #undef MBEDTLS_DEPRECATED
  262. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  263. #if defined(MBEDTLS_SELF_TEST)
  264. /**
  265. * \brief Checkup routine
  266. *
  267. * \return 0 if successful, or 1 if the test failed
  268. *
  269. * \warning MD2 is considered a weak message digest and its use
  270. * constitutes a security risk. We recommend considering
  271. * stronger message digests instead.
  272. *
  273. */
  274. int mbedtls_md2_self_test( int verbose );
  275. #endif /* MBEDTLS_SELF_TEST */
  276. #ifdef __cplusplus
  277. }
  278. #endif
  279. #endif /* mbedtls_md2.h */