Coverage Report

Created: 2026-04-08 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/libfido2/src/extern.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2018-2026 Yubico AB. All rights reserved.
3
 * Use of this source code is governed by a BSD-style
4
 * license that can be found in the LICENSE file.
5
 * SPDX-License-Identifier: BSD-2-Clause
6
 */
7
8
#ifndef _EXTERN_H
9
#define _EXTERN_H
10
11
#ifdef __MINGW32__
12
#include <sys/types.h>
13
#endif
14
15
#ifdef HAVE_SIGNAL_H
16
#include <signal.h>
17
#endif
18
19
#include <stdint.h>
20
21
#include "fido/types.h"
22
#include "blob.h"
23
24
#ifdef __cplusplus
25
extern "C" {
26
#endif /* __cplusplus */
27
28
/* aes128 */
29
int aes128_cbc_dec(const fido_blob_t *, const fido_blob_t *, fido_blob_t *);
30
31
/* aes256 */
32
int aes256_cbc_dec(const fido_dev_t *, const fido_blob_t *,
33
    const fido_blob_t *, fido_blob_t *);
34
int aes256_cbc_enc(const fido_dev_t *, const fido_blob_t *,
35
    const fido_blob_t *, fido_blob_t *);
36
int aes256_gcm_dec(const fido_blob_t *, const fido_blob_t *,
37
    const fido_blob_t *, const fido_blob_t *, fido_blob_t *);
38
int aes256_gcm_enc(const fido_blob_t *, const fido_blob_t *,
39
    const fido_blob_t *, const fido_blob_t *, fido_blob_t *);
40
41
/* hdkf-sha256 */
42
int hkdf_sha256(uint8_t *, size_t, const char *, const fido_blob_t *);
43
44
/* cbor encoding functions */
45
cbor_item_t *cbor_build_uint(const uint64_t);
46
cbor_item_t *cbor_flatten_vector(cbor_item_t **, size_t);
47
cbor_item_t *cbor_encode_assert_opt(fido_opt_t, fido_opt_t);
48
cbor_item_t *cbor_encode_change_pin_auth(const fido_dev_t *,
49
    const fido_blob_t *, const fido_blob_t *, const fido_blob_t *);
50
cbor_item_t *cbor_encode_cred_ext(const fido_dev_t *, const fido_cred_extin_t *,
51
    const fido_blob_t *, const es256_pk_t *);
52
cbor_item_t *cbor_encode_assert_ext(fido_dev_t *,
53
    const fido_assert_ext_t *, const fido_blob_t *, const es256_pk_t *);
54
cbor_item_t *cbor_encode_cred_opt(fido_opt_t, fido_opt_t);
55
cbor_item_t *cbor_encode_pin_auth(const fido_dev_t *, const fido_blob_t *,
56
    const fido_blob_t *);
57
cbor_item_t *cbor_encode_pin_opt(const fido_dev_t *);
58
cbor_item_t *cbor_encode_pubkey(const fido_blob_t *);
59
cbor_item_t *cbor_encode_pubkey_list(const fido_blob_array_t *);
60
cbor_item_t *cbor_encode_pubkey_param(int);
61
cbor_item_t *cbor_encode_rp_entity(const fido_rp_t *);
62
cbor_item_t *cbor_encode_str_array(const fido_str_array_t *);
63
cbor_item_t *cbor_encode_user_entity(const fido_user_t *);
64
cbor_item_t *es256_pk_encode(const es256_pk_t *, int);
65
66
/* cbor decoding functions */
67
int cbor_decode_attstmt(const cbor_item_t *, fido_attstmt_t *);
68
int cbor_decode_attobj(const cbor_item_t *, fido_cred_t *);
69
int cbor_decode_bool(const cbor_item_t *, bool *);
70
int cbor_decode_cred_authdata(const cbor_item_t *, int, fido_blob_t *,
71
    fido_authdata_t *, fido_attcred_t *, fido_cred_extout_t *);
72
int cbor_decode_assert_authdata(const cbor_item_t *, fido_blob_t *,
73
    fido_authdata_t *, fido_assert_extattr_t *);
74
int cbor_decode_cred_id(const cbor_item_t *, fido_blob_t *);
75
int cbor_decode_fmt(const cbor_item_t *, char **);
76
int cbor_decode_pubkey(const cbor_item_t *, int *, void *);
77
int cbor_decode_rp_entity(const cbor_item_t *, fido_rp_t *);
78
int cbor_decode_uint64(const cbor_item_t *, uint64_t *);
79
int cbor_decode_user(const cbor_item_t *, fido_user_t *);
80
int es256_pk_decode(const cbor_item_t *, es256_pk_t *);
81
int es384_pk_decode(const cbor_item_t *, es384_pk_t *);
82
int rs256_pk_decode(const cbor_item_t *, rs256_pk_t *);
83
int eddsa_pk_decode(const cbor_item_t *, eddsa_pk_t *);
84
85
/* auxiliary cbor routines */
86
int cbor_add_bool(cbor_item_t *, const char *, fido_opt_t);
87
int cbor_add_bytestring(cbor_item_t *, const char *, const unsigned char *,
88
    size_t);
89
int cbor_add_string(cbor_item_t *, const char *, const char *);
90
int cbor_array_iter(const cbor_item_t *, void *, int(*)(const cbor_item_t *,
91
    void *));
92
int cbor_build_frame(uint8_t, cbor_item_t *[], size_t, fido_blob_t *);
93
int cbor_bytestring_copy(const cbor_item_t *, unsigned char **, size_t *);
94
int cbor_map_iter(const cbor_item_t *, void *, int(*)(const cbor_item_t *,
95
    const cbor_item_t *, void *));
96
int cbor_string_copy(const cbor_item_t *, char **);
97
int cbor_parse_reply(const unsigned char *, size_t, void *,
98
    int(*)(const cbor_item_t *, const cbor_item_t *, void *));
99
int cbor_add_uv_params(fido_dev_t *, uint8_t, const fido_blob_t *,
100
    const es256_pk_t *, const fido_blob_t *, const char *, const char *,
101
    cbor_item_t **, cbor_item_t **, int *);
102
void cbor_vector_free(cbor_item_t **, size_t);
103
int cbor_array_append(cbor_item_t **, cbor_item_t *);
104
int cbor_array_drop(cbor_item_t **, size_t);
105
106
/* deflate */
107
int fido_compress(fido_blob_t *, const fido_blob_t *);
108
int fido_uncompress(fido_blob_t *, const fido_blob_t *, size_t);
109
110
#ifndef nitems
111
566k
#define nitems(_a)      (sizeof((_a)) / sizeof((_a)[0]))
112
#endif
113
114
/* buf */
115
int fido_buf_read(const unsigned char **, size_t *, void *, size_t);
116
int fido_buf_write(unsigned char **, size_t *, const void *, size_t);
117
118
/* hid i/o */
119
void *fido_hid_open(const char *);
120
void  fido_hid_close(void *);
121
int fido_hid_read(void *, unsigned char *, size_t, int);
122
int fido_hid_write(void *, const unsigned char *, size_t);
123
int fido_hid_get_usage(const uint8_t *, size_t, uint32_t *);
124
int fido_hid_get_report_len(const uint8_t *, size_t, size_t *, size_t *);
125
int fido_hid_unix_open(const char *);
126
int fido_hid_unix_wait(int, int, const fido_sigset_t *);
127
int fido_hid_set_sigmask(void *, const fido_sigset_t *);
128
size_t fido_hid_report_in_len(void *);
129
size_t fido_hid_report_out_len(void *);
130
131
/* nfc i/o */
132
bool fido_is_nfc(const char *);
133
bool nfc_is_fido(const char *);
134
void *fido_nfc_open(const char *);
135
void  fido_nfc_close(void *);
136
int fido_nfc_read(void *, unsigned char *, size_t, int);
137
int fido_nfc_write(void *, const unsigned char *, size_t);
138
int fido_nfc_rx(fido_dev_t *, uint8_t, unsigned char *, size_t, int);
139
int fido_nfc_tx(fido_dev_t *, uint8_t, const unsigned char *, size_t);
140
int fido_nfc_set_sigmask(void *, const fido_sigset_t *);
141
int fido_dev_set_nfc(fido_dev_t *);
142
143
/* pcsc i/o */
144
bool fido_is_pcsc(const char *);
145
void *fido_pcsc_open(const char *);
146
void  fido_pcsc_close(void *);
147
int fido_pcsc_read(void *, unsigned char *, size_t, int);
148
int fido_pcsc_write(void *, const unsigned char *, size_t);
149
int fido_pcsc_rx(fido_dev_t *, uint8_t, unsigned char *, size_t, int);
150
int fido_pcsc_tx(fido_dev_t *, uint8_t, const unsigned char *, size_t);
151
int fido_dev_set_pcsc(fido_dev_t *);
152
153
/* windows hello */
154
int fido_winhello_manifest(fido_dev_info_t *, size_t, size_t *);
155
int fido_winhello_open(fido_dev_t *);
156
int fido_winhello_close(fido_dev_t *);
157
int fido_winhello_cancel(fido_dev_t *);
158
int fido_winhello_get_assert(fido_dev_t *, fido_assert_t *, const char *, int);
159
int fido_winhello_get_cbor_info(fido_dev_t *, fido_cbor_info_t *);
160
int fido_winhello_make_cred(fido_dev_t *, fido_cred_t *, const char *, int);
161
162
/* generic i/o */
163
int fido_rx_cbor_status(fido_dev_t *, int *);
164
int fido_rx(fido_dev_t *, uint8_t, void *, size_t, int *);
165
int fido_tx(fido_dev_t *, uint8_t, const void *, size_t, int *);
166
167
/* log */
168
#ifdef FIDO_NO_DIAGNOSTIC
169
#define fido_log_init(...)      do { /* nothing */ } while (0)
170
#define fido_log_debug(...)     do { /* nothing */ } while (0)
171
#define fido_log_xxd(...)       do { /* nothing */ } while (0)
172
#define fido_log_error(...)     do { /* nothing */ } while (0)
173
#else
174
#ifdef __GNUC__
175
void fido_log_init(void);
176
void fido_log_debug(const char *, ...)
177
    __attribute__((__format__ (printf, 1, 2)));
178
void fido_log_xxd(const void *, size_t, const char *, ...)
179
    __attribute__((__format__ (printf, 3, 4)));
180
void fido_log_error(int, const char *, ...)
181
    __attribute__((__format__ (printf, 2, 3)));
182
#else
183
void fido_log_init(void);
184
void fido_log_debug(const char *, ...);
185
void fido_log_xxd(const void *, size_t, const char *, ...);
186
void fido_log_error(int, const char *, ...);
187
#endif /* __GNUC__ */
188
#endif /* FIDO_NO_DIAGNOSTIC */
189
190
/* u2f */
191
int u2f_register(fido_dev_t *, fido_cred_t *, int *);
192
int u2f_authenticate(fido_dev_t *, fido_assert_t *, int *);
193
int u2f_get_touch_begin(fido_dev_t *, int *);
194
int u2f_get_touch_status(fido_dev_t *, int *, int *);
195
196
/* unexposed fido ops */
197
uint8_t fido_dev_get_pin_protocol(const fido_dev_t *);
198
int fido_dev_authkey(fido_dev_t *, es256_pk_t *, int *);
199
int fido_dev_get_cbor_info_wait(fido_dev_t *, fido_cbor_info_t *, int *);
200
int fido_dev_get_uv_token(fido_dev_t *, uint8_t, const char *,
201
    const fido_blob_t *, const es256_pk_t *, const char *, fido_blob_t *,
202
    int *);
203
const fido_blob_t *fido_dev_puat_blob(const fido_dev_t *);
204
uint64_t fido_dev_maxmsgsize(const fido_dev_t *);
205
int fido_do_ecdh(fido_dev_t *, es256_pk_t **, fido_blob_t **, int *);
206
207
/* types */
208
void fido_algo_array_free(fido_algo_array_t *);
209
void fido_byte_array_free(fido_byte_array_t *);
210
void fido_cert_array_free(fido_cert_array_t *);
211
void fido_opt_array_free(fido_opt_array_t *);
212
void fido_str_array_free(fido_str_array_t *);
213
void fido_algo_free(fido_algo_t *);
214
int fido_str_array_pack(fido_str_array_t *, const char * const *, size_t);
215
216
/* misc */
217
void fido_assert_reset_rx(fido_assert_t *);
218
void fido_assert_reset_tx(fido_assert_t *);
219
void fido_cred_reset_rx(fido_cred_t *);
220
void fido_cred_reset_tx(fido_cred_t *);
221
void fido_cbor_info_reset(fido_cbor_info_t *);
222
int fido_blob_serialise(fido_blob_t *, const cbor_item_t *);
223
int fido_check_flags(uint8_t, fido_opt_t, fido_opt_t);
224
int fido_check_rp_id(const char *, const unsigned char *);
225
int fido_get_random(void *, size_t);
226
int fido_sha256(fido_blob_t *, const u_char *, size_t);
227
int fido_time_now(struct timespec *);
228
int fido_time_delta(const struct timespec *, int *);
229
int fido_to_uint64(const char *, int, uint64_t *);
230
231
/* crypto */
232
int es256_verify_sig(const fido_blob_t *, EVP_PKEY *, const fido_blob_t *);
233
int es384_verify_sig(const fido_blob_t *, EVP_PKEY *, const fido_blob_t *);
234
int rs256_verify_sig(const fido_blob_t *, EVP_PKEY *, const fido_blob_t *);
235
int eddsa_verify_sig(const fido_blob_t *, EVP_PKEY *, const fido_blob_t *);
236
int rs1_verify_sig(const fido_blob_t *, EVP_PKEY *, const fido_blob_t *);
237
int es256_pk_verify_sig(const fido_blob_t *, const es256_pk_t *,
238
    const fido_blob_t *);
239
int es384_pk_verify_sig(const fido_blob_t *, const es384_pk_t *,
240
    const fido_blob_t *);
241
int rs256_pk_verify_sig(const fido_blob_t *, const rs256_pk_t *,
242
    const fido_blob_t *);
243
int eddsa_pk_verify_sig(const fido_blob_t *, const eddsa_pk_t *,
244
    const fido_blob_t *);
245
int fido_get_signed_hash(int, fido_blob_t *, const fido_blob_t *,
246
    const fido_blob_t *);
247
int fido_get_signed_hash_tpm(fido_blob_t *, const fido_blob_t *,
248
    const fido_blob_t *, const fido_attstmt_t *, const fido_attcred_t *);
249
250
/* device manifest functions */
251
int fido_hid_manifest(fido_dev_info_t *, size_t, size_t *);
252
int fido_nfc_manifest(fido_dev_info_t *, size_t, size_t *);
253
int fido_pcsc_manifest(fido_dev_info_t *, size_t, size_t *);
254
255
/* fuzzing instrumentation */
256
#ifdef FIDO_FUZZ
257
uint32_t uniform_random(uint32_t);
258
#endif
259
260
/* internal device capability flags */
261
80.9k
#define FIDO_DEV_PIN_SET        0x0001
262
120k
#define FIDO_DEV_PIN_UNSET      0x0002
263
75.2k
#define FIDO_DEV_CRED_PROT      0x0004
264
92.2k
#define FIDO_DEV_CREDMAN        0x0008
265
227k
#define FIDO_DEV_PIN_PROTOCOL1  0x0010
266
264k
#define FIDO_DEV_PIN_PROTOCOL2  0x0020
267
83.5k
#define FIDO_DEV_UV_SET         0x0040
268
44.8k
#define FIDO_DEV_UV_UNSET       0x0080
269
60.0k
#define FIDO_DEV_TOKEN_PERMS    0x0100
270
16.8k
#define FIDO_DEV_WINHELLO       0x0200
271
64.4k
#define FIDO_DEV_CREDMAN_PRE    0x0400
272
29.2k
#define FIDO_DEV_BIO_SET        0x0800
273
29.8k
#define FIDO_DEV_BIO_UNSET      0x1000
274
275
/* miscellanea */
276
43.5k
#define FIDO_DUMMY_CLIENTDATA   ""
277
22.5k
#define FIDO_DUMMY_RP_ID        "localhost"
278
1.46k
#define FIDO_DUMMY_USER_NAME    "dummy"
279
22.4k
#define FIDO_DUMMY_USER_ID      1
280
#define FIDO_WINHELLO_PATH      "windows://hello"
281
15.1M
#define FIDO_NFC_PREFIX         "nfc:"
282
6.22M
#define FIDO_PCSC_PREFIX        "pcsc:"
283
284
#ifdef __cplusplus
285
} /* extern "C" */
286
#endif /* __cplusplus */
287
288
#endif /* !_EXTERN_H */