sha.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #include "ets_sys.h"
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. typedef enum {
  29. SHA1 = 0,
  30. SHA2_224,
  31. SHA2_256,
  32. SHA2_384,
  33. SHA2_512,
  34. SHA2_512224,
  35. SHA2_512256,
  36. SHA2_512T,
  37. SHA_TYPE_MAX
  38. } SHA_TYPE;
  39. typedef struct SHAContext {
  40. bool start;
  41. bool in_hardware; // Is this context currently in peripheral? Needs to be manually cleared if multiple SHAs are interleaved
  42. SHA_TYPE type;
  43. uint32_t state[16]; // For SHA1/SHA224/SHA256, used 8, other used 16
  44. unsigned char buffer[128]; // For SHA1/SHA224/SHA256, used 64, other used 128
  45. uint32_t total_bits[4];
  46. } SHA_CTX;
  47. void ets_sha_enable(void);
  48. void ets_sha_disable(void);
  49. ets_status_t ets_sha_init(SHA_CTX *ctx, SHA_TYPE type);
  50. ets_status_t ets_sha_starts(SHA_CTX *ctx, uint16_t sha512_t);
  51. void ets_sha_get_state(SHA_CTX *ctx);
  52. void ets_sha_process(SHA_CTX *ctx, const unsigned char *input);
  53. void ets_sha_update(SHA_CTX *ctx, const unsigned char *input, uint32_t input_bytes, bool update_ctx);
  54. ets_status_t ets_sha_finish(SHA_CTX *ctx, unsigned char *output);
  55. #ifdef __cplusplus
  56. }
  57. #endif
  58. #endif /* _ROM_SHA_H_ */