utils_md5.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (C) 2012-2019 UCloud. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License").
  5. * You may not use this file except in compliance with the License.
  6. * A copy of the License is located at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * or in the "license" file accompanying this file. This file is distributed
  11. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  12. * express or implied. See the License for the specific language governing
  13. * permissions and limitations under the License.
  14. */
  15. #ifndef C_SDK_UTILS_MD5_H_
  16. #define C_SDK_UTILS_MD5_H_
  17. #include "uiot_import.h"
  18. typedef struct {
  19. uint32_t total[2]; /*!< number of bytes processed */
  20. uint32_t state[4]; /*!< intermediate digest state */
  21. unsigned char buffer[64]; /*!< data block being processed */
  22. } iot_md5_context;
  23. /**
  24. * @brief 初始化MD5上下文
  25. *
  26. * @param ctx MD5上下文指针
  27. */
  28. void utils_md5_init(iot_md5_context *ctx);
  29. /**
  30. * @brief 清空MD5上下文
  31. *
  32. * @param ctx MD5上下文指针
  33. */
  34. void utils_md5_free(iot_md5_context *ctx);
  35. /**
  36. * @brief 拷贝MD5上下文
  37. *
  38. * @param dst 目标MD5上下文
  39. * @param src 源MD5上下文
  40. */
  41. void utils_md5_clone(iot_md5_context *dst,
  42. const iot_md5_context *src);
  43. /**
  44. * @brief 设置MD5上下文
  45. *
  46. * @param ctx MD5上下文指针
  47. */
  48. void utils_md5_starts(iot_md5_context *ctx);
  49. /**
  50. * @brief MD5过程缓冲区
  51. *
  52. * @param ctx MD5上下文指针
  53. * @param input 输入数据
  54. * @param ilen 输入数据长度
  55. */
  56. void utils_md5_update(iot_md5_context *ctx, const unsigned char *input, size_t ilen);
  57. /**
  58. * @brief MD5数据
  59. *
  60. * @param ctx MD5上下文指针
  61. * @param output MD5校验和结果
  62. */
  63. void utils_md5_finish(iot_md5_context *ctx, unsigned char output[16]);
  64. /* 内部使用 */
  65. void utils_md5_process(iot_md5_context *ctx, const unsigned char data[64]);
  66. /**
  67. * @brief Output = MD5( input buffer )
  68. *
  69. * @param input 输入数据
  70. * @param ilen 输入数据长度
  71. * @param output MD5校验和结果
  72. */
  73. void utils_md5(const unsigned char *input, size_t ilen, unsigned char output[16]);
  74. int8_t utils_hb2hex(uint8_t hb);
  75. void utils_md5_finish_hb2hex(void *md5, char *output_str);
  76. #endif //C_SDK_UTILS_MD5_H_