utils_sha1.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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_SHA1_H_
  19. #define QCLOUD_IOT_UTILS_SHA1_H_
  20. #include "qcloud_iot_import.h"
  21. /**
  22. * \brief SHA-1 context structure
  23. */
  24. typedef struct {
  25. uint32_t total[2]; /*!< number of bytes processed */
  26. uint32_t state[5]; /*!< intermediate digest state */
  27. unsigned char buffer[64]; /*!< data block being processed */
  28. } iot_sha1_context;
  29. /**
  30. * \brief Initialize SHA-1 context
  31. *
  32. * \param ctx SHA-1 context to be initialized
  33. */
  34. void utils_sha1_init(iot_sha1_context *ctx);
  35. /**
  36. * \brief Clear SHA-1 context
  37. *
  38. * \param ctx SHA-1 context to be cleared
  39. */
  40. void utils_sha1_free(iot_sha1_context *ctx);
  41. /**
  42. * \brief Clone (the state of) a SHA-1 context
  43. *
  44. * \param dst The destination context
  45. * \param src The context to be cloned
  46. */
  47. void utils_sha1_clone(iot_sha1_context *dst, const iot_sha1_context *src);
  48. /**
  49. * \brief SHA-1 context setup
  50. *
  51. * \param ctx context to be initialized
  52. */
  53. void utils_sha1_starts(iot_sha1_context *ctx);
  54. /**
  55. * \brief SHA-1 process buffer
  56. *
  57. * \param ctx SHA-1 context
  58. * \param input buffer holding the data
  59. * \param ilen length of the input data
  60. */
  61. void utils_sha1_update(iot_sha1_context *ctx, const unsigned char *input, size_t ilen);
  62. /**
  63. * \brief SHA-1 final digest
  64. *
  65. * \param ctx SHA-1 context
  66. * \param output SHA-1 checksum result
  67. */
  68. void utils_sha1_finish(iot_sha1_context *ctx, unsigned char output[20]);
  69. /* Internal use */
  70. void utils_sha1_process(iot_sha1_context *ctx, const unsigned char data[64]);
  71. /**
  72. * \brief Output = SHA-1( input buffer )
  73. *
  74. * \param input buffer holding the data
  75. * \param ilen length of the input data
  76. * \param output SHA-1 checksum result
  77. */
  78. void utils_sha1(const unsigned char *input, size_t ilen, unsigned char output[20]);
  79. #endif