Skip to content

Commit

Permalink
[spinel] use local variables to export mac key before sending over SP…
Browse files Browse the repository at this point in the history
…INEL (openthread#9536)

In RadioSpinel::SetMacKey we try to reuse the otMacKey passed to
export the literal key from PSA to be sent over SPINEL to RCP. But as
the passed param is const, we cant really use this. Better option is
to extract it into a local buffer and use that to pass the keys to
RCP.
  • Loading branch information
hemanth-silabs authored Oct 17, 2023
1 parent cd5768b commit 6bfe59d
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/lib/spinel/radio_spinel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,35 +884,43 @@ otError RadioSpinel::SetMacKey(uint8_t aKeyIdMode,
const otMacKeyMaterial *aCurrKey,
const otMacKeyMaterial *aNextKey)
{
otError error;
size_t aKeySize;
otError error;
size_t aKeySize;
otMacKey prevKey;
otMacKey currKey;
otMacKey nextKey;

VerifyOrExit((aPrevKey != nullptr) && (aCurrKey != nullptr) && (aNextKey != nullptr), error = kErrorInvalidArgs);

#if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
SuccessOrExit(error = otPlatCryptoExportKey(aPrevKey->mKeyMaterial.mKeyRef, aPrevKey->mKeyMaterial.mKey.m8,
sizeof(aPrevKey->mKeyMaterial.mKey.m8), &aKeySize));
SuccessOrExit(error = otPlatCryptoExportKey(aCurrKey->mKeyMaterial.mKeyRef, aCurrKey->mKeyMaterial.mKey.m8,
sizeof(aCurrKey->mKeyMaterial.mKey.m8), &aKeySize));
SuccessOrExit(error = otPlatCryptoExportKey(aNextKey->mKeyMaterial.mKeyRef, aNextKey->mKeyMaterial.mKey.m8,
sizeof(aNextKey->mKeyMaterial.mKey.m8), &aKeySize));
SuccessOrExit(error =
otPlatCryptoExportKey(aPrevKey->mKeyMaterial.mKeyRef, prevKey.m8, OT_MAC_KEY_SIZE, &aKeySize));
SuccessOrExit(error =
otPlatCryptoExportKey(aCurrKey->mKeyMaterial.mKeyRef, currKey.m8, OT_MAC_KEY_SIZE, &aKeySize));
SuccessOrExit(error =
otPlatCryptoExportKey(aNextKey->mKeyMaterial.mKeyRef, nextKey.m8, OT_MAC_KEY_SIZE, &aKeySize));
#else
OT_UNUSED_VARIABLE(aKeySize);

prevKey = aPrevKey->mKeyMaterial.mKey;
currKey = aCurrKey->mKeyMaterial.mKey;
nextKey = aNextKey->mKeyMaterial.mKey;
#endif

SuccessOrExit(error = Set(SPINEL_PROP_RCP_MAC_KEY,
SPINEL_DATATYPE_UINT8_S SPINEL_DATATYPE_UINT8_S SPINEL_DATATYPE_DATA_WLEN_S
SPINEL_DATATYPE_DATA_WLEN_S SPINEL_DATATYPE_DATA_WLEN_S,
aKeyIdMode, aKeyId, aPrevKey->mKeyMaterial.mKey.m8, sizeof(otMacKey),
aCurrKey->mKeyMaterial.mKey.m8, sizeof(otMacKey), aNextKey->mKeyMaterial.mKey.m8,
sizeof(otMacKey)));
aKeyIdMode, aKeyId, prevKey.m8, OT_MAC_KEY_SIZE, currKey.m8, OT_MAC_KEY_SIZE, nextKey.m8,
OT_MAC_KEY_SIZE));

#if OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT > 0
mKeyIdMode = aKeyIdMode;
mKeyId = aKeyId;
memcpy(mPrevKey.m8, aPrevKey->mKeyMaterial.mKey.m8, OT_MAC_KEY_SIZE);
memcpy(mCurrKey.m8, aCurrKey->mKeyMaterial.mKey.m8, OT_MAC_KEY_SIZE);
memcpy(mNextKey.m8, aNextKey->mKeyMaterial.mKey.m8, OT_MAC_KEY_SIZE);

mPrevKey = prevKey;
mCurrKey = currKey;
mNextKey = nextKey;

mMacKeySet = true;
#endif

Expand Down

0 comments on commit 6bfe59d

Please sign in to comment.