hmac.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_HMAC_H_
  15. #define _ROM_HMAC_H_
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. #include <stdint.h>
  20. #include <stdlib.h>
  21. #include "efuse.h"
  22. void ets_hmac_enable(void);
  23. void ets_hmac_disable(void);
  24. /* Use the "upstream" HMAC key (ETS_EFUSE_KEY_PURPOSE_HMAC_UP)
  25. to digest a message.
  26. */
  27. int ets_hmac_calculate_message(ets_efuse_block_t key_block, const void *message, size_t message_len, uint8_t *hmac);
  28. /* Calculate a downstream HMAC message to temporarily enable JTAG, or
  29. to generate a Digital Signature data decryption key.
  30. - purpose must be ETS_EFUSE_KEY_PURPOSE_HMAC_DOWN_DIGITAL_SIGNATURE
  31. or ETS_EFUSE_KEY_PURPOSE_HMAC_DOWN_JTAG
  32. - key_block must be in range ETS_EFUSE_BLOCK_KEY0 toETS_EFUSE_BLOCK_KEY6.
  33. This efuse block must have the corresponding purpose set in "purpose", or
  34. ETS_EFUSE_KEY_PURPOSE_HMAC_DOWN_ALL.
  35. The result of this HMAC calculation is only made available "downstream" to the
  36. corresponding hardware module, and cannot be accessed by software.
  37. */
  38. int ets_hmac_calculate_downstream(ets_efuse_block_t key_block, ets_efuse_purpose_t purpose);
  39. /* Invalidate a downstream HMAC value previously calculated by ets_hmac_calculate_downstream().
  40. *
  41. * - purpose must match a previous call to ets_hmac_calculate_downstream().
  42. *
  43. * After this function is called, the corresponding internal operation (JTAG or DS) will no longer
  44. * have access to the generated key.
  45. */
  46. int ets_hmac_invalidate_downstream(ets_efuse_purpose_t purpose);
  47. #ifdef __cplusplus
  48. }
  49. #endif
  50. #endif // _ROM_HMAC_H_