Skip to content

Commit

Permalink
Reduce the size of FabricInfo by reordering some members. (project-ch…
Browse files Browse the repository at this point in the history
…ip#28278)

* Reduce the size of FabricInfo by reordering some members.

On 32-bit systems this changes the size from 152 bytes to 144 bytes.

On 64-bit systems this changes the size from 168 bytes to 152 bytes.

* Address review comment.

* Remove static asserts, because offsetof is not happy on FabricInfo.
  • Loading branch information
bzbarsky-apple authored and Alexi Poth committed Aug 15, 2023
1 parent 9af7b3a commit 5b99fc2
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/credentials/FabricTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,27 @@ class DLL_EXPORT FabricInfo
return TLV::EstimateStructOverhead(sizeof(uint16_t), Crypto::P256SerializedKeypair::Capacity());
}

NodeId mNodeId = kUndefinedNodeId;
FabricId mFabricId = kUndefinedFabricId;
FabricIndex mFabricIndex = kUndefinedFabricIndex;
NodeId mNodeId = kUndefinedNodeId;
FabricId mFabricId = kUndefinedFabricId;
// We cache the compressed fabric id since it's used so often and costly to get.
CompressedFabricId mCompressedFabricId = kUndefinedCompressedFabricId;
// We cache the root public key since it's used so often and costly to get.
Crypto::P256PublicKey mRootPublicKey;

VendorId mVendorId = VendorId::NotSpecified;
// mFabricLabel is 33 bytes, so ends on a 1 mod 4 byte boundary.
char mFabricLabel[kFabricLabelMaxLengthInBytes + 1] = { '\0' };
mutable Crypto::P256Keypair * mOperationalKey = nullptr;
bool mHasExternallyOwnedOperationalKey = false;

// mFabricIndex, mVendorId, mHasExternallyOwnedOperationalKey are 4 bytes
// and do not end up with any padding if they come after the 33-byte
// mFabricLabel, so end on a 1 mod 4 byte boundary.
FabricIndex mFabricIndex = kUndefinedFabricIndex;
VendorId mVendorId = VendorId::NotSpecified;
bool mHasExternallyOwnedOperationalKey = false;

// 3 bytes of padding here, since mOperationalKey needs to be void*-aligned,
// so has to be at a 0 mod 4 byte location.

mutable Crypto::P256Keypair * mOperationalKey = nullptr;

CHIP_ERROR CommitToStorage(PersistentStorageDelegate * storage) const;
CHIP_ERROR LoadFromStorage(PersistentStorageDelegate * storage, FabricIndex newFabricIndex, const ByteSpan & rcac,
Expand Down

0 comments on commit 5b99fc2

Please sign in to comment.