Replaced Logger usage with LOG_x (#548)
This commit is contained in:
committed by
GitHub
parent
ecad2248d9
commit
9d5993930d
@@ -1,6 +1,6 @@
|
||||
#include <Tactility/crypt/Crypt.h>
|
||||
|
||||
#include <Tactility/Logger.h>
|
||||
#include <tactility/log.h>
|
||||
#include <tactility/check.h>
|
||||
|
||||
#include <mbedtls/aes.h>
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
namespace tt::crypt {
|
||||
|
||||
static const auto LOGGER = Logger("Crypt");
|
||||
constexpr auto* TAG = "Crypt";
|
||||
|
||||
#define TT_NVS_NAMESPACE "tt_secure"
|
||||
|
||||
@@ -28,7 +28,7 @@ static void get_hardware_key(uint8_t key[32]) {
|
||||
uint8_t mac[8];
|
||||
// MAC can be 6 or 8 bytes
|
||||
size_t mac_length = esp_mac_addr_len_get(ESP_MAC_EFUSE_FACTORY);
|
||||
LOGGER.info("Using MAC with length {}", mac_length);
|
||||
LOG_I(TAG, "Using MAC with length %u", (unsigned)mac_length);
|
||||
check(mac_length <= 8);
|
||||
ESP_ERROR_CHECK(esp_read_mac(mac, ESP_MAC_EFUSE_FACTORY));
|
||||
|
||||
@@ -67,13 +67,13 @@ static void get_nvs_key(uint8_t key[32]) {
|
||||
esp_err_t result = nvs_open(TT_NVS_NAMESPACE, NVS_READWRITE, &handle);
|
||||
|
||||
if (result != ESP_OK) {
|
||||
LOGGER.error("Failed to get key from NVS ({})", esp_err_to_name(result));
|
||||
LOG_E(TAG, "Failed to get key from NVS (%s)", esp_err_to_name(result));
|
||||
check(false, "NVS error");
|
||||
}
|
||||
|
||||
size_t length = 32;
|
||||
if (nvs_get_blob(handle, "key", key, &length) == ESP_OK) {
|
||||
LOGGER.info("Fetched key from NVS ({} bytes)", length);
|
||||
LOG_I(TAG, "Fetched key from NVS (%u bytes)", (unsigned)length);
|
||||
check(length == 32);
|
||||
} else {
|
||||
// TODO: Improved randomness
|
||||
@@ -84,7 +84,7 @@ static void get_nvs_key(uint8_t key[32]) {
|
||||
key[i] = (uint8_t)(rand());
|
||||
}
|
||||
ESP_ERROR_CHECK(nvs_set_blob(handle, "key", key, 32));
|
||||
LOGGER.info("Stored new key in NVS");
|
||||
LOG_I(TAG, "Stored new key in NVS");
|
||||
}
|
||||
|
||||
nvs_close(handle);
|
||||
@@ -110,8 +110,8 @@ static void xorKey(const uint8_t* inLeft, const uint8_t* inRight, uint8_t* out,
|
||||
*/
|
||||
static void getKey(uint8_t key[32]) {
|
||||
#if !defined(CONFIG_SECURE_BOOT) || !defined(CONFIG_SECURE_FLASH_ENC_ENABLED)
|
||||
LOGGER.warn("Using tt_secure_* code with secure boot and/or flash encryption disabled.");
|
||||
LOGGER.warn("An attacker with physical access to your ESP32 can decrypt your secure data.");
|
||||
LOG_W(TAG, "Using tt_secure_* code with secure boot and/or flash encryption disabled.");
|
||||
LOG_W(TAG, "An attacker with physical access to your ESP32 can decrypt your secure data.");
|
||||
#endif
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
@@ -122,7 +122,7 @@ static void getKey(uint8_t key[32]) {
|
||||
get_nvs_key(nvs_key);
|
||||
xorKey(hardware_key, nvs_key, key, 32);
|
||||
#else
|
||||
LOGGER.warn("Using unsafe key for debugging purposes.");
|
||||
LOG_W(TAG, "Using unsafe key for debugging purposes.");
|
||||
memset(key, 0, 32);
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user