public.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef __PUBLIC_H
  2. #define __PUBLIC_H
  3. #include "esp_err.h"
  4. #include "sdkconfig.h"
  5. #include <stddef.h>
  6. #include "esp_log.h"
  7. #define IOT_TRUE (1) /* indicate boolean value true */
  8. #define IOT_FALSE (0) /* indicate boolean value false */
  9. #include <stdint.h>
  10. #define SHA1_DIGEST_SIZE (20)
  11. /**
  12. * \brief SHA-1 context structure
  13. */
  14. typedef struct {
  15. uint32_t total[2]; /*!< number of bytes processed */
  16. uint32_t state[5]; /*!< intermediate digest state */
  17. unsigned char buffer[64]; /*!< data block being processed */
  18. } iot_sha1_context;
  19. /**
  20. * \brief Initialize SHA-1 context
  21. *
  22. * \param ctx SHA-1 context to be initialized
  23. */
  24. void utils_sha1_init(iot_sha1_context *ctx);
  25. /**
  26. * \brief Clear SHA-1 context
  27. *
  28. * \param ctx SHA-1 context to be cleared
  29. */
  30. void utils_sha1_free(iot_sha1_context *ctx);
  31. /**
  32. * \brief Clone (the state of) a SHA-1 context
  33. *
  34. * \param dst The destination context
  35. * \param src The context to be cloned
  36. */
  37. void utils_sha1_clone(iot_sha1_context *dst,
  38. const iot_sha1_context *src);
  39. /**
  40. * \brief SHA-1 context setup
  41. *
  42. * \param ctx context to be initialized
  43. */
  44. void utils_sha1_starts(iot_sha1_context *ctx);
  45. /**
  46. * \brief SHA-1 process buffer
  47. *
  48. * \param ctx SHA-1 context
  49. * \param input buffer holding the data
  50. * \param ilen length of the input data
  51. */
  52. void utils_sha1_update(iot_sha1_context *ctx, const unsigned char *input, uint32_t ilen);
  53. /**
  54. * \brief SHA-1 final digest
  55. *
  56. * \param ctx SHA-1 context
  57. * \param output SHA-1 checksum result
  58. */
  59. void utils_sha1_finish(iot_sha1_context *ctx, unsigned char output[20]);
  60. /* Internal use */
  61. void utils_sha1_process(iot_sha1_context *ctx, const unsigned char data[64]);
  62. /**
  63. * \brief Output = SHA-1( input buffer )
  64. *
  65. * \param input buffer holding the data
  66. * \param ilen length of the input data
  67. * \param output SHA-1 checksum result
  68. */
  69. void utils_sha1(const unsigned char *input, uint32_t ilen, unsigned char output[20]);
  70. void utils_hmac_sha1(const char *msg, int msg_len, char *digest, const char *key, int key_len);
  71. void utils_hmac_sha1_hex(const char *msg, int msg_len, char *digest, const char *key, int key_len);
  72. #endif