piv_apdu.c
depends on piv_apdu.h
API
Cstruct command_apdu
A parsed ISO 7816 command APDU: class, instruction, parameters, data payload, and optional Le (expected response length).
Fstatic int finish(const uint8_t *data, size_t data_len, uint16_t sw, uint8_t *response, size_t response_cap, size_t *response_len)
Write data and a status word to the response buffer and record its length, returning 0 on success or -1 if the buffer is too small.
handle_change_pin, handle_general_authenticate, handle_get_data, handle_verify, piv_apdu_transmitFstatic int parse_command(const uint8_t *command, size_t command_len, struct command_apdu *apdu)
Parse an ISO 7816 command APDU from bytes: extract CLA, INS, P1, P2, data length, data, and optional Le. Return 0 on success or -1 if the length is invalid.
piv_apdu_transmitFstatic size_t ber_length_bytes(size_t len)
Return the number of bytes needed to encode a BER length: 1 if less than 128, 2 if up to 255, or 3 if up to 65535.
build_certificate, wrap_tlvFstatic int put_ber_length(uint8_t *out, size_t cap, size_t len, size_t *written)
Encode a BER length into the output buffer: 1 byte for lengths under 128, 2 for up to 255, 3 for up to 65535. Return 0 on success or -1 if the buffer is too small.
build_certificate, wrap_tlvFstatic int emit_pending(struct piv_apdu *piv, size_t requested, uint8_t *response, size_t response_cap, size_t *response_len)
Emit a chunk of a pending response, up to the requested size, followed by a status word indicating how many bytes remain: SW_SUCCESS if done, or SW_BYTES_REMAINING with the count.
piv_apdu_transmit, send_dataFstatic bool aid_matches(const uint8_t *data, size_t len)
Return true if the data buffer matches the PIV AID or the PIV AID truncated form.
piv_apdu_transmitFstatic uint16_t pin_result_status(int result, uint8_t retries)
Return the status word for a PIN verify or change result: 0x9000 for success, 0x63Cn for retries remaining, 0x6983 if blocked, or 0x6982 otherwise.
handle_change_pin, handle_verifyFstatic size_t der_integer(const uint8_t value[32], uint8_t out[35])
Encode a 32-byte value as a DER integer with a leading zero byte if the high bit is set, returning the encoded length.
handle_general_authenticateFvoid piv_apdu_init(struct piv_apdu *piv, const struct piv_apdu_backend *backend, void *backend_ctx, bool pin_required)
Initialize a PIV APDU engine with a backend, backend context, and a flag indicating whether PIN is required for presence signatures.
Fvoid piv_apdu_reset(struct piv_apdu *piv)
Reset the PIV APDU engine state: clear selection, PIN verification, and pending data.
Undocumented (10)
wrap_tlv, send_data, build_ccc, build_chuid, build_certificate, handle_get_data, handle_verify, handle_change_pin, handle_general_authenticate, piv_apdu_transmit