hmac.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2018 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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef _ROM_HMAC_H_
  14. #define _ROM_HMAC_H_
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include <stdint.h>
  19. #include <stdlib.h>
  20. #include "efuse.h"
  21. void ets_hmac_enable(void);
  22. void ets_hmac_disable(void);
  23. /* Use the "upstream" HMAC key (ETS_EFUSE_KEY_PURPOSE_HMAC_UP)
  24. to digest a message.
  25. */
  26. int ets_hmac_calculate_message(ets_efuse_block_t key_block, const void *message, size_t message_len, uint8_t *hmac);
  27. /* Calculate a downstream HMAC message to temporarily enable JTAG, or
  28. to generate a Digital Signature data decryption key.
  29. - purpose must be ETS_EFUSE_KEY_PURPOSE_HMAC_DOWN_DIGITAL_SIGNATURE
  30. or ETS_EFUSE_KEY_PURPOSE_HMAC_DOWN_JTAG
  31. - key_block must be in range ETS_EFUSE_BLOCK_KEY0 toETS_EFUSE_BLOCK_KEY6.
  32. This efuse block must have the corresponding purpose set in "purpose", or
  33. ETS_EFUSE_KEY_PURPOSE_HMAC_DOWN_ALL.
  34. The result of this HMAC calculation is only made available "downstream" to the
  35. corresponding hardware module, and cannot be accessed by software.
  36. */
  37. int ets_hmac_calculate_downstream(ets_efuse_block_t key_block, ets_efuse_purpose_t purpose);
  38. /* Invalidate a downstream HMAC value previously calculated by ets_hmac_calculate_downstream().
  39. *
  40. * - purpose must match a previous call to ets_hmac_calculate_downstream().
  41. *
  42. * After this function is called, the corresponding internal operation (JTAG or DS) will no longer
  43. * have access to the generated key.
  44. */
  45. int ets_hmac_invalidate_downstream(ets_efuse_purpose_t purpose);
  46. #ifdef __cplusplus
  47. }
  48. #endif
  49. #endif // _ROM_HMAC_H_