tiny_md5.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**
  2. * \file md5.h
  3. *
  4. * Based on TropicSSL: Copyright (C) 2017 Shanghai Real-Thread Technology Co., Ltd
  5. *
  6. * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
  7. *
  8. * Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * * Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. * * Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in the
  20. * documentation and/or other materials provided with the distribution.
  21. * * Neither the names of PolarSSL or XySSL nor the names of its contributors
  22. * may be used to endorse or promote products derived from this software
  23. * without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  28. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  30. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  31. * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  32. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  33. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. */
  37. #ifndef TINY_CRYPT_MD5_H__
  38. #define TINY_CRYPT_MD5_H__
  39. /**
  40. * \brief MD5 context structure
  41. */
  42. typedef struct {
  43. uint32_t total[2]; /*!< number of bytes processed */
  44. uint32_t state[4]; /*!< intermediate digest state */
  45. uint8_t buffer[64]; /*!< data block being processed */
  46. uint8_t ipad[64]; /*!< HMAC: inner padding */
  47. uint8_t opad[64]; /*!< HMAC: outer padding */
  48. } tiny_md5_context;
  49. #ifdef __cplusplus
  50. extern "C" {
  51. #endif
  52. /**
  53. * \brief MD5 context setup
  54. *
  55. * \param ctx context to be initialized
  56. */
  57. void tiny_md5_starts(tiny_md5_context * ctx);
  58. /**
  59. * \brief MD5 process buffer
  60. *
  61. * \param ctx MD5 context
  62. * \param input buffer holding the data
  63. * \param ilen length of the input data
  64. */
  65. void tiny_md5_update(tiny_md5_context * ctx, uint8_t *input, int ilen);
  66. /**
  67. * \brief MD5 final digest
  68. *
  69. * \param ctx MD5 context
  70. * \param output MD5 checksum result
  71. */
  72. void tiny_md5_finish(tiny_md5_context * ctx, uint8_t output[16]);
  73. /**
  74. * \brief Output = MD5( input buffer )
  75. *
  76. * \param input buffer holding the data
  77. * \param ilen length of the input data
  78. * \param output MD5 checksum result
  79. */
  80. void tiny_md5(uint8_t *input, int ilen, uint8_t output[16]);
  81. /**
  82. * \brief MD5 HMAC context setup
  83. *
  84. * \param ctx HMAC context to be initialized
  85. * \param key HMAC secret key
  86. * \param keylen length of the HMAC key
  87. */
  88. void tiny_md5_hmac_starts(tiny_md5_context * ctx, uint8_t *key, int keylen);
  89. /**
  90. * \brief MD5 HMAC process buffer
  91. *
  92. * \param ctx HMAC context
  93. * \param input buffer holding the data
  94. * \param ilen length of the input data
  95. */
  96. void tiny_md5_hmac_update(tiny_md5_context * ctx, uint8_t *input, int ilen);
  97. /**
  98. * \brief MD5 HMAC final digest
  99. *
  100. * \param ctx HMAC context
  101. * \param output MD5 HMAC checksum result
  102. */
  103. void tiny_md5_hmac_finish(tiny_md5_context * ctx, uint8_t output[16]);
  104. /**
  105. * \brief Output = HMAC-MD5( hmac key, input buffer )
  106. *
  107. * \param key HMAC secret key
  108. * \param keylen length of the HMAC key
  109. * \param input buffer holding the data
  110. * \param ilen length of the input data
  111. * \param output HMAC-MD5 result
  112. */
  113. void tiny_md5_hmac(uint8_t *key, int keylen,
  114. uint8_t *input, int ilen, uint8_t output[16]);
  115. #ifdef __cplusplus
  116. }
  117. #endif
  118. #endif /* md5.h */