xref: /openbsd-src/lib/libfido2/src/fido/bio.h (revision 739189a35a238815a54c8f21927a51f4ca78fa67)
1d75efeb7Sdjm /*
2d75efeb7Sdjm  * Copyright (c) 2019 Yubico AB. All rights reserved.
3d75efeb7Sdjm  * Use of this source code is governed by a BSD-style
4d75efeb7Sdjm  * license that can be found in the LICENSE file.
5d75efeb7Sdjm  */
6d75efeb7Sdjm 
7d75efeb7Sdjm #ifndef _FIDO_BIO_H
8d75efeb7Sdjm #define _FIDO_BIO_H
9d75efeb7Sdjm 
10d75efeb7Sdjm #include <stdint.h>
11d75efeb7Sdjm #include <stdlib.h>
12d75efeb7Sdjm 
1332a20e26Sdjm #ifdef _FIDO_INTERNAL
1432a20e26Sdjm #include "blob.h"
15d75efeb7Sdjm #include "fido/err.h"
16d75efeb7Sdjm #include "fido/param.h"
1732a20e26Sdjm #include "fido/types.h"
1832a20e26Sdjm #else
1932a20e26Sdjm #include <fido.h>
2032a20e26Sdjm #include <fido/err.h>
2132a20e26Sdjm #include <fido/param.h>
2232a20e26Sdjm #endif
23d75efeb7Sdjm 
24*739189a3Sdjm #ifdef __cplusplus
25*739189a3Sdjm extern "C" {
26*739189a3Sdjm #endif /* __cplusplus */
27*739189a3Sdjm 
28d75efeb7Sdjm #ifdef _FIDO_INTERNAL
29d75efeb7Sdjm struct fido_bio_template {
30d75efeb7Sdjm 	fido_blob_t id;
31d75efeb7Sdjm 	char *name;
32d75efeb7Sdjm };
33d75efeb7Sdjm 
34d75efeb7Sdjm struct fido_bio_template_array {
35d75efeb7Sdjm 	struct fido_bio_template *ptr;
36d75efeb7Sdjm 	size_t n_alloc; /* number of allocated entries */
37d75efeb7Sdjm 	size_t n_rx;    /* number of populated entries */
38d75efeb7Sdjm };
39d75efeb7Sdjm 
40d75efeb7Sdjm struct fido_bio_enroll {
41d75efeb7Sdjm 	uint8_t remaining_samples;
42d75efeb7Sdjm 	uint8_t last_status;
43d75efeb7Sdjm 	fido_blob_t *token;
44d75efeb7Sdjm };
45d75efeb7Sdjm 
46d75efeb7Sdjm struct fido_bio_info {
47d75efeb7Sdjm 	uint8_t type;
48d75efeb7Sdjm 	uint8_t max_samples;
49d75efeb7Sdjm };
50d75efeb7Sdjm #endif
51d75efeb7Sdjm 
52d75efeb7Sdjm typedef struct fido_bio_template fido_bio_template_t;
53d75efeb7Sdjm typedef struct fido_bio_template_array fido_bio_template_array_t;
54d75efeb7Sdjm typedef struct fido_bio_enroll fido_bio_enroll_t;
55d75efeb7Sdjm typedef struct fido_bio_info fido_bio_info_t;
56d75efeb7Sdjm 
57d75efeb7Sdjm #define FIDO_BIO_ENROLL_FP_GOOD				0x00
58d75efeb7Sdjm #define FIDO_BIO_ENROLL_FP_TOO_HIGH			0x01
59d75efeb7Sdjm #define FIDO_BIO_ENROLL_FP_TOO_LOW			0x02
60d75efeb7Sdjm #define FIDO_BIO_ENROLL_FP_TOO_LEFT			0x03
61d75efeb7Sdjm #define FIDO_BIO_ENROLL_FP_TOO_RIGHT			0x04
62d75efeb7Sdjm #define FIDO_BIO_ENROLL_FP_TOO_FAST			0x05
63d75efeb7Sdjm #define FIDO_BIO_ENROLL_FP_TOO_SLOW			0x06
64d75efeb7Sdjm #define FIDO_BIO_ENROLL_FP_POOR_QUALITY			0x07
65d75efeb7Sdjm #define FIDO_BIO_ENROLL_FP_TOO_SKEWED			0x08
66d75efeb7Sdjm #define FIDO_BIO_ENROLL_FP_TOO_SHORT			0x09
67d75efeb7Sdjm #define FIDO_BIO_ENROLL_FP_MERGE_FAILURE		0x0a
68d75efeb7Sdjm #define FIDO_BIO_ENROLL_FP_EXISTS			0x0b
69d75efeb7Sdjm #define FIDO_BIO_ENROLL_FP_DATABASE_FULL		0x0c
70d75efeb7Sdjm #define FIDO_BIO_ENROLL_NO_USER_ACTIVITY		0x0d
71d75efeb7Sdjm #define FIDO_BIO_ENROLL_NO_USER_PRESENCE_TRANSITION	0x0e
72d75efeb7Sdjm 
73d75efeb7Sdjm const char *fido_bio_template_name(const fido_bio_template_t *);
74d75efeb7Sdjm const fido_bio_template_t *fido_bio_template(const fido_bio_template_array_t *,
75d75efeb7Sdjm     size_t);
76d75efeb7Sdjm const unsigned char *fido_bio_template_id_ptr(const fido_bio_template_t *);
77d75efeb7Sdjm fido_bio_enroll_t *fido_bio_enroll_new(void);
78d75efeb7Sdjm fido_bio_info_t *fido_bio_info_new(void);
79d75efeb7Sdjm fido_bio_template_array_t *fido_bio_template_array_new(void);
80d75efeb7Sdjm fido_bio_template_t *fido_bio_template_new(void);
81d75efeb7Sdjm int fido_bio_dev_enroll_begin(fido_dev_t *, fido_bio_template_t *,
82d75efeb7Sdjm     fido_bio_enroll_t *, uint32_t, const char *);
83d75efeb7Sdjm int fido_bio_dev_enroll_cancel(fido_dev_t *);
84d75efeb7Sdjm int fido_bio_dev_enroll_continue(fido_dev_t *, const fido_bio_template_t *,
85d75efeb7Sdjm     fido_bio_enroll_t *, uint32_t);
86d75efeb7Sdjm int fido_bio_dev_enroll_remove(fido_dev_t *, const fido_bio_template_t *,
87d75efeb7Sdjm     const char *);
88d75efeb7Sdjm int fido_bio_dev_get_info(fido_dev_t *, fido_bio_info_t *);
89d75efeb7Sdjm int fido_bio_dev_get_template_array(fido_dev_t *, fido_bio_template_array_t *,
90d75efeb7Sdjm     const char *);
91d75efeb7Sdjm int fido_bio_dev_set_template_name(fido_dev_t *, const fido_bio_template_t *,
92d75efeb7Sdjm     const char *);
93d75efeb7Sdjm int fido_bio_template_set_id(fido_bio_template_t *, const unsigned char *,
94d75efeb7Sdjm     size_t);
95d75efeb7Sdjm int fido_bio_template_set_name(fido_bio_template_t *, const char *);
96d75efeb7Sdjm size_t fido_bio_template_array_count(const fido_bio_template_array_t *);
97d75efeb7Sdjm size_t fido_bio_template_id_len(const fido_bio_template_t *);
98d75efeb7Sdjm uint8_t fido_bio_enroll_last_status(const fido_bio_enroll_t *);
99d75efeb7Sdjm uint8_t fido_bio_enroll_remaining_samples(const fido_bio_enroll_t *);
100d75efeb7Sdjm uint8_t fido_bio_info_max_samples(const fido_bio_info_t *);
101d75efeb7Sdjm uint8_t fido_bio_info_type(const fido_bio_info_t *);
102d75efeb7Sdjm void fido_bio_enroll_free(fido_bio_enroll_t **);
103d75efeb7Sdjm void fido_bio_info_free(fido_bio_info_t **);
104d75efeb7Sdjm void fido_bio_template_array_free(fido_bio_template_array_t **);
105d75efeb7Sdjm void fido_bio_template_free(fido_bio_template_t **);
106d75efeb7Sdjm 
107*739189a3Sdjm #ifdef __cplusplus
108*739189a3Sdjm } /* extern "C" */
109*739189a3Sdjm #endif /* __cplusplus */
110*739189a3Sdjm 
111d75efeb7Sdjm #endif /* !_FIDO_BIO_H */
112