xref: /freebsd/lib/libsecureboot/openpgp/decode.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 #ifdef USE_BEARSSL
29*5fff9558SSimon J. Gerraty unsigned char * mpi2bn(unsigned char **pptr, size_t *sz);
30*5fff9558SSimon J. Gerraty #else
31*5fff9558SSimon J. Gerraty # include <openssl/bn.h>
32*5fff9558SSimon J. Gerraty # include <openssl/rsa.h>
33*5fff9558SSimon J. Gerraty # include <openssl/evp.h>
34*5fff9558SSimon J. Gerraty 
35*5fff9558SSimon J. Gerraty BIGNUM * mpi2bn(unsigned char **pptr);
36*5fff9558SSimon J. Gerraty #endif
37*5fff9558SSimon J. Gerraty 
38*5fff9558SSimon J. Gerraty #define NEW(x) calloc(1,sizeof(x))
39*5fff9558SSimon J. Gerraty 
40*5fff9558SSimon J. Gerraty #define OPENPGP_TAG_ISTAG	0200
41*5fff9558SSimon J. Gerraty #define OPENPGP_TAG_ISNEW	0100
42*5fff9558SSimon J. Gerraty #define OPENPGP_TAG_NEW_MASK	0077
43*5fff9558SSimon J. Gerraty #define OPENPGP_TAG_OLD_MASK	0074
44*5fff9558SSimon J. Gerraty #define OPENPGP_TAG_OLD_TYPE	0003
45*5fff9558SSimon J. Gerraty 
46*5fff9558SSimon J. Gerraty typedef int (*decoder_t)(int, unsigned char **, int, void *);
47*5fff9558SSimon J. Gerraty 
48*5fff9558SSimon J. Gerraty unsigned char * i2octets(int n, size_t i);
49*5fff9558SSimon J. Gerraty int octets2i(unsigned char *ptr, size_t n);
50*5fff9558SSimon J. Gerraty char * octets2hex(unsigned char *ptr, size_t n);
51*5fff9558SSimon J. Gerraty int decode_tag(unsigned char *ptr, int *isnew, int *ltype);
52*5fff9558SSimon J. Gerraty unsigned char * decode_mpi(unsigned char **pptr, size_t *sz);
53*5fff9558SSimon J. Gerraty unsigned char * dearmor(char *pem, size_t nbytes, size_t *len);
54*5fff9558SSimon J. Gerraty int decode_packet(int want, unsigned char **pptr, size_t nbytes,
55*5fff9558SSimon J. Gerraty 		  decoder_t decoder, void *decoder_arg);
56*5fff9558SSimon J. Gerraty unsigned char * decode_subpacket(unsigned char **pptr, int *stag, int *sz);
57