From 30aea859a2df9f1e059853a6c74268f01a1d88c9 Mon Sep 17 00:00:00 2001 From: Mathieu Kardous Date: Thu, 7 Dec 2023 20:54:06 -0500 Subject: [PATCH] replace helpers with memcpy --- src/app/icd/ICDCheckInSender.cpp | 3 ++- src/app/icd/ICDMonitoringTable.cpp | 33 +++++++++++++++--------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/app/icd/ICDCheckInSender.cpp b/src/app/icd/ICDCheckInSender.cpp index 069a2e829d8ab5..ea827c2c7ac6c1 100644 --- a/src/app/icd/ICDCheckInSender.cpp +++ b/src/app/icd/ICDCheckInSender.cpp @@ -89,7 +89,8 @@ CHIP_ERROR ICDCheckInSender::RequestResolve(ICDMonitoringEntry & entry, FabricTa AddressResolve::NodeLookupRequest request(peerId); - Crypto::CopySymmetric128BitsKeyHandle(entry.aesKeyHandle, mAesKeyHandle); + memcpy(mAesKeyHandle.AsMutable(), + entry.aesKeyHandle.As(), sizeof(Crypto::Symmetric128BitsKeyByteArray)); CHIP_ERROR err = AddressResolve::Resolver::Instance().LookupNode(request, mAddressLookupHandle); diff --git a/src/app/icd/ICDMonitoringTable.cpp b/src/app/icd/ICDMonitoringTable.cpp index 6a81c6bf4bb35f..53d202c9fc169c 100644 --- a/src/app/icd/ICDMonitoringTable.cpp +++ b/src/app/icd/ICDMonitoringTable.cpp @@ -43,12 +43,10 @@ CHIP_ERROR ICDMonitoringEntry::Serialize(TLV::TLVWriter & writer) const ReturnErrorOnFailure(writer.Put(TLV::ContextTag(Fields::kCheckInNodeID), checkInNodeID)); ReturnErrorOnFailure(writer.Put(TLV::ContextTag(Fields::kMonitoredSubject), monitoredSubject)); - ByteSpan aesKeybuf; - Crypto::GetByteSpanFromSymmetric128BitsKeyHandle(aesKeyHandle, aesKeybuf); + ByteSpan aesKeybuf(aesKeyHandle.As()); ReturnErrorOnFailure(writer.Put(TLV::ContextTag(Fields::kAesKeyHandle), aesKeybuf)); - ByteSpan hmacKeybuf; - Crypto::GetByteSpanFromSymmetric128BitsKeyHandle(hmacKeyHandle, hmacKeybuf); + ByteSpan hmacKeybuf(hmacKeyHandle.As()); ReturnErrorOnFailure(writer.Put(TLV::ContextTag(Fields::kHmacKeyHandle), hmacKeybuf)); ReturnErrorOnFailure(writer.EndContainer(outer)); @@ -83,7 +81,8 @@ CHIP_ERROR ICDMonitoringEntry::Deserialize(TLV::TLVReader & reader) // simply copy the data as is in the keyHandle. // Calling SetKey here would create another keyHandle in storage and will cause // keyHandle leakage in some implementations. - ReturnErrorOnFailure(Crypto::GetSymmetric128BitsKeyHandleFromByteSpan(aesKeyHandle, buf)); + memcpy(aesKeyHandle.AsMutable(), buf.data(), + sizeof(Crypto::Symmetric128BitsKeyByteArray)); keyHandleValid = true; } break; @@ -103,14 +102,8 @@ CHIP_ERROR ICDMonitoringEntry::Deserialize(TLV::TLVReader & reader) // simply copy the data as is in the keyHandle. // Calling SetKey here would create another keyHandle in storage and will cause // keyHandle leakage in some implementations. - error = Crypto::GetSymmetric128BitsKeyHandleFromByteSpan(hmacKeyHandle, buf); - if (error != CHIP_NO_ERROR) - { - // If setting the KeyHandle from the buffer failed, we need to set an invalid key handle - // even if the AesKeyHandle is valid. - keyHandleValid = false; - return error; - } + memcpy(hmacKeyHandle.AsMutable(), buf.data(), + sizeof(Crypto::Symmetric128BitsKeyByteArray)); } break; default: @@ -220,8 +213,12 @@ ICDMonitoringEntry & ICDMonitoringEntry::operator=(const ICDMonitoringEntry & ic index = icdMonitoringEntry.index; keyHandleValid = icdMonitoringEntry.keyHandleValid; symmetricKeystore = icdMonitoringEntry.symmetricKeystore; - Crypto::CopySymmetric128BitsKeyHandle(icdMonitoringEntry.aesKeyHandle, aesKeyHandle); - Crypto::CopySymmetric128BitsKeyHandle(icdMonitoringEntry.hmacKeyHandle, hmacKeyHandle); + memcpy(aesKeyHandle.AsMutable(), + icdMonitoringEntry.aesKeyHandle.As(), + sizeof(Crypto::Symmetric128BitsKeyByteArray)); + memcpy(hmacKeyHandle.AsMutable(), + icdMonitoringEntry.hmacKeyHandle.As(), + sizeof(Crypto::Symmetric128BitsKeyByteArray)); return *this; } @@ -262,8 +259,10 @@ CHIP_ERROR ICDMonitoringTable::Set(uint16_t index, const ICDMonitoringEntry & en e.monitoredSubject = entry.monitoredSubject; e.index = index; - Crypto::CopySymmetric128BitsKeyHandle(entry.aesKeyHandle, e.aesKeyHandle); - Crypto::CopySymmetric128BitsKeyHandle(entry.hmacKeyHandle, e.hmacKeyHandle); + memcpy(e.aesKeyHandle.AsMutable(), + entry.aesKeyHandle.As(), sizeof(Crypto::Symmetric128BitsKeyByteArray)); + memcpy(e.hmacKeyHandle.AsMutable(), + entry.hmacKeyHandle.As(), sizeof(Crypto::Symmetric128BitsKeyByteArray)); return e.Save(this->mStorage); }