Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2018 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 | | */ |
6 | | |
7 | | #ifndef _EXTERN_H |
8 | | #define _EXTERN_H |
9 | | |
10 | | #include <stdint.h> |
11 | | |
12 | | #include "fido/types.h" |
13 | | #include "blob.h" |
14 | | |
15 | | #ifdef __cplusplus |
16 | | extern "C" { |
17 | | #endif /* __cplusplus */ |
18 | | |
19 | | /* aes256 */ |
20 | | int aes256_cbc_dec(const fido_blob_t *, const fido_blob_t *, fido_blob_t *); |
21 | | int aes256_cbc_enc(const fido_blob_t *, const fido_blob_t *, fido_blob_t *); |
22 | | |
23 | | /* cbor encoding functions */ |
24 | | cbor_item_t *cbor_flatten_vector(cbor_item_t **, size_t); |
25 | | cbor_item_t *cbor_encode_assert_options(fido_opt_t, fido_opt_t); |
26 | | cbor_item_t *cbor_encode_change_pin_auth(const fido_blob_t *, |
27 | | const fido_blob_t *, const fido_blob_t *); |
28 | | cbor_item_t *cbor_encode_extensions(const fido_cred_ext_t *); |
29 | | cbor_item_t *cbor_encode_hmac_secret_param(const fido_blob_t *, |
30 | | const es256_pk_t *, const fido_blob_t *); |
31 | | cbor_item_t *cbor_encode_options(fido_opt_t, fido_opt_t); |
32 | | cbor_item_t *cbor_encode_pin_auth(const fido_blob_t *, const fido_blob_t *); |
33 | | cbor_item_t *cbor_encode_pin_enc(const fido_blob_t *, const fido_blob_t *); |
34 | | cbor_item_t *cbor_encode_pin_hash_enc(const fido_blob_t *, const fido_blob_t *); |
35 | | cbor_item_t *cbor_encode_pin_opt(void); |
36 | | cbor_item_t *cbor_encode_pubkey(const fido_blob_t *); |
37 | | cbor_item_t *cbor_encode_pubkey_list(const fido_blob_array_t *); |
38 | | cbor_item_t *cbor_encode_pubkey_param(int); |
39 | | cbor_item_t *cbor_encode_rp_entity(const fido_rp_t *); |
40 | | cbor_item_t *cbor_encode_set_pin_auth(const fido_blob_t *, const fido_blob_t *); |
41 | | cbor_item_t *cbor_encode_user_entity(const fido_user_t *); |
42 | | cbor_item_t *es256_pk_encode(const es256_pk_t *, int); |
43 | | |
44 | | /* cbor decoding functions */ |
45 | | int cbor_decode_attstmt(const cbor_item_t *, fido_attstmt_t *); |
46 | | int cbor_decode_cred_authdata(const cbor_item_t *, int, fido_blob_t *, |
47 | | fido_authdata_t *, fido_attcred_t *, fido_cred_ext_t *); |
48 | | int cbor_decode_assert_authdata(const cbor_item_t *, fido_blob_t *, |
49 | | fido_authdata_t *, int *, fido_blob_t *); |
50 | | int cbor_decode_cred_id(const cbor_item_t *, fido_blob_t *); |
51 | | int cbor_decode_fmt(const cbor_item_t *, char **); |
52 | | int cbor_decode_pubkey(const cbor_item_t *, int *, void *); |
53 | | int cbor_decode_rp_entity(const cbor_item_t *, fido_rp_t *); |
54 | | int cbor_decode_uint64(const cbor_item_t *, uint64_t *); |
55 | | int cbor_decode_user(const cbor_item_t *, fido_user_t *); |
56 | | int es256_pk_decode(const cbor_item_t *, es256_pk_t *); |
57 | | int rs256_pk_decode(const cbor_item_t *, rs256_pk_t *); |
58 | | int eddsa_pk_decode(const cbor_item_t *, eddsa_pk_t *); |
59 | | |
60 | | /* auxiliary cbor routines */ |
61 | | int cbor_add_bool(cbor_item_t *, const char *, fido_opt_t); |
62 | | int cbor_add_bytestring(cbor_item_t *, const char *, const unsigned char *, |
63 | | size_t); |
64 | | int cbor_add_string(cbor_item_t *, const char *, const char *); |
65 | | int cbor_array_iter(const cbor_item_t *, void *, int(*)(const cbor_item_t *, |
66 | | void *)); |
67 | | int cbor_build_frame(uint8_t, cbor_item_t *[], size_t, fido_blob_t *); |
68 | | int cbor_bytestring_copy(const cbor_item_t *, unsigned char **, size_t *); |
69 | | int cbor_map_iter(const cbor_item_t *, void *, int(*)(const cbor_item_t *, |
70 | | const cbor_item_t *, void *)); |
71 | | int cbor_string_copy(const cbor_item_t *, char **); |
72 | | int cbor_parse_reply(const unsigned char *, size_t, void *, |
73 | | int(*)(const cbor_item_t *, const cbor_item_t *, void *)); |
74 | | int cbor_add_pin_params(fido_dev_t *, const fido_blob_t *, const es256_pk_t *, |
75 | | const fido_blob_t *,const char *, cbor_item_t **, cbor_item_t **); |
76 | | void cbor_vector_free(cbor_item_t **, size_t); |
77 | | |
78 | | #ifndef nitems |
79 | 28.2k | #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) |
80 | | #endif |
81 | | |
82 | | /* buf */ |
83 | | int fido_buf_read(const unsigned char **, size_t *, void *, size_t); |
84 | | int fido_buf_write(unsigned char **, size_t *, const void *, size_t); |
85 | | |
86 | | /* hid i/o */ |
87 | | void *fido_hid_open(const char *); |
88 | | void fido_hid_close(void *); |
89 | | int fido_hid_read(void *, unsigned char *, size_t, int); |
90 | | int fido_hid_write(void *, const unsigned char *, size_t); |
91 | | int fido_hid_get_usage(const uint8_t *, size_t, uint32_t *); |
92 | | int fido_hid_get_report_len(const uint8_t *, size_t, size_t *, size_t *); |
93 | | int fido_hid_unix_open(const char *); |
94 | | int fido_hid_unix_wait(int, int); |
95 | | size_t fido_hid_report_in_len(void *); |
96 | | size_t fido_hid_report_out_len(void *); |
97 | | |
98 | | /* generic i/o */ |
99 | | int fido_rx_cbor_status(fido_dev_t *, int); |
100 | | int fido_rx(fido_dev_t *, uint8_t, void *, size_t, int); |
101 | | int fido_tx(fido_dev_t *, uint8_t, const void *, size_t); |
102 | | |
103 | | /* log */ |
104 | | #ifdef FIDO_NO_DIAGNOSTIC |
105 | | #define fido_log_init(...) do { /* nothing */ } while (0) |
106 | | #define fido_log_debug(...) do { /* nothing */ } while (0) |
107 | | #define fido_log_xxd(...) do { /* nothing */ } while (0) |
108 | | #else |
109 | | #ifdef __GNUC__ |
110 | | void fido_log_init(void); |
111 | | void fido_log_debug(const char *, ...) |
112 | | __attribute__((__format__ (printf, 1, 2))); |
113 | | void fido_log_xxd(const void *, size_t); |
114 | | #else |
115 | | void fido_log_init(void); |
116 | | void fido_log_debug(const char *, ...); |
117 | | void fido_log_xxd(const void *, size_t); |
118 | | #endif /* __GNUC__ */ |
119 | | #endif /* FIDO_NO_DIAGNOSTIC */ |
120 | | |
121 | | /* u2f */ |
122 | | int u2f_register(fido_dev_t *, fido_cred_t *, int); |
123 | | int u2f_authenticate(fido_dev_t *, fido_assert_t *, int); |
124 | | int u2f_get_touch_begin(fido_dev_t *); |
125 | | int u2f_get_touch_status(fido_dev_t *, int *, int); |
126 | | |
127 | | /* unexposed fido ops */ |
128 | | int fido_dev_authkey(fido_dev_t *, es256_pk_t *); |
129 | | int fido_dev_get_cbor_info_wait(fido_dev_t *, fido_cbor_info_t *, int); |
130 | | int fido_dev_get_pin_token(fido_dev_t *, const char *, const fido_blob_t *, |
131 | | const es256_pk_t *, fido_blob_t *); |
132 | | int fido_do_ecdh(fido_dev_t *, es256_pk_t **, fido_blob_t **); |
133 | | |
134 | | /* misc */ |
135 | | void fido_assert_reset_rx(fido_assert_t *); |
136 | | void fido_assert_reset_tx(fido_assert_t *); |
137 | | void fido_cred_reset_rx(fido_cred_t *); |
138 | | void fido_cred_reset_tx(fido_cred_t *); |
139 | | int fido_check_rp_id(const char *, const unsigned char *); |
140 | | int fido_check_flags(uint8_t, fido_opt_t, fido_opt_t); |
141 | | int fido_get_random(void *, size_t); |
142 | | |
143 | | /* crypto */ |
144 | | int fido_verify_sig_es256(const fido_blob_t *, const es256_pk_t *, |
145 | | const fido_blob_t *); |
146 | | int fido_verify_sig_rs256(const fido_blob_t *, const rs256_pk_t *, |
147 | | const fido_blob_t *); |
148 | | int fido_verify_sig_eddsa(const fido_blob_t *, const eddsa_pk_t *, |
149 | | const fido_blob_t *); |
150 | | int fido_get_signed_hash(int, fido_blob_t *, const fido_blob_t *, |
151 | | const fido_blob_t *); |
152 | | |
153 | | /* hid device manifest */ |
154 | | int fido_hid_manifest(fido_dev_info_t *, size_t, size_t *); |
155 | | |
156 | | /* device manifest registration */ |
157 | | typedef int (*dev_manifest_func_t)(fido_dev_info_t *, size_t, size_t *); |
158 | | int fido_dev_register_manifest_func(const dev_manifest_func_t); |
159 | | void fido_dev_unregister_manifest_func(const dev_manifest_func_t); |
160 | | |
161 | | /* fuzzing instrumentation */ |
162 | | #ifdef FIDO_FUZZ |
163 | | uint32_t uniform_random(uint32_t); |
164 | | #endif |
165 | | |
166 | | /* internal device capability flags */ |
167 | 4.55k | #define FIDO_DEV_PIN_SET 0x01 |
168 | 4.51k | #define FIDO_DEV_PIN_UNSET 0x02 |
169 | 4.16k | #define FIDO_DEV_CRED_PROT 0x04 |
170 | 3.89k | #define FIDO_DEV_CREDMAN 0x08 |
171 | | |
172 | | /* miscellanea */ |
173 | 2.77k | #define FIDO_DUMMY_CLIENTDATA "" |
174 | 1.45k | #define FIDO_DUMMY_RP_ID "localhost" |
175 | 122 | #define FIDO_DUMMY_USER_NAME "dummy" |
176 | 1.44k | #define FIDO_DUMMY_USER_ID 1 |
177 | | |
178 | | #ifdef __cplusplus |
179 | | } /* extern "C" */ |
180 | | #endif /* __cplusplus */ |
181 | | |
182 | | #endif /* !_EXTERN_H */ |