sha.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef _ROM_SHA_H_
  7. #define _ROM_SHA_H_
  8. #include <stdint.h>
  9. #include <stdbool.h>
  10. #include "ets_sys.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. typedef enum {
  15. SHA1 = 0,
  16. SHA2_224,
  17. SHA2_256,
  18. SHA_TYPE_MAX
  19. } SHA_TYPE;
  20. typedef struct SHAContext {
  21. bool start;
  22. bool in_hardware; // Is this context currently in peripheral? Needs to be manually cleared if multiple SHAs are interleaved
  23. SHA_TYPE type;
  24. uint32_t state[16]; // For SHA1/SHA224/SHA256, used 8, other used 16
  25. unsigned char buffer[128]; // For SHA1/SHA224/SHA256, used 64, other used 128
  26. uint32_t total_bits[4];
  27. } SHA_CTX;
  28. void ets_sha_enable(void);
  29. void ets_sha_disable(void);
  30. ets_status_t ets_sha_init(SHA_CTX *ctx, SHA_TYPE type);
  31. ets_status_t ets_sha_starts(SHA_CTX *ctx, uint16_t sha512_t);
  32. void ets_sha_get_state(SHA_CTX *ctx);
  33. void ets_sha_process(SHA_CTX *ctx, const unsigned char *input);
  34. void ets_sha_update(SHA_CTX *ctx, const unsigned char *input, uint32_t input_bytes, bool update_ctx);
  35. ets_status_t ets_sha_finish(SHA_CTX *ctx, unsigned char *output);
  36. #ifdef __cplusplus
  37. }
  38. #endif
  39. #endif /* _ROM_SHA_H_ */