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