Skip to content

Commit

Permalink
Add ICD CIP and DAC key slots for PSA
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejbaczmanski committed Aug 12, 2024
1 parent 5f5d696 commit 0f6de14
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/crypto/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ source_set("public_headers") {
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/core:types",
"${chip_root}/src/lib/support",
"${chip_root}/src/app/icd/server:icd-server-config",
"${nlassert_root}:nlassert",
]
}
Expand Down
20 changes: 17 additions & 3 deletions src/crypto/CHIPCryptoPALPSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#pragma once

#include "CHIPCryptoPAL.h"
#include <app/icd/server/ICDServerConfig.h>
#include <lib/core/DataModelTypes.h>
#include <lib/support/SafePointerCast.h>

Expand Down Expand Up @@ -55,14 +56,27 @@ namespace Crypto {
#define CHIP_CONFIG_CRYPTO_PSA_KEY_ID_BASE 0x30000
#endif // CHIP_CONFIG_CRYPTO_PSA_KEY_ID_BASE

#if CHIP_CONFIG_ENABLE_ICD_CIP
static constexpr uint32_t kMaxICDClientKeys = CHIP_CONFIG_ICD_CLIENTS_SUPPORTED_PER_FABRIC * CHIP_CONFIG_MAX_FABRICS;
#endif // CHIP_CONFIG_ENABLE_ICD_CIP

/**
* @brief Defines subranges of the PSA key identifier space used by Matter.
*/
enum class KeyIdBase : psa_key_id_t
{
Minimum = CHIP_CONFIG_CRYPTO_PSA_KEY_ID_BASE,
Operational = Minimum, ///< Base of the PSA key ID range for Node Operational Certificate private keys
Maximum = Operational + kMaxValidFabricIndex,
Minimum = CHIP_CONFIG_CRYPTO_PSA_KEY_ID_BASE,
Operational = Minimum, ///< Base of the PSA key ID range for Node Operational Certificate private keys
DACPrivKey = Operational + kMaxValidFabricIndex + 1,
#if CHIP_CONFIG_ENABLE_ICD_CIP
ICDHmacKeyRangeStart = DACPrivKey + 1,
ICDAesKeyRangeStart = ICDHmacKeyRangeStart + kMaxICDClientKeys,
ICDKeysRangeEnd = ICDAesKeyRangeStart + kMaxICDClientKeys,
#else
// If Check-In Protocol is disabled, set ICDKeysRangeEnd to previous key, to allow setting next key ID to `ICDKeysRangeEnd + 1`
ICDKeysRangeEnd = DACPrivKey,
#endif // CHIP_CONFIG_ENABLE_ICD_CIP
Maximum = ICDKeysRangeEnd,
};

static_assert(to_underlying(KeyIdBase::Minimum) >= PSA_KEY_ID_USER_MIN && to_underlying(KeyIdBase::Maximum) <= PSA_KEY_ID_USER_MAX,
Expand Down

0 comments on commit 0f6de14

Please sign in to comment.