27#define ALIRO_PROTO_ACCESS 0x00u
28#define ALIRO_PROTO_NOTIFICATION 0x02u
31#define ALIRO_AP_OP_COMMAND 0x00u
32#define ALIRO_AP_OP_RESPONSE 0x01u
35#define ALIRO_NOTIF_EVENT 0x00u
36#define ALIRO_NOTIF_INITIATE_AP 0x05u
41#define ALIRO_INS_AUTH0 0x80u
42#define ALIRO_INS_AUTH1 0x81u
43#define ALIRO_INS_EXCHANGE 0xC9u
46#define ALIRO_TAG_EXP_PHASE 0x41u
47#define ALIRO_TAG_USER_POL 0x42u
48#define ALIRO_TAG_VERSION 0x5Cu
49#define ALIRO_TAG_READER_EPH 0x87u
50#define ALIRO_TAG_TXID 0x4Cu
51#define ALIRO_TAG_READER_ID 0x4Du
52#define ALIRO_TAG_SIG 0x9Eu
53#define ALIRO_TAG_DEVICE_PUBX \
55#define ALIRO_TAG_USAGE 0x93u
56#define ALIRO_TAG_DEVICE_PUB 0x5Au
57#define ALIRO_TAG_STATUS 0x97u
58#define ALIRO_TAG_URSK_READY 0x98u
68void aliro_tlv_w_init(
struct aliro_tlv_w *w, uint8_t *buf,
size_t cap);
69void aliro_tlv_put(
struct aliro_tlv_w *w, uint8_t tag,
const uint8_t *val,
size_t len);
70void aliro_tlv_put_u8(
struct aliro_tlv_w *w, uint8_t tag, uint8_t v);
71void aliro_tlv_put_u16(
struct aliro_tlv_w *w, uint8_t tag, uint16_t v);
72void aliro_tlv_put_empty(
struct aliro_tlv_w *w, uint8_t tag);
73int aliro_tlv_w_finish(
struct aliro_tlv_w *w,
size_t *out_len);
76int aliro_tlv_find(
const uint8_t *buf,
size_t buf_len, uint8_t tag,
const uint8_t **val,
80int aliro_apdu_build_auth0(uint8_t exp_phase, uint8_t user_policy, uint16_t version,
81 const uint8_t reader_eph_pub[65],
const uint8_t txid[16],
82 const uint8_t reader_id[32], uint8_t *out,
size_t cap,
size_t *out_len);
83int aliro_apdu_build_auth1(uint8_t cred_type,
const uint8_t sig[64], uint8_t *out,
size_t cap,
89#define ALIRO_AUTH_READER 1
90#define ALIRO_AUTH_DEVICE 0
91int aliro_apdu_build_authdata(
int which,
const uint8_t reader_id[32],
const uint8_t device_pubx[32],
92 const uint8_t reader_eph_pubx[32],
const uint8_t txid[16],
93 uint8_t *out,
size_t cap,
size_t *out_len);
96int aliro_apdu_build_exchange(
int have_status, uint16_t reader_status,
int ursk_ready, uint8_t *out,
97 size_t cap,
size_t *out_len);
102int aliro_apdu_wrap(uint8_t ins,
const uint8_t *tlv,
size_t tlv_len, uint8_t *out,
size_t cap,
109int aliro_apdu_strip_sw(
const uint8_t *buf,
size_t *len, uint16_t *sw);
114struct aliro_auth0_response {
115 uint8_t device_eph_pub[65];
117 uint8_t cryptogram[64];
119int aliro_apdu_parse_auth0_response(
const uint8_t *buf,
size_t len,
struct aliro_auth0_response *r);
124struct aliro_auth1_response {
126 uint8_t device_pub[65];
127 uint8_t device_sig[64];
130int aliro_apdu_parse_auth1_response(
const uint8_t *buf,
size_t len,
struct aliro_auth1_response *r);
133#define ALIRO_ENVELOPE_HDR 4u
134int aliro_ble_frame(uint8_t type, uint8_t opcode,
const uint8_t *payload,
size_t plen, uint8_t *out,
135 size_t cap,
size_t *out_len);
136int aliro_ble_unframe(
const uint8_t *buf,
size_t len, uint8_t *type, uint8_t *opcode,
137 const uint8_t **payload,
size_t *plen);