REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
utils Namespace Reference

Classes

struct  _dcp_handle
 
union  _dcp_hash_block
 
struct  _dcp_hash_ctx_internal
 
struct  _dcp_hash_ctx_t
 
struct  _dcp_work_packet
 
struct  DCP_Type
 DCP - Register Layout Typedef. More...
 

Typedefs

typedef enum utils::_dcp_ch_enable _dcp_ch_enable_t
 
typedef enum utils::_dcp_channel dcp_channel_t
 
typedef enum utils::_dcp_key_slot dcp_key_slot_t
 
typedef enum utils::_dcp_swap dcp_swap_t
 
typedef enum utils::_dcp_hash_algo_t dcp_hash_algo_t
 
typedef struct utils::_dcp_hash_ctx_t dcp_hash_ctx_t
 
typedef union utils::_dcp_hash_block dcp_hash_block_t
 
typedef enum utils::_dcp_hash_algo_state dcp_hash_algo_state_t
 
typedef struct utils::_dcp_handle dcp_handle_t
 
typedef struct utils::_dcp_hash_ctx_internal dcp_hash_ctx_internal_t
 
typedef struct utils::_dcp_work_packet dcp_work_packet_t
 

Enumerations

enum  _generic_status {
  kStatus_Success = 0 , kStatus_Fail = 1 , kStatus_ReadOnly = 2 , kStatus_OutOfRange = 3 ,
  kStatus_InvalidArgument = 4 , kStatus_Timeout = 5 , kStatus_DCP_Again = 6
}
 
enum  _dcp_ch_enable {
  kDCP_chDisable = 0U , kDCP_ch0Enable = 1U , kDCP_ch1Enable = 2U , kDCP_ch2Enable = 4U ,
  kDCP_ch3Enable = 8U , kDCP_chEnableAll = 15U
}
 
enum  _dcp_channel { kDCP_Channel0 = (1u << 16) , kDCP_Channel1 = (1u << 17) , kDCP_Channel2 = (1u << 18) , kDCP_Channel3 = (1u << 19) }
 
enum  _dcp_key_slot {
  kDCP_KeySlot0 = 0U , kDCP_KeySlot1 = 1U , kDCP_KeySlot2 = 2U , kDCP_KeySlot3 = 3U ,
  kDCP_OtpKey = 4U , kDCP_OtpUniqueKey = 5U , kDCP_PayloadKey = 6U
}
 
enum  _dcp_swap {
  kDCP_NoSwap = 0x0U , kDCP_KeyByteSwap = 0x40000U , kDCP_KeyWordSwap = 0x80000U , kDCP_InputByteSwap = 0x100000U ,
  kDCP_InputWordSwap = 0x200000U , kDCP_OutputByteSwap = 0x400000U , kDCP_OutputWordSwap = 0x800000U
}
 
enum  _dcp_hash_algo_t { kDCP_Sha1 , kDCP_Sha256 , kDCP_Crc32 }
 
enum  _dcp_hash_digest_len { kDCP_OutLenSha1 = 20u , kDCP_OutLenSha256 = 32u , kDCP_OutLenCrc32 = 4u }
 
enum  _dcp_work_packet_bit_definitions {
  kDCP_CONTROL0_DECR_SEMAPHOR = 1u << 1 , kDCP_CONTROL0_ENABLE_HASH = 1u << 6 , kDCP_CONTROL0_HASH_INIT = 1u << 12 , kDCP_CONTROL0_HASH_TERM = 1u << 13 ,
  kDCP_CONTROL1_HASH_SELECT_SHA256 = 2u << 16 , kDCP_CONTROL1_HASH_SELECT_SHA1 = 0u << 16 , kDCP_CONTROL1_HASH_SELECT_CRC32 = 1u << 16
}
 
enum  _dcp_hash_algo_state { kDCP_StateHashInit = 1u , kDCP_StateHashUpdate }
 

Functions

void check_and_log_crash ()
 Logs out what has been captured by the Teensy CrashReport tooling, cf.
 
static FLASHMEM void dcp_reverse_and_copy (uint8_t *src, uint8_t *dest, size_t src_len)
 
static FLASHMEM uint32_t dcp_get_channel_status (dcp_channel_t channel)
 
static FLASHMEM void dcp_clear_status ()
 
static FLASHMEM void dcp_clear_channel_status (uint32_t mask)
 
uint32_t DCP_WaitForChannelComplete (dcp_handle_t *handle)
 
static FLASHMEM uint32_t dcp_schedule_work (dcp_handle_t *handle, dcp_work_packet_t *dcpPacket)
 
static FLASHMEM uint32_t dcp_hash_update_non_blocking (dcp_hash_ctx_internal_t *ctxInternal, dcp_work_packet_t *dcpPacket, const uint8_t *msg, size_t size)
 
void dcp_hash_update (dcp_hash_ctx_internal_t *ctxInternal, const uint8_t *msg, size_t size)
 
FLASHMEM void dcp_hash_process_message_data (dcp_hash_ctx_internal_t *ctxInternal, const uint8_t *message, size_t messageSize)
 
