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