xref: /minix3/crypto/external/bsd/netpgp/dist/src/lib/packet.h (revision ebfedea0ce5bbe81e252ddf32d732e40fb633fae)
1*ebfedea0SLionel Sambuc /*-
2*ebfedea0SLionel Sambuc  * Copyright (c) 2009 The NetBSD Foundation, Inc.
3*ebfedea0SLionel Sambuc  * All rights reserved.
4*ebfedea0SLionel Sambuc  *
5*ebfedea0SLionel Sambuc  * This code is derived from software contributed to The NetBSD Foundation
6*ebfedea0SLionel Sambuc  * by Alistair Crooks (agc@NetBSD.org)
7*ebfedea0SLionel Sambuc  *
8*ebfedea0SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
9*ebfedea0SLionel Sambuc  * modification, are permitted provided that the following conditions
10*ebfedea0SLionel Sambuc  * are met:
11*ebfedea0SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
12*ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
13*ebfedea0SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
14*ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
15*ebfedea0SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
16*ebfedea0SLionel Sambuc  *
17*ebfedea0SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18*ebfedea0SLionel Sambuc  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19*ebfedea0SLionel Sambuc  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20*ebfedea0SLionel Sambuc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21*ebfedea0SLionel Sambuc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22*ebfedea0SLionel Sambuc  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23*ebfedea0SLionel Sambuc  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*ebfedea0SLionel Sambuc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25*ebfedea0SLionel Sambuc  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26*ebfedea0SLionel Sambuc  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27*ebfedea0SLionel Sambuc  * POSSIBILITY OF SUCH DAMAGE.
28*ebfedea0SLionel Sambuc  */
29*ebfedea0SLionel Sambuc /*
30*ebfedea0SLionel Sambuc  * Copyright (c) 2005-2008 Nominet UK (www.nic.uk)
31*ebfedea0SLionel Sambuc  * All rights reserved.
32*ebfedea0SLionel Sambuc  * Contributors: Ben Laurie, Rachel Willmer. The Contributors have asserted
33*ebfedea0SLionel Sambuc  * their moral rights under the UK Copyright Design and Patents Act 1988 to
34*ebfedea0SLionel Sambuc  * be recorded as the authors of this copyright work.
35*ebfedea0SLionel Sambuc  *
36*ebfedea0SLionel Sambuc  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
37*ebfedea0SLionel Sambuc  * use this file except in compliance with the License.
38*ebfedea0SLionel Sambuc  *
39*ebfedea0SLionel Sambuc  * You may obtain a copy of the License at
40*ebfedea0SLionel Sambuc  *     http://www.apache.org/licenses/LICENSE-2.0
41*ebfedea0SLionel Sambuc  *
42*ebfedea0SLionel Sambuc  * Unless required by applicable law or agreed to in writing, software
43*ebfedea0SLionel Sambuc  * distributed under the License is distributed on an "AS IS" BASIS,
44*ebfedea0SLionel Sambuc  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45*ebfedea0SLionel Sambuc  *
46*ebfedea0SLionel Sambuc  * See the License for the specific language governing permissions and
47*ebfedea0SLionel Sambuc  * limitations under the License.
48*ebfedea0SLionel Sambuc  */
49*ebfedea0SLionel Sambuc 
50*ebfedea0SLionel Sambuc /** \file
51*ebfedea0SLionel Sambuc  * packet related headers.
52*ebfedea0SLionel Sambuc  */
53*ebfedea0SLionel Sambuc 
54*ebfedea0SLionel Sambuc #ifndef PACKET_H_
55*ebfedea0SLionel Sambuc #define PACKET_H_
56*ebfedea0SLionel Sambuc 
57*ebfedea0SLionel Sambuc #include <time.h>
58*ebfedea0SLionel Sambuc 
59*ebfedea0SLionel Sambuc #ifdef HAVE_OPENSSL_BN_H
60*ebfedea0SLionel Sambuc #include <openssl/bn.h>
61*ebfedea0SLionel Sambuc #endif
62*ebfedea0SLionel Sambuc 
63*ebfedea0SLionel Sambuc #include "types.h"
64*ebfedea0SLionel Sambuc #include "errors.h"
65*ebfedea0SLionel Sambuc 
66*ebfedea0SLionel Sambuc /* structure to keep track of printing state variables */
67*ebfedea0SLionel Sambuc typedef struct pgp_printstate_t {
68*ebfedea0SLionel Sambuc 	unsigned	unarmoured;
69*ebfedea0SLionel Sambuc 	unsigned	skipping;
70*ebfedea0SLionel Sambuc 	int		indent;
71*ebfedea0SLionel Sambuc } pgp_printstate_t;
72*ebfedea0SLionel Sambuc 
73*ebfedea0SLionel Sambuc /** General-use structure for variable-length data
74*ebfedea0SLionel Sambuc  */
75*ebfedea0SLionel Sambuc 
76*ebfedea0SLionel Sambuc typedef struct {
77*ebfedea0SLionel Sambuc 	size_t           len;
78*ebfedea0SLionel Sambuc 	uint8_t		*contents;
79*ebfedea0SLionel Sambuc 	uint8_t		 mmapped;	/* contents need an munmap(2) */
80*ebfedea0SLionel Sambuc } pgp_data_t;
81*ebfedea0SLionel Sambuc 
82*ebfedea0SLionel Sambuc /************************************/
83*ebfedea0SLionel Sambuc /* Packet Tags - RFC4880, 4.2 */
84*ebfedea0SLionel Sambuc /************************************/
85*ebfedea0SLionel Sambuc 
86*ebfedea0SLionel Sambuc /** Packet Tag - Bit 7 Mask (this bit is always set).
87*ebfedea0SLionel Sambuc  * The first byte of a packet is the "Packet Tag".  It always
88*ebfedea0SLionel Sambuc  * has bit 7 set.  This is the mask for it.
89*ebfedea0SLionel Sambuc  *
90*ebfedea0SLionel Sambuc  * \see RFC4880 4.2
91*ebfedea0SLionel Sambuc  */
92*ebfedea0SLionel Sambuc #define PGP_PTAG_ALWAYS_SET		0x80
93*ebfedea0SLionel Sambuc 
94*ebfedea0SLionel Sambuc /** Packet Tag - New Format Flag.
95*ebfedea0SLionel Sambuc  * Bit 6 of the Packet Tag is the packet format indicator.
96*ebfedea0SLionel Sambuc  * If it is set, the new format is used, if cleared the
97*ebfedea0SLionel Sambuc  * old format is used.
98*ebfedea0SLionel Sambuc  *
99*ebfedea0SLionel Sambuc  * \see RFC4880 4.2
100*ebfedea0SLionel Sambuc  */
101*ebfedea0SLionel Sambuc #define PGP_PTAG_NEW_FORMAT		0x40
102*ebfedea0SLionel Sambuc 
103*ebfedea0SLionel Sambuc 
104*ebfedea0SLionel Sambuc /** Old Packet Format: Mask for content tag.
105*ebfedea0SLionel Sambuc  * In the old packet format bits 5 to 2 (including)
106*ebfedea0SLionel Sambuc  * are the content tag.  This is the mask to apply
107*ebfedea0SLionel Sambuc  * to the packet tag.  Note that you need to
108*ebfedea0SLionel Sambuc  * shift by #PGP_PTAG_OF_CONTENT_TAG_SHIFT bits.
109*ebfedea0SLionel Sambuc  *
110*ebfedea0SLionel Sambuc  * \see RFC4880 4.2
111*ebfedea0SLionel Sambuc  */
112*ebfedea0SLionel Sambuc #define PGP_PTAG_OF_CONTENT_TAG_MASK	0x3c
113*ebfedea0SLionel Sambuc /** Old Packet Format: Offset for the content tag.
114*ebfedea0SLionel Sambuc  * As described at #PGP_PTAG_OF_CONTENT_TAG_MASK the
115*ebfedea0SLionel Sambuc  * content tag needs to be shifted after being masked
116*ebfedea0SLionel Sambuc  * out from the Packet Tag.
117*ebfedea0SLionel Sambuc  *
118*ebfedea0SLionel Sambuc  * \see RFC4880 4.2
119*ebfedea0SLionel Sambuc  */
120*ebfedea0SLionel Sambuc #define PGP_PTAG_OF_CONTENT_TAG_SHIFT	2
121*ebfedea0SLionel Sambuc /** Old Packet Format: Mask for length type.
122*ebfedea0SLionel Sambuc  * Bits 1 and 0 of the packet tag are the length type
123*ebfedea0SLionel Sambuc  * in the old packet format.
124*ebfedea0SLionel Sambuc  *
125*ebfedea0SLionel Sambuc  * See #pgp_ptag_of_lt_t for the meaning of the values.
126*ebfedea0SLionel Sambuc  *
127*ebfedea0SLionel Sambuc  * \see RFC4880 4.2
128*ebfedea0SLionel Sambuc  */
129*ebfedea0SLionel Sambuc #define PGP_PTAG_OF_LENGTH_TYPE_MASK	0x03
130*ebfedea0SLionel Sambuc 
131*ebfedea0SLionel Sambuc 
132*ebfedea0SLionel Sambuc /** Old Packet Format Lengths.
133*ebfedea0SLionel Sambuc  * Defines the meanings of the 2 bits for length type in the
134*ebfedea0SLionel Sambuc  * old packet format.
135*ebfedea0SLionel Sambuc  *
136*ebfedea0SLionel Sambuc  * \see RFC4880 4.2.1
137*ebfedea0SLionel Sambuc  */
138*ebfedea0SLionel Sambuc typedef enum {
139*ebfedea0SLionel Sambuc 	PGP_PTAG_OLD_LEN_1 = 0x00,	/* Packet has a 1 byte length -
140*ebfedea0SLionel Sambuc 					 * header is 2 bytes long. */
141*ebfedea0SLionel Sambuc 	PGP_PTAG_OLD_LEN_2 = 0x01,	/* Packet has a 2 byte length -
142*ebfedea0SLionel Sambuc 					 * header is 3 bytes long. */
143*ebfedea0SLionel Sambuc 	PGP_PTAG_OLD_LEN_4 = 0x02,	/* Packet has a 4 byte
144*ebfedea0SLionel Sambuc 						 * length - header is 5 bytes
145*ebfedea0SLionel Sambuc 						 * long. */
146*ebfedea0SLionel Sambuc 	PGP_PTAG_OLD_LEN_INDETERMINATE = 0x03	/* Packet has a
147*ebfedea0SLionel Sambuc 						 * indeterminate length. */
148*ebfedea0SLionel Sambuc } pgp_ptag_of_lt_t;
149*ebfedea0SLionel Sambuc 
150*ebfedea0SLionel Sambuc 
151*ebfedea0SLionel Sambuc /** New Packet Format: Mask for content tag.
152*ebfedea0SLionel Sambuc  * In the new packet format the 6 rightmost bits
153*ebfedea0SLionel Sambuc  * are the content tag.  This is the mask to apply
154*ebfedea0SLionel Sambuc  * to the packet tag.  Note that you need to
155*ebfedea0SLionel Sambuc  * shift by #PGP_PTAG_NF_CONTENT_TAG_SHIFT bits.
156*ebfedea0SLionel Sambuc  *
157*ebfedea0SLionel Sambuc  * \see RFC4880 4.2
158*ebfedea0SLionel Sambuc  */
159*ebfedea0SLionel Sambuc #define PGP_PTAG_NF_CONTENT_TAG_MASK	0x3f
160*ebfedea0SLionel Sambuc /** New Packet Format: Offset for the content tag.
161*ebfedea0SLionel Sambuc  * As described at #PGP_PTAG_NF_CONTENT_TAG_MASK the
162*ebfedea0SLionel Sambuc  * content tag needs to be shifted after being masked
163*ebfedea0SLionel Sambuc  * out from the Packet Tag.
164*ebfedea0SLionel Sambuc  *
165*ebfedea0SLionel Sambuc  * \see RFC4880 4.2
166*ebfedea0SLionel Sambuc  */
167*ebfedea0SLionel Sambuc #define PGP_PTAG_NF_CONTENT_TAG_SHIFT	0
168*ebfedea0SLionel Sambuc 
169*ebfedea0SLionel Sambuc /* PTag Content Tags */
170*ebfedea0SLionel Sambuc /***************************/
171*ebfedea0SLionel Sambuc 
172*ebfedea0SLionel Sambuc /** Package Tags (aka Content Tags) and signature subpacket types.
173*ebfedea0SLionel Sambuc  * This enumerates all rfc-defined packet tag values and the
174*ebfedea0SLionel Sambuc  * signature subpacket type values that we understand.
175*ebfedea0SLionel Sambuc  *
176*ebfedea0SLionel Sambuc  * \see RFC4880 4.3
177*ebfedea0SLionel Sambuc  * \see RFC4880 5.2.3.1
178*ebfedea0SLionel Sambuc  */
179*ebfedea0SLionel Sambuc typedef enum {
180*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_RESERVED = 0,	/* Reserved - a packet tag must
181*ebfedea0SLionel Sambuc 					 * not have this value */
182*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_PK_SESSION_KEY = 1,	/* Public-Key Encrypted Session
183*ebfedea0SLionel Sambuc 					 * Key Packet */
184*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_SIGNATURE = 2,	/* Signature Packet */
185*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_SK_SESSION_KEY = 3,	/* Symmetric-Key Encrypted Session
186*ebfedea0SLionel Sambuc 					 * Key Packet */
187*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_1_PASS_SIG = 4,	/* One-Pass Signature
188*ebfedea0SLionel Sambuc 						 * Packet */
189*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_SECRET_KEY = 5,	/* Secret Key Packet */
190*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_PUBLIC_KEY = 6,	/* Public Key Packet */
191*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_SECRET_SUBKEY = 7,	/* Secret Subkey Packet */
192*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_COMPRESSED = 8,	/* Compressed Data Packet */
193*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_SE_DATA = 9,/* Symmetrically Encrypted Data Packet */
194*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_MARKER = 10,/* Marker Packet */
195*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_LITDATA = 11,	/* Literal Data Packet */
196*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_TRUST = 12,	/* Trust Packet */
197*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_USER_ID = 13,	/* User ID Packet */
198*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_PUBLIC_SUBKEY = 14,	/* Public Subkey Packet */
199*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_RESERVED2 = 15,	/* reserved */
200*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_RESERVED3 = 16,	/* reserved */
201*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_USER_ATTR = 17,	/* User Attribute Packet */
202*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_SE_IP_DATA = 18,	/* Sym. Encrypted and Integrity
203*ebfedea0SLionel Sambuc 					 * Protected Data Packet */
204*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_MDC = 19,	/* Modification Detection Code Packet */
205*ebfedea0SLionel Sambuc 
206*ebfedea0SLionel Sambuc 	PGP_PARSER_PTAG = 0x100,/* Internal Use: The packet is the "Packet
207*ebfedea0SLionel Sambuc 				 * Tag" itself - used when callback sends
208*ebfedea0SLionel Sambuc 				 * back the PTag. */
209*ebfedea0SLionel Sambuc 	PGP_PTAG_RAW_SS = 0x101,/* Internal Use: content is raw sig subtag */
210*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_ALL = 0x102,/* Internal Use: select all subtags */
211*ebfedea0SLionel Sambuc 	PGP_PARSER_PACKET_END = 0x103,
212*ebfedea0SLionel Sambuc 
213*ebfedea0SLionel Sambuc 	/* signature subpackets (0x200-2ff) (type+0x200) */
214*ebfedea0SLionel Sambuc 	/* only those we can parse are listed here */
215*ebfedea0SLionel Sambuc 	PGP_PTAG_SIG_SUBPKT_BASE = 0x200,	/* Base for signature
216*ebfedea0SLionel Sambuc 							 * subpacket types - All
217*ebfedea0SLionel Sambuc 							 * signature type values
218*ebfedea0SLionel Sambuc 							 * are relative to this
219*ebfedea0SLionel Sambuc 							 * value. */
220*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_CREATION_TIME = 0x200 + 2,	/* signature creation time */
221*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_EXPIRATION_TIME = 0x200 + 3,	/* signature
222*ebfedea0SLionel Sambuc 							 * expiration time */
223*ebfedea0SLionel Sambuc 
224*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_EXPORT_CERT = 0x200 + 4,	/* exportable certification */
225*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_TRUST = 0x200 + 5,	/* trust signature */
226*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_REGEXP = 0x200 + 6,	/* regular expression */
227*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_REVOCABLE = 0x200 + 7,	/* revocable */
228*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_KEY_EXPIRY = 0x200 + 9,	/* key expiration
229*ebfedea0SLionel Sambuc 							 * time */
230*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_RESERVED = 0x200 + 10,	/* reserved */
231*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_PREFERRED_SKA = 0x200 + 11,	/* preferred symmetric
232*ebfedea0SLionel Sambuc 						 * algs */
233*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_REVOCATION_KEY = 0x200 + 12,	/* revocation key */
234*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_ISSUER_KEY_ID = 0x200 + 16,	/* issuer key ID */
235*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_NOTATION_DATA = 0x200 + 20,	/* notation data */
236*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_PREFERRED_HASH = 0x200 + 21,	/* preferred hash
237*ebfedea0SLionel Sambuc 							 * algs */
238*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_PREF_COMPRESS = 0x200 + 22,	/* preferred
239*ebfedea0SLionel Sambuc 							 * compression
240*ebfedea0SLionel Sambuc 							 * algorithms */
241*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_KEYSERV_PREFS = 0x200 + 23,	/* key server
242*ebfedea0SLionel Sambuc 							 * preferences */
243*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_PREF_KEYSERV = 0x200 + 24,	/* Preferred Key
244*ebfedea0SLionel Sambuc 							 * Server */
245*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_PRIMARY_USER_ID = 0x200 + 25,	/* primary User ID */
246*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_POLICY_URI = 0x200 + 26,	/* Policy URI */
247*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_KEY_FLAGS = 0x200 + 27,	/* key flags */
248*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_SIGNERS_USER_ID = 0x200 + 28,	/* Signer's User ID */
249*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_REVOCATION_REASON = 0x200 + 29,	/* reason for
250*ebfedea0SLionel Sambuc 							 * revocation */
251*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_FEATURES = 0x200 + 30,	/* features */
252*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_SIGNATURE_TARGET = 0x200 + 31,	/* signature target */
253*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_EMBEDDED_SIGNATURE = 0x200 + 32,	/* embedded signature */
254*ebfedea0SLionel Sambuc 
255*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_USERDEFINED00 = 0x200 + 100,	/* internal or
256*ebfedea0SLionel Sambuc 							 * user-defined */
257*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_USERDEFINED01 = 0x200 + 101,
258*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_USERDEFINED02 = 0x200 + 102,
259*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_USERDEFINED03 = 0x200 + 103,
260*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_USERDEFINED04 = 0x200 + 104,
261*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_USERDEFINED05 = 0x200 + 105,
262*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_USERDEFINED06 = 0x200 + 106,
263*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_USERDEFINED07 = 0x200 + 107,
264*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_USERDEFINED08 = 0x200 + 108,
265*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_USERDEFINED09 = 0x200 + 109,
266*ebfedea0SLionel Sambuc 	PGP_PTAG_SS_USERDEFINED10 = 0x200 + 110,
267*ebfedea0SLionel Sambuc 
268*ebfedea0SLionel Sambuc 	/* pseudo content types */
269*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_LITDATA_HEADER = 0x300,
270*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_LITDATA_BODY = 0x300 + 1,
271*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_SIGNATURE_HEADER = 0x300 + 2,
272*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_SIGNATURE_FOOTER = 0x300 + 3,
273*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_ARMOUR_HEADER = 0x300 + 4,
274*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_ARMOUR_TRAILER = 0x300 + 5,
275*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_SIGNED_CLEARTEXT_HEADER = 0x300 + 6,
276*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_SIGNED_CLEARTEXT_BODY = 0x300 + 7,
277*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_SIGNED_CLEARTEXT_TRAILER = 0x300 + 8,
278*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_UNARMOURED_TEXT = 0x300 + 9,
279*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_ENCRYPTED_SECRET_KEY = 0x300 + 10,	/* In this case the
280*ebfedea0SLionel Sambuc 							 * algorithm specific
281*ebfedea0SLionel Sambuc 							 * fields will not be
282*ebfedea0SLionel Sambuc 							 * initialised */
283*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_SE_DATA_HEADER = 0x300 + 11,
284*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_SE_DATA_BODY = 0x300 + 12,
285*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_SE_IP_DATA_HEADER = 0x300 + 13,
286*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_SE_IP_DATA_BODY = 0x300 + 14,
287*ebfedea0SLionel Sambuc 	PGP_PTAG_CT_ENCRYPTED_PK_SESSION_KEY = 0x300 + 15,
288*ebfedea0SLionel Sambuc 
289*ebfedea0SLionel Sambuc 	/* commands to the callback */
290*ebfedea0SLionel Sambuc 	PGP_GET_PASSPHRASE = 0x400,
291*ebfedea0SLionel Sambuc 	PGP_GET_SECKEY = 0x400 + 1,
292*ebfedea0SLionel Sambuc 
293*ebfedea0SLionel Sambuc 	/* Errors */
294*ebfedea0SLionel Sambuc 	PGP_PARSER_ERROR = 0x500,	/* Internal Use: Parser Error */
295*ebfedea0SLionel Sambuc 	PGP_PARSER_ERRCODE = 0x500 + 1	/* Internal Use: Parser Error
296*ebfedea0SLionel Sambuc 					 * with errcode returned */
297*ebfedea0SLionel Sambuc } pgp_content_enum;
298*ebfedea0SLionel Sambuc 
299*ebfedea0SLionel Sambuc enum {
300*ebfedea0SLionel Sambuc 	PGP_REVOCATION_NO_REASON	= 0,
301*ebfedea0SLionel Sambuc 	PGP_REVOCATION_SUPERSEDED	= 1,
302*ebfedea0SLionel Sambuc 	PGP_REVOCATION_COMPROMISED	= 2,
303*ebfedea0SLionel Sambuc 	PGP_REVOCATION_RETIRED		= 3,
304*ebfedea0SLionel Sambuc 	PGP_REVOCATION_NO_LONGER_VALID	= 0x20
305*ebfedea0SLionel Sambuc };
306*ebfedea0SLionel Sambuc 
307*ebfedea0SLionel Sambuc /** Structure to hold one error code */
308*ebfedea0SLionel Sambuc typedef struct {
309*ebfedea0SLionel Sambuc 	pgp_errcode_t   errcode;
310*ebfedea0SLionel Sambuc } pgp_parser_errcode_t;
311*ebfedea0SLionel Sambuc 
312*ebfedea0SLionel Sambuc /** Structure to hold one packet tag.
313*ebfedea0SLionel Sambuc  * \see RFC4880 4.2
314*ebfedea0SLionel Sambuc  */
315*ebfedea0SLionel Sambuc typedef struct {
316*ebfedea0SLionel Sambuc 	unsigned        new_format;	/* Whether this packet tag is new
317*ebfedea0SLionel Sambuc 					 * (1) or old format (0) */
318*ebfedea0SLionel Sambuc 	unsigned        type;	/* content_tag value - See
319*ebfedea0SLionel Sambuc 					 * #pgp_content_enum for meanings */
320*ebfedea0SLionel Sambuc 	pgp_ptag_of_lt_t length_type;	/* Length type (#pgp_ptag_of_lt_t)
321*ebfedea0SLionel Sambuc 					 * - only if this packet tag is old
322*ebfedea0SLionel Sambuc 					 * format.  Set to 0 if new format. */
323*ebfedea0SLionel Sambuc 	unsigned        length;	/* The length of the packet.  This value
324*ebfedea0SLionel Sambuc 				 * is set when we read and compute the length
325*ebfedea0SLionel Sambuc 				 * information, not at the same moment we
326*ebfedea0SLionel Sambuc 				 * create the packet tag structure. Only
327*ebfedea0SLionel Sambuc 	 * defined if #readc is set. *//* XXX: Ben, is this correct? */
328*ebfedea0SLionel Sambuc 	unsigned        position;	/* The position (within the
329*ebfedea0SLionel Sambuc 					 * current reader) of the packet */
330*ebfedea0SLionel Sambuc 	unsigned	size;	/* number of bits */
331*ebfedea0SLionel Sambuc } pgp_ptag_t;
332*ebfedea0SLionel Sambuc 
333*ebfedea0SLionel Sambuc /** Public Key Algorithm Numbers.
334*ebfedea0SLionel Sambuc  * OpenPGP assigns a unique Algorithm Number to each algorithm that is part of OpenPGP.
335*ebfedea0SLionel Sambuc  *
336*ebfedea0SLionel Sambuc  * This lists algorithm numbers for public key algorithms.
337*ebfedea0SLionel Sambuc  *
338*ebfedea0SLionel Sambuc  * \see RFC4880 9.1
339*ebfedea0SLionel Sambuc  */
340*ebfedea0SLionel Sambuc typedef enum {
341*ebfedea0SLionel Sambuc 	PGP_PKA_NOTHING	= 0,	/* No PKA */
342*ebfedea0SLionel Sambuc 	PGP_PKA_RSA = 1,	/* RSA (Encrypt or Sign) */
343*ebfedea0SLionel Sambuc 	PGP_PKA_RSA_ENCRYPT_ONLY = 2,	/* RSA Encrypt-Only (deprecated -
344*ebfedea0SLionel Sambuc 					 * \see RFC4880 13.5) */
345*ebfedea0SLionel Sambuc 	PGP_PKA_RSA_SIGN_ONLY = 3,	/* RSA Sign-Only (deprecated -
346*ebfedea0SLionel Sambuc 					 * \see RFC4880 13.5) */
347*ebfedea0SLionel Sambuc 	PGP_PKA_ELGAMAL = 16,	/* Elgamal (Encrypt-Only) */
348*ebfedea0SLionel Sambuc 	PGP_PKA_DSA = 17,	/* DSA (Digital Signature Algorithm) */
349*ebfedea0SLionel Sambuc 	PGP_PKA_RESERVED_ELLIPTIC_CURVE = 18,	/* Reserved for Elliptic
350*ebfedea0SLionel Sambuc 						 * Curve */
351*ebfedea0SLionel Sambuc 	PGP_PKA_RESERVED_ECDSA = 19,	/* Reserved for ECDSA */
352*ebfedea0SLionel Sambuc 	PGP_PKA_ELGAMAL_ENCRYPT_OR_SIGN = 20,	/* Deprecated. */
353*ebfedea0SLionel Sambuc 	PGP_PKA_RESERVED_DH = 21,	/* Reserved for Diffie-Hellman
354*ebfedea0SLionel Sambuc 					 * (X9.42, as defined for
355*ebfedea0SLionel Sambuc 					 * IETF-S/MIME) */
356*ebfedea0SLionel Sambuc 	PGP_PKA_PRIVATE00 = 100,/* Private/Experimental Algorithm */
357*ebfedea0SLionel Sambuc 	PGP_PKA_PRIVATE01 = 101,/* Private/Experimental Algorithm */
358*ebfedea0SLionel Sambuc 	PGP_PKA_PRIVATE02 = 102,/* Private/Experimental Algorithm */
359*ebfedea0SLionel Sambuc 	PGP_PKA_PRIVATE03 = 103,/* Private/Experimental Algorithm */
360*ebfedea0SLionel Sambuc 	PGP_PKA_PRIVATE04 = 104,/* Private/Experimental Algorithm */
361*ebfedea0SLionel Sambuc 	PGP_PKA_PRIVATE05 = 105,/* Private/Experimental Algorithm */
362*ebfedea0SLionel Sambuc 	PGP_PKA_PRIVATE06 = 106,/* Private/Experimental Algorithm */
363*ebfedea0SLionel Sambuc 	PGP_PKA_PRIVATE07 = 107,/* Private/Experimental Algorithm */
364*ebfedea0SLionel Sambuc 	PGP_PKA_PRIVATE08 = 108,/* Private/Experimental Algorithm */
365*ebfedea0SLionel Sambuc 	PGP_PKA_PRIVATE09 = 109,/* Private/Experimental Algorithm */
366*ebfedea0SLionel Sambuc 	PGP_PKA_PRIVATE10 = 110	/* Private/Experimental Algorithm */
367*ebfedea0SLionel Sambuc } pgp_pubkey_alg_t;
368*ebfedea0SLionel Sambuc 
369*ebfedea0SLionel Sambuc /** Structure to hold one DSA public key params.
370*ebfedea0SLionel Sambuc  *
371*ebfedea0SLionel Sambuc  * \see RFC4880 5.5.2
372*ebfedea0SLionel Sambuc  */
373*ebfedea0SLionel Sambuc typedef struct {
374*ebfedea0SLionel Sambuc 	BIGNUM         *p;	/* DSA prime p */
375*ebfedea0SLionel Sambuc 	BIGNUM         *q;	/* DSA group order q */
376*ebfedea0SLionel Sambuc 	BIGNUM         *g;	/* DSA group generator g */
377*ebfedea0SLionel Sambuc 	BIGNUM         *y;	/* DSA public key value y (= g^x mod p
378*ebfedea0SLionel Sambuc 				 * with x being the secret) */
379*ebfedea0SLionel Sambuc } pgp_dsa_pubkey_t;
380*ebfedea0SLionel Sambuc 
381*ebfedea0SLionel Sambuc /** Structure to hold an RSA public key.
382*ebfedea0SLionel Sambuc  *
383*ebfedea0SLionel Sambuc  * \see RFC4880 5.5.2
384*ebfedea0SLionel Sambuc  */
385*ebfedea0SLionel Sambuc typedef struct {
386*ebfedea0SLionel Sambuc 	BIGNUM         *n;	/* RSA public modulus n */
387*ebfedea0SLionel Sambuc 	BIGNUM         *e;	/* RSA public encryption exponent e */
388*ebfedea0SLionel Sambuc } pgp_rsa_pubkey_t;
389*ebfedea0SLionel Sambuc 
390*ebfedea0SLionel Sambuc /** Structure to hold an ElGamal public key params.
391*ebfedea0SLionel Sambuc  *
392*ebfedea0SLionel Sambuc  * \see RFC4880 5.5.2
393*ebfedea0SLionel Sambuc  */
394*ebfedea0SLionel Sambuc typedef struct {
395*ebfedea0SLionel Sambuc 	BIGNUM         *p;	/* ElGamal prime p */
396*ebfedea0SLionel Sambuc 	BIGNUM         *g;	/* ElGamal group generator g */
397*ebfedea0SLionel Sambuc 	BIGNUM         *y;	/* ElGamal public key value y (= g^x mod p
398*ebfedea0SLionel Sambuc 				 * with x being the secret) */
399*ebfedea0SLionel Sambuc } pgp_elgamal_pubkey_t;
400*ebfedea0SLionel Sambuc 
401*ebfedea0SLionel Sambuc /** Version.
402*ebfedea0SLionel Sambuc  * OpenPGP has two different protocol versions: version 3 and version 4.
403*ebfedea0SLionel Sambuc  *
404*ebfedea0SLionel Sambuc  * \see RFC4880 5.2
405*ebfedea0SLionel Sambuc  */
406*ebfedea0SLionel Sambuc typedef enum {
407*ebfedea0SLionel Sambuc 	PGP_V2 = 2,		/* Version 2 (essentially the same as v3) */
408*ebfedea0SLionel Sambuc 	PGP_V3 = 3,		/* Version 3 */
409*ebfedea0SLionel Sambuc 	PGP_V4 = 4		/* Version 4 */
410*ebfedea0SLionel Sambuc } pgp_version_t;
411*ebfedea0SLionel Sambuc 
412*ebfedea0SLionel Sambuc /** Structure to hold a pgp public key */
413*ebfedea0SLionel Sambuc typedef struct {
414*ebfedea0SLionel Sambuc 	pgp_version_t		version;/* version of the key (v3, v4...) */
415*ebfedea0SLionel Sambuc 	time_t			birthtime;
416*ebfedea0SLionel Sambuc 	time_t			duration;
417*ebfedea0SLionel Sambuc 		/* validity period of the key in days since
418*ebfedea0SLionel Sambuc 		* creation.  A value of 0 has a special meaning
419*ebfedea0SLionel Sambuc 		* indicating this key does not expire.  Only used with
420*ebfedea0SLionel Sambuc 		* v3 keys.  */
421*ebfedea0SLionel Sambuc 	unsigned		days_valid;	/* v4 duration */
422*ebfedea0SLionel Sambuc 	pgp_pubkey_alg_t	alg;	/* Public Key Algorithm type */
423*ebfedea0SLionel Sambuc 	union {
424*ebfedea0SLionel Sambuc 		pgp_dsa_pubkey_t dsa;	/* A DSA public key */
425*ebfedea0SLionel Sambuc 		pgp_rsa_pubkey_t rsa;	/* An RSA public key */
426*ebfedea0SLionel Sambuc 		pgp_elgamal_pubkey_t elgamal;	/* An ElGamal public key */
427*ebfedea0SLionel Sambuc 	}			key;	/* Public Key Parameters */
428*ebfedea0SLionel Sambuc } pgp_pubkey_t;
429*ebfedea0SLionel Sambuc 
430*ebfedea0SLionel Sambuc /** Structure to hold data for one RSA secret key
431*ebfedea0SLionel Sambuc  */
432*ebfedea0SLionel Sambuc typedef struct {
433*ebfedea0SLionel Sambuc 	BIGNUM         *d;
434*ebfedea0SLionel Sambuc 	BIGNUM         *p;
435*ebfedea0SLionel Sambuc 	BIGNUM         *q;
436*ebfedea0SLionel Sambuc 	BIGNUM         *u;
437*ebfedea0SLionel Sambuc } pgp_rsa_seckey_t;
438*ebfedea0SLionel Sambuc 
439*ebfedea0SLionel Sambuc /** pgp_dsa_seckey_t */
440*ebfedea0SLionel Sambuc typedef struct {
441*ebfedea0SLionel Sambuc 	BIGNUM         *x;
442*ebfedea0SLionel Sambuc } pgp_dsa_seckey_t;
443*ebfedea0SLionel Sambuc 
444*ebfedea0SLionel Sambuc /** pgp_elgamal_seckey_t */
445*ebfedea0SLionel Sambuc typedef struct {
446*ebfedea0SLionel Sambuc 	BIGNUM         *x;
447*ebfedea0SLionel Sambuc } pgp_elgamal_seckey_t;
448*ebfedea0SLionel Sambuc 
449*ebfedea0SLionel Sambuc /** s2k_usage_t
450*ebfedea0SLionel Sambuc  */
451*ebfedea0SLionel Sambuc typedef enum {
452*ebfedea0SLionel Sambuc 	PGP_S2KU_NONE = 0,
453*ebfedea0SLionel Sambuc 	PGP_S2KU_ENCRYPTED_AND_HASHED = 254,
454*ebfedea0SLionel Sambuc 	PGP_S2KU_ENCRYPTED = 255
455*ebfedea0SLionel Sambuc } pgp_s2k_usage_t;
456*ebfedea0SLionel Sambuc 
457*ebfedea0SLionel Sambuc /** s2k_specifier_t
458*ebfedea0SLionel Sambuc  */
459*ebfedea0SLionel Sambuc typedef enum {
460*ebfedea0SLionel Sambuc 	PGP_S2KS_SIMPLE = 0,
461*ebfedea0SLionel Sambuc 	PGP_S2KS_SALTED = 1,
462*ebfedea0SLionel Sambuc 	PGP_S2KS_ITERATED_AND_SALTED = 3
463*ebfedea0SLionel Sambuc } pgp_s2k_specifier_t;
464*ebfedea0SLionel Sambuc 
465*ebfedea0SLionel Sambuc /** Symmetric Key Algorithm Numbers.
466*ebfedea0SLionel Sambuc  * OpenPGP assigns a unique Algorithm Number to each algorithm that is
467*ebfedea0SLionel Sambuc  * part of OpenPGP.
468*ebfedea0SLionel Sambuc  *
469*ebfedea0SLionel Sambuc  * This lists algorithm numbers for symmetric key algorithms.
470*ebfedea0SLionel Sambuc  *
471*ebfedea0SLionel Sambuc  * \see RFC4880 9.2
472*ebfedea0SLionel Sambuc  */
473*ebfedea0SLionel Sambuc typedef enum {
474*ebfedea0SLionel Sambuc 	PGP_SA_PLAINTEXT = 0,	/* Plaintext or unencrypted data */
475*ebfedea0SLionel Sambuc 	PGP_SA_IDEA = 1,	/* IDEA */
476*ebfedea0SLionel Sambuc 	PGP_SA_TRIPLEDES = 2,	/* TripleDES */
477*ebfedea0SLionel Sambuc 	PGP_SA_CAST5 = 3,	/* CAST5 */
478*ebfedea0SLionel Sambuc 	PGP_SA_BLOWFISH = 4,	/* Blowfish */
479*ebfedea0SLionel Sambuc 	PGP_SA_AES_128 = 7,	/* AES with 128-bit key (AES) */
480*ebfedea0SLionel Sambuc 	PGP_SA_AES_192 = 8,	/* AES with 192-bit key */
481*ebfedea0SLionel Sambuc 	PGP_SA_AES_256 = 9,	/* AES with 256-bit key */
482*ebfedea0SLionel Sambuc 	PGP_SA_TWOFISH = 10,	/* Twofish with 256-bit key (TWOFISH) */
483*ebfedea0SLionel Sambuc 	PGP_SA_CAMELLIA_128 = 100,	/* Camellia with 128-bit key (CAMELLIA) */
484*ebfedea0SLionel Sambuc 	PGP_SA_CAMELLIA_192 = 101,	/* Camellia with 192-bit key */
485*ebfedea0SLionel Sambuc 	PGP_SA_CAMELLIA_256 = 102	/* Camellia with 256-bit key */
486*ebfedea0SLionel Sambuc } pgp_symm_alg_t;
487*ebfedea0SLionel Sambuc 
488*ebfedea0SLionel Sambuc #define PGP_SA_DEFAULT_CIPHER	PGP_SA_CAST5
489*ebfedea0SLionel Sambuc 
490*ebfedea0SLionel Sambuc /** Hashing Algorithm Numbers.
491*ebfedea0SLionel Sambuc  * OpenPGP assigns a unique Algorithm Number to each algorithm that is
492*ebfedea0SLionel Sambuc  * part of OpenPGP.
493*ebfedea0SLionel Sambuc  *
494*ebfedea0SLionel Sambuc  * This lists algorithm numbers for hash algorithms.
495*ebfedea0SLionel Sambuc  *
496*ebfedea0SLionel Sambuc  * \see RFC4880 9.4
497*ebfedea0SLionel Sambuc  */
498*ebfedea0SLionel Sambuc typedef enum {
499*ebfedea0SLionel Sambuc 	PGP_HASH_UNKNOWN = -1,	/* used to indicate errors */
500*ebfedea0SLionel Sambuc 	PGP_HASH_MD5 = 1,	/* MD5 */
501*ebfedea0SLionel Sambuc 	PGP_HASH_SHA1 = 2,	/* SHA-1 */
502*ebfedea0SLionel Sambuc 	PGP_HASH_RIPEMD = 3,	/* RIPEMD160 */
503*ebfedea0SLionel Sambuc 
504*ebfedea0SLionel Sambuc 	PGP_HASH_SHA256 = 8,	/* SHA256 */
505*ebfedea0SLionel Sambuc 	PGP_HASH_SHA384 = 9,	/* SHA384 */
506*ebfedea0SLionel Sambuc 	PGP_HASH_SHA512 = 10,	/* SHA512 */
507*ebfedea0SLionel Sambuc 	PGP_HASH_SHA224 = 11	/* SHA224 */
508*ebfedea0SLionel Sambuc } pgp_hash_alg_t;
509*ebfedea0SLionel Sambuc 
510*ebfedea0SLionel Sambuc #define	PGP_DEFAULT_HASH_ALGORITHM	PGP_HASH_SHA256
511*ebfedea0SLionel Sambuc 
512*ebfedea0SLionel Sambuc void   pgp_calc_mdc_hash(const uint8_t *,
513*ebfedea0SLionel Sambuc 			const size_t,
514*ebfedea0SLionel Sambuc 			const uint8_t *,
515*ebfedea0SLionel Sambuc 			const unsigned,
516*ebfedea0SLionel Sambuc 			uint8_t *);
517*ebfedea0SLionel Sambuc unsigned   pgp_is_hash_alg_supported(const pgp_hash_alg_t *);
518*ebfedea0SLionel Sambuc 
519*ebfedea0SLionel Sambuc /* Maximum block size for symmetric crypto */
520*ebfedea0SLionel Sambuc #define PGP_MAX_BLOCK_SIZE	16
521*ebfedea0SLionel Sambuc 
522*ebfedea0SLionel Sambuc /* Maximum key size for symmetric crypto */
523*ebfedea0SLionel Sambuc #define PGP_MAX_KEY_SIZE	32
524*ebfedea0SLionel Sambuc 
525*ebfedea0SLionel Sambuc /* Salt size for hashing */
526*ebfedea0SLionel Sambuc #define PGP_SALT_SIZE		8
527*ebfedea0SLionel Sambuc 
528*ebfedea0SLionel Sambuc /* Max hash size */
529*ebfedea0SLionel Sambuc #define PGP_MAX_HASH_SIZE	64
530*ebfedea0SLionel Sambuc 
531*ebfedea0SLionel Sambuc /** pgp_seckey_t
532*ebfedea0SLionel Sambuc  */
533*ebfedea0SLionel Sambuc typedef struct pgp_seckey_t {
534*ebfedea0SLionel Sambuc 	pgp_pubkey_t			pubkey;		/* public key */
535*ebfedea0SLionel Sambuc 	pgp_s2k_usage_t		s2k_usage;
536*ebfedea0SLionel Sambuc 	pgp_s2k_specifier_t		s2k_specifier;
537*ebfedea0SLionel Sambuc 	pgp_symm_alg_t		alg;		/* symmetric alg */
538*ebfedea0SLionel Sambuc 	pgp_hash_alg_t		hash_alg;	/* hash algorithm */
539*ebfedea0SLionel Sambuc 	uint8_t				salt[PGP_SALT_SIZE];
540*ebfedea0SLionel Sambuc 	unsigned			octetc;
541*ebfedea0SLionel Sambuc 	uint8_t				iv[PGP_MAX_BLOCK_SIZE];
542*ebfedea0SLionel Sambuc 	union {
543*ebfedea0SLionel Sambuc 		pgp_rsa_seckey_t		rsa;
544*ebfedea0SLionel Sambuc 		pgp_dsa_seckey_t		dsa;
545*ebfedea0SLionel Sambuc 		pgp_elgamal_seckey_t		elgamal;
546*ebfedea0SLionel Sambuc 	}				key;
547*ebfedea0SLionel Sambuc 	unsigned			checksum;
548*ebfedea0SLionel Sambuc 	uint8_t			       *checkhash;
549*ebfedea0SLionel Sambuc } pgp_seckey_t;
550*ebfedea0SLionel Sambuc 
551*ebfedea0SLionel Sambuc /** Signature Type.
552*ebfedea0SLionel Sambuc  * OpenPGP defines different signature types that allow giving
553*ebfedea0SLionel Sambuc  * different meanings to signatures.  Signature types include 0x10 for
554*ebfedea0SLionel Sambuc  * generitc User ID certifications (used when Ben signs Weasel's key),
555*ebfedea0SLionel Sambuc  * Subkey binding signatures, document signatures, key revocations,
556*ebfedea0SLionel Sambuc  * etc.
557*ebfedea0SLionel Sambuc  *
558*ebfedea0SLionel Sambuc  * Different types are used in different places, and most make only
559*ebfedea0SLionel Sambuc  * sense in their intended location (for instance a subkey binding has
560*ebfedea0SLionel Sambuc  * no place on a UserID).
561*ebfedea0SLionel Sambuc  *
562*ebfedea0SLionel Sambuc  * \see RFC4880 5.2.1
563*ebfedea0SLionel Sambuc  */
564*ebfedea0SLionel Sambuc typedef enum {
565*ebfedea0SLionel Sambuc 	PGP_SIG_BINARY = 0x00,	/* Signature of a binary document */
566*ebfedea0SLionel Sambuc 	PGP_SIG_TEXT = 0x01,	/* Signature of a canonical text document */
567*ebfedea0SLionel Sambuc 	PGP_SIG_STANDALONE = 0x02,	/* Standalone signature */
568*ebfedea0SLionel Sambuc 
569*ebfedea0SLionel Sambuc 	PGP_CERT_GENERIC = 0x10,/* Generic certification of a User ID and
570*ebfedea0SLionel Sambuc 				 * Public Key packet */
571*ebfedea0SLionel Sambuc 	PGP_CERT_PERSONA = 0x11,/* Persona certification of a User ID and
572*ebfedea0SLionel Sambuc 				 * Public Key packet */
573*ebfedea0SLionel Sambuc 	PGP_CERT_CASUAL = 0x12,	/* Casual certification of a User ID and
574*ebfedea0SLionel Sambuc 				 * Public Key packet */
575*ebfedea0SLionel Sambuc 	PGP_CERT_POSITIVE = 0x13,	/* Positive certification of a
576*ebfedea0SLionel Sambuc 					 * User ID and Public Key packet */
577*ebfedea0SLionel Sambuc 
578*ebfedea0SLionel Sambuc 	PGP_SIG_SUBKEY = 0x18,	/* Subkey Binding Signature */
579*ebfedea0SLionel Sambuc 	PGP_SIG_PRIMARY = 0x19,	/* Primary Key Binding Signature */
580*ebfedea0SLionel Sambuc 	PGP_SIG_DIRECT = 0x1f,	/* Signature directly on a key */
581*ebfedea0SLionel Sambuc 
582*ebfedea0SLionel Sambuc 	PGP_SIG_REV_KEY = 0x20,	/* Key revocation signature */
583*ebfedea0SLionel Sambuc 	PGP_SIG_REV_SUBKEY = 0x28,	/* Subkey revocation signature */
584*ebfedea0SLionel Sambuc 	PGP_SIG_REV_CERT = 0x30,/* Certification revocation signature */
585*ebfedea0SLionel Sambuc 
586*ebfedea0SLionel Sambuc 	PGP_SIG_TIMESTAMP = 0x40,	/* Timestamp signature */
587*ebfedea0SLionel Sambuc 
588*ebfedea0SLionel Sambuc 	PGP_SIG_3RD_PARTY = 0x50/* Third-Party Confirmation signature */
589*ebfedea0SLionel Sambuc } pgp_sig_type_t;
590*ebfedea0SLionel Sambuc 
591*ebfedea0SLionel Sambuc /** Struct to hold params of an RSA signature */
592*ebfedea0SLionel Sambuc typedef struct pgp_rsa_sig_t {
593*ebfedea0SLionel Sambuc 	BIGNUM         *sig;	/* the signature value (m^d % n) */
594*ebfedea0SLionel Sambuc } pgp_rsa_sig_t;
595*ebfedea0SLionel Sambuc 
596*ebfedea0SLionel Sambuc /** Struct to hold params of a DSA signature */
597*ebfedea0SLionel Sambuc typedef struct pgp_dsa_sig_t {
598*ebfedea0SLionel Sambuc 	BIGNUM         *r;	/* DSA value r */
599*ebfedea0SLionel Sambuc 	BIGNUM         *s;	/* DSA value s */
600*ebfedea0SLionel Sambuc } pgp_dsa_sig_t;
601*ebfedea0SLionel Sambuc 
602*ebfedea0SLionel Sambuc /** pgp_elgamal_signature_t */
603*ebfedea0SLionel Sambuc typedef struct pgp_elgamal_sig_t {
604*ebfedea0SLionel Sambuc 	BIGNUM         *r;
605*ebfedea0SLionel Sambuc 	BIGNUM         *s;
606*ebfedea0SLionel Sambuc } pgp_elgamal_sig_t;
607*ebfedea0SLionel Sambuc 
608*ebfedea0SLionel Sambuc #define PGP_KEY_ID_SIZE		8
609*ebfedea0SLionel Sambuc #define PGP_FINGERPRINT_SIZE	20
610*ebfedea0SLionel Sambuc 
611*ebfedea0SLionel Sambuc /** Struct to hold a signature packet.
612*ebfedea0SLionel Sambuc  *
613*ebfedea0SLionel Sambuc  * \see RFC4880 5.2.2
614*ebfedea0SLionel Sambuc  * \see RFC4880 5.2.3
615*ebfedea0SLionel Sambuc  */
616*ebfedea0SLionel Sambuc typedef struct pgp_sig_info_t {
617*ebfedea0SLionel Sambuc 	pgp_version_t   version;/* signature version number */
618*ebfedea0SLionel Sambuc 	pgp_sig_type_t  type;	/* signature type value */
619*ebfedea0SLionel Sambuc 	time_t          birthtime;	/* creation time of the signature */
620*ebfedea0SLionel Sambuc 	time_t          duration;	/* number of seconds it's valid for */
621*ebfedea0SLionel Sambuc 	uint8_t		signer_id[PGP_KEY_ID_SIZE];	/* Eight-octet key ID
622*ebfedea0SLionel Sambuc 							 * of signer */
623*ebfedea0SLionel Sambuc 	pgp_pubkey_alg_t key_alg;	/* public key algorithm number */
624*ebfedea0SLionel Sambuc 	pgp_hash_alg_t hash_alg;	/* hashing algorithm number */
625*ebfedea0SLionel Sambuc 	union {
626*ebfedea0SLionel Sambuc 		pgp_rsa_sig_t	rsa;	/* An RSA Signature */
627*ebfedea0SLionel Sambuc 		pgp_dsa_sig_t	dsa;	/* A DSA Signature */
628*ebfedea0SLionel Sambuc 		pgp_elgamal_sig_t	elgamal;	/* deprecated */
629*ebfedea0SLionel Sambuc 		pgp_data_t	unknown;	/* private or experimental */
630*ebfedea0SLionel Sambuc 	}			sig;	/* signature params */
631*ebfedea0SLionel Sambuc 	size_t          v4_hashlen;
632*ebfedea0SLionel Sambuc 	uint8_t		*v4_hashed;
633*ebfedea0SLionel Sambuc 	unsigned	 birthtime_set:1;
634*ebfedea0SLionel Sambuc 	unsigned	 signer_id_set:1;
635*ebfedea0SLionel Sambuc 	unsigned	 duration_set:1;
636*ebfedea0SLionel Sambuc } pgp_sig_info_t;
637*ebfedea0SLionel Sambuc 
638*ebfedea0SLionel Sambuc /** Struct used when parsing a signature */
639*ebfedea0SLionel Sambuc typedef struct pgp_sig_t {
640*ebfedea0SLionel Sambuc 	pgp_sig_info_t info;	/* The signature information */
641*ebfedea0SLionel Sambuc 	/* The following fields are only used while parsing the signature */
642*ebfedea0SLionel Sambuc 	uint8_t		 hash2[2];	/* high 2 bytes of hashed value */
643*ebfedea0SLionel Sambuc 	size_t		 v4_hashstart;	/* only valid if accumulate is set */
644*ebfedea0SLionel Sambuc 	pgp_hash_t     *hash;	/* the hash filled in for the data so far */
645*ebfedea0SLionel Sambuc } pgp_sig_t;
646*ebfedea0SLionel Sambuc 
647*ebfedea0SLionel Sambuc /** The raw bytes of a signature subpacket */
648*ebfedea0SLionel Sambuc 
649*ebfedea0SLionel Sambuc typedef struct pgp_ss_raw_t {
650*ebfedea0SLionel Sambuc 	pgp_content_enum	 tag;
651*ebfedea0SLionel Sambuc 	size_t          	 length;
652*ebfedea0SLionel Sambuc 	uint8_t			*raw;
653*ebfedea0SLionel Sambuc } pgp_ss_raw_t;
654*ebfedea0SLionel Sambuc 
655*ebfedea0SLionel Sambuc /** Signature Subpacket : Trust Level */
656*ebfedea0SLionel Sambuc 
657*ebfedea0SLionel Sambuc typedef struct pgp_ss_trust_t {
658*ebfedea0SLionel Sambuc 	uint8_t			 level;		/* Trust Level */
659*ebfedea0SLionel Sambuc 	uint8_t			 amount;	/* Amount */
660*ebfedea0SLionel Sambuc } pgp_ss_trust_t;
661*ebfedea0SLionel Sambuc 
662*ebfedea0SLionel Sambuc /** Signature Subpacket : Notation Data */
663*ebfedea0SLionel Sambuc typedef struct pgp_ss_notation_t {
664*ebfedea0SLionel Sambuc 	pgp_data_t		flags;
665*ebfedea0SLionel Sambuc 	pgp_data_t		name;
666*ebfedea0SLionel Sambuc 	pgp_data_t		value;
667*ebfedea0SLionel Sambuc } pgp_ss_notation_t;
668*ebfedea0SLionel Sambuc 
669*ebfedea0SLionel Sambuc /** Signature Subpacket : Signature Target */
670*ebfedea0SLionel Sambuc typedef struct pgp_ss_sig_target_t {
671*ebfedea0SLionel Sambuc 	pgp_pubkey_alg_t	pka_alg;
672*ebfedea0SLionel Sambuc 	pgp_hash_alg_t		hash_alg;
673*ebfedea0SLionel Sambuc 	pgp_data_t		hash;
674*ebfedea0SLionel Sambuc } pgp_ss_sig_target_t;
675*ebfedea0SLionel Sambuc 
676*ebfedea0SLionel Sambuc /** pgp_subpacket_t */
677*ebfedea0SLionel Sambuc typedef struct pgp_subpacket_t {
678*ebfedea0SLionel Sambuc 	size_t          	 length;
679*ebfedea0SLionel Sambuc 	uint8_t			*raw;
680*ebfedea0SLionel Sambuc } pgp_subpacket_t;
681*ebfedea0SLionel Sambuc 
682*ebfedea0SLionel Sambuc /** Types of Compression */
683*ebfedea0SLionel Sambuc typedef enum {
684*ebfedea0SLionel Sambuc 	PGP_C_NONE = 0,
685*ebfedea0SLionel Sambuc 	PGP_C_ZIP = 1,
686*ebfedea0SLionel Sambuc 	PGP_C_ZLIB = 2,
687*ebfedea0SLionel Sambuc 	PGP_C_BZIP2 = 3
688*ebfedea0SLionel Sambuc } pgp_compression_type_t;
689*ebfedea0SLionel Sambuc 
690*ebfedea0SLionel Sambuc /** pgp_one_pass_sig_t */
691*ebfedea0SLionel Sambuc typedef struct {
692*ebfedea0SLionel Sambuc 	uint8_t			version;
693*ebfedea0SLionel Sambuc 	pgp_sig_type_t		sig_type;
694*ebfedea0SLionel Sambuc 	pgp_hash_alg_t		hash_alg;
695*ebfedea0SLionel Sambuc 	pgp_pubkey_alg_t	key_alg;
696*ebfedea0SLionel Sambuc 	uint8_t			keyid[PGP_KEY_ID_SIZE];
697*ebfedea0SLionel Sambuc 	unsigned		nested;
698*ebfedea0SLionel Sambuc } pgp_one_pass_sig_t;
699*ebfedea0SLionel Sambuc 
700*ebfedea0SLionel Sambuc /** Signature Subpacket : Revocation Key */
701*ebfedea0SLionel Sambuc typedef struct {
702*ebfedea0SLionel Sambuc 	uint8_t   		class;
703*ebfedea0SLionel Sambuc 	uint8_t   		algid;
704*ebfedea0SLionel Sambuc 	uint8_t   		fingerprint[PGP_FINGERPRINT_SIZE];
705*ebfedea0SLionel Sambuc } pgp_ss_revocation_key_t;
706*ebfedea0SLionel Sambuc 
707*ebfedea0SLionel Sambuc /** Signature Subpacket : Revocation Reason */
708*ebfedea0SLionel Sambuc typedef struct {
709*ebfedea0SLionel Sambuc 	uint8_t   		 code;
710*ebfedea0SLionel Sambuc 	char			*reason;
711*ebfedea0SLionel Sambuc } pgp_ss_revocation_t;
712*ebfedea0SLionel Sambuc 
713*ebfedea0SLionel Sambuc /** litdata_type_t */
714*ebfedea0SLionel Sambuc typedef enum {
715*ebfedea0SLionel Sambuc 	PGP_LDT_BINARY = 'b',
716*ebfedea0SLionel Sambuc 	PGP_LDT_TEXT = 't',
717*ebfedea0SLionel Sambuc 	PGP_LDT_UTF8 = 'u',
718*ebfedea0SLionel Sambuc 	PGP_LDT_LOCAL = 'l',
719*ebfedea0SLionel Sambuc 	PGP_LDT_LOCAL2 = '1'
720*ebfedea0SLionel Sambuc } pgp_litdata_enum;
721*ebfedea0SLionel Sambuc 
722*ebfedea0SLionel Sambuc /** pgp_litdata_header_t */
723*ebfedea0SLionel Sambuc typedef struct {
724*ebfedea0SLionel Sambuc 	pgp_litdata_enum	format;
725*ebfedea0SLionel Sambuc 	char			filename[256];
726*ebfedea0SLionel Sambuc 	time_t			mtime;
727*ebfedea0SLionel Sambuc } pgp_litdata_header_t;
728*ebfedea0SLionel Sambuc 
729*ebfedea0SLionel Sambuc /** pgp_litdata_body_t */
730*ebfedea0SLionel Sambuc typedef struct {
731*ebfedea0SLionel Sambuc 	unsigned         length;
732*ebfedea0SLionel Sambuc 	uint8_t		*data;
733*ebfedea0SLionel Sambuc 	void		*mem;		/* pgp_memory_t pointer */
734*ebfedea0SLionel Sambuc } pgp_litdata_body_t;
735*ebfedea0SLionel Sambuc 
736*ebfedea0SLionel Sambuc /** pgp_header_var_t */
737*ebfedea0SLionel Sambuc typedef struct {
738*ebfedea0SLionel Sambuc 	char           *key;
739*ebfedea0SLionel Sambuc 	char           *value;
740*ebfedea0SLionel Sambuc } pgp_header_var_t;
741*ebfedea0SLionel Sambuc 
742*ebfedea0SLionel Sambuc /** pgp_headers_t */
743*ebfedea0SLionel Sambuc typedef struct {
744*ebfedea0SLionel Sambuc 	pgp_header_var_t	*headers;
745*ebfedea0SLionel Sambuc 	unsigned	         headerc;
746*ebfedea0SLionel Sambuc } pgp_headers_t;
747*ebfedea0SLionel Sambuc 
748*ebfedea0SLionel Sambuc /** pgp_armour_header_t */
749*ebfedea0SLionel Sambuc typedef struct {
750*ebfedea0SLionel Sambuc 	const char	*type;
751*ebfedea0SLionel Sambuc 	pgp_headers_t	 headers;
752*ebfedea0SLionel Sambuc } pgp_armour_header_t;
753*ebfedea0SLionel Sambuc 
754*ebfedea0SLionel Sambuc /** pgp_fixed_body_t */
755*ebfedea0SLionel Sambuc typedef struct pgp_fixed_body_t {
756*ebfedea0SLionel Sambuc 	unsigned        length;
757*ebfedea0SLionel Sambuc 	uint8_t		data[8192];	/* \todo fix hard-coded value? */
758*ebfedea0SLionel Sambuc } pgp_fixed_body_t;
759*ebfedea0SLionel Sambuc 
760*ebfedea0SLionel Sambuc /** pgp_dyn_body_t */
761*ebfedea0SLionel Sambuc typedef struct pgp_dyn_body_t {
762*ebfedea0SLionel Sambuc 	unsigned         length;
763*ebfedea0SLionel Sambuc 	uint8_t		*data;
764*ebfedea0SLionel Sambuc } pgp_dyn_body_t;
765*ebfedea0SLionel Sambuc 
766*ebfedea0SLionel Sambuc enum {
767*ebfedea0SLionel Sambuc 	PGP_SE_IP_DATA_VERSION = 1,
768*ebfedea0SLionel Sambuc 	PGP_PKSK_V3 = 3
769*ebfedea0SLionel Sambuc };
770*ebfedea0SLionel Sambuc 
771*ebfedea0SLionel Sambuc /** pgp_pk_sesskey_params_rsa_t */
772*ebfedea0SLionel Sambuc typedef struct {
773*ebfedea0SLionel Sambuc 	BIGNUM         *encrypted_m;
774*ebfedea0SLionel Sambuc 	BIGNUM         *m;
775*ebfedea0SLionel Sambuc } pgp_pk_sesskey_params_rsa_t;
776*ebfedea0SLionel Sambuc 
777*ebfedea0SLionel Sambuc /** pgp_pk_sesskey_params_elgamal_t */
778*ebfedea0SLionel Sambuc typedef struct {
779*ebfedea0SLionel Sambuc 	BIGNUM         *g_to_k;
780*ebfedea0SLionel Sambuc 	BIGNUM         *encrypted_m;
781*ebfedea0SLionel Sambuc } pgp_pk_sesskey_params_elgamal_t;
782*ebfedea0SLionel Sambuc 
783*ebfedea0SLionel Sambuc /** pgp_pk_sesskey_params_t */
784*ebfedea0SLionel Sambuc typedef union {
785*ebfedea0SLionel Sambuc 	pgp_pk_sesskey_params_rsa_t rsa;
786*ebfedea0SLionel Sambuc 	pgp_pk_sesskey_params_elgamal_t elgamal;
787*ebfedea0SLionel Sambuc } pgp_pk_sesskey_params_t;
788*ebfedea0SLionel Sambuc 
789*ebfedea0SLionel Sambuc /** pgp_pk_sesskey_t */
790*ebfedea0SLionel Sambuc typedef struct {
791*ebfedea0SLionel Sambuc 	unsigned			version;
792*ebfedea0SLionel Sambuc 	uint8_t				key_id[PGP_KEY_ID_SIZE];
793*ebfedea0SLionel Sambuc 	pgp_pubkey_alg_t		alg;
794*ebfedea0SLionel Sambuc 	pgp_pk_sesskey_params_t	params;
795*ebfedea0SLionel Sambuc 	pgp_symm_alg_t		symm_alg;
796*ebfedea0SLionel Sambuc 	uint8_t				key[PGP_MAX_KEY_SIZE];
797*ebfedea0SLionel Sambuc 	uint16_t			checksum;
798*ebfedea0SLionel Sambuc } pgp_pk_sesskey_t;
799*ebfedea0SLionel Sambuc 
800*ebfedea0SLionel Sambuc /** pgp_seckey_passphrase_t */
801*ebfedea0SLionel Sambuc typedef struct {
802*ebfedea0SLionel Sambuc 	const pgp_seckey_t *seckey;
803*ebfedea0SLionel Sambuc 	char          **passphrase;	/* point somewhere that gets filled
804*ebfedea0SLionel Sambuc 					 * in to work around constness of
805*ebfedea0SLionel Sambuc 					 * content */
806*ebfedea0SLionel Sambuc } pgp_seckey_passphrase_t;
807*ebfedea0SLionel Sambuc 
808*ebfedea0SLionel Sambuc /** pgp_get_seckey_t */
809*ebfedea0SLionel Sambuc typedef struct {
810*ebfedea0SLionel Sambuc 	const pgp_seckey_t **seckey;
811*ebfedea0SLionel Sambuc 	const pgp_pk_sesskey_t *pk_sesskey;
812*ebfedea0SLionel Sambuc } pgp_get_seckey_t;
813*ebfedea0SLionel Sambuc 
814*ebfedea0SLionel Sambuc /** pgp_parser_union_content_t */
815*ebfedea0SLionel Sambuc typedef union {
816*ebfedea0SLionel Sambuc 	const char 			*error;
817*ebfedea0SLionel Sambuc 	pgp_parser_errcode_t		errcode;
818*ebfedea0SLionel Sambuc 	pgp_ptag_t			ptag;
819*ebfedea0SLionel Sambuc 	pgp_pubkey_t			pubkey;
820*ebfedea0SLionel Sambuc 	pgp_data_t			trust;
821*ebfedea0SLionel Sambuc 	uint8_t				*userid;
822*ebfedea0SLionel Sambuc 	pgp_data_t			userattr;
823*ebfedea0SLionel Sambuc 	pgp_sig_t			sig;
824*ebfedea0SLionel Sambuc 	pgp_ss_raw_t			ss_raw;
825*ebfedea0SLionel Sambuc 	pgp_ss_trust_t		ss_trust;
826*ebfedea0SLionel Sambuc 	unsigned			ss_revocable;
827*ebfedea0SLionel Sambuc 	time_t				ss_time;
828*ebfedea0SLionel Sambuc 	uint8_t				ss_issuer[PGP_KEY_ID_SIZE];
829*ebfedea0SLionel Sambuc 	pgp_ss_notation_t		ss_notation;
830*ebfedea0SLionel Sambuc 	pgp_subpacket_t		packet;
831*ebfedea0SLionel Sambuc 	pgp_compression_type_t	compressed;
832*ebfedea0SLionel Sambuc 	pgp_one_pass_sig_t		one_pass_sig;
833*ebfedea0SLionel Sambuc 	pgp_data_t			ss_skapref;
834*ebfedea0SLionel Sambuc 	pgp_data_t			ss_hashpref;
835*ebfedea0SLionel Sambuc 	pgp_data_t			ss_zpref;
836*ebfedea0SLionel Sambuc 	pgp_data_t			ss_key_flags;
837*ebfedea0SLionel Sambuc 	pgp_data_t			ss_key_server_prefs;
838*ebfedea0SLionel Sambuc 	unsigned			ss_primary_userid;
839*ebfedea0SLionel Sambuc 	char				*ss_regexp;
840*ebfedea0SLionel Sambuc 	char				*ss_policy;
841*ebfedea0SLionel Sambuc 	char				*ss_keyserv;
842*ebfedea0SLionel Sambuc 	pgp_ss_revocation_key_t	ss_revocation_key;
843*ebfedea0SLionel Sambuc 	pgp_data_t			ss_userdef;
844*ebfedea0SLionel Sambuc 	pgp_data_t			ss_unknown;
845*ebfedea0SLionel Sambuc 	pgp_litdata_header_t		litdata_header;
846*ebfedea0SLionel Sambuc 	pgp_litdata_body_t		litdata_body;
847*ebfedea0SLionel Sambuc 	pgp_dyn_body_t		mdc;
848*ebfedea0SLionel Sambuc 	pgp_data_t			ss_features;
849*ebfedea0SLionel Sambuc 	pgp_ss_sig_target_t		ss_sig_target;
850*ebfedea0SLionel Sambuc 	pgp_data_t			ss_embedded_sig;
851*ebfedea0SLionel Sambuc 	pgp_ss_revocation_t		ss_revocation;
852*ebfedea0SLionel Sambuc 	pgp_seckey_t			seckey;
853*ebfedea0SLionel Sambuc 	uint8_t				*ss_signer;
854*ebfedea0SLionel Sambuc 	pgp_armour_header_t		armour_header;
855*ebfedea0SLionel Sambuc 	const char 			*armour_trailer;
856*ebfedea0SLionel Sambuc 	pgp_headers_t			cleartext_head;
857*ebfedea0SLionel Sambuc 	pgp_fixed_body_t		cleartext_body;
858*ebfedea0SLionel Sambuc 	struct pgp_hash_t		*cleartext_trailer;
859*ebfedea0SLionel Sambuc 	pgp_dyn_body_t		unarmoured_text;
860*ebfedea0SLionel Sambuc 	pgp_pk_sesskey_t		pk_sesskey;
861*ebfedea0SLionel Sambuc 	pgp_seckey_passphrase_t	skey_passphrase;
862*ebfedea0SLionel Sambuc 	unsigned			se_ip_data_header;
863*ebfedea0SLionel Sambuc 	pgp_dyn_body_t		se_ip_data_body;
864*ebfedea0SLionel Sambuc 	pgp_fixed_body_t		se_data_body;
865*ebfedea0SLionel Sambuc 	pgp_get_seckey_t		get_seckey;
866*ebfedea0SLionel Sambuc } pgp_contents_t;
867*ebfedea0SLionel Sambuc 
868*ebfedea0SLionel Sambuc /** pgp_packet_t */
869*ebfedea0SLionel Sambuc struct pgp_packet_t {
870*ebfedea0SLionel Sambuc 	pgp_content_enum	tag;		/* type of contents */
871*ebfedea0SLionel Sambuc 	uint8_t			critical;	/* for sig subpackets */
872*ebfedea0SLionel Sambuc 	pgp_contents_t	u;		/* union for contents */
873*ebfedea0SLionel Sambuc };
874*ebfedea0SLionel Sambuc 
875*ebfedea0SLionel Sambuc /** pgp_fingerprint_t */
876*ebfedea0SLionel Sambuc typedef struct {
877*ebfedea0SLionel Sambuc 	uint8_t			fingerprint[PGP_FINGERPRINT_SIZE];
878*ebfedea0SLionel Sambuc 	unsigned        	length;
879*ebfedea0SLionel Sambuc 	pgp_hash_alg_t	hashtype;
880*ebfedea0SLionel Sambuc } pgp_fingerprint_t;
881*ebfedea0SLionel Sambuc 
882*ebfedea0SLionel Sambuc int pgp_keyid(uint8_t *, const size_t, const pgp_pubkey_t *, pgp_hash_alg_t);
883*ebfedea0SLionel Sambuc int pgp_fingerprint(pgp_fingerprint_t *, const pgp_pubkey_t *, pgp_hash_alg_t);
884*ebfedea0SLionel Sambuc 
885*ebfedea0SLionel Sambuc void pgp_finish(void);
886*ebfedea0SLionel Sambuc void pgp_pubkey_free(pgp_pubkey_t *);
887*ebfedea0SLionel Sambuc void pgp_userid_free(uint8_t **);
888*ebfedea0SLionel Sambuc void pgp_data_free(pgp_data_t *);
889*ebfedea0SLionel Sambuc void pgp_sig_free(pgp_sig_t *);
890*ebfedea0SLionel Sambuc void pgp_ss_notation_free(pgp_ss_notation_t *);
891*ebfedea0SLionel Sambuc void pgp_ss_revocation_free(pgp_ss_revocation_t *);
892*ebfedea0SLionel Sambuc void pgp_ss_sig_target_free(pgp_ss_sig_target_t *);
893*ebfedea0SLionel Sambuc 
894*ebfedea0SLionel Sambuc void pgp_subpacket_free(pgp_subpacket_t *);
895*ebfedea0SLionel Sambuc void pgp_parser_content_free(pgp_packet_t *);
896*ebfedea0SLionel Sambuc void pgp_seckey_free(pgp_seckey_t *);
897*ebfedea0SLionel Sambuc void pgp_pk_sesskey_free(pgp_pk_sesskey_t *);
898*ebfedea0SLionel Sambuc 
899*ebfedea0SLionel Sambuc int pgp_print_packet(pgp_printstate_t *, const pgp_packet_t *);
900*ebfedea0SLionel Sambuc 
901*ebfedea0SLionel Sambuc #define DYNARRAY(type, arr)	\
902*ebfedea0SLionel Sambuc 	unsigned arr##c; unsigned arr##vsize; type *arr##s
903*ebfedea0SLionel Sambuc 
904*ebfedea0SLionel Sambuc #define EXPAND_ARRAY(str, arr) do {					\
905*ebfedea0SLionel Sambuc 	if (str->arr##c == str->arr##vsize) {				\
906*ebfedea0SLionel Sambuc 		void	*__newarr;					\
907*ebfedea0SLionel Sambuc 		char	*__newarrc;					\
908*ebfedea0SLionel Sambuc 		unsigned	__newsize;				\
909*ebfedea0SLionel Sambuc 		__newsize = (str->arr##vsize * 2) + 10; 		\
910*ebfedea0SLionel Sambuc 		if ((__newarrc = __newarr = realloc(str->arr##s,	\
911*ebfedea0SLionel Sambuc 			__newsize * sizeof(*str->arr##s))) == NULL) {	\
912*ebfedea0SLionel Sambuc 			(void) fprintf(stderr, "EXPAND_ARRAY - bad realloc\n"); \
913*ebfedea0SLionel Sambuc 		} else {						\
914*ebfedea0SLionel Sambuc 			(void) memset(&__newarrc[str->arr##vsize * sizeof(*str->arr##s)], \
915*ebfedea0SLionel Sambuc 				0x0, (__newsize - str->arr##vsize) * sizeof(*str->arr##s)); \
916*ebfedea0SLionel Sambuc 			str->arr##s = __newarr;				\
917*ebfedea0SLionel Sambuc 			str->arr##vsize = __newsize;			\
918*ebfedea0SLionel Sambuc 		}							\
919*ebfedea0SLionel Sambuc 	}								\
920*ebfedea0SLionel Sambuc } while(/*CONSTCOND*/0)
921*ebfedea0SLionel Sambuc 
922*ebfedea0SLionel Sambuc /** pgp_keydata_key_t
923*ebfedea0SLionel Sambuc  */
924*ebfedea0SLionel Sambuc typedef union {
925*ebfedea0SLionel Sambuc 	pgp_pubkey_t pubkey;
926*ebfedea0SLionel Sambuc 	pgp_seckey_t seckey;
927*ebfedea0SLionel Sambuc } pgp_keydata_key_t;
928*ebfedea0SLionel Sambuc 
929*ebfedea0SLionel Sambuc 
930*ebfedea0SLionel Sambuc /* sigpacket_t */
931*ebfedea0SLionel Sambuc typedef struct {
932*ebfedea0SLionel Sambuc 	uint8_t			**userid;
933*ebfedea0SLionel Sambuc 	pgp_subpacket_t	*packet;
934*ebfedea0SLionel Sambuc } sigpacket_t;
935*ebfedea0SLionel Sambuc 
936*ebfedea0SLionel Sambuc /* user revocation info */
937*ebfedea0SLionel Sambuc typedef struct pgp_revoke_t {
938*ebfedea0SLionel Sambuc 	uint32_t		 uid;		/* index in uid array */
939*ebfedea0SLionel Sambuc 	uint8_t			 code;		/* revocation code */
940*ebfedea0SLionel Sambuc 	char			*reason;	/* c'mon, spill the beans */
941*ebfedea0SLionel Sambuc } pgp_revoke_t;
942*ebfedea0SLionel Sambuc 
943*ebfedea0SLionel Sambuc /** signature subpackets */
944*ebfedea0SLionel Sambuc typedef struct pgp_subsig_t {
945*ebfedea0SLionel Sambuc 	uint32_t		uid;		/* index in userid array in key */
946*ebfedea0SLionel Sambuc 	pgp_sig_t		sig;		/* trust signature */
947*ebfedea0SLionel Sambuc 	uint8_t			trustlevel;	/* level of trust */
948*ebfedea0SLionel Sambuc 	uint8_t			trustamount;	/* amount of trust */
949*ebfedea0SLionel Sambuc } pgp_subsig_t;
950*ebfedea0SLionel Sambuc 
951*ebfedea0SLionel Sambuc /* describes a user's key */
952*ebfedea0SLionel Sambuc struct pgp_key_t {
953*ebfedea0SLionel Sambuc 	DYNARRAY(uint8_t *, uid);		/* array of user ids */
954*ebfedea0SLionel Sambuc 	DYNARRAY(pgp_subpacket_t, packet);	/* array of raw subpackets */
955*ebfedea0SLionel Sambuc 	DYNARRAY(pgp_subsig_t, subsig);	/* array of signature subkeys */
956*ebfedea0SLionel Sambuc 	DYNARRAY(pgp_revoke_t, revoke);	/* array of signature revocations */
957*ebfedea0SLionel Sambuc 	pgp_content_enum	type;		/* type of key */
958*ebfedea0SLionel Sambuc 	pgp_keydata_key_t	key;		/* pubkey/seckey data */
959*ebfedea0SLionel Sambuc 	pgp_pubkey_t		sigkey;		/* signature key */
960*ebfedea0SLionel Sambuc 	uint8_t			sigid[PGP_KEY_ID_SIZE];
961*ebfedea0SLionel Sambuc 	pgp_fingerprint_t	sigfingerprint;	/* pgp signature fingerprint */
962*ebfedea0SLionel Sambuc 	pgp_pubkey_t		enckey;		/* encryption key */
963*ebfedea0SLionel Sambuc 	uint8_t			encid[PGP_KEY_ID_SIZE];
964*ebfedea0SLionel Sambuc 	pgp_fingerprint_t	encfingerprint;	/* pgp encryption id fingerprint */
965*ebfedea0SLionel Sambuc 	uint32_t		uid0;		/* primary uid index in uids array */
966*ebfedea0SLionel Sambuc 	uint8_t			revoked;	/* key has been revoked */
967*ebfedea0SLionel Sambuc 	pgp_revoke_t		revocation;	/* revocation reason */
968*ebfedea0SLionel Sambuc };
969*ebfedea0SLionel Sambuc 
970*ebfedea0SLionel Sambuc #define MDC_PKT_TAG	0xd3
971*ebfedea0SLionel Sambuc 
972*ebfedea0SLionel Sambuc #endif /* PACKET_H_ */
973