Skip to content

Commit 3dbcd79

Browse files
committed
Add efuse based data to salt
1 parent a1aac45 commit 3dbcd79

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

wled00/util.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "soc/rtc.h"
1313
#endif
1414
#include "mbedtls/sha1.h" // for SHA1 on ESP32
15+
#include "esp_efuse.h"
1516
#endif
1617

1718

@@ -1154,6 +1155,35 @@ String computeSHA1(const String& input) {
11541155
#endif
11551156
}
11561157

1158+
#ifdef ESP32
1159+
static String dump_raw_block(esp_efuse_block_t block)
1160+
{
1161+
const int WORDS = 8; // ESP32: 8×32-bit words per block i.e. 256bits
1162+
uint32_t buf[WORDS] = {0};
1163+
1164+
const esp_efuse_desc_t d = {
1165+
.efuse_block = block,
1166+
.bit_start = 0,
1167+
.bit_count = WORDS * 32
1168+
};
1169+
const esp_efuse_desc_t* field[2] = { &d, NULL };
1170+
1171+
esp_err_t err = esp_efuse_read_field_blob(field, buf, WORDS * 32);
1172+
if (err != ESP_OK) {
1173+
return "";
1174+
}
1175+
1176+
String result = "";
1177+
for (const unsigned int i : buf) {
1178+
char line[32];
1179+
sprintf(line, "0x%08X", i);
1180+
result += line;
1181+
}
1182+
return result;
1183+
}
1184+
#endif
1185+
1186+
11571187
// Generate a device ID based on SHA1 hash of MAC address salted with "WLED"
11581188
// Returns: original SHA1 + last 2 chars of double-hashed SHA1 (42 chars total)
11591189
String getDeviceId() {
@@ -1173,7 +1203,11 @@ String getDeviceId() {
11731203
#ifdef ESP8266
11741204
String deviceString = String(macStr) + "WLED" + ESP.getChipId();
11751205
#else
1176-
String deviceString = String(macStr) + "WLED" + ESP.getChipModel() + ESP.getChipRevision() + ESP.getEfuseMac();
1206+
String deviceString = String(macStr) + "WLED" + ESP.getChipModel() + ESP.getChipRevision();
1207+
deviceString += dump_raw_block(EFUSE_BLK0);
1208+
deviceString += dump_raw_block(EFUSE_BLK1);
1209+
deviceString += dump_raw_block(EFUSE_BLK2);
1210+
deviceString += dump_raw_block(EFUSE_BLK3);
11771211
#endif
11781212
String firstHash = computeSHA1(deviceString);
11791213

0 commit comments

Comments
 (0)