sha.h 1.8 KB

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