Skip to content

Commit f565fc2

Browse files
committed
change(nvs_flash): Add a private dependency of the nvs_sec_provider component
- Closes #17256
1 parent f60bcaa commit f565fc2

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

components/nvs_flash/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ if(BOOTLOADER_BUILD)
77
"src/nvs_bootloader_xts_aes.c")
88

99
set(requires "esp_partition")
10+
set(priv_requires "mbedtls" "nvs_sec_provider")
1011

1112
idf_component_register(SRCS "${srcs}"
1213
REQUIRES "${requires}"
13-
PRIV_REQUIRES "mbedtls"
14+
PRIV_REQUIRES "${priv_requires}"
1415
INCLUDE_DIRS "include"
1516
PRIV_INCLUDE_DIRS "private_include"
1617
)
@@ -60,10 +61,9 @@ else()
6061
"src/nvs_bootloader.c")
6162

6263
set(requires esp_partition)
63-
if(${target} STREQUAL "linux")
64-
set(priv_requires spi_flash)
65-
else()
66-
set(priv_requires spi_flash esp_libc esptool_py)
64+
set(priv_requires spi_flash)
65+
if(NOT ${target} STREQUAL "linux")
66+
list(APPEND priv_requires esp_libc esptool_py nvs_sec_provider)
6767
endif()
6868

6969
idf_component_register(SRCS "${srcs}"

components/nvs_sec_provider/CMakeLists.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ if(${target} STREQUAL "linux")
44
return() # This component is not supported by the POSIX/Linux simulator
55
endif()
66

7-
if(BOOTLOADER_BUILD)
8-
set(srcs "nvs_bootloader_sec_provider.c")
9-
else()
10-
set(srcs "nvs_sec_provider.c")
7+
if(NOT CONFIG_NVS_SEC_KEY_PROTECT_NONE)
8+
if(BOOTLOADER_BUILD)
9+
set(srcs "nvs_bootloader_sec_provider.c")
10+
else()
11+
set(srcs "nvs_sec_provider.c")
12+
endif()
1113
endif()
1214

1315
idf_component_register(SRCS ${srcs}
@@ -22,4 +24,6 @@ idf_component_register(SRCS ${srcs}
2224
# Thus, the symbols from this component are not placed in the .map file and
2325
# hence the constructor, which initialises the encryption scheme for the default
2426
# NVS partition, never executes. The following is a workaround for the same.
25-
target_link_libraries(${COMPONENT_LIB} PRIVATE "-u nvs_sec_provider_include_impl")
27+
if(NOT CONFIG_NVS_SEC_KEY_PROTECT_NONE)
28+
target_link_libraries(${COMPONENT_LIB} PRIVATE "-u nvs_sec_provider_include_impl")
29+
endif()

components/nvs_sec_provider/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ menu "NVS Security Provider"
2727
Requires the specified eFuse block (NVS_SEC_HMAC_EFUSE_KEY_ID or the v2 API argument)
2828
to be empty or pre-written with a key with the purpose ESP_EFUSE_KEY_PURPOSE_HMAC_UP
2929

30+
config NVS_SEC_KEY_PROTECT_NONE
31+
bool "None"
32+
help
33+
Select this option if key derivation/protection is handled by
34+
a custom implementation, and not by the nvs_sec_provider component.
35+
3036
endchoice
3137

3238
config NVS_SEC_HMAC_EFUSE_KEY_ID

docs/en/api-reference/storage/nvs_encryption.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ The component :component:`nvs_sec_provider` stores all the implementation-specif
219219

220220
This component offers factory functions with which a particular security scheme can be registered without having to worry about the APIs to generate and read the encryption keys (e.g., :cpp:func:`nvs_sec_provider_register_hmac`). Refer to the :example:`security/nvs_encryption_hmac` example for API usage.
221221

222+
.. note::
223+
224+
To use a custom implementation for NVS encryption key derivation or protection (instead of the ones provided by the :component:`nvs_sec_provider` component), select the :ref:`CONFIG_NVS_SEC_KEY_PROTECTION_SCHEME` -> ``CONFIG_NVS_SEC_KEY_PROTECT_NONE`` configuration option.
222225

223226
API Reference
224227
-------------

0 commit comments

Comments
 (0)