sha.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 esp32/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. #include <stddef.h>
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. typedef struct SHAContext {
  29. bool start;
  30. uint32_t total_input_bits[4];
  31. } SHA_CTX;
  32. enum SHA_TYPE {
  33. SHA1 = 0,
  34. SHA2_256,
  35. SHA2_384,
  36. SHA2_512,
  37. SHA_INVALID = -1,
  38. };
  39. /* Do not use these function in multi core mode due to
  40. * inside they have no safe implementation (without DPORT workaround).
  41. */
  42. void ets_sha_init(SHA_CTX *ctx);
  43. void ets_sha_enable(void);
  44. void ets_sha_disable(void);
  45. void ets_sha_update(SHA_CTX *ctx, enum SHA_TYPE type, const uint8_t *input, size_t input_bits);
  46. void ets_sha_finish(SHA_CTX *ctx, enum SHA_TYPE type, uint8_t *output);
  47. #ifdef __cplusplus
  48. }
  49. #endif
  50. #endif /* _ROM_SHA_H_ */