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

Declarations for BPv7 block CRC handling. More...

#include "crc.h"
#include <arpa/inet.h>
#include <inttypes.h>
#include <BPSecLib_Private.h>
+ Include dependency graph for crc.c:

Data Structures

struct  mock_bpa_crc_desc_t
 

Functions

static void mock_bpa_crc_crc16_init (void *state)
 
static void mock_bpa_crc_crc16_update (void *state, UsefulBufC data)
 
static void mock_bpa_crc_crc16_finalize (void *state, uint8_t out[MOCK_BPA_CRC_CRC16_LEN])
 
static void mock_bpa_crc_crc32c_init (void *state)
 
static void mock_bpa_crc_crc32c_update (void *state, UsefulBufC data)
 
static void mock_bpa_crc_crc32c_finalize (void *state, uint8_t out[MOCK_BPA_CRC_CRC32C_LEN])
 
static const mock_bpa_crc_desc_tget_desc (BSL_BundleCRCType_e crc_type)
 
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.
 

Variables

static const mock_bpa_crc_desc_t mock_bpa_crc_desc_crc16
 
static const mock_bpa_crc_desc_t mock_bpa_crc_desc_crc32c
 

Detailed Description

Declarations for BPv7 block CRC handling.

Function Documentation

◆ get_desc()

◆ 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_crc16_finalize()

static void mock_bpa_crc_crc16_finalize ( void *  state,
uint8_t  out[MOCK_BPA_CRC_CRC16_LEN] 
)
static

◆ mock_bpa_crc_crc16_init()

static void mock_bpa_crc_crc16_init ( void *  state)
static

◆ mock_bpa_crc_crc16_update()

static void mock_bpa_crc_crc16_update ( void *  state,
UsefulBufC  data 
)
static

◆ mock_bpa_crc_crc32c_finalize()

static void mock_bpa_crc_crc32c_finalize ( void *  state,
uint8_t  out[MOCK_BPA_CRC_CRC32C_LEN] 
)
static

◆ mock_bpa_crc_crc32c_init()

static void mock_bpa_crc_crc32c_init ( void *  state)
static

◆ mock_bpa_crc_crc32c_update()

static void mock_bpa_crc_crc32c_update ( void *  state,
UsefulBufC  data 
)
static

◆ 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().

Variable Documentation

◆ mock_bpa_crc_desc_crc16

const mock_bpa_crc_desc_t mock_bpa_crc_desc_crc16
static
Initial value:
= { .out_size = MOCK_BPA_CRC_CRC16_LEN,
.state_size = sizeof(uint16_t),
static void mock_bpa_crc_crc16_init(void *state)
Definition crc.c:33
static void mock_bpa_crc_crc16_finalize(void *state, uint8_t out[MOCK_BPA_CRC_CRC16_LEN])
Definition crc.c:66
static void mock_bpa_crc_crc16_update(void *state, UsefulBufC data)
Definition crc.c:40
#define MOCK_BPA_CRC_CRC16_LEN
Length of CRC-16.
Definition crc.h:40

Referenced by get_desc().

◆ mock_bpa_crc_desc_crc32c

const mock_bpa_crc_desc_t mock_bpa_crc_desc_crc32c
static
Initial value:
= { .out_size = MOCK_BPA_CRC_CRC32C_LEN,
.state_size = sizeof(uint32_t),
static void mock_bpa_crc_crc32c_finalize(void *state, uint8_t out[MOCK_BPA_CRC_CRC32C_LEN])
Definition crc.c:112
static void mock_bpa_crc_crc32c_init(void *state)
Definition crc.c:77
static void mock_bpa_crc_crc32c_update(void *state, UsefulBufC data)
Definition crc.c:84
#define MOCK_BPA_CRC_CRC32C_LEN
Length of CRC-32C.
Definition crc.h:43

Referenced by get_desc().