|
CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
|
Go to the source code of this file.
Functions | |
| uint8_t | t1_lrc (const uint8_t *buf, size_t len) |
| Compute the longitudinal redundancy check (LRC) of a buffer. | |
| uint16_t | t1_crc (const uint8_t *buf, size_t len) |
| Compute the ISO/IEC 13239 CRC-16 of a buffer (polynomial 0x1021, initial value 0xFFFF, no final XOR, MSB first). Used as the alternative EDC when CRC is negotiated. | |
| static t1_status_t | append_edc (uint8_t *out, size_t prologue_and_inf_len, bool use_crc, size_t out_cap, size_t *out_len) |
| t1_status_t | t1_block_encode_i (uint8_t nad, uint8_t ns, bool more, const uint8_t *inf, uint8_t inf_len, bool use_crc, uint8_t *out, size_t out_cap, size_t *out_len) |
| Encode an I-block. | |
| t1_status_t | t1_block_encode_r (uint8_t nad, uint8_t nr, t1_r_error_t err, bool use_crc, uint8_t *out, size_t out_cap, size_t *out_len) |
| Encode an R-block. | |
| t1_status_t | t1_block_encode_s (uint8_t nad, t1_s_subtype_t subtype, const uint8_t *inf, uint8_t inf_len, bool use_crc, uint8_t *out, size_t out_cap, size_t *out_len) |
| Encode an S-block. | |
| t1_status_t | t1_block_decode (const uint8_t *buf, size_t buf_len, bool use_crc, t1_block_t *out) |
| Decode a T=1 block. | |
|
static |
Definition at line 58 of file t1_block.cpp.
References t1_crc(), T1_ERR_OUT_BUF, t1_lrc(), and T1_OK.
Referenced by t1_block_encode_i(), t1_block_encode_r(), and t1_block_encode_s().
| t1_status_t t1_block_decode | ( | const uint8_t * | buf, |
| size_t | buf_len, | ||
| bool | use_crc, | ||
| t1_block_t * | out ) |
Decode a T=1 block.
The decoder validates LEN, EDC, and PCB encoding rules. Reserved bits in I- and R-blocks must be zero; otherwise T1_ERR_PCB is returned.
| buf | Input bytes. |
| buf_len | Number of bytes available. |
| use_crc | If true, expect 2-byte CRC; otherwise LRC. |
| out | Decoded block (INF pointer aliases into buf). |
Definition at line 147 of file t1_block.cpp.
References t1_block_t::edc_ok, t1_block_t::i_more, t1_block_t::i_ns, t1_block_t::inf, t1_block_t::inf_len, t1_block_t::kind, t1_block_t::nad, t1_block_t::pcb, t1_block_t::r_err, t1_block_t::r_nr, t1_block_t::s_subtype, T1_BLOCK_I, T1_BLOCK_R, T1_BLOCK_S, t1_crc(), T1_ERR_LEN, T1_ERR_NULL, T1_ERR_PCB, T1_ERR_SHORT, T1_LEN_RESERVED, t1_lrc(), T1_OK, and t1_block_t::use_crc.
| t1_status_t t1_block_encode_i | ( | uint8_t | nad, |
| uint8_t | ns, | ||
| bool | more, | ||
| const uint8_t * | inf, | ||
| uint8_t | inf_len, | ||
| bool | use_crc, | ||
| uint8_t * | out, | ||
| size_t | out_cap, | ||
| size_t * | out_len ) |
Encode an I-block.
| nad | Node address. |
| ns | Sequence number (0 or 1). |
| more | More-data flag (chaining). |
| inf | Information field payload (may be NULL when inf_len == 0). |
| inf_len | Payload length (<= T1_INF_MAX). |
| use_crc | Use 2-byte CRC instead of LRC. |
| out | Output buffer (caller-allocated, at least 4 + inf_len + (use_crc ? 1 : 0) bytes). |
| out_cap | Output capacity in bytes. |
| out_len | Receives total bytes written. |
Definition at line 75 of file t1_block.cpp.
References append_edc(), T1_ERR_INF_TOO_BIG, T1_ERR_NULL, T1_ERR_OUT_BUF, T1_ERR_PCB, and T1_INF_MAX.
Referenced by t1_state_next_outbound().
| t1_status_t t1_block_encode_r | ( | uint8_t | nad, |
| uint8_t | nr, | ||
| t1_r_error_t | err, | ||
| bool | use_crc, | ||
| uint8_t * | out, | ||
| size_t | out_cap, | ||
| size_t * | out_len ) |
Encode an R-block.
| nad | Node address. |
| nr | Expected sequence number (0 or 1). |
| err | Error indicator. |
| use_crc | EDC algorithm select. |
| out | Output buffer. |
| out_cap | Output buffer capacity. |
| out_len | Receives bytes written. |
Definition at line 103 of file t1_block.cpp.
References append_edc(), T1_ERR_NULL, T1_ERR_OUT_BUF, and T1_ERR_PCB.
Referenced by encode_rblock().
| t1_status_t t1_block_encode_s | ( | uint8_t | nad, |
| t1_s_subtype_t | subtype, | ||
| const uint8_t * | inf, | ||
| uint8_t | inf_len, | ||
| bool | use_crc, | ||
| uint8_t * | out, | ||
| size_t | out_cap, | ||
| size_t * | out_len ) |
Encode an S-block.
| nad | Node address. |
| subtype | S-block subtype (request or response). |
| inf | Optional info payload (e.g. IFS new value). |
| inf_len | Length of the info payload (0..254). |
| use_crc | EDC algorithm select. |
| out | Output buffer. |
| out_cap | Output buffer capacity. |
| out_len | Receives bytes written. |
Definition at line 123 of file t1_block.cpp.
References append_edc(), T1_ERR_INF_TOO_BIG, T1_ERR_NULL, T1_ERR_OUT_BUF, T1_ERR_PCB, and T1_INF_MAX.
Referenced by encode_sblock_response().
| uint16_t t1_crc | ( | const uint8_t * | buf, |
| size_t | len ) |
Compute the ISO/IEC 13239 CRC-16 of a buffer (polynomial 0x1021, initial value 0xFFFF, no final XOR, MSB first). Used as the alternative EDC when CRC is negotiated.
Definition at line 41 of file t1_block.cpp.
Referenced by append_edc(), and t1_block_decode().
| uint8_t t1_lrc | ( | const uint8_t * | buf, |
| size_t | len ) |
Compute the longitudinal redundancy check (LRC) of a buffer.
LRC is the bytewise XOR of all bytes in buf. Used as the default EDC byte when the T=1 protocol parameters do not select CRC.
| buf | Buffer pointer. |
| len | Number of bytes to fold into the LRC. |
Definition at line 33 of file t1_block.cpp.
Referenced by append_edc(), and t1_block_decode().