xref: /freebsd-src/contrib/libfido2/src/fido/credman.h (revision 2ccfa855b2fc331819953e3de1b1c15ce5b95a7e)
10afa8e06SEd Maste /*
20afa8e06SEd Maste  * Copyright (c) 2019-2021 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_CREDMAN_H
300afa8e06SEd Maste #define _FIDO_CREDMAN_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_credman_metadata {
520afa8e06SEd Maste 	uint64_t rk_existing;
530afa8e06SEd Maste 	uint64_t rk_remaining;
540afa8e06SEd Maste };
550afa8e06SEd Maste 
560afa8e06SEd Maste struct fido_credman_single_rp {
570afa8e06SEd Maste 	fido_rp_t rp_entity;
580afa8e06SEd Maste 	fido_blob_t rp_id_hash;
590afa8e06SEd Maste };
600afa8e06SEd Maste 
610afa8e06SEd Maste struct fido_credman_rp {
620afa8e06SEd Maste 	struct fido_credman_single_rp *ptr;
630afa8e06SEd Maste 	size_t n_alloc; /* number of allocated entries */
640afa8e06SEd Maste 	size_t n_rx;    /* number of populated entries */
650afa8e06SEd Maste };
660afa8e06SEd Maste 
670afa8e06SEd Maste struct fido_credman_rk {
680afa8e06SEd Maste 	fido_cred_t *ptr;
690afa8e06SEd Maste 	size_t n_alloc; /* number of allocated entries */
700afa8e06SEd Maste 	size_t n_rx;    /* number of populated entries */
710afa8e06SEd Maste };
720afa8e06SEd Maste #endif
730afa8e06SEd Maste 
740afa8e06SEd Maste typedef struct fido_credman_metadata fido_credman_metadata_t;
750afa8e06SEd Maste typedef struct fido_credman_rk fido_credman_rk_t;
760afa8e06SEd Maste typedef struct fido_credman_rp fido_credman_rp_t;
770afa8e06SEd Maste 
780afa8e06SEd Maste const char *fido_credman_rp_id(const fido_credman_rp_t *, size_t);
790afa8e06SEd Maste const char *fido_credman_rp_name(const fido_credman_rp_t *, size_t);
800afa8e06SEd Maste 
810afa8e06SEd Maste const fido_cred_t *fido_credman_rk(const fido_credman_rk_t *, size_t);
820afa8e06SEd Maste const unsigned char *fido_credman_rp_id_hash_ptr(const fido_credman_rp_t *,
830afa8e06SEd Maste     size_t);
840afa8e06SEd Maste 
850afa8e06SEd Maste fido_credman_metadata_t *fido_credman_metadata_new(void);
860afa8e06SEd Maste fido_credman_rk_t *fido_credman_rk_new(void);
870afa8e06SEd Maste fido_credman_rp_t *fido_credman_rp_new(void);
880afa8e06SEd Maste 
890afa8e06SEd Maste int fido_credman_del_dev_rk(fido_dev_t *, const unsigned char *, size_t,
900afa8e06SEd Maste     const char *);
910afa8e06SEd Maste int fido_credman_get_dev_metadata(fido_dev_t *, fido_credman_metadata_t *,
920afa8e06SEd Maste     const char *);
930afa8e06SEd Maste int fido_credman_get_dev_rk(fido_dev_t *, const char *, fido_credman_rk_t *,
940afa8e06SEd Maste     const char *);
950afa8e06SEd Maste int fido_credman_get_dev_rp(fido_dev_t *, fido_credman_rp_t *, const char *);
960afa8e06SEd Maste int fido_credman_set_dev_rk(fido_dev_t *, fido_cred_t *, const char *);
970afa8e06SEd Maste 
980afa8e06SEd Maste size_t fido_credman_rk_count(const fido_credman_rk_t *);
990afa8e06SEd Maste size_t fido_credman_rp_count(const fido_credman_rp_t *);
1000afa8e06SEd Maste size_t fido_credman_rp_id_hash_len(const fido_credman_rp_t *, size_t);
1010afa8e06SEd Maste 
1020afa8e06SEd Maste uint64_t fido_credman_rk_existing(const fido_credman_metadata_t *);
1030afa8e06SEd Maste uint64_t fido_credman_rk_remaining(const fido_credman_metadata_t *);
1040afa8e06SEd Maste 
1050afa8e06SEd Maste void fido_credman_metadata_free(fido_credman_metadata_t **);
1060afa8e06SEd Maste void fido_credman_rk_free(fido_credman_rk_t **);
1070afa8e06SEd Maste void fido_credman_rp_free(fido_credman_rp_t **);
1080afa8e06SEd Maste 
1090afa8e06SEd Maste #ifdef __cplusplus
1100afa8e06SEd Maste } /* extern "C" */
1110afa8e06SEd Maste #endif /* __cplusplus */
1120afa8e06SEd Maste 
1130afa8e06SEd Maste #endif /* !_FIDO_CREDMAN_H */
114