md2.h 8.9 KB

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