hmac.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef _ROM_HMAC_H_
  7. #define _ROM_HMAC_H_
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #include <stdint.h>
  12. #include <stdlib.h>
  13. #include "efuse.h"
  14. void ets_hmac_enable(void);
  15. void ets_hmac_disable(void);
  16. /* Use the "upstream" HMAC key (ETS_EFUSE_KEY_PURPOSE_HMAC_UP)
  17. to digest a message.
  18. */
  19. int ets_hmac_calculate_message(ets_efuse_block_t key_block, const void *message, size_t message_len, uint8_t *hmac);
  20. /* Calculate a downstream HMAC message to temporarily enable JTAG, or
  21. to generate a Digital Signature data decryption key.
  22. - purpose must be ETS_EFUSE_KEY_PURPOSE_HMAC_DOWN_DIGITAL_SIGNATURE
  23. or ETS_EFUSE_KEY_PURPOSE_HMAC_DOWN_JTAG
  24. - key_block must be in range ETS_EFUSE_BLOCK_KEY0 toETS_EFUSE_BLOCK_KEY6.
  25. This efuse block must have the corresponding purpose set in "purpose", or
  26. ETS_EFUSE_KEY_PURPOSE_HMAC_DOWN_ALL.
  27. The result of this HMAC calculation is only made available "downstream" to the
  28. corresponding hardware module, and cannot be accessed by software.
  29. */
  30. int ets_hmac_calculate_downstream(ets_efuse_block_t key_block, ets_efuse_purpose_t purpose);
  31. /* Invalidate a downstream HMAC value previously calculated by ets_hmac_calculate_downstream().
  32. *
  33. * - purpose must match a previous call to ets_hmac_calculate_downstream().
  34. *
  35. * After this function is called, the corresponding internal operation (JTAG or DS) will no longer
  36. * have access to the generated key.
  37. */
  38. int ets_hmac_invalidate_downstream(ets_efuse_purpose_t purpose);
  39. #ifdef __cplusplus
  40. }
  41. #endif
  42. #endif // _ROM_HMAC_H_