CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
apdu.h File Reference
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>

Go to the source code of this file.

Classes

struct  cdc::mod_gpg::openpgp::apdu_t

Namespaces

namespace  cdc
namespace  cdc::mod_gpg
namespace  cdc::mod_gpg::openpgp

Macros

#define CLA_ISO7816   0x00
#define CLA_CHAIN   0x10
#define INS_SELECT   0xA4
#define INS_GET_DATA   0xCA
#define INS_PUT_DATA   0xDA
#define INS_PUT_DATA_ODD   0xDB
#define INS_VERIFY   0x20
#define INS_CHANGE_PIN   0x24
#define INS_RESET_RETRY   0x2C
#define INS_PSO   0x2A
#define INS_INTERNAL_AUTH   0x88
#define INS_GENERATE_KEYPAIR   0x47
#define INS_GET_CHALLENGE   0x84
#define INS_GET_RESPONSE   0xC0
#define INS_TERMINATE   0xE6
#define INS_ACTIVATE   0x44
#define INS_GET_VERSION   0xF1
#define INS_MSE   0x22
#define PSO_CDS   0x9E9A
#define PSO_DEC   0x8086
#define PSO_ENC   0x8680

Functions

bool apdu_parse (const uint8_t *raw, size_t raw_len, apdu_t *apdu)
 ISO 7816 APDU parsing/building helpers for CDC Badge OpenPGP stack.
size_t apdu_build_response (uint8_t *buf, size_t buf_max, const uint8_t *data, size_t data_len, uint16_t sw)
 Builds APDU response payload with status word trailer.
static size_t apdu_sw (uint8_t *buf, uint16_t sw)

Macro Definition Documentation

◆ CLA_CHAIN

#define CLA_CHAIN   0x10

Definition at line 19 of file apdu.h.

◆ CLA_ISO7816

#define CLA_ISO7816   0x00

Definition at line 18 of file apdu.h.

◆ INS_ACTIVATE

#define INS_ACTIVATE   0x44

Definition at line 35 of file apdu.h.

Referenced by openpgp_process_apdu().

◆ INS_CHANGE_PIN

#define INS_CHANGE_PIN   0x24

Definition at line 27 of file apdu.h.

Referenced by openpgp_process_apdu().

◆ INS_GENERATE_KEYPAIR

#define INS_GENERATE_KEYPAIR   0x47

Definition at line 31 of file apdu.h.

Referenced by openpgp_process_apdu().

◆ INS_GET_CHALLENGE

#define INS_GET_CHALLENGE   0x84

Definition at line 32 of file apdu.h.

Referenced by openpgp_process_apdu().

◆ INS_GET_DATA

#define INS_GET_DATA   0xCA

Definition at line 23 of file apdu.h.

Referenced by openpgp_process_apdu().

◆ INS_GET_RESPONSE

#define INS_GET_RESPONSE   0xC0

Definition at line 33 of file apdu.h.

Referenced by openpgp_process_apdu().

◆ INS_GET_VERSION

#define INS_GET_VERSION   0xF1

Definition at line 36 of file apdu.h.

◆ INS_INTERNAL_AUTH

#define INS_INTERNAL_AUTH   0x88

Definition at line 30 of file apdu.h.

Referenced by openpgp_process_apdu().

◆ INS_MSE

#define INS_MSE   0x22

Definition at line 37 of file apdu.h.

Referenced by openpgp_process_apdu().

◆ INS_PSO

#define INS_PSO   0x2A

Definition at line 29 of file apdu.h.

Referenced by openpgp_process_apdu().

◆ INS_PUT_DATA

#define INS_PUT_DATA   0xDA

Definition at line 24 of file apdu.h.

Referenced by openpgp_process_apdu().

◆ INS_PUT_DATA_ODD

#define INS_PUT_DATA_ODD   0xDB

Definition at line 25 of file apdu.h.

Referenced by openpgp_process_apdu().

◆ INS_RESET_RETRY

#define INS_RESET_RETRY   0x2C

Definition at line 28 of file apdu.h.

Referenced by openpgp_process_apdu().

◆ INS_SELECT

#define INS_SELECT   0xA4

Definition at line 22 of file apdu.h.

Referenced by openpgp_process_apdu().

◆ INS_TERMINATE

#define INS_TERMINATE   0xE6

Definition at line 34 of file apdu.h.

Referenced by openpgp_process_apdu().

◆ INS_VERIFY

#define INS_VERIFY   0x20

Definition at line 26 of file apdu.h.

Referenced by openpgp_process_apdu().

◆ PSO_CDS

#define PSO_CDS   0x9E9A

Definition at line 40 of file apdu.h.

◆ PSO_DEC

#define PSO_DEC   0x8086

Definition at line 41 of file apdu.h.

◆ PSO_ENC

#define PSO_ENC   0x8680

Definition at line 42 of file apdu.h.

Function Documentation

◆ apdu_build_response()

size_t apdu_build_response ( uint8_t * buf,
size_t buf_max,
const uint8_t * data,
size_t data_len,
uint16_t sw )

Builds APDU response payload with status word trailer.

Parameters
bufOutput response buffer.
buf_maxCapacity of buf.
dataOptional payload bytes.
data_lenPayload length.
swISO7816 status word.
Returns
Total bytes written to buf.

Definition at line 99 of file apdu.cpp.

Referenced by cmd_generate_keypair(), cmd_get_data(), cmd_internal_authenticate(), cmd_pso_cds(), cmd_pso_decipher(), cmd_pso_decipher_aes(), and openpgp_process_apdu().

◆ apdu_parse()

bool apdu_parse ( const uint8_t * raw,
size_t raw_len,
apdu_t * apdu )

ISO 7816 APDU parsing/building helpers for CDC Badge OpenPGP stack.

Based on pico-openpgp (https://github.com/polhenarejos/pico-openpgp).

Parses raw APDU bytes into structured representation.

Parameters
rawRaw APDU buffer.
raw_lenLength of raw.
apduOutput APDU structure.
Returns
true if APDU framing is valid and parsing succeeded.

Definition at line 17 of file apdu.cpp.

Referenced by openpgp_process_apdu().

◆ apdu_sw()