sha.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. ROM functions for hardware SHA support.
  3. It is not recommended to use these functions directly. If using
  4. them from esp-idf then use the esp_sha_lock_engine() and
  5. esp_sha_lock_memory_block() functions in hwcrypto/sha.h to ensure
  6. exclusive access.
  7. */
  8. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  9. //
  10. // Licensed under the Apache License, Version 2.0 (the "License");
  11. // you may not use this file except in compliance with the License.
  12. // You may obtain a copy of the License at
  13. // http://www.apache.org/licenses/LICENSE-2.0
  14. //
  15. // Unless required by applicable law or agreed to in writing, software
  16. // distributed under the License is distributed on an "AS IS" BASIS,
  17. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. // See the License for the specific language governing permissions and
  19. // limitations under the License.
  20. #ifndef _ROM_SHA_H_
  21. #define _ROM_SHA_H_
  22. #include <stdint.h>
  23. #include <stdbool.h>
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. typedef struct SHAContext {
  28. bool start;
  29. uint32_t total_input_bits[4];
  30. } SHA_CTX;
  31. enum SHA_TYPE {
  32. SHA1 = 0,
  33. SHA2_256,
  34. SHA2_384,
  35. SHA2_512,
  36. SHA_INVALID = -1,
  37. };
  38. void ets_sha_init(SHA_CTX *ctx);
  39. void ets_sha_enable(void);
  40. void ets_sha_disable(void);
  41. void ets_sha_update(SHA_CTX *ctx, enum SHA_TYPE type, const uint8_t *input, size_t input_bits);
  42. void ets_sha_finish(SHA_CTX *ctx, enum SHA_TYPE type, uint8_t *output);
  43. #ifdef __cplusplus
  44. }
  45. #endif
  46. #endif /* _ROM_SHA_H_ */