BSL v1.1.1 - 19.g31939de
AMMOS Bundle Protocol Security Library (BSL)
Loading...
Searching...
No Matches
crc.h File Reference

Declarations for BPv7 block CRC handling. More...

#include <BPSecLib_Public.h>
#include <qcbor/UsefulBuf.h>
#include <stdbool.h>
#include <stdint.h>
+ Include dependency graph for crc.h:
+ This graph shows which files directly or indirectly include this file:

Macros

#define MOCK_BPA_CRC_CRC16_LEN   2
 Length of CRC-16.
 
#define MOCK_BPA_CRC_CRC32C_LEN   4
 Length of CRC-32C.
 

Functions

void mock_bpa_crc_oneshot (uint8_t *out, UsefulBufC data, BSL_BundleCRCType_e crc_type)
 Direct CRC function for testing.
 
UsefulBufC mock_bpa_crc_zero (BSL_BundleCRCType_e crc_type)
 Get an empty placeholder for a CRC value.
 
void mock_bpa_crc_apply (UsefulBuf buf, size_t begin, size_t end, BSL_BundleCRCType_e crc_type)
 Apply a CRC function to an encoded block.
 
bool mock_bpa_crc_check (UsefulBufC buf, size_t begin, size_t end, BSL_BundleCRCType_e crc_type, size_t got_len)
 Check the CRC of an encoded block.
 

Detailed Description

Declarations for BPv7 block CRC handling.

Macro Definition Documentation

◆ MOCK_BPA_CRC_CRC16_LEN

#define MOCK_BPA_CRC_CRC16_LEN   2

Length of CRC-16.

◆ MOCK_BPA_CRC_CRC32C_LEN

#define MOCK_BPA_CRC_CRC32C_LEN   4

Length of CRC-32C.

Function Documentation

◆ mock_bpa_crc_apply()

void mock_bpa_crc_apply ( UsefulBuf  buf,
size_t  begin,
size_t  end,
BSL_BundleCRCType_e  crc_type 
)

Apply a CRC function to an encoded block.

Parameters
bufThe buffer holding the encoded block. The buffer contents will be modified to hold the correct CRC value.
beginThe start of the block array
endThe end of the block array
crc_typeThe needed CRC type.

References buf, mock_bpa_crc_desc_t::finalize, get_desc(), mock_bpa_crc_desc_t::init, mock_bpa_crc_zero(), mock_bpa_crc_desc_t::out_size, mock_bpa_crc_desc_t::state_size, and mock_bpa_crc_desc_t::update.

Referenced by bsl_mock_encode_canonical(), and bsl_mock_encode_primary().

◆ mock_bpa_crc_check()

bool mock_bpa_crc_check ( UsefulBufC  buf,
size_t  begin,
size_t  end,
BSL_BundleCRCType_e  crc_type,
size_t  got_len 
)

Check the CRC of an encoded block.

This will manipulate the block to clear its current value.

Parameters
bufThe buffer holding the encoded block.
beginThe start of the block array
endThe end of the block array
crc_typeThe needed CRC type.
got_lenThe actual byte string length decoded.
Returns
True if the CRC value agrees.

References BSL_LOG_ERR, buf, mock_bpa_crc_desc_t::finalize, get_desc(), mock_bpa_crc_desc_t::init, mock_bpa_crc_zero(), mock_bpa_crc_desc_t::out_size, mock_bpa_crc_desc_t::state_size, and mock_bpa_crc_desc_t::update.

Referenced by bsl_mock_decode_canonical(), and bsl_mock_decode_primary().

◆ mock_bpa_crc_oneshot()

void mock_bpa_crc_oneshot ( uint8_t *  out,
UsefulBufC  data,
BSL_BundleCRCType_e  crc_type 
)

Direct CRC function for testing.

Parameters
[out]outThe buffer to write into. Its size must be appropriate for the crc_type. The written value will be BPv7-compatible CRC value in network byte order.
[in]dataThe data to read.
crc_typeThe needed CRC type.

References mock_bpa_crc_desc_t::finalize, get_desc(), mock_bpa_crc_desc_t::init, mock_bpa_crc_desc_t::state_size, and mock_bpa_crc_desc_t::update.

Referenced by test_mock_bpa_crc_crc16(), and test_mock_bpa_crc_crc32c().

◆ mock_bpa_crc_zero()

UsefulBufC mock_bpa_crc_zero ( BSL_BundleCRCType_e  crc_type)

Get an empty placeholder for a CRC value.

Parameters
crc_typeThe needed CRC type.
Returns
A constant buffer to write.

References BSL_BUNDLECRCTYPE_16, BSL_BUNDLECRCTYPE_32, BSL_BUNDLECRCTYPE_NONE, MOCK_BPA_CRC_CRC16_LEN, and MOCK_BPA_CRC_CRC32C_LEN.

Referenced by bsl_mock_encode_canonical(), bsl_mock_encode_primary(), mock_bpa_crc_apply(), and mock_bpa_crc_check().