2
0

md2.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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 The Mbed TLS Contributors
  12. * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  13. *
  14. * This file is provided under the Apache License 2.0, or the
  15. * GNU General Public License v2.0 or later.
  16. *
  17. * **********
  18. * Apache License 2.0:
  19. *
  20. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  21. * not use this file except in compliance with the License.
  22. * You may obtain a copy of the License at
  23. *
  24. * http://www.apache.org/licenses/LICENSE-2.0
  25. *
  26. * Unless required by applicable law or agreed to in writing, software
  27. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  28. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  29. * See the License for the specific language governing permissions and
  30. * limitations under the License.
  31. *
  32. * **********
  33. *
  34. * **********
  35. * GNU General Public License v2.0 or later:
  36. *
  37. * This program is free software; you can redistribute it and/or modify
  38. * it under the terms of the GNU General Public License as published by
  39. * the Free Software Foundation; either version 2 of the License, or
  40. * (at your option) any later version.
  41. *
  42. * This program is distributed in the hope that it will be useful,
  43. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  44. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  45. * GNU General Public License for more details.
  46. *
  47. * You should have received a copy of the GNU General Public License along
  48. * with this program; if not, write to the Free Software Foundation, Inc.,
  49. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  50. *
  51. * **********
  52. *
  53. */
  54. #ifndef MBEDTLS_MD2_H
  55. #define MBEDTLS_MD2_H
  56. #if !defined(MBEDTLS_CONFIG_FILE)
  57. #include "config.h"
  58. #else
  59. #include MBEDTLS_CONFIG_FILE
  60. #endif
  61. #include <stddef.h>
  62. /* MBEDTLS_ERR_MD2_HW_ACCEL_FAILED is deprecated and should not be used. */
  63. #define MBEDTLS_ERR_MD2_HW_ACCEL_FAILED -0x002B /**< MD2 hardware accelerator failed */
  64. #ifdef __cplusplus
  65. extern "C" {
  66. #endif
  67. #if !defined(MBEDTLS_MD2_ALT)
  68. // Regular implementation
  69. //
  70. /**
  71. * \brief MD2 context structure
  72. *
  73. * \warning MD2 is considered a weak message digest and its use
  74. * constitutes a security risk. We recommend considering
  75. * stronger message digests instead.
  76. *
  77. */
  78. typedef struct mbedtls_md2_context
  79. {
  80. unsigned char cksum[16]; /*!< checksum of the data block */
  81. unsigned char state[48]; /*!< intermediate digest state */
  82. unsigned char buffer[16]; /*!< data block being processed */
  83. size_t left; /*!< amount of data in buffer */
  84. }
  85. mbedtls_md2_context;
  86. #else /* MBEDTLS_MD2_ALT */
  87. #include "md2_alt.h"
  88. #endif /* MBEDTLS_MD2_ALT */
  89. /**
  90. * \brief Initialize MD2 context
  91. *
  92. * \param ctx MD2 context to be initialized
  93. *
  94. * \warning MD2 is considered a weak message digest and its use
  95. * constitutes a security risk. We recommend considering
  96. * stronger message digests instead.
  97. *
  98. */
  99. void mbedtls_md2_init( mbedtls_md2_context *ctx );
  100. /**
  101. * \brief Clear MD2 context
  102. *
  103. * \param ctx MD2 context to be cleared
  104. *
  105. * \warning MD2 is considered a weak message digest and its use
  106. * constitutes a security risk. We recommend considering
  107. * stronger message digests instead.
  108. *
  109. */
  110. void mbedtls_md2_free( mbedtls_md2_context *ctx );
  111. /**
  112. * \brief Clone (the state of) an MD2 context
  113. *
  114. * \param dst The destination context
  115. * \param src The context to be cloned
  116. *
  117. * \warning MD2 is considered a weak message digest and its use
  118. * constitutes a security risk. We recommend considering
  119. * stronger message digests instead.
  120. *
  121. */
  122. void mbedtls_md2_clone( mbedtls_md2_context *dst,
  123. const mbedtls_md2_context *src );
  124. /**
  125. * \brief MD2 context setup
  126. *
  127. * \param ctx context to be initialized
  128. *
  129. * \return 0 if successful
  130. *
  131. * \warning MD2 is considered a weak message digest and its use
  132. * constitutes a security risk. We recommend considering
  133. * stronger message digests instead.
  134. *
  135. */
  136. int mbedtls_md2_starts_ret( mbedtls_md2_context *ctx );
  137. /**
  138. * \brief MD2 process buffer
  139. *
  140. * \param ctx MD2 context
  141. * \param input buffer holding the data
  142. * \param ilen length of the input data
  143. *
  144. * \return 0 if successful
  145. *
  146. * \warning MD2 is considered a weak message digest and its use
  147. * constitutes a security risk. We recommend considering
  148. * stronger message digests instead.
  149. *
  150. */
  151. int mbedtls_md2_update_ret( mbedtls_md2_context *ctx,
  152. const unsigned char *input,
  153. size_t ilen );
  154. /**
  155. * \brief MD2 final digest
  156. *
  157. * \param ctx MD2 context
  158. * \param output MD2 checksum result
  159. *
  160. * \return 0 if successful
  161. *
  162. * \warning MD2 is considered a weak message digest and its use
  163. * constitutes a security risk. We recommend considering
  164. * stronger message digests instead.
  165. *
  166. */
  167. int mbedtls_md2_finish_ret( mbedtls_md2_context *ctx,
  168. unsigned char output[16] );
  169. /**
  170. * \brief MD2 process data block (internal use only)
  171. *
  172. * \param ctx MD2 context
  173. *
  174. * \return 0 if successful
  175. *
  176. * \warning MD2 is considered a weak message digest and its use
  177. * constitutes a security risk. We recommend considering
  178. * stronger message digests instead.
  179. *
  180. */
  181. int mbedtls_internal_md2_process( mbedtls_md2_context *ctx );
  182. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  183. #if defined(MBEDTLS_DEPRECATED_WARNING)
  184. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  185. #else
  186. #define MBEDTLS_DEPRECATED
  187. #endif
  188. /**
  189. * \brief MD2 context setup
  190. *
  191. * \deprecated Superseded by mbedtls_md2_starts_ret() in 2.7.0
  192. *
  193. * \param ctx context to be initialized
  194. *
  195. * \warning MD2 is considered a weak message digest and its use
  196. * constitutes a security risk. We recommend considering
  197. * stronger message digests instead.
  198. *
  199. */
  200. MBEDTLS_DEPRECATED void mbedtls_md2_starts( mbedtls_md2_context *ctx );
  201. /**
  202. * \brief MD2 process buffer
  203. *
  204. * \deprecated Superseded by mbedtls_md2_update_ret() in 2.7.0
  205. *
  206. * \param ctx MD2 context
  207. * \param input buffer holding the data
  208. * \param ilen length of the input data
  209. *
  210. * \warning MD2 is considered a weak message digest and its use
  211. * constitutes a security risk. We recommend considering
  212. * stronger message digests instead.
  213. *
  214. */
  215. MBEDTLS_DEPRECATED void mbedtls_md2_update( mbedtls_md2_context *ctx,
  216. const unsigned char *input,
  217. size_t ilen );
  218. /**
  219. * \brief MD2 final digest
  220. *
  221. * \deprecated Superseded by mbedtls_md2_finish_ret() in 2.7.0
  222. *
  223. * \param ctx MD2 context
  224. * \param output MD2 checksum result
  225. *
  226. * \warning MD2 is considered a weak message digest and its use
  227. * constitutes a security risk. We recommend considering
  228. * stronger message digests instead.
  229. *
  230. */
  231. MBEDTLS_DEPRECATED void mbedtls_md2_finish( mbedtls_md2_context *ctx,
  232. unsigned char output[16] );
  233. /**
  234. * \brief MD2 process data block (internal use only)
  235. *
  236. * \deprecated Superseded by mbedtls_internal_md2_process() in 2.7.0
  237. *
  238. * \param ctx MD2 context
  239. *
  240. * \warning MD2 is considered a weak message digest and its use
  241. * constitutes a security risk. We recommend considering
  242. * stronger message digests instead.
  243. *
  244. */
  245. MBEDTLS_DEPRECATED void mbedtls_md2_process( mbedtls_md2_context *ctx );
  246. #undef MBEDTLS_DEPRECATED
  247. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  248. /**
  249. * \brief Output = MD2( input buffer )
  250. *
  251. * \param input buffer holding the data
  252. * \param ilen length of the input data
  253. * \param output MD2 checksum result
  254. *
  255. * \warning MD2 is considered a weak message digest and its use
  256. * constitutes a security risk. We recommend considering
  257. * stronger message digests instead.
  258. *
  259. */
  260. int mbedtls_md2_ret( const unsigned char *input,
  261. size_t ilen,
  262. unsigned char output[16] );
  263. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  264. #if defined(MBEDTLS_DEPRECATED_WARNING)
  265. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  266. #else
  267. #define MBEDTLS_DEPRECATED
  268. #endif
  269. /**
  270. * \brief Output = MD2( input buffer )
  271. *
  272. * \deprecated Superseded by mbedtls_md2_ret() in 2.7.0
  273. *
  274. * \param input buffer holding the data
  275. * \param ilen length of the input data
  276. * \param output MD2 checksum result
  277. *
  278. * \warning MD2 is considered a weak message digest and its use
  279. * constitutes a security risk. We recommend considering
  280. * stronger message digests instead.
  281. *
  282. */
  283. MBEDTLS_DEPRECATED void mbedtls_md2( const unsigned char *input,
  284. size_t ilen,
  285. unsigned char output[16] );
  286. #undef MBEDTLS_DEPRECATED
  287. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  288. #if defined(MBEDTLS_SELF_TEST)
  289. /**
  290. * \brief Checkup routine
  291. *
  292. * \return 0 if successful, or 1 if the test failed
  293. *
  294. * \warning MD2 is considered a weak message digest and its use
  295. * constitutes a security risk. We recommend considering
  296. * stronger message digests instead.
  297. *
  298. */
  299. int mbedtls_md2_self_test( int verbose );
  300. #endif /* MBEDTLS_SELF_TEST */
  301. #ifdef __cplusplus
  302. }
  303. #endif
  304. #endif /* mbedtls_md2.h */