xref: /freebsd/lib/libsecureboot/openpgp/packet.h (revision 42b38843)
15fff9558SSimon J. Gerraty /*-
25fff9558SSimon J. Gerraty  * Copyright (c) 2018, Juniper Networks, Inc.
35fff9558SSimon J. Gerraty  *
45fff9558SSimon J. Gerraty  * Redistribution and use in source and binary forms, with or without
55fff9558SSimon J. Gerraty  * modification, are permitted provided that the following conditions
65fff9558SSimon J. Gerraty  * are met:
75fff9558SSimon J. Gerraty  * 1. Redistributions of source code must retain the above copyright
85fff9558SSimon J. Gerraty  *    notice, this list of conditions and the following disclaimer.
95fff9558SSimon J. Gerraty  * 2. Redistributions in binary form must reproduce the above copyright
105fff9558SSimon J. Gerraty  *    notice, this list of conditions and the following disclaimer in the
115fff9558SSimon J. Gerraty  *    documentation and/or other materials provided with the distribution.
125fff9558SSimon J. Gerraty  *
135fff9558SSimon J. Gerraty  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
145fff9558SSimon J. Gerraty  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
155fff9558SSimon J. Gerraty  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
165fff9558SSimon J. Gerraty  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
175fff9558SSimon J. Gerraty  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
185fff9558SSimon J. Gerraty  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
195fff9558SSimon J. Gerraty  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
205fff9558SSimon J. Gerraty  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
215fff9558SSimon J. Gerraty  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
225fff9558SSimon J. Gerraty  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
235fff9558SSimon J. Gerraty  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
245fff9558SSimon J. Gerraty  */
255fff9558SSimon J. Gerraty /*
265fff9558SSimon J. Gerraty  */
275fff9558SSimon J. Gerraty 
285fff9558SSimon J. Gerraty #include <sys/queue.h>
295fff9558SSimon J. Gerraty 
305fff9558SSimon J. Gerraty /*
315fff9558SSimon J. Gerraty  * Structs to represent what we need
325fff9558SSimon J. Gerraty  */
335fff9558SSimon J. Gerraty 
345fff9558SSimon J. Gerraty typedef struct OpenPGP_user {
355fff9558SSimon J. Gerraty 	char *id;
365fff9558SSimon J. Gerraty 	char *name;
375fff9558SSimon J. Gerraty } OpenPGP_user;
385fff9558SSimon J. Gerraty 
395fff9558SSimon J. Gerraty struct OpenPGP_key_ {
405fff9558SSimon J. Gerraty 	char *id;
415fff9558SSimon J. Gerraty 	int sig_alg;
425fff9558SSimon J. Gerraty 	OpenPGP_user *user;
435fff9558SSimon J. Gerraty #ifdef USE_BEARSSL
445fff9558SSimon J. Gerraty 	br_rsa_public_key *key;
455fff9558SSimon J. Gerraty #else
465fff9558SSimon J. Gerraty 	EVP_PKEY *key;
475fff9558SSimon J. Gerraty #endif
485fff9558SSimon J. Gerraty 	LIST_ENTRY(OpenPGP_key_) entries;
495fff9558SSimon J. Gerraty };
505fff9558SSimon J. Gerraty 
515fff9558SSimon J. Gerraty typedef struct OpenPGP_key_ OpenPGP_key;
525fff9558SSimon J. Gerraty 
535fff9558SSimon J. Gerraty typedef struct OpenPGP_sig {
545fff9558SSimon J. Gerraty 	char *key_id;
555fff9558SSimon J. Gerraty 	int sig_type;
565fff9558SSimon J. Gerraty 	int sig_alg;
575fff9558SSimon J. Gerraty 	int hash_alg;
585fff9558SSimon J. Gerraty 	unsigned char *pgpbytes;
595fff9558SSimon J. Gerraty 	size_t pgpbytes_len;
605fff9558SSimon J. Gerraty 	unsigned char *sig;
615fff9558SSimon J. Gerraty 	size_t sig_len;
625fff9558SSimon J. Gerraty } OpenPGP_sig;
635fff9558SSimon J. Gerraty 
645fff9558SSimon J. Gerraty void openpgp_trust_add(OpenPGP_key *key);
655fff9558SSimon J. Gerraty OpenPGP_key * openpgp_trust_get(const char *keyID);
665fff9558SSimon J. Gerraty OpenPGP_key * load_key_file(const char *kfile);
675fff9558SSimon J. Gerraty OpenPGP_key * load_key_id(const char *keyID);
685fff9558SSimon J. Gerraty void initialize(void);
695fff9558SSimon J. Gerraty char * get_error_string(void);
705fff9558SSimon J. Gerraty int openpgp_verify(const char *filename, unsigned char *fdata, size_t fbytes,
715fff9558SSimon J. Gerraty     unsigned char *sdata, size_t sbytes, int flags);
725fff9558SSimon J. Gerraty int openpgp_verify_file(const char *filename, unsigned char *fdata,
735fff9558SSimon J. Gerraty     size_t nbytes);
745fff9558SSimon J. Gerraty 
755fff9558SSimon J. Gerraty /* packet decoders */
765fff9558SSimon J. Gerraty #define DECODER_DECL(x)							\
775fff9558SSimon J. Gerraty 	ssize_t decode_##x(int, unsigned char **, size_t, OpenPGP_##x *)
785fff9558SSimon J. Gerraty 
795fff9558SSimon J. Gerraty DECODER_DECL(user);
805fff9558SSimon J. Gerraty DECODER_DECL(key);
815fff9558SSimon J. Gerraty DECODER_DECL(sig);
82