md2.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
  39. !defined(inline) && !defined(__cplusplus)
  40. #define inline __inline
  41. #endif
  42. #if !defined(MBEDTLS_MD2_ALT)
  43. // Regular implementation
  44. //
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. /**
  49. * \brief MD2 context structure
  50. *
  51. * \warning MD2 is considered a weak message digest and its use
  52. * constitutes a security risk. We recommend considering
  53. * stronger message digests instead.
  54. *
  55. */
  56. typedef struct
  57. {
  58. unsigned char cksum[16]; /*!< checksum of the data block */
  59. unsigned char state[48]; /*!< intermediate digest state */
  60. unsigned char buffer[16]; /*!< data block being processed */
  61. size_t left; /*!< amount of data in buffer */
  62. }
  63. mbedtls_md2_context;
  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 static inline void mbedtls_md2_starts(
  176. mbedtls_md2_context *ctx )
  177. {
  178. mbedtls_md2_starts_ret( ctx );
  179. }
  180. /**
  181. * \brief MD2 process buffer
  182. *
  183. * \deprecated Superseded by mbedtls_md2_update_ret() in 2.7.0
  184. *
  185. * \param ctx MD2 context
  186. * \param input buffer holding the data
  187. * \param ilen length of the input data
  188. *
  189. * \warning MD2 is considered a weak message digest and its use
  190. * constitutes a security risk. We recommend considering
  191. * stronger message digests instead.
  192. *
  193. */
  194. MBEDTLS_DEPRECATED static inline void mbedtls_md2_update(
  195. mbedtls_md2_context *ctx,
  196. const unsigned char *input,
  197. size_t ilen )
  198. {
  199. mbedtls_md2_update_ret( ctx, input, ilen );
  200. }
  201. /**
  202. * \brief MD2 final digest
  203. *
  204. * \deprecated Superseded by mbedtls_md2_finish_ret() in 2.7.0
  205. *
  206. * \param ctx MD2 context
  207. * \param output MD2 checksum result
  208. *
  209. * \warning MD2 is considered a weak message digest and its use
  210. * constitutes a security risk. We recommend considering
  211. * stronger message digests instead.
  212. *
  213. */
  214. MBEDTLS_DEPRECATED static inline void mbedtls_md2_finish(
  215. mbedtls_md2_context *ctx,
  216. unsigned char output[16] )
  217. {
  218. mbedtls_md2_finish_ret( ctx, output );
  219. }
  220. /**
  221. * \brief MD2 process data block (internal use only)
  222. *
  223. * \deprecated Superseded by mbedtls_internal_md2_process() in 2.7.0
  224. *
  225. * \param ctx MD2 context
  226. *
  227. * \warning MD2 is considered a weak message digest and its use
  228. * constitutes a security risk. We recommend considering
  229. * stronger message digests instead.
  230. *
  231. */
  232. MBEDTLS_DEPRECATED static inline void mbedtls_md2_process(
  233. mbedtls_md2_context *ctx )
  234. {
  235. mbedtls_internal_md2_process( ctx );
  236. }
  237. #undef MBEDTLS_DEPRECATED
  238. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  239. #ifdef __cplusplus
  240. }
  241. #endif
  242. #else /* MBEDTLS_MD2_ALT */
  243. #include "md2_alt.h"
  244. #endif /* MBEDTLS_MD2_ALT */
  245. #ifdef __cplusplus
  246. extern "C" {
  247. #endif
  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 static inline void mbedtls_md2( const unsigned char *input,
  284. size_t ilen,
  285. unsigned char output[16] )
  286. {
  287. mbedtls_md2_ret( input, ilen, output );
  288. }
  289. #undef MBEDTLS_DEPRECATED
  290. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  291. /**
  292. * \brief Checkup routine
  293. *
  294. * \return 0 if successful, or 1 if the test failed
  295. *
  296. * \warning MD2 is considered a weak message digest and its use
  297. * constitutes a security risk. We recommend considering
  298. * stronger message digests instead.
  299. *
  300. */
  301. int mbedtls_md2_self_test( int verbose );
  302. #ifdef __cplusplus
  303. }
  304. #endif
  305. #endif /* mbedtls_md2.h */