utils_sha1.h 3.5 KB

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