Coverage Report

Created: 2020-03-07 10:10

/libfido2/src/extern.h
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
63.6k
#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
92
/* generic i/o */
93
int fido_rx_cbor_status(fido_dev_t *, int);
94
int fido_rx(fido_dev_t *, uint8_t, void *, size_t, int);
95
int fido_tx(fido_dev_t *, uint8_t, const void *, size_t);
96
97
/* log */
98
#ifdef FIDO_NO_DIAGNOSTIC
99
#define fido_log_init(...)      do { /* nothing */ } while (0)
100
#define fido_log_debug(...)     do { /* nothing */ } while (0)
101
#define fido_log_xxd(...)       do { /* nothing */ } while (0)
102
#else
103
#ifdef __GNUC__
104
void fido_log_init(void);
105
void fido_log_debug(const char *, ...)
106
    __attribute__((__format__ (printf, 1, 2)));
107
void fido_log_xxd(const void *, size_t);
108
#else
109
void fido_log_init(void);
110
void fido_log_debug(const char *, ...);
111
void fido_log_xxd(const void *, size_t);
112
#endif /* __GNUC__ */
113
#endif /* FIDO_NO_DIAGNOSTIC */
114
115
/* u2f */
116
int u2f_register(fido_dev_t *, fido_cred_t *, int);
117
int u2f_authenticate(fido_dev_t *, fido_assert_t *, int);
118
119
/* unexposed fido ops */
120
int fido_dev_authkey(fido_dev_t *, es256_pk_t *);
121
int fido_dev_get_cbor_info_wait(fido_dev_t *, fido_cbor_info_t *, int);
122
int fido_dev_get_pin_token(fido_dev_t *, const char *, const fido_blob_t *,
123
    const es256_pk_t *, fido_blob_t *);
124
int fido_do_ecdh(fido_dev_t *, es256_pk_t **, fido_blob_t **);
125
126
/* misc */
127
void fido_assert_reset_rx(fido_assert_t *);
128
void fido_assert_reset_tx(fido_assert_t *);
129
void fido_cred_reset_rx(fido_cred_t *);
130
void fido_cred_reset_tx(fido_cred_t *);
131
int fido_check_rp_id(const char *, const unsigned char *);
132
int fido_check_flags(uint8_t, fido_opt_t, fido_opt_t);
133
134
/* crypto */
135
int fido_verify_sig_es256(const fido_blob_t *, const es256_pk_t *,
136
    const fido_blob_t *);
137
int fido_verify_sig_rs256(const fido_blob_t *, const rs256_pk_t *,
138
    const fido_blob_t *);
139
int fido_verify_sig_eddsa(const fido_blob_t *, const eddsa_pk_t *,
140
    const fido_blob_t *);
141
int fido_get_signed_hash(int, fido_blob_t *, const fido_blob_t *,
142
    const fido_blob_t *);
143
144
/* hid device manifest */
145
int fido_hid_manifest(fido_dev_info_t *, size_t, size_t *);
146
147
/* device manifest registration */
148
typedef int (*dev_manifest_func_t)(fido_dev_info_t *, size_t, size_t *);
149
int fido_dev_register_manifest_func(const dev_manifest_func_t);
150
void fido_dev_unregister_manifest_func(const dev_manifest_func_t);
151
152
#ifdef __cplusplus
153
} /* extern "C" */
154
#endif /* __cplusplus */
155
156
#endif /* !_EXTERN_H */