1
0

md5.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * \file md5.h
  3. */
  4. #ifndef _MD5_H
  5. #define _MD5_H
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. /**
  10. * \brief MD5 context structure
  11. */
  12. typedef struct
  13. {
  14. unsigned long total[2]; /*!< number of bytes processed */
  15. unsigned long state[4]; /*!< intermediate digest state */
  16. unsigned char buffer[64]; /*!< data block being processed */
  17. unsigned char ipad[64]; /*!< HMAC: inner padding */
  18. unsigned char opad[64]; /*!< HMAC: outer padding */
  19. }
  20. md5_context;
  21. /**
  22. * \brief MD5 context setup
  23. *
  24. * \param ctx context to be initialized
  25. */
  26. void md5_starts( md5_context *ctx );
  27. /**
  28. * \brief MD5 process buffer
  29. *
  30. * \param ctx MD5 context
  31. * \param input buffer holding the data
  32. * \param ilen length of the input data
  33. */
  34. void md5_update( md5_context *ctx, unsigned char *input, int ilen );
  35. /**
  36. * \brief MD5 final digest
  37. *
  38. * \param ctx MD5 context
  39. * \param output MD5 checksum result
  40. */
  41. void md5_finish( md5_context *ctx, unsigned char *output );
  42. /**
  43. * \brief Output = MD5( input buffer )
  44. *
  45. * \param input buffer holding the data
  46. * \param ilen length of the input data
  47. * \param output MD5 checksum result
  48. */
  49. void md5( unsigned char *input, int ilen,
  50. unsigned char *output );
  51. /**
  52. * \brief Output = MD5( file contents )
  53. *
  54. * \param path input file name
  55. * \param output MD5 checksum result
  56. *
  57. * \return 0 if successful, 1 if fopen failed,
  58. * or 2 if fread failed
  59. */
  60. int md5_file( char *path, unsigned char *output );
  61. /**
  62. * \brief MD5 HMAC context setup
  63. *
  64. * \param ctx HMAC context to be initialized
  65. * \param key HMAC secret key
  66. * \param keylen length of the HMAC key
  67. */
  68. void md5_hmac_starts( md5_context *ctx,
  69. unsigned char *key, int keylen );
  70. /**
  71. * \brief MD5 HMAC process buffer
  72. *
  73. * \param ctx HMAC context
  74. * \param input buffer holding the data
  75. * \param ilen length of the input data
  76. */
  77. void md5_hmac_update( md5_context *ctx,
  78. unsigned char *input, int ilen );
  79. /**
  80. * \brief MD5 HMAC final digest
  81. *
  82. * \param ctx HMAC context
  83. * \param output MD5 HMAC checksum result
  84. */
  85. void md5_hmac_finish( md5_context *ctx, unsigned char *output );
  86. /**
  87. * \brief Output = HMAC-MD5( hmac key, input buffer )
  88. *
  89. * \param key HMAC secret key
  90. * \param keylen length of the HMAC key
  91. * \param input buffer holding the data
  92. * \param ilen length of the input data
  93. * \param output HMAC-MD5 result
  94. */
  95. void md5_hmac( unsigned char *key, int keylen,
  96. unsigned char *input, int ilen,
  97. unsigned char *output );
  98. /**
  99. * \brief Checkup routine
  100. *
  101. * \return 0 if successful, or 1 if the test failed
  102. */
  103. int md5_self_test( int verbose );
  104. #ifdef __cplusplus
  105. }
  106. #endif
  107. #endif /* md5.h */