Skip to content

Commit

Permalink
Properly set CASE salt span sizes and CASE cleanups (#8929)
Browse files Browse the repository at this point in the history
* Properly set CASE salt span sizes and CASE cleanups

- Caller and callee code for Sigma2/Sigma3 salt
  generation need to stay in sync for correct
  usage. If salt buffer grows, but output doesn't
  it can cause garbage data to be used since the
  salt output MutableByteSpan is assumed correct-sized
  rather than ensured to be of correct size.
- This change makes use of the computed final size
  to make sure it stays in sync.
- This change also cleans-up:
  - Random value buffers on heap now on stack
  - Opcert buffers reduced on stack
  - No longer trusting some sizes on wire where
    a max buffer size on stack is used
  - De-uint16-ify several variables
  - Reduce scope of HKDF for SR2K/SR3K
  - Remove some superfluous size variables

Testing done: cert tests and unit tests run successfully

Fixes: #8913
Issue: #8924

* Restyled by clang-format

* Restyled by clang-format

* Add comment per @msandstedt

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Aug 25, 2021
1 parent 39b7804 commit 4710520
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 125 deletions.
4 changes: 2 additions & 2 deletions src/lib/core/CHIPTLV.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ class DLL_EXPORT TLVReader
* TLVBackingStore.
*
*/
CHIP_ERROR GetBytes(uint8_t * buf, uint32_t bufSize);
CHIP_ERROR GetBytes(uint8_t * buf, size_t bufSize);

/**
* Allocates and returns a buffer containing the value of the current byte or UTF8 string.
Expand Down Expand Up @@ -487,7 +487,7 @@ class DLL_EXPORT TLVReader
* TLVBackingStore.
*
*/
CHIP_ERROR GetString(char * buf, uint32_t bufSize);
CHIP_ERROR GetString(char * buf, size_t bufSize);

/**
* Allocates and returns a buffer containing the null-terminated value of the current byte or UTF8
Expand Down
4 changes: 2 additions & 2 deletions src/lib/core/CHIPTLVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ CHIP_ERROR TLVReader::Get(ByteSpan & v)
return CHIP_NO_ERROR;
}

CHIP_ERROR TLVReader::GetBytes(uint8_t * buf, uint32_t bufSize)
CHIP_ERROR TLVReader::GetBytes(uint8_t * buf, size_t bufSize)
{
if (!TLVTypeIsString(ElementType()))
return CHIP_ERROR_WRONG_TLV_TYPE;
Expand All @@ -283,7 +283,7 @@ CHIP_ERROR TLVReader::GetBytes(uint8_t * buf, uint32_t bufSize)
return CHIP_NO_ERROR;
}

CHIP_ERROR TLVReader::GetString(char * buf, uint32_t bufSize)
CHIP_ERROR TLVReader::GetString(char * buf, size_t bufSize)
{
if (!TLVTypeIsString(ElementType()))
return CHIP_ERROR_WRONG_TLV_TYPE;
Expand Down
Loading

0 comments on commit 4710520

Please sign in to comment.