Skip to content

Commit

Permalink
Fix endianness on IPK computation (#8421)
Browse files Browse the repository at this point in the history
* Fix endianness on IPK computation

* Restyled by clang-format

* Use LittleEndian::BufferWriter

* Restyled by clang-format

* Check if data was serialized

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
SergeyVasiliev and restyled-commits authored Jul 16, 2021
1 parent 96e3510 commit 0c6ce9f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/protocols/secure_channel/CASESession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,9 +1272,14 @@ CHIP_ERROR CASESession::ConstructTBS3Data(const uint8_t * responderOpCert, uint3

CHIP_ERROR CASESession::ComputeIPK(const uint16_t sessionID, uint8_t * ipk, size_t ipkLen)
{
uint8_t sid[2];
Encoding::LittleEndian::BufferWriter bbuf(sid, sizeof(sid));
bbuf.Put16(sessionID);
VerifyOrReturnError(bbuf.Fit(), CHIP_ERROR_NO_MEMORY);

HKDF_sha_crypto mHKDF;
ReturnErrorOnFailure(mHKDF.HKDF_SHA256(mFabricSecret, mFabricSecret.Length(), reinterpret_cast<const uint8_t *>(&sessionID),
sizeof(sessionID), kIPKInfo, sizeof(kIPKInfo), ipk, ipkLen));
ReturnErrorOnFailure(mHKDF.HKDF_SHA256(mFabricSecret, mFabricSecret.Length(), bbuf.Buffer(), bbuf.Size(), kIPKInfo,
sizeof(kIPKInfo), ipk, ipkLen));

return CHIP_NO_ERROR;
}
Expand Down

0 comments on commit 0c6ce9f

Please sign in to comment.