hmac.h 2.0 KB

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