xref: /freebsd/lib/libsecureboot/openpgp/packet.h (revision 42b388439bd3795e09258c57a74ce9eec3651c7b)
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  */
27*5fff9558SSimon J. Gerraty 
28*5fff9558SSimon J. Gerraty #include <sys/queue.h>
29*5fff9558SSimon J. Gerraty 
30*5fff9558SSimon J. Gerraty /*
31*5fff9558SSimon J. Gerraty  * Structs to represent what we need
32*5fff9558SSimon J. Gerraty  */
33*5fff9558SSimon J. Gerraty 
34*5fff9558SSimon J. Gerraty typedef struct OpenPGP_user {
35*5fff9558SSimon J. Gerraty 	char *id;
36*5fff9558SSimon J. Gerraty 	char *name;
37*5fff9558SSimon J. Gerraty } OpenPGP_user;
38*5fff9558SSimon J. Gerraty 
39*5fff9558SSimon J. Gerraty struct OpenPGP_key_ {
40*5fff9558SSimon J. Gerraty 	char *id;
41*5fff9558SSimon J. Gerraty 	int sig_alg;
42*5fff9558SSimon J. Gerraty 	OpenPGP_user *user;
43*5fff9558SSimon J. Gerraty #ifdef USE_BEARSSL
44*5fff9558SSimon J. Gerraty 	br_rsa_public_key *key;
45*5fff9558SSimon J. Gerraty #else
46*5fff9558SSimon J. Gerraty 	EVP_PKEY *key;
47*5fff9558SSimon J. Gerraty #endif
48*5fff9558SSimon J. Gerraty 	LIST_ENTRY(OpenPGP_key_) entries;
49*5fff9558SSimon J. Gerraty };
50*5fff9558SSimon J. Gerraty 
51*5fff9558SSimon J. Gerraty typedef struct OpenPGP_key_ OpenPGP_key;
52*5fff9558SSimon J. Gerraty 
53*5fff9558SSimon J. Gerraty typedef struct OpenPGP_sig {
54*5fff9558SSimon J. Gerraty 	char *key_id;
55*5fff9558SSimon J. Gerraty 	int sig_type;
56*5fff9558SSimon J. Gerraty 	int sig_alg;
57*5fff9558SSimon J. Gerraty 	int hash_alg;
58*5fff9558SSimon J. Gerraty 	unsigned char *pgpbytes;
59*5fff9558SSimon J. Gerraty 	size_t pgpbytes_len;
60*5fff9558SSimon J. Gerraty 	unsigned char *sig;
61*5fff9558SSimon J. Gerraty 	size_t sig_len;
62*5fff9558SSimon J. Gerraty } OpenPGP_sig;
63*5fff9558SSimon J. Gerraty 
64*5fff9558SSimon J. Gerraty void openpgp_trust_add(OpenPGP_key *key);
65*5fff9558SSimon J. Gerraty OpenPGP_key * openpgp_trust_get(const char *keyID);
66*5fff9558SSimon J. Gerraty OpenPGP_key * load_key_file(const char *kfile);
67*5fff9558SSimon J. Gerraty OpenPGP_key * load_key_id(const char *keyID);
68*5fff9558SSimon J. Gerraty void initialize(void);
69*5fff9558SSimon J. Gerraty char * get_error_string(void);
70*5fff9558SSimon J. Gerraty int openpgp_verify(const char *filename, unsigned char *fdata, size_t fbytes,
71*5fff9558SSimon J. Gerraty     unsigned char *sdata, size_t sbytes, int flags);
72*5fff9558SSimon J. Gerraty int openpgp_verify_file(const char *filename, unsigned char *fdata,
73*5fff9558SSimon J. Gerraty     size_t nbytes);
74*5fff9558SSimon J. Gerraty 
75*5fff9558SSimon J. Gerraty /* packet decoders */
76*5fff9558SSimon J. Gerraty #define DECODER_DECL(x)							\
77*5fff9558SSimon J. Gerraty 	ssize_t decode_##x(int, unsigned char **, size_t, OpenPGP_##x *)
78*5fff9558SSimon J. Gerraty 
79*5fff9558SSimon J. Gerraty DECODER_DECL(user);
80*5fff9558SSimon J. Gerraty DECODER_DECL(key);
81*5fff9558SSimon J. Gerraty DECODER_DECL(sig);
82