utils_md5.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Tencent is pleased to support the open source community by making IoT Hub
  3. available.
  4. * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
  5. * Licensed under the MIT License (the "License"); you may not use this file
  6. except in
  7. * compliance with the License. You may obtain a copy of the License at
  8. * http://opensource.org/licenses/MIT
  9. * Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is
  11. * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  12. KIND,
  13. * either express or implied. See the License for the specific language
  14. governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #ifndef QCLOUD_IOT_UTILS_MD5_H_
  19. #define QCLOUD_IOT_UTILS_MD5_H_
  20. #include "qcloud_iot_import.h"
  21. typedef struct {
  22. uint32_t total[2]; /*!< number of bytes processed */
  23. uint32_t state[4]; /*!< intermediate digest state */
  24. unsigned char buffer[64]; /*!< data block being processed */
  25. } iot_md5_context;
  26. /**
  27. * @brief init MD5 context
  28. *
  29. * @param ctx MD5 context
  30. */
  31. void utils_md5_init(iot_md5_context *ctx);
  32. /**
  33. * @brief free MD5 context
  34. *
  35. * @param ctx MD5 context
  36. */
  37. void utils_md5_free(iot_md5_context *ctx);
  38. /**
  39. * @brief clone MD5 context
  40. *
  41. * @param dst destination MD5 context
  42. * @param src source MD5 context
  43. */
  44. void utils_md5_clone(iot_md5_context *dst, const iot_md5_context *src);
  45. /**
  46. * @brief start MD5 calculation
  47. *
  48. * @param ctx MD5 context
  49. */
  50. void utils_md5_starts(iot_md5_context *ctx);
  51. /**
  52. * @brief MD5 update
  53. *
  54. * @param ctx MD5 context
  55. * @param input input data
  56. * @param ilen data length
  57. */
  58. void utils_md5_update(iot_md5_context *ctx, const unsigned char *input, size_t ilen);
  59. /**
  60. * @brief finish MD5 calculation
  61. *
  62. * @param ctx MD5 context
  63. * @param output MD5 result
  64. */
  65. void utils_md5_finish(iot_md5_context *ctx, unsigned char output[16]);
  66. /* MD5 internal process */
  67. void utils_md5_process(iot_md5_context *ctx, const unsigned char data[64]);
  68. /**
  69. * @brief Output = MD5( input buffer )
  70. *
  71. * @param input data input
  72. * @param ilen data lenght
  73. * @param output MD5 result
  74. */
  75. void utils_md5(const unsigned char *input, size_t ilen, unsigned char output[16]);
  76. /**
  77. * @brief Output = MD5( input buffer )
  78. *
  79. * @param input data input
  80. * @param ilen data lenght
  81. * @param output string MD5 result
  82. */
  83. void utils_md5_str(const unsigned char *input, size_t ilen, unsigned char *output);
  84. int8_t utils_hb2hex(uint8_t hb);
  85. #endif