sha.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2020 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef _ROM_SHA_H_
  15. #define _ROM_SHA_H_
  16. #include <stdint.h>
  17. #include <stdbool.h>
  18. #include "ets_sys.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. typedef enum {
  23. SHA1 = 0,
  24. SHA2_224,
  25. SHA2_256,
  26. SHA_TYPE_MAX
  27. } SHA_TYPE;
  28. typedef struct SHAContext {
  29. bool start;
  30. bool in_hardware; // Is this context currently in peripheral? Needs to be manually cleared if multiple SHAs are interleaved
  31. SHA_TYPE type;
  32. uint32_t state[16]; // For SHA1/SHA224/SHA256, used 8, other used 16
  33. unsigned char buffer[128]; // For SHA1/SHA224/SHA256, used 64, other used 128
  34. uint32_t total_bits[4];
  35. } SHA_CTX;
  36. void ets_sha_enable(void);
  37. void ets_sha_disable(void);
  38. ets_status_t ets_sha_init(SHA_CTX *ctx, SHA_TYPE type);
  39. ets_status_t ets_sha_starts(SHA_CTX *ctx, uint16_t sha512_t);
  40. void ets_sha_get_state(SHA_CTX *ctx);
  41. void ets_sha_process(SHA_CTX *ctx, const unsigned char *input);
  42. void ets_sha_update(SHA_CTX *ctx, const unsigned char *input, uint32_t input_bytes, bool update_ctx);
  43. ets_status_t ets_sha_finish(SHA_CTX *ctx, unsigned char *output);
  44. #ifdef __cplusplus
  45. }
  46. #endif
  47. #endif /* _ROM_SHA_H_ */