utils_md5.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (c) 2016-2022 Bouffalolab.
  3. *
  4. * This file is part of
  5. * *** Bouffalolab Software Dev Kit ***
  6. * (see www.bouffalolab.com).
  7. *
  8. * Redistribution and use in source and binary forms, with or without modification,
  9. * are permitted provided that the following conditions are met:
  10. * 1. Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright notice,
  13. * this list of conditions and the following disclaimer in the documentation
  14. * and/or other materials provided with the distribution.
  15. * 3. Neither the name of Bouffalo Lab nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  25. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  26. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  27. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef _IOTX_COMMON_MD5_H_
  31. #define _IOTX_COMMON_MD5_H_
  32. #include "iot_import.h"
  33. typedef struct {
  34. uint32_t total[2]; /*!< number of bytes processed */
  35. uint32_t state[4]; /*!< intermediate digest state */
  36. unsigned char buffer[64]; /*!< data block being processed */
  37. } iot_md5_context;
  38. /**
  39. * \brief Initialize MD5 context
  40. *
  41. * \param ctx MD5 context to be initialized
  42. */
  43. void utils_md5_init(iot_md5_context *ctx);
  44. /**
  45. * \brief Clear MD5 context
  46. *
  47. * \param ctx MD5 context to be cleared
  48. */
  49. void utils_md5_free(iot_md5_context *ctx);
  50. /**
  51. * \brief Clone (the state of) an MD5 context
  52. *
  53. * \param dst The destination context
  54. * \param src The context to be cloned
  55. */
  56. void utils_md5_clone(iot_md5_context *dst,
  57. const iot_md5_context *src);
  58. /**
  59. * \brief MD5 context setup
  60. *
  61. * \param ctx context to be initialized
  62. */
  63. void utils_md5_starts(iot_md5_context *ctx);
  64. /**
  65. * \brief MD5 process buffer
  66. *
  67. * \param ctx MD5 context
  68. * \param input buffer holding the data
  69. * \param ilen length of the input data
  70. */
  71. void utils_md5_update(iot_md5_context *ctx, const unsigned char *input, size_t ilen);
  72. /**
  73. * \brief MD5 final digest
  74. *
  75. * \param ctx MD5 context
  76. * \param output MD5 checksum result
  77. */
  78. void utils_md5_finish(iot_md5_context *ctx, unsigned char output[16]);
  79. /* Internal use */
  80. void utils_md5_process(iot_md5_context *ctx, const unsigned char data[64]);
  81. /**
  82. * \brief Output = MD5( input buffer )
  83. *
  84. * \param input buffer holding the data
  85. * \param ilen length of the input data
  86. * \param output MD5 checksum result
  87. */
  88. void utils_md5(const unsigned char *input, size_t ilen, unsigned char output[16]);
  89. #endif