FLASHMEM void DCP_HASH_Init (dcp_handle_t *handle, dcp_hash_ctx_t *ctx, dcp_hash_algo_t algo)
 
FLASHMEM void DCP_HASH_Update (dcp_hash_ctx_t *ctx, const uint8_t *input, size_t inputSize)
 
FLASHMEM void DCP_HASH_Finish (dcp_hash_ctx_t *ctx, uint8_t *output)
 
FLASHMEM void dcp_init ()
 
FLASHMEM void prhash (unsigned char *h, int n)
 
FLASHMEM void demo_sha256 ()
 
FLASHMEM void demo_crc32 ()
 
FLASHMEM void hash (const uint8_t *msg, size_t msg_len, uint8_t *out_hash, dcp_hash_algo_t algo)
 
FLASHMEM void hash_sha256 (const uint8_t *msg, size_t msg_len, uint8_t *out_hash)
 Computes the SHA256 sum of an arbitrary message (large memory segment).
 
FLASHMEM void hash_sha1 (const uint8_t *msg, size_t msg_len, uint8_t *out_hash)
 
uint32_t rotr (uint32_t x, uint32_t n)
 
uint32_t ch (uint32_t x, uint32_t y, uint32_t z)
 
uint32_t maj (uint32_t x, uint32_t y, uint32_t z)
 
uint32_t sigma0 (uint32_t x)
 
uint32_t sigma1 (uint32_t x)
 

Variables

constexpr std::array< uint32_t, 64 > K
 
constexpr std::array< uint32_t, 4 > H1 = {0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476}
 

Typedef Documentation

◆ _dcp_ch_enable_t

◆ dcp_channel_t

◆ dcp_handle_t

◆ dcp_hash_algo_state_t

◆ dcp_hash_algo_t

◆ dcp_hash_block_t

◆ dcp_hash_ctx_internal_t

◆ dcp_hash_ctx_t

◆ dcp_key_slot_t

◆ dcp_swap_t

◆ dcp_work_packet_t

Enumeration Type Documentation

◆ _dcp_ch_enable

Enumerator
kDCP_chDisable 

DCP channel disable.

kDCP_ch0Enable 

DCP channel 0 enable.

kDCP_ch1Enable 

DCP channel 1 enable.

kDCP_ch2Enable 

DCP channel 2 enable.

kDCP_ch3Enable 

DCP channel 3 enable.

kDCP_chEnableAll 

DCP channel enable all.

Definition at line 68 of file dcp.cpp.

◆ _dcp_channel

Enumerator
kDCP_Channel0 

DCP channel 0.

kDCP_Channel1 

DCP channel 1.

kDCP_Channel2 

DCP channel 2.

kDCP_Channel3 

DCP channel 3.

Definition at line 77 of file dcp.cpp.

◆ _dcp_hash_algo_state

Enumerator
kDCP_StateHashInit 

Init state.

kDCP_StateHashUpdate 

Update state.

Definition at line 135 of file dcp.cpp.

◆ _dcp_hash_algo_t

Enumerator
kDCP_Sha1 

SHA_1.

kDCP_Sha256 

SHA_256.

kDCP_Crc32 

CRC_32.

Definition at line 104 of file dcp.cpp.

◆ _dcp_hash_digest_len

Enumerator
kDCP_OutLenSha1 
kDCP_OutLenSha256 
kDCP_OutLenCrc32 

Definition at line 110 of file dcp.cpp.

◆ _dcp_key_slot

Enumerator
kDCP_KeySlot0 

DCP key slot 0.

kDCP_KeySlot1 

DCP key slot 1.

kDCP_KeySlot2 

DCP key slot 2.

kDCP_KeySlot3 

DCP key slot 3.

kDCP_OtpKey 

DCP OTP key.

kDCP_OtpUniqueKey 

DCP unique OTP key.

kDCP_PayloadKey 

DCP payload key.

Definition at line 84 of file dcp.cpp.

◆ _dcp_swap

Enumerator
kDCP_NoSwap 
kDCP_KeyByteSwap 
kDCP_KeyWordSwap 
kDCP_InputByteSwap 
kDCP_InputWordSwap 
kDCP_OutputByteSwap 
kDCP_OutputWordSwap 

Definition at line 94 of file dcp.cpp.

◆ _dcp_work_packet_bit_definitions

Enumerator
kDCP_CONTROL0_DECR_SEMAPHOR 
kDCP_CONTROL0_ENABLE_HASH 
kDCP_CONTROL0_HASH_INIT 
kDCP_CONTROL0_HASH_TERM 
kDCP_CONTROL1_HASH_SELECT_SHA256 
kDCP_CONTROL1_HASH_SELECT_SHA1 
kDCP_CONTROL1_HASH_SELECT_CRC32 

Definition at line 116 of file dcp.cpp.

◆ _generic_status

Enumerator
kStatus_Success 
kStatus_Fail 
kStatus_ReadOnly 
kStatus_OutOfRange 
kStatus_InvalidArgument 
kStatus_Timeout 
kStatus_DCP_Again 

