xref: /freebsd/contrib/libfido2/src/fido/bio.h (revision 2ccfa855)
10afa8e06SEd Maste /*
20afa8e06SEd Maste  * Copyright (c) 2019 Yubico AB. All rights reserved.
3*2ccfa855SEd Maste  * SPDX-License-Identifier: BSD-2-Clause
4*2ccfa855SEd Maste  *
5*2ccfa855SEd Maste  * Redistribution and use in source and binary forms, with or without
6*2ccfa855SEd Maste  * modification, are permitted provided that the following conditions are
7*2ccfa855SEd Maste  * met:
8*2ccfa855SEd Maste  *
9*2ccfa855SEd Maste  *    1. Redistributions of source code must retain the above copyright
10*2ccfa855SEd Maste  *       notice, this list of conditions and the following disclaimer.
11*2ccfa855SEd Maste  *    2. Redistributions in binary form must reproduce the above copyright
12*2ccfa855SEd Maste  *       notice, this list of conditions and the following disclaimer in
13*2ccfa855SEd Maste  *       the documentation and/or other materials provided with the
14*2ccfa855SEd Maste  *       distribution.
15*2ccfa855SEd Maste  *
16*2ccfa855SEd Maste  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17*2ccfa855SEd Maste  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18*2ccfa855SEd Maste  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19*2ccfa855SEd Maste  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20*2ccfa855SEd Maste  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21*2ccfa855SEd Maste  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22*2ccfa855SEd Maste  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23*2ccfa855SEd Maste  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24*2ccfa855SEd Maste  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25*2ccfa855SEd Maste  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26*2ccfa855SEd Maste  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
270afa8e06SEd Maste  */
280afa8e06SEd Maste 
290afa8e06SEd Maste #ifndef _FIDO_BIO_H
300afa8e06SEd Maste #define _FIDO_BIO_H
310afa8e06SEd Maste 
320afa8e06SEd Maste #include <stdint.h>
330afa8e06SEd Maste #include <stdlib.h>
340afa8e06SEd Maste 
350afa8e06SEd Maste #ifdef _FIDO_INTERNAL
360afa8e06SEd Maste #include "blob.h"
370afa8e06SEd Maste #include "fido/err.h"
380afa8e06SEd Maste #include "fido/param.h"
390afa8e06SEd Maste #include "fido/types.h"
400afa8e06SEd Maste #else
410afa8e06SEd Maste #include <fido.h>
420afa8e06SEd Maste #include <fido/err.h>
430afa8e06SEd Maste #include <fido/param.h>
440afa8e06SEd Maste #endif
450afa8e06SEd Maste 
460afa8e06SEd Maste #ifdef __cplusplus
470afa8e06SEd Maste extern "C" {
480afa8e06SEd Maste #endif /* __cplusplus */
490afa8e06SEd Maste 
500afa8e06SEd Maste #ifdef _FIDO_INTERNAL
510afa8e06SEd Maste struct fido_bio_template {
520afa8e06SEd Maste 	fido_blob_t id;
530afa8e06SEd Maste 	char *name;
540afa8e06SEd Maste };
550afa8e06SEd Maste 
560afa8e06SEd Maste struct fido_bio_template_array {
570afa8e06SEd Maste 	struct fido_bio_template *ptr;
580afa8e06SEd Maste 	size_t n_alloc; /* number of allocated entries */
590afa8e06SEd Maste 	size_t n_rx;    /* number of populated entries */
600afa8e06SEd Maste };
610afa8e06SEd Maste 
620afa8e06SEd Maste struct fido_bio_enroll {
630afa8e06SEd Maste 	uint8_t remaining_samples;
640afa8e06SEd Maste 	uint8_t last_status;
650afa8e06SEd Maste 	fido_blob_t *token;
660afa8e06SEd Maste };
670afa8e06SEd Maste 
680afa8e06SEd Maste struct fido_bio_info {
690afa8e06SEd Maste 	uint8_t type;
700afa8e06SEd Maste 	uint8_t max_samples;
710afa8e06SEd Maste };
720afa8e06SEd Maste #endif
730afa8e06SEd Maste 
740afa8e06SEd Maste typedef struct fido_bio_template fido_bio_template_t;
750afa8e06SEd Maste typedef struct fido_bio_template_array fido_bio_template_array_t;
760afa8e06SEd Maste typedef struct fido_bio_enroll fido_bio_enroll_t;
770afa8e06SEd Maste typedef struct fido_bio_info fido_bio_info_t;
780afa8e06SEd Maste 
790afa8e06SEd Maste #define FIDO_BIO_ENROLL_FP_GOOD				0x00
800afa8e06SEd Maste #define FIDO_BIO_ENROLL_FP_TOO_HIGH			0x01
810afa8e06SEd Maste #define FIDO_BIO_ENROLL_FP_TOO_LOW			0x02
820afa8e06SEd Maste #define FIDO_BIO_ENROLL_FP_TOO_LEFT			0x03
830afa8e06SEd Maste #define FIDO_BIO_ENROLL_FP_TOO_RIGHT			0x04
840afa8e06SEd Maste #define FIDO_BIO_ENROLL_FP_TOO_FAST			0x05
850afa8e06SEd Maste #define FIDO_BIO_ENROLL_FP_TOO_SLOW			0x06
860afa8e06SEd Maste #define FIDO_BIO_ENROLL_FP_POOR_QUALITY			0x07
870afa8e06SEd Maste #define FIDO_BIO_ENROLL_FP_TOO_SKEWED			0x08
880afa8e06SEd Maste #define FIDO_BIO_ENROLL_FP_TOO_SHORT			0x09
890afa8e06SEd Maste #define FIDO_BIO_ENROLL_FP_MERGE_FAILURE		0x0a
900afa8e06SEd Maste #define FIDO_BIO_ENROLL_FP_EXISTS			0x0b
910afa8e06SEd Maste #define FIDO_BIO_ENROLL_FP_DATABASE_FULL		0x0c
920afa8e06SEd Maste #define FIDO_BIO_ENROLL_NO_USER_ACTIVITY		0x0d
930afa8e06SEd Maste #define FIDO_BIO_ENROLL_NO_USER_PRESENCE_TRANSITION	0x0e
940afa8e06SEd Maste 
950afa8e06SEd Maste const char *fido_bio_template_name(const fido_bio_template_t *);
960afa8e06SEd Maste const fido_bio_template_t *fido_bio_template(const fido_bio_template_array_t *,
970afa8e06SEd Maste     size_t);
980afa8e06SEd Maste const unsigned char *fido_bio_template_id_ptr(const fido_bio_template_t *);
990afa8e06SEd Maste fido_bio_enroll_t *fido_bio_enroll_new(void);
1000afa8e06SEd Maste fido_bio_info_t *fido_bio_info_new(void);
1010afa8e06SEd Maste fido_bio_template_array_t *fido_bio_template_array_new(void);
1020afa8e06SEd Maste fido_bio_template_t *fido_bio_template_new(void);
1030afa8e06SEd Maste int fido_bio_dev_enroll_begin(fido_dev_t *, fido_bio_template_t *,
1040afa8e06SEd Maste     fido_bio_enroll_t *, uint32_t, const char *);
1050afa8e06SEd Maste int fido_bio_dev_enroll_cancel(fido_dev_t *);
1060afa8e06SEd Maste int fido_bio_dev_enroll_continue(fido_dev_t *, const fido_bio_template_t *,
1070afa8e06SEd Maste     fido_bio_enroll_t *, uint32_t);
1080afa8e06SEd Maste int fido_bio_dev_enroll_remove(fido_dev_t *, const fido_bio_template_t *,
1090afa8e06SEd Maste     const char *);
1100afa8e06SEd Maste int fido_bio_dev_get_info(fido_dev_t *, fido_bio_info_t *);
1110afa8e06SEd Maste int fido_bio_dev_get_template_array(fido_dev_t *, fido_bio_template_array_t *,
1120afa8e06SEd Maste     const char *);
1130afa8e06SEd Maste int fido_bio_dev_set_template_name(fido_dev_t *, const fido_bio_template_t *,
1140afa8e06SEd Maste     const char *);
1150afa8e06SEd Maste int fido_bio_template_set_id(fido_bio_template_t *, const unsigned char *,
1160afa8e06SEd Maste     size_t);
1170afa8e06SEd Maste int fido_bio_template_set_name(fido_bio_template_t *, const char *);
1180afa8e06SEd Maste size_t fido_bio_template_array_count(const fido_bio_template_array_t *);
1190afa8e06SEd Maste size_t fido_bio_template_id_len(const fido_bio_template_t *);
1200afa8e06SEd Maste uint8_t fido_bio_enroll_last_status(const fido_bio_enroll_t *);
1210afa8e06SEd Maste uint8_t fido_bio_enroll_remaining_samples(const fido_bio_enroll_t *);
1220afa8e06SEd Maste uint8_t fido_bio_info_max_samples(const fido_bio_info_t *);
1230afa8e06SEd Maste uint8_t fido_bio_info_type(const fido_bio_info_t *);
1240afa8e06SEd Maste void fido_bio_enroll_free(fido_bio_enroll_t **);
1250afa8e06SEd Maste void fido_bio_info_free(fido_bio_info_t **);
1260afa8e06SEd Maste void fido_bio_template_array_free(fido_bio_template_array_t **);
1270afa8e06SEd Maste void fido_bio_template_free(fido_bio_template_t **);
1280afa8e06SEd Maste 
1290afa8e06SEd Maste #ifdef __cplusplus
1300afa8e06SEd Maste } /* extern "C" */
1310afa8e06SEd Maste #endif /* __cplusplus */
1320afa8e06SEd Maste 
1330afa8e06SEd Maste #endif /* !_FIDO_BIO_H */
134