[spinel] use local variables to export mac key before sending over SPINEL (#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.
This commit is contained in:
hemanth-silabs
2023-10-17 11:39:25 -07:00
committed by GitHub
parent cd5768b89d
commit 6bfe59dabf
+22 -14
View File
@@ -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