Definition at line 58 of file dcp.cpp.

Function Documentation

◆ ch()

uint32_t utils::ch ( uint32_t x,
uint32_t y,
uint32_t z )
inline

Definition at line 25 of file dcp.cpp.

◆ check_and_log_crash()

void utils::check_and_log_crash ( )

Logs out what has been captured by the Teensy CrashReport tooling, cf.

https://www.pjrc.com/teensy/td_crashreport.html

This can help to debug faults generated by the memory protection unit (MPU) such as null pointer references or other pointer arithmetics gone bad. In order to have this work, the microcontroller needs to do a "soft-reboot" which preserves the RAM content so the "post-mortem report" is available.

In order to understand the error codes, have a loook at the IMXRT1060 processor architecture manual, for instance at https://www.pjrc.com/teensy/DDI0403Ee_arm_v7m_ref_manual.pdf at page 611

Definition at line 23 of file crash_report.cpp.

Referenced by setup().

◆ dcp_clear_channel_status()

static FLASHMEM void utils::dcp_clear_channel_status ( uint32_t mask)
static

Definition at line 294 of file dcp.cpp.

References DCP, kDCP_Channel0, kDCP_Channel1, kDCP_Channel2, kDCP_Channel3, and uint32_t.

Referenced by dcp_init(), and DCP_WaitForChannelComplete().

◆ dcp_clear_status()

static FLASHMEM void utils::dcp_clear_status ( )
static

Definition at line 289 of file dcp.cpp.

References DCP, utils::DCP_Type::STAT, and uint32_t.

Referenced by dcp_init(), and DCP_WaitForChannelComplete().

◆ dcp_get_channel_status()

static FLASHMEM uint32_t utils::dcp_get_channel_status ( dcp_channel_t channel)
static

◆ DCP_HASH_Finish()

◆ DCP_HASH_Init()

◆ dcp_hash_process_message_data()

FLASHMEM void utils::dcp_hash_process_message_data ( dcp_hash_ctx_internal_t * ctxInternal,
const uint8_t * message,
size_t messageSize )

◆ DCP_HASH_Update()

◆ dcp_hash_update()

void utils::dcp_hash_update ( dcp_hash_ctx_internal_t * ctxInternal,
const uint8_t * msg,
size_t size )

◆ dcp_hash_update_non_blocking()

◆ dcp_init()

FLASHMEM void utils::dcp_init ( )

◆ dcp_reverse_and_copy()

static FLASHMEM void utils::dcp_reverse_and_copy ( uint8_t * src,
uint8_t * dest,
size_t src_len )
static

Definition at line 246 of file dcp.cpp.

References src.

Referenced by DCP_HASH_Finish().

◆ dcp_schedule_work()

static FLASHMEM uint32_t utils::dcp_schedule_work ( dcp_handle_t * handle,
dcp_work_packet_t * dcpPacket )
static

◆ DCP_WaitForChannelComplete()

uint32_t utils::DCP_WaitForChannelComplete ( dcp_handle_t * handle)

◆ demo_crc32()

◆ demo_sha256()

◆ hash()

FLASHMEM void utils::hash ( const uint8_t * msg,
size_t msg_len,
uint8_t * out_hash,
dcp_hash_algo_t algo )

◆ hash_sha1()

void utils::hash_sha1 ( const uint8_t * msg,
size_t msg_len,
uint8_t * out_hash )

Definition at line 634 of file dcp.cpp.

References hash(), and kDCP_Sha1.

◆ hash_sha256()

void utils::hash_sha256 ( const uint8_t * msg,
size_t msg_len,
uint8_t * out_hash )

Computes the SHA256 sum of an arbitrary message (large memory segment).

Outputs an uint8_t[32]. Use for instance prhash(out_hash, 32) for a string representation.

Definition at line 630 of file dcp.cpp.

References hash(), and kDCP_Sha256.

◆ maj()

uint32_t utils::maj ( uint32_t x,
uint32_t y,
uint32_t z )
inline

Definition at line 27 of file dcp.cpp.

◆ prhash()

FLASHMEM void utils::prhash ( unsigned char * h,
int n )

Definition at line 549 of file dcp.cpp.

Referenced by demo_crc32(), and demo_sha256().

◆ rotr()

uint32_t utils::rotr ( uint32_t x,
uint32_t n )
inline

Definition at line 23 of file dcp.cpp.

Referenced by sigma0(), and sigma1().

◆ sigma0()

uint32_t utils::sigma0 ( uint32_t x)
inline

Definition at line 29 of file dcp.cpp.

References rotr().

◆ sigma1()

uint32_t utils::sigma1 ( uint32_t x)
inline

Definition at line 31 of file dcp.cpp.

References rotr().

Variable Documentation

◆ H1

std::array<uint32_t, 4> utils::H1 = {0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476}
constexpr

Definition at line 20 of file dcp.cpp.

◆ K

std::array<uint32_t, 64> utils::K
constexpr
Initial value:
= {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2}

Definition at line 9 of file dcp.cpp.