xref: /freebsd/lib/libsecureboot/openpgp/packet.h (revision 5fff9558a43aaac53da41dc23c250c4e84f6fb02)
1*5fff9558SSimon J. Gerraty /*-
2*5fff9558SSimon J. Gerraty  * Copyright (c) 2018, Juniper Networks, Inc.
3*5fff9558SSimon J. Gerraty  *
4*5fff9558SSimon J. Gerraty  * Redistribution and use in source and binary forms, with or without
5*5fff9558SSimon J. Gerraty  * modification, are permitted provided that the following conditions
6*5fff9558SSimon J. Gerraty  * are met:
7*5fff9558SSimon J. Gerraty  * 1. Redistributions of source code must retain the above copyright
8*5fff9558SSimon J. Gerraty  *    notice, this list of conditions and the following disclaimer.
9*5fff9558SSimon J. Gerraty  * 2. Redistributions in binary form must reproduce the above copyright
10*5fff9558SSimon J. Gerraty  *    notice, this list of conditions and the following disclaimer in the
11*5fff9558SSimon J. Gerraty  *    documentation and/or other materials provided with the distribution.
12*5fff9558SSimon J. Gerraty  *
13*5fff9558SSimon J. Gerraty  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14*5fff9558SSimon J. Gerraty  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15*5fff9558SSimon J. Gerraty  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16*5fff9558SSimon J. Gerraty  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
17*5fff9558SSimon J. Gerraty  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18*5fff9558SSimon J. Gerraty  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19*5fff9558SSimon J. Gerraty  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20*5fff9558SSimon J. Gerraty  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21*5fff9558SSimon J. Gerraty  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22*5fff9558SSimon J. Gerraty  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23*5fff9558SSimon J. Gerraty  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24*5fff9558SSimon J. Gerraty  */
25*5fff9558SSimon J. Gerraty /*
26*5fff9558SSimon J. Gerraty  * $FreeBSD$
27*5fff9558SSimon J. Gerraty  */
28*5fff9558SSimon J. Gerraty 
29*5fff9558SSimon J. Gerraty #include <sys/queue.h>
30*5fff9558SSimon J. Gerraty 
31*5fff9558SSimon J. Gerraty /*
32*5fff9558SSimon J. Gerraty  * Structs to represent what we need
33*5fff9558SSimon J. Gerraty  */
34*5fff9558SSimon J. Gerraty 
35*5fff9558SSimon J. Gerraty typedef struct OpenPGP_user {
36*5fff9558SSimon J. Gerraty 	char *id;
37*5fff9558SSimon J. Gerraty 	char *name;
38*5fff9558SSimon J. Gerraty } OpenPGP_user;
39*5fff9558SSimon J. Gerraty 
40*5fff9558SSimon J. Gerraty struct OpenPGP_key_ {
41*5fff9558SSimon J. Gerraty 	char *id;
42*5fff9558SSimon J. Gerraty 	int sig_alg;
43*5fff9558SSimon J. Gerraty 	OpenPGP_user *user;
44*5fff9558SSimon J. Gerraty #ifdef USE_BEARSSL
45*5fff9558SSimon J. Gerraty 	br_rsa_public_key *key;
46*5fff9558SSimon J. Gerraty #else
47*5fff9558SSimon J. Gerraty 	EVP_PKEY *key;
48*5fff9558SSimon J. Gerraty #endif
49*5fff9558SSimon J. Gerraty 	LIST_ENTRY(OpenPGP_key_) entries;
50*5fff9558SSimon J. Gerraty };
51*5fff9558SSimon J. Gerraty 
52*5fff9558SSimon J. Gerraty typedef struct OpenPGP_key_ OpenPGP_key;
53*5fff9558SSimon J. Gerraty 
54*5fff9558SSimon J. Gerraty typedef struct OpenPGP_sig {
55*5fff9558SSimon J. Gerraty 	char *key_id;
56*5fff9558SSimon J. Gerraty 	int sig_type;
57*5fff9558SSimon J. Gerraty 	int sig_alg;
58*5fff9558SSimon J. Gerraty 	int hash_alg;
59*5fff9558SSimon J. Gerraty 	unsigned char *pgpbytes;
60*5fff9558SSimon J. Gerraty 	size_t pgpbytes_len;
61*5fff9558SSimon J. Gerraty 	unsigned char *sig;
62*5fff9558SSimon J. Gerraty 	size_t sig_len;
63*5fff9558SSimon J. Gerraty } OpenPGP_sig;
64*5fff9558SSimon J. Gerraty 
65*5fff9558SSimon J. Gerraty void openpgp_trust_add(OpenPGP_key *key);
66*5fff9558SSimon J. Gerraty OpenPGP_key * openpgp_trust_get(const char *keyID);
67*5fff9558SSimon J. Gerraty OpenPGP_key * load_key_file(const char *kfile);
68*5fff9558SSimon J. Gerraty OpenPGP_key * load_key_id(const char *keyID);
69*5fff9558SSimon J. Gerraty void initialize(void);
70*5fff9558SSimon J. Gerraty char * get_error_string(void);
71*5fff9558SSimon J. Gerraty int openpgp_verify(const char *filename, unsigned char *fdata, size_t fbytes,
72*5fff9558SSimon J. Gerraty     unsigned char *sdata, size_t sbytes, int flags);
73*5fff9558SSimon J. Gerraty int openpgp_verify_file(const char *filename, unsigned char *fdata,
74*5fff9558SSimon J. Gerraty     size_t nbytes);
75*5fff9558SSimon J. Gerraty 
76*5fff9558SSimon J. Gerraty /* packet decoders */
77*5fff9558SSimon J. Gerraty #define DECODER_DECL(x)							\
78*5fff9558SSimon J. Gerraty 	ssize_t decode_##x(int, unsigned char **, size_t, OpenPGP_##x *)
79*5fff9558SSimon J. Gerraty 
80*5fff9558SSimon J. Gerraty DECODER_DECL(user);
81*5fff9558SSimon J. Gerraty DECODER_DECL(key);
82*5fff9558SSimon J. Gerraty DECODER_DECL(sig);
83