md5.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * category: [algorithm]
  3. * apply status:
  4. * edit status:
  5. * build status:
  6. * description:
  7. */
  8. #ifndef __MD5_H__
  9. #define __MD5_H__
  10. #pragma once
  11. #include "config.h"
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #include <stdlib.h>
  16. #include <stdint.h>
  17. #define MD5_DIGESTSIZE 16
  18. typedef struct md5_ctx_t md5_ctx_t;
  19. /** MD5 context. */
  20. struct md5_ctx_t {
  21. /** state (ABCD) */
  22. uint32_t state[4];
  23. /** number of bits, modulo 2^64 (lsb first) */
  24. uint32_t count[2];
  25. /** input buffer */
  26. unsigned char buffer[64];
  27. };
  28. TOOLKIT_API int md5_init(md5_ctx_t *context);
  29. /**
  30. * MD5 block update operation. Continue an MD5 message-digest operation,
  31. * processing another message block, and updating the context.
  32. * @param context The MD5 content to update.
  33. * @param input next message block to update
  34. * @param inputLen The length of the next message block
  35. */
  36. TOOLKIT_API int md5_update(md5_ctx_t *context,const void *input,size_t inputLen);
  37. /**
  38. * MD5 finalization. Ends an MD5 message-digest operation, writing the
  39. * message digest and zeroing the context
  40. * @param digest The final MD5 digest
  41. * @param context The MD5 content we are finalizing.
  42. */
  43. TOOLKIT_API int md5_final(unsigned char digest[MD5_DIGESTSIZE],md5_ctx_t *context);
  44. /**
  45. * MD5 in one step
  46. * @param digest The final MD5 digest
  47. * @param input The message block to use
  48. * @param inputLen The length of the message block
  49. */
  50. TOOLKIT_API int md5(unsigned char digest[MD5_DIGESTSIZE],const void *input,size_t inputLen);
  51. #ifdef __cplusplus
  52. } // extern "C" {
  53. #endif
  54. #endif // __MD5_H__