Coverage Report

Created: 2026-08-13 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gnupg/g10/packet.h
Line
Count
Source
1
/* packet.h - OpenPGP packet definitions
2
 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3
 *               2007 Free Software Foundation, Inc.
4
 * Copyright (C) 2015 g10 Code GmbH
5
 *
6
 * This file is part of GnuPG.
7
 *
8
 * GnuPG is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation; either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * GnuPG is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
#ifndef G10_PACKET_H
23
#define G10_PACKET_H
24
25
#include "../common/types.h"
26
#include "../common/iobuf.h"
27
#include "../common/strlist.h"
28
#include "dek.h"
29
#include "filter.h"
30
#include "../common/openpgpdefs.h"
31
#include "../common/userids.h"
32
#include "../common/util.h"
33
34
#define DEBUG_PARSE_PACKET 1
35
36
/* Maximum length of packets to avoid excessive memory allocation.  */
37
1.49M
#define MAX_KEY_PACKET_LENGTH     (256 * 1024)
38
47.3k
#define MAX_UID_PACKET_LENGTH     (  2 * 1024)
39
5.45k
#define MAX_COMMENT_PACKET_LENGTH ( 64 * 1024)
40
11.8k
#define MAX_ATTR_PACKET_LENGTH    ( 16 * 1024*1024)
41
42
/* Constants to allocate static MPI arrays.  */
43
#define PUBKEY_MAX_NPKEY  OPENPGP_MAX_NPKEY
44
35.7k
#define PUBKEY_MAX_NSKEY  OPENPGP_MAX_NSKEY
45
#define PUBKEY_MAX_NSIG   OPENPGP_MAX_NSIG
46
0
#define PUBKEY_MAX_NENC   OPENPGP_MAX_NENC
47
48
/* Usage flags */
49
394k
#define PUBKEY_USAGE_SIG     GCRY_PK_USAGE_SIGN  /* Good for signatures. */
50
620k
#define PUBKEY_USAGE_ENC     GCRY_PK_USAGE_ENCR  /* Good for encryption. */
51
406k
#define PUBKEY_USAGE_CERT    GCRY_PK_USAGE_CERT  /* Also good to certify keys.*/
52
7.81k
#define PUBKEY_USAGE_AUTH    GCRY_PK_USAGE_AUTH  /* Good for authentication. */
53
0
#define PUBKEY_USAGE_UNKNOWN GCRY_PK_USAGE_UNKN  /* Unknown usage flag. */
54
0
#define PUBKEY_USAGE_NONE    256                 /* No usage given. */
55
#if  (GCRY_PK_USAGE_SIGN | GCRY_PK_USAGE_ENCR | GCRY_PK_USAGE_CERT \
56
      | GCRY_PK_USAGE_AUTH | GCRY_PK_USAGE_UNKN) >= 256
57
# error Please choose another value for PUBKEY_USAGE_NONE
58
#endif
59
307k
#define PUBKEY_USAGE_GROUP   512                 /* Group flag.  */
60
310k
#define PUBKEY_USAGE_RENC    1024                /* Restricted encryption.  */
61
0
#define PUBKEY_USAGE_TIME    2048                /* Timestamp use.  */
62
63
4.12k
#define PUBKEY_USAGE_VERIFY  16384               /* Verify only modifier.  */
64
65
/* The usage bits which can be derived from the algo.  */
66
3.12k
#define PUBKEY_USAGE_BASIC_MASK  (PUBKEY_USAGE_SIG|PUBKEY_USAGE_ENC\
67
3.12k
                                  |PUBKEY_USAGE_CERT|PUBKEY_USAGE_AUTH)
68
69
/* The usage bits which define encryption.  */
70
0
#define PUBKEY_USAGE_XENC_MASK  (PUBKEY_USAGE_ENC | PUBKEY_USAGE_RENC)
71
72
/* The signature classes.  */
73
#define SIGCLASS_DATA    0x00   /* Signature on a binary document.       */
74
#define SIGCLASS_TEXT    0x01   /* Signature on a text document.         */
75
#define SIGCLASS_SALONE  0x02   /* Standalone signature.                 */
76
2.49M
#define SIGCLASS_CERT    0x10   /* User ID certification signature.      */
77
#define SIGCLASS_CERT11  0x11   /* User ID certification signature.      */
78
#define SIGCLASS_CERT12  0x12   /* User ID certification signature.      */
79
#define SIGCLASS_CERT13  0x13   /* User ID certification signature.      */
80
1.20M
#define SIGCLASS_SUBKEY  0x18   /* Key binding signature.                */
81
760k
#define SIGCLASS_BACKSIG 0x19   /* Primary key binding signature.        */
82
683k
#define SIGCLASS_KEY     0x1f   /* Direct key signature (on primary key) */
83
601k
#define SIGCLASS_KEYREV  0x20   /* Key revoction signature.              */
84
1.04M
#define SIGCLASS_SUBREV  0x28   /* Subkey revocation signature.          */
85
188k
#define SIGCLASS_CERTREV 0x30   /* Certification revocation signature.   */
86
87
/* Bitflags to convey hints on what kind of signature is created.  */
88
0
#define SIGNHINT_KEYSIG  1
89
0
#define SIGNHINT_SELFSIG 2
90
0
#define SIGNHINT_ADSK    4
91
92
93
/* Helper macros.  */
94
15.2M
#define is_RSA(a)     ((a)==PUBKEY_ALGO_RSA || (a)==PUBKEY_ALGO_RSA_E \
95
15.2M
           || (a)==PUBKEY_ALGO_RSA_S )
96
0
#define is_ELGAMAL(a) ((a)==PUBKEY_ALGO_ELGAMAL_E)
97
0
#define is_DSA(a)     ((a)==PUBKEY_ALGO_DSA)
98
99
/* A pointer to the packet object.  */
100
typedef struct packet_struct PACKET;
101
102
/* PKT_GPG_CONTROL types */
103
typedef enum {
104
    CTRLPKT_CLEARSIGN_START = 1,
105
    CTRLPKT_PIPEMODE = 2,
106
    CTRLPKT_PLAINTEXT_MARK =3
107
} ctrlpkttype_t;
108
109
typedef enum {
110
    PREFTYPE_NONE = 0,
111
    PREFTYPE_SYM = 1,
112
    PREFTYPE_HASH = 2,
113
    PREFTYPE_ZIP = 3,
114
    PREFTYPE_AEAD = 4
115
} preftype_t;
116
117
typedef struct {
118
    byte type;
119
    byte value;
120
} prefitem_t;
121
122
/* A string-to-key specifier as defined in RFC 4880, Section 3.7.  */
123
typedef struct
124
{
125
  int  mode;      /* Must be an integer due to the GNU modes 1001 et al.  */
126
  byte hash_algo;
127
  byte salt[8];
128
  /* The *coded* (i.e., the serialized version) iteration count.  */
129
  u32  count;
130
} STRING2KEY;
131
132
/* A symmetric-key encrypted session key packet as defined in RFC
133
   4880, Section 5.3.  All fields are serialized.  */
134
typedef struct {
135
  /* We support version 4 (rfc4880) and 5 (rfc4880bis).  */
136
  byte version;
137
  /* The cipher algorithm used to encrypt the session key.  Note that
138
   * this may be different from the algorithm that is used to encrypt
139
   * bulk data.  */
140
  byte cipher_algo;
141
  /* The AEAD algorithm or 0 for CFB encryption.  */
142
  byte aead_algo;
143
  /* The string-to-key specifier.  */
144
  STRING2KEY s2k;
145
  /* The length of SESKEY in bytes or 0 if this packet does not
146
     encrypt a session key.  (In the latter case, the results of the
147
     S2K function on the password is the session key. See RFC 4880,
148
     Section 5.3.)  */
149
  byte seskeylen;
150
  /* The malloced session key as encrypted by the S2K specifier.  For
151
   * AEAD this includes the nonce and the authentication tag.  */
152
  byte *seskey;
153
} PKT_symkey_enc;
154
155
/* A public-key encrypted session key packet as defined in RFC 4880,
156
   Section 5.1.  All fields are serialized.  */
157
typedef struct {
158
  /* The 64-bit keyid.  */
159
  u32     keyid[2];
160
  /* The packet's version.  Currently, only version 3 is defined.  */
161
  byte    version;
162
  /* The algorithm used for the public key encryption scheme.  */
163
  byte    pubkey_algo;
164
  /* The session key algorithm used by some pubkey algos.  */
165
  byte    seskey_algo;
166
  /* Whether to hide the key id.  This value is not directly
167
     serialized.  */
168
  byte    throw_keyid;
169
  /* The encrypted session key.  */
170
  gcry_mpi_t     data[PUBKEY_MAX_NENC];
171
} PKT_pubkey_enc;
172
173
174
/* An object to build a list of public-key and symkey encrypted
175
 * session key.  Note that we use a dedicated union here instead of
176
 * the usual PACKET type to avoid the need for extra allocations. */
177
struct seskey_enc_list
178
{
179
  struct seskey_enc_list *next;
180
  int result; /* The error code decrypting the session key.  */
181
  int u_sym;  /* Use the sym member.  */
182
  union {
183
    PKT_pubkey_enc pub;
184
    PKT_symkey_enc sym;
185
  } u;
186
};
187
188
189
/* An object to record some properties of a PKT_pubkey_enc packet.  */
190
struct pubkey_enc_info_item
191
{
192
  struct pubkey_enc_info_item *next;
193
  /* 3 fields copied from a PKT_pubkey_enc:  */
194
  u32     keyid[2];
195
  byte    version;
196
  byte    pubkey_algo;
197
};
198
199
200
/* A one-pass signature packet as defined in RFC 4880, Section
201
   5.4.  All fields are serialized.  */
202
typedef struct {
203
    u32     keyid[2];     /* The 64-bit keyid */
204
    /* The signature's classification (RFC 4880, Section 5.2.1).  */
205
    byte    sig_class;
206
    byte    digest_algo;    /* algorithm used for digest */
207
    byte    pubkey_algo;    /* algorithm used for public key scheme */
208
    /* A message can be signed by multiple keys.  In this case, there
209
       are n one-pass signature packets before the message to sign and
210
       n signatures packets after the message.  It is conceivable that
211
       someone wants to not only sign the message, but all of the
212
       signatures.  Now we need to distinguish between signing the
213
       message and signing the message plus the surrounding
214
       signatures.  This is the point of this flag.  If set, it means:
215
       I sign all of the data starting at the next packet.  */
216
    byte    last;
217
} PKT_onepass_sig;
218
219
220
/* A v4 OpenPGP signature has a hashed and unhashed area containing
221
   co-called signature subpackets (RFC 4880, Section 5.2.3).  These
222
   areas are described by this data structure.  Use enum_sig_subpkt to
223
   parse this area.  */
224
typedef struct {
225
    size_t size;  /* allocated */
226
    size_t len;   /* used (serialized) */
227
    byte data[1]; /* the serialized subpackes (serialized) */
228
} subpktarea_t;
229
230
/* The in-memory representation of a designated revoker signature
231
   subpacket (RFC 4880, Section 5.2.3.15).  */
232
struct revocation_key {
233
  /* A bit field.  0x80 must be set.  0x40 means this information is
234
     sensitive (and should not be uploaded to a keyserver by
235
     default).  */
236
  byte class;
237
  /* The public-key algorithm ID.  */
238
  byte algid;
239
  /* The length of the fingerprint.  */
240
  byte fprlen;
241
  /* The fingerprint of the authorized key.  */
242
  byte fpr[MAX_FINGERPRINT_LEN];
243
};
244
245
/* Information about the to be revoked key of a revocation signature. */
246
struct rev_subject_info_s {
247
  /* The length of the fingerprint. */
248
  byte fprlen;
249
  /* Fingerprint of the to be revoked key. */
250
  byte fpr[MAX_FINGERPRINT_LEN];
251
252
};
253
254
/* A signature packet (RFC 4880, Section 5.2).  Only a subset of these
255
   fields are directly serialized (these are marked as such); the rest
256
   are read from the subpackets, which are not synthesized when
257
   serializing this data structure (i.e., when using build_packet()).
258
   Instead, the subpackets must be created by hand.  */
259
typedef struct
260
{
261
  struct
262
  {
263
    unsigned checked:1;         /* Signature has been checked. */
264
    unsigned valid:1;           /* Signature is good (if checked is set). */
265
    unsigned chosen_selfsig:1;  /* A selfsig that is the chosen one. */
266
    unsigned unknown_critical:1;
267
    unsigned exportable:1;
268
    unsigned revocable:1;
269
    unsigned policy_url:1;  /* At least one policy URL is present */
270
    unsigned notation:1;    /* At least one notation is present */
271
    unsigned pref_ks:1;     /* At least one preferred keyserver is present */
272
    unsigned key_block:1;   /* A key block subpacket is present.  */
273
    unsigned expired:1;
274
  } flags;
275
  /* The key that allegedly generated this signature.  (Directly
276
     serialized in v3 sigs; for v4 sigs, this must be explicitly added
277
     as an issuer subpacket (5.2.3.5.)  */
278
  u32     keyid[2];
279
  /* When the signature was made (seconds since the Epoch).  (Directly
280
     serialized in v3 sigs; for v4 sigs, this must be explicitly added
281
     as a signature creation time subpacket (5.2.3.4).)  */
282
  u32     timestamp;
283
  u32     expiredate;     /* Expires at this date or 0 if not at all. */
284
  /* The serialization format used / to use.  If 0, then defaults to
285
     version 3.  (Serialized.)  */
286
  byte    version;
287
  /* The signature type. (See RFC 4880, Section 5.2.1.)  */
288
  byte    sig_class;
289
  /* Algorithm used for public key scheme (e.g., PUBKEY_ALGO_RSA).
290
     (Serialized.)  */
291
  byte    pubkey_algo;
292
  /* Algorithm used for digest (e.g., DIGEST_ALGO_SHA1).
293
     (Serialized.)  */
294
  byte    digest_algo;
295
  byte    trust_depth;
296
  byte    trust_value;
297
  const byte *trust_regexp;
298
  struct revocation_key *revkey;
299
  int numrevkeys;
300
  int help_counter;          /* Used internally by some functions.  */
301
  char *signers_uid;         /* Malloced value of the SIGNERS_UID
302
                              * subpacket or NULL.  This string has
303
                              * already been sanitized.  */
304
  subpktarea_t *hashed;      /* All subpackets with hashed data (v4, v5 only). */
305
  subpktarea_t *unhashed;    /* Ditto for unhashed data. */
306
  /* First 2 bytes of the digest.  (Serialized.  Note: this is not
307
     automatically filled in when serializing a signature!)  */
308
  byte digest_start[2];
309
  /* The signature.  (Serialized.)  */
310
  gcry_mpi_t  data[PUBKEY_MAX_NSIG];
311
  /* The message digest and its length (in bytes).  Note the maximum
312
     digest length is 512 bits (64 bytes).  If DIGEST_LEN is 0, then
313
     the digest's value has not been saved here.  */
314
  byte digest[512 / 8];
315
  int digest_len;
316
  /* Info about the to-be-revoked key in a revocation signature.*/
317
  struct rev_subject_info_s *rev_subject_info;
318
} PKT_signature;
319
320
2.14k
#define ATTRIB_IMAGE 1
321
322
/* This is the cooked form of attributes.  */
323
struct user_attribute {
324
  byte type;
325
  const byte *data;
326
  u32 len;
327
};
328
329
330
/* A user id (RFC 4880, Section 5.11) or a user attribute packet (RFC
331
   4880, Section 5.12).  Only a subset of these fields are directly
332
   serialized (these are marked as such); the rest are read from the
333
   self-signatures in merge_keys_and_selfsig()).  */
334
typedef struct
335
{
336
  int ref;              /* reference counter */
337
  /* The length of NAME.  */
338
  int len;
339
  struct user_attribute *attribs;
340
  int numattribs;
341
  /* If this is not NULL, the packet is a user attribute rather than a
342
     user id (See RFC 4880 5.12).  (Serialized.)  */
343
  byte *attrib_data;
344
  /* The length of ATTRIB_DATA.  */
345
  unsigned long attrib_len;
346
  byte *namehash;
347
  u16 help_key_usage;
348
  u32 help_key_expire;
349
  int help_full_count;
350
  int help_marginal_count;
351
  u32 expiredate;       /* expires at this date or 0 if not at all */
352
  prefitem_t *prefs;    /* list of preferences (may be NULL)*/
353
  u32 created;          /* according to the self-signature */
354
  u32 keyupdate;        /* From the ring trust packet.  */
355
  char *updateurl;      /* NULL or the URL of the last update origin.  */
356
  byte keyorg;          /* From the ring trust packet.  */
357
  byte selfsigversion;
358
  struct
359
  {
360
    unsigned int mdc:1;
361
    unsigned int aead:1;
362
    unsigned int ks_modify:1;
363
    unsigned int compacted:1;
364
    unsigned int primary:2; /* 2 if set via the primary flag, 1 if calculated */
365
                            /* Note that this flag is set in a
366
                             * keyblock at max for one User ID and for
367
                             * one User Attribute per keyblock.  */
368
    unsigned int revoked:1;
369
    unsigned int expired:1;
370
  } flags;
371
372
  char *mbox;   /* NULL or the result of mailbox_from_userid.  */
373
374
  /* The text contained in the user id packet, which is normally the
375
   * name and email address of the key holder (See RFC 4880 5.11).
376
   * (Serialized.). For convenience an extra Nul is always appended.  */
377
  char name[1];
378
} PKT_user_id;
379
380
381
382
struct revoke_info
383
{
384
  /* Revoked at this date */
385
  u32 date;
386
  /* The keyid of the revoking key (selfsig or designated revoker) */
387
  u32 keyid[2];
388
  /* A malloced string of len reason_comment_len with the raw reason
389
   * string or NULL if not given.  */
390
  char *reason_comment;
391
  size_t reason_comment_len;
392
  /* The algo of the revoking key */
393
  byte algo;
394
  /* The reason code. */
395
  byte reason_code;
396
  /* Whether the above reason fields are valid. */
397
  byte got_reason;
398
};
399
400
401
/* Information pertaining to secret keys. */
402
struct seckey_info
403
{
404
  unsigned int is_protected:1; /* The secret info is protected and must */
405
      /* be decrypted before use, the protected */
406
      /* MPIs are simply (void*) pointers to memory */
407
      /* and should never be passed to a mpi_xxx() */
408
  unsigned int sha1chk:1; /* SHA1 is used instead of a 16 bit checksum */
409
  u16 csum;   /* Checksum for old protection modes.  */
410
  byte algo;            /* Cipher used to protect the secret information. */
411
  STRING2KEY s2k;       /* S2K parameter.  */
412
  byte ivlen;           /* Used length of the IV.  */
413
  byte iv[16];          /* Initialization vector for CFB mode.  */
414
};
415
416
417
/****************
418
 * The in-memory representation of a public key (RFC 4880, Section
419
 * 5.5).  Note: this structure contains significantly more information
420
 * than is contained in an OpenPGP public key packet.  This
421
 * information is derived from the self-signed signatures (by
422
 * merge_keys_and_selfsig()) and is ignored when serializing the
423
 * packet.  The fields that are actually written out when serializing
424
 * this packet are marked as accordingly.
425
 *
426
 * We assume that secret keys have the same number of parameters as
427
 * the public key and that the public parameters are the first items
428
 * in the PKEY array.  Thus NPKEY is always less than NSKEY and it is
429
 * possible to compare the secret and public keys by comparing the
430
 * first NPKEY elements of the PKEY array.  Note that since GnuPG 2.1
431
 * we don't use secret keys anymore directly because they are managed
432
 * by gpg-agent.  However for parsing OpenPGP key files we need a way
433
 * to temporary store those secret keys.  We do this by putting them
434
 * into the public key structure and extending the PKEY field to NSKEY
435
 * elements; the extra secret key information are stored in the
436
 * SECKEY_INFO field.
437
 */
438
typedef struct
439
{
440
  /* When the key was created.  (Serialized.)  */
441
  u32     timestamp;
442
  u32     expiredate;     /* expires at this date or 0 if not at all */
443
  u32     max_expiredate; /* must not expire past this date */
444
  struct revoke_info revoked;
445
  /* An OpenPGP packet consists of a header and a body.  This is the
446
     size of the header.  If this is 0, an appropriate size is
447
     automatically chosen based on the size of the body.
448
     (Serialized.)  */
449
  byte    hdrbytes;
450
  /* The serialization format.  If 0, the default version (4) is used
451
     when serializing.  (Serialized.)  */
452
  byte    version;
453
  byte    selfsigversion; /* highest version of all of the self-sigs */
454
  byte    fprlen;         /* 0 or length of FPR.  */
455
  byte    pubkey_algo;    /* The public key algorithm.  (PGP format)  */
456
  u16     pubkey_usage;   /* carries the usage info.            */
457
  u16     req_usage;      /* hack to pass a request to getkey() */
458
  u32     has_expired;    /* set to the expiration date if expired */
459
  /* keyid of the primary key.  Never access this value directly.
460
     Instead, use pk_main_keyid().  */
461
  u32     main_keyid[2];
462
  /* keyid of this key.  Never access this value directly!  Instead,
463
     use pk_keyid().  */
464
  u32     keyid[2];
465
  /* Fingerprint of the key.  Only valid if FPRLEN is not 0.  */
466
  byte    fpr[MAX_FINGERPRINT_LEN];
467
  prefitem_t *prefs;      /* list of preferences (may be NULL) */
468
  struct
469
  {
470
    unsigned int mdc:1;           /* MDC feature set.  */
471
    unsigned int aead:1;          /* AEAD feature set.  */
472
    unsigned int disabled_valid:1;/* The next flag is valid.  */
473
    unsigned int disabled:1;      /* The key has been disabled.  */
474
    unsigned int primary:1;       /* This is a primary key.  */
475
    unsigned int revoked:2;       /* Key has been revoked.
476
                                     1 = revoked by the owner
477
                                     2 = revoked by designated revoker.  */
478
    unsigned int maybe_revoked:1; /* A designated revocation is
479
                                     present, but without the key to
480
                                     check it.  */
481
    unsigned int valid:1;         /* Key (especially subkey) is valid.  */
482
    unsigned int dont_cache:1;    /* Do not cache this key.  */
483
    unsigned int backsig:2;       /* 0=none, 1=bad, 2=good.  */
484
    unsigned int serialno_valid:1;/* SERIALNO below is valid.  */
485
    unsigned int exact:1;         /* Found via exact (!) search.  */
486
  } flags;
487
  PKT_user_id *user_id;   /* If != NULL: found by that uid. */
488
  struct revocation_key *revkey;
489
  int     numrevkeys;
490
  u32     trust_timestamp;
491
  byte    trust_depth;
492
  byte    trust_value;
493
  byte    keyorg;         /* From the ring trust packet.  */
494
  u32     keyupdate;      /* From the ring trust packet.  */
495
  char    *updateurl;     /* NULL or the URL of the last update origin.  */
496
  const byte *trust_regexp;
497
  char    *serialno;      /* Malloced hex string or NULL if it is
498
                             likely not on a card.  See also
499
                             flags.serialno_valid.  */
500
  /* If not NULL this malloced structure describes a secret key.
501
     (Serialized.)  */
502
  struct seckey_info *seckey_info;
503
  /* The public key.  Contains pubkey_get_npkey (pubkey_algo) +
504
     pubkey_get_nskey (pubkey_algo) MPIs.  (If pubkey_get_npkey
505
     returns 0, then the algorithm is not understood and the PKEY
506
     contains a single opaque MPI.)  (Serialized.)  */
507
  gcry_mpi_t  pkey[PUBKEY_MAX_NSKEY]; /* Right, NSKEY elements.  */
508
} PKT_public_key;
509
510
/* Evaluates as true if the pk is disabled, and false if it isn't.  If
511
   there is no disable value cached, fill one in. */
512
#define pk_is_disabled(a)                                       \
513
0
  (((a)->flags.disabled_valid)?                                 \
514
0
   ((a)->flags.disabled):(cache_disabled_value(ctrl,(a))))
515
516
517
typedef struct {
518
    int  len;     /* length of data */
519
    char data[1];
520
} PKT_comment;
521
522
/* A compression packet (RFC 4880, Section 5.6).  */
523
typedef struct {
524
  /* Not used.  */
525
  u32 len;
526
  /* Whether the serialized version of the packet used / should use
527
     the new format.  */
528
  byte  new_ctb;
529
  /* The compression algorithm.  */
530
  byte  algorithm;
531
  /* An iobuf holding the data to be decompressed.  (This is not used
532
     for compression!)  */
533
  iobuf_t buf;
534
} PKT_compressed;
535
536
/* A symmetrically encrypted data packet (RFC 4880, Section 5.7) or a
537
   symmetrically encrypted integrity protected data packet (Section
538
   5.13) */
539
typedef struct {
540
  /* Remaining length of encrypted data. */
541
  u32  len;
542
  /* When encrypting in CFB mode, the first block size bytes of data
543
   * are random data and the following 2 bytes are copies of the last
544
   * two bytes of the random data (RFC 4880, Section 5.7).  This
545
   * provides a simple check that the key is correct.  EXTRALEN is the
546
   * size of this extra data or, in AEAD mode, the length of the
547
   * headers and the tags.  This is used by build_packet when writing
548
   * out the packet's header. */
549
  int  extralen;
550
  /* Whether the serialized version of the packet used / should use
551
     the new format.  */
552
  byte new_ctb;
553
  /* Whether the packet has an indeterminate length (old format) or
554
     was encoded using partial body length headers (new format).
555
     Note: this is ignored when encrypting.  */
556
  byte is_partial;
557
  /* If 0, MDC is disabled.  Otherwise, the MDC method that was used
558
     (only DIGEST_ALGO_SHA1 has ever been defined).  */
559
  byte mdc_method;
560
  /* If 0, AEAD is not used.  Otherwise, the used AEAD algorithm.
561
   * MDC_METHOD (above) shall be zero if AEAD is used.  */
562
  byte aead_algo;
563
  /* The cipher algo for/from the AEAD packet.  0 for other encryption
564
   * packets. */
565
  byte cipher_algo;
566
  /* The chunk byte from the AEAD packet.  */
567
  byte chunkbyte;
568
569
  /* An iobuf holding the data to be decrypted.  (This is not used for
570
     encryption!)  */
571
  iobuf_t buf;
572
} PKT_encrypted;
573
574
typedef struct {
575
    byte hash[20];
576
} PKT_mdc;
577
578
579
/* Subtypes for the ring trust packet.  */
580
53.6M
#define RING_TRUST_SIG 0  /* The classical signature cache.  */
581
76.5M
#define RING_TRUST_KEY 1  /* A KEYORG on a primary key.      */
582
38.3M
#define RING_TRUST_UID 2  /* A KEYORG on a user id.          */
583
584
/* The local only ring trust packet which OpenPGP declares as
585
 * implementation defined.  GnuPG uses this to cache signature
586
 * verification status and since 2.1.18 also to convey information
587
 * about the origin of a key.  Note that this packet is not part
588
 * struct packet_struct because we use it only local in the packet
589
 * parser and builder. */
590
typedef struct {
591
  unsigned int trustval;
592
  unsigned int sigcache;
593
  unsigned char subtype; /* The subtype of this ring trust packet.   */
594
  unsigned char keyorg;  /* The origin of the key (KEYORG_*).        */
595
  u32 keyupdate;         /* The wall time the key was last updated.  */
596
  char *url;             /* NULL or the URL of the source.           */
597
} PKT_ring_trust;
598
599
600
/* A plaintext packet (see RFC 4880, 5.9).  */
601
typedef struct {
602
  /* The length of data in BUF or 0 if unknown.  */
603
  u32  len;
604
  /* A buffer containing the data stored in the packet's body.  */
605
  iobuf_t buf;
606
  byte new_ctb;
607
  byte is_partial;      /* partial length encoded */
608
  /* The data's formatting.  This is either 'b', 't', 'u', 'l' or '1'
609
     (however, the last two are deprecated).  */
610
  int mode;
611
  u32 timestamp;
612
  /* The name of the file.  This can be at most 255 characters long,
613
     since namelen is just a byte in the serialized format.  */
614
  int  namelen;
615
  char name[1];
616
} PKT_plaintext;
617
618
typedef struct {
619
    int  control;
620
    size_t datalen;
621
    char data[1];
622
} PKT_gpg_control;
623
624
/* combine all packets into a union */
625
struct packet_struct {
626
    pkttype_t pkttype;
627
    union {
628
  void *generic;
629
  PKT_symkey_enc  *symkey_enc;  /* PKT_SYMKEY_ENC */
630
  PKT_pubkey_enc  *pubkey_enc;  /* PKT_PUBKEY_ENC */
631
  PKT_onepass_sig *onepass_sig; /* PKT_ONEPASS_SIG */
632
  PKT_signature *signature; /* PKT_SIGNATURE */
633
  PKT_public_key  *public_key;  /* PKT_PUBLIC_[SUB]KEY */
634
  PKT_public_key  *secret_key;  /* PKT_SECRET_[SUB]KEY */
635
  PKT_comment *comment; /* PKT_COMMENT */
636
  PKT_user_id *user_id; /* PKT_USER_ID */
637
  PKT_compressed  *compressed;  /* PKT_COMPRESSED */
638
  PKT_encrypted *encrypted; /* PKT_ENCRYPTED[_MDC|_AEAD] */
639
  PKT_mdc   *mdc;   /* PKT_MDC */
640
  PKT_plaintext *plaintext; /* PKT_PLAINTEXT */
641
        PKT_gpg_control *gpg_control;   /* PKT_GPG_CONTROL */
642
    } pkt;
643
};
644
645
24.5M
#define init_packet(a) do { (a)->pkttype = 0;   \
646
24.5M
          (a)->pkt.generic = NULL;  \
647
24.5M
           } while(0)
648
649
650
/* A notation.  See RFC 4880, Section 5.2.3.16.  */
651
struct notation
652
{
653
  /* The notation's name.  */
654
  char *name;
655
  /* If the notation is human readable, then the value is stored here
656
     as a NUL-terminated string.  If it is not human readable a human
657
     readable approximation of the binary value _may_ be stored
658
     here.  */
659
  char *value;
660
  /* Sometimes we want to %-expand the value.  In these cases, we save
661
     that transformed value here.  */
662
  char *altvalue;
663
  /* If the notation is not human readable or the function does not
664
     want to distinguish that, then the value is stored here.  */
665
  unsigned char *bdat;
666
  /* The amount of data stored in BDAT.
667
668
     Note: if this is 0 and BDAT is NULL, this does not necessarily
669
     mean that the value is human readable.  It could be that we have
670
     a 0-length value.  To determine whether the notation is human
671
     readable, always check if VALUE is not NULL.  This works, because
672
     if a human-readable value has a length of 0, we will still
673
     allocate space for the NUL byte.  */
674
  size_t blen;
675
  struct
676
  {
677
    /* The notation is critical.  */
678
    unsigned int critical:1;
679
    /* The notation is human readable.  */
680
    unsigned int human:1;
681
    /* The notation should be deleted.  */
682
    unsigned int ignore:1;
683
  } flags;
684
685
  /* A field to facilitate creating a list of notations.  */
686
  struct notation *next;
687
};
688
typedef struct notation *notation_t;
689
690
/*-- mainproc.c --*/
691
void reset_literals_seen(void);
692
int proc_packets (ctrl_t ctrl, void *ctx, iobuf_t a );
693
int proc_signature_packets (ctrl_t ctrl, void *ctx, iobuf_t a,
694
          strlist_t signedfiles, const char *sigfile );
695
int proc_signature_packets_by_fd (ctrl_t ctrl, void *anchor, IOBUF a,
696
                                  gnupg_fd_t signed_data_fd);
697
gpg_error_t proc_encryption_packets (ctrl_t ctrl, void *ctx, iobuf_t a,
698
                                     DEK **r_dek,
699
                                     struct seskey_enc_list **r_list);
700
701
int list_packets( iobuf_t a );
702
703
const byte *issuer_fpr_raw (PKT_signature *sig, size_t *r_len);
704
char *issuer_fpr_string (PKT_signature *sig);
705
706
/*-- parse-packet.c --*/
707
708
709
void register_known_notation (const char *string);
710
711
/* Sets the packet list mode to MODE (i.e., whether we are dumping a
712
   packet or not).  Returns the current mode.  This allows for
713
   temporarily suspending dumping by doing the following:
714
715
     int saved_mode = set_packet_list_mode (0);
716
     ...
717
     set_packet_list_mode (saved_mode);
718
*/
719
int set_packet_list_mode( int mode );
720
721
722
/* A context used with parse_packet.  */
723
struct parse_packet_ctx_s
724
{
725
  iobuf_t inp;       /* The input stream with the packets.  */
726
  struct packet_struct last_pkt; /* The last parsed packet.  */
727
  int free_last_pkt; /* Indicates that LAST_PKT must be freed.  */
728
  int skip_meta;     /* Skip ring trust packets.  */
729
  int only_fookey_enc;  /* Stop if the packet is not {sym,pub}key_enc. */
730
  unsigned int n_parsed_packets;  /* Number of parsed packets.  */
731
  int last_ctb;      /* The last CTB read.  */
732
};
733
typedef struct parse_packet_ctx_s *parse_packet_ctx_t;
734
735
35.6k
#define init_parse_packet(a,i) do { \
736
35.6k
    (a)->inp = (i);                 \
737
35.6k
    (a)->last_pkt.pkttype = 0;      \
738
35.6k
    (a)->last_pkt.pkt.generic= NULL;\
739
35.6k
    (a)->free_last_pkt = 0;         \
740
35.6k
    (a)->skip_meta = 0;             \
741
35.6k
    (a)->only_fookey_enc = 0;       \
742
35.6k
    (a)->n_parsed_packets = 0;      \
743
35.6k
    (a)->last_ctb = 1;              \
744
35.6k
  } while (0)
745
746
35.6k
#define deinit_parse_packet(a) do { \
747
35.6k
    if ((a)->free_last_pkt)         \
748
35.6k
      free_packet (NULL, (a));      \
749
35.6k
  } while (0)
750
751
752
#if DEBUG_PARSE_PACKET
753
/* There are debug functions and should not be used directly.  */
754
int dbg_search_packet (parse_packet_ctx_t ctx, PACKET *pkt,
755
                       off_t *retpos, int with_uid,
756
                       const char* file, int lineno  );
757
int dbg_parse_packet (parse_packet_ctx_t ctx, PACKET *ret_pkt,
758
                      const char *file, int lineno);
759
int dbg_copy_all_packets( iobuf_t inp, iobuf_t out,
760
                          const char* file, int lineno  );
761
int dbg_copy_some_packets( iobuf_t inp, iobuf_t out, off_t stopoff,
762
                           const char* file, int lineno  );
763
int dbg_skip_some_packets( iobuf_t inp, unsigned n,
764
                           const char* file, int lineno );
765
#define search_packet( a,b,c,d )   \
766
0
             dbg_search_packet( (a), (b), (c), (d), __FILE__, __LINE__ )
767
#define parse_packet( a, b )  \
768
24.5M
       dbg_parse_packet( (a), (b), __FILE__, __LINE__ )
769
#define copy_all_packets( a,b )  \
770
0
             dbg_copy_all_packets((a),(b), __FILE__, __LINE__ )
771
#define copy_some_packets( a,b,c ) \
772
0
             dbg_copy_some_packets((a),(b),(c), __FILE__, __LINE__ )
773
#define skip_some_packets( a,b ) \
774
0
             dbg_skip_some_packets((a),(b), __FILE__, __LINE__ )
775
#else
776
/* Return the next valid OpenPGP packet in *PKT.  (This function will
777
 * skip any packets whose type is 0.)  CTX must have been setup prior to
778
 * calling this function.
779
 *
780
 * Returns 0 on success, -1 if EOF is reached, and an error code
781
 * otherwise.  In the case of an error, the packet in *PKT may be
782
 * partially constructed.  As such, even if there is an error, it is
783
 * necessary to free *PKT to avoid a resource leak.  To detect what
784
 * has been allocated, clear *PKT before calling this function.  */
785
int parse_packet (parse_packet_ctx_t ctx, PACKET *pkt);
786
787
/* Return the first OpenPGP packet in *PKT that contains a key (either
788
 * a public subkey, a public key, a secret subkey or a secret key) or,
789
 * if WITH_UID is set, a user id.
790
 *
791
 * Saves the position in the pipeline of the start of the returned
792
 * packet (according to iobuf_tell) in RETPOS, if it is not NULL.
793
 *
794
 * The return semantics are the same as parse_packet.  */
795
int search_packet (parse_packet_ctx_t ctx, PACKET *pkt,
796
                   off_t *retpos, int with_uid);
797
798
/* Copy all packets (except invalid packets, i.e., those with a type
799
 * of 0) from INP to OUT until either an error occurs or EOF is
800
 * reached.
801
 *
802
 * Returns -1 when end of file is reached or an error code, if an
803
 * error occurred.  (Note: this function never returns 0, because it
804
 * effectively keeps going until it gets an EOF.)  */
805
int copy_all_packets (iobuf_t inp, iobuf_t out );
806
807
/* Like copy_all_packets, but stops at the first packet that starts at
808
 * or after STOPOFF (as indicated by iobuf_tell).
809
 *
810
 * Example: if STOPOFF is 100, the first packet in INP goes from
811
 * 0 to 110 and the next packet starts at offset 111, then the packet
812
 * starting at offset 0 will be completely processed (even though it
813
 * extends beyond STOPOFF) and the packet starting at offset 111 will
814
 * not be processed at all.  */
815
int copy_some_packets (iobuf_t inp, iobuf_t out, off_t stopoff);
816
817
/* Skips the next N packets from INP.
818
 *
819
 * If parsing a packet returns an error code, then the function stops
820
 * immediately and returns the error code.  Note: in the case of an
821
 * error, this function does not indicate how many packets were
822
 * successfully processed.  */
823
int skip_some_packets (iobuf_t inp, unsigned int n);
824
#endif
825
826
/* Parse a signature packet and store it in *SIG.
827
828
   The signature packet is read from INP.  The OpenPGP header (the tag
829
   and the packet's length) have already been read; the next byte read
830
   from INP should be the first byte of the packet's contents.  The
831
   packet's type (as extract from the tag) must be passed as PKTTYPE
832
   and the packet's length must be passed as PKTLEN.  This is used as
833
   the upper bound on the amount of data read from INP.  If the packet
834
   is shorter than PKTLEN, the data at the end will be silently
835
   skipped.  If an error occurs, an error code will be returned.  -1
836
   means the EOF was encountered.  0 means parsing was successful.  */
837
int parse_signature( iobuf_t inp, int pkttype, unsigned long pktlen,
838
         PKT_signature *sig );
839
840
/* Given a signature packet, either:
841
 *
842
 *   - test whether there are any subpackets with the critical bit set
843
 *     that we don't understand,
844
 *
845
 *   - list the subpackets, or,
846
 *
847
 *   - find a subpacket with a specific type.
848
 *
849
 * The WANT_HASHED flag indicates that the hashed area shall be
850
 * considered.
851
 *
852
 * REQTYPE indicates the type of operation.
853
 *
854
 * If REQTYPE is SIGSUBPKT_TEST_CRITICAL, then this function checks
855
 * whether there are any subpackets that have the critical bit and
856
 * which GnuPG cannot handle.  If GnuPG understands all subpackets
857
 * whose critical bit is set, then this function returns simply
858
 * returns SUBPKTS.  If there is a subpacket whose critical bit is set
859
 * and which GnuPG does not understand, then this function returns
860
 * NULL and, if START is not NULL, sets *START to the 1-based index of
861
 * the subpacket that violates the constraint.
862
 *
863
 * If REQTYPE is SIGSUBPKT_LIST_HASHED or SIGSUBPKT_LIST_UNHASHED, the
864
 * packets are dumped.  Note: if REQTYPE is SIGSUBPKT_LIST_HASHED,
865
 * this function does not check whether the hash is correct; this is
866
 * merely an indication of the section that the subpackets came from.
867
 *
868
 * If REQTYPE is anything else, then this function interprets the
869
 * values as a subpacket type and looks for the first subpacket with
870
 * that type.  If such a packet is found, *CRITICAL (if not NULL) is
871
 * set if the critical bit was set, *RET_N is set to the offset of the
872
 * subpacket's content within the SUBPKTS buffer, *START is set to the
873
 * 1-based index of the subpacket within the buffer, and returns
874
 * &SUBPKTS[*RET_N].
875
 *
876
 * *START is the number of initial subpackets to not consider.  Thus,
877
 * if *START is 2, then the first 2 subpackets are ignored.
878
 */
879
const byte *enum_sig_subpkt (PKT_signature *sig, int want_hashed,
880
                             sigsubpkttype_t reqtype,
881
                             size_t *ret_n, int *start, int *critical );
882
883
/* Shorthand for:
884
 *
885
 *    enum_sig_subpkt (sig, want_hashed, reqtype, ret_n, NULL, NULL);
886
 */
887
const byte *parse_sig_subpkt (PKT_signature *sig, int want_hashed,
888
                              sigsubpkttype_t reqtype,
889
                              size_t *ret_n );
890
891
/* This calls parse_sig_subpkt first on the hashed signature area in
892
 * SIG and then, if that returns NULL, calls parse_sig_subpkt on the
893
 * unhashed subpacket area in SIG.  */
894
const byte *parse_sig_subpkt2 (PKT_signature *sig, sigsubpkttype_t reqtype);
895
896
/* Returns whether the N byte large buffer BUFFER is sufficient to
897
   hold a subpacket of type TYPE.  Note: the buffer refers to the
898
   contents of the subpacket (not the header) and it must already be
899
   initialized: for some subpackets, it checks some internal
900
   constraints.
901
902
   Returns 0 if the size is acceptable.  Returns -2 if the buffer is
903
   definitely too short.  To check for an error, check whether the
904
   return value is less than 0.  */
905
int parse_one_sig_subpkt( const byte *buffer, size_t n, int type );
906
907
/* Looks for revocation key subpackets (see RFC 4880 5.2.3.15) in the
908
   hashed area of the signature packet.  Any that are found are added
909
   to SIG->REVKEY and SIG->NUMREVKEYS is updated appropriately.  */
910
void parse_revkeys(PKT_signature *sig);
911
912
/* Extract the attributes from the buffer at UID->ATTRIB_DATA and
913
   update UID->ATTRIBS and UID->NUMATTRIBS accordingly.  */
914
int parse_attribute_subpkts(PKT_user_id *uid);
915
916
/* Set the UID->NAME field according to the attributes.  MAX_NAMELEN
917
   must be at least 71.  */
918
void make_attribute_uidname(PKT_user_id *uid, size_t max_namelen);
919
920
/* Allocate and initialize a new GPG control packet.  DATA is the data
921
   to save in the packet.  */
922
PACKET *create_gpg_control ( ctrlpkttype_t type,
923
                             const byte *data,
924
                             size_t datalen );
925
926
/*-- build-packet.c --*/
927
gpg_error_t build_keyblock_image (kbnode_t keyblock, iobuf_t *r_iobuf);
928
int build_packet (iobuf_t out, PACKET *pkt);
929
gpg_error_t build_packet_and_meta (iobuf_t out, PACKET *pkt);
930
gpg_error_t gpg_mpi_write (iobuf_t out, gcry_mpi_t a, unsigned int *t_nwritten);
931
gpg_error_t gpg_mpi_write_opaque_nohdr (iobuf_t out, gcry_mpi_t a);
932
gpg_error_t gpg_mpi_write_opaque_32 (iobuf_t out, gcry_mpi_t a,
933
                                     unsigned int *r_nwritten);
934
u32 calc_packet_length( PACKET *pkt );
935
void build_sig_subpkt( PKT_signature *sig, sigsubpkttype_t type,
936
      const byte *buffer, size_t buflen );
937
void build_sig_subpkt_from_sig (PKT_signature *sig, PKT_public_key *pksk,
938
                                unsigned int signhints);
939
int  delete_sig_subpkt(subpktarea_t *buffer, sigsubpkttype_t type );
940
void build_attribute_subpkt(PKT_user_id *uid,byte type,
941
          const void *buf,u32 buflen,
942
          const void *header,u32 headerlen);
943
struct notation *string_to_notation(const char *string,int is_utf8);
944
struct notation *name_value_to_notation (const char *name, const char *value);
945
struct notation *blob_to_notation(const char *name,
946
                                  const char *data, size_t len);
947
struct notation *sig_to_notation(PKT_signature *sig);
948
struct notation *search_sig_notations (PKT_signature *sig, const char *name);
949
void free_notation (struct notation *notation);
950
951
/*-- free-packet.c --*/
952
void free_symkey_enc( PKT_symkey_enc *enc );
953
954
void release_pubkey_enc_parts (PKT_pubkey_enc *enc);
955
void free_pubkey_enc( PKT_pubkey_enc *enc );
956
void copy_pubkey_enc_parts (PKT_pubkey_enc *dst, PKT_pubkey_enc *src);
957
958
void free_seckey_enc( PKT_signature *enc );
959
960
void release_public_key_parts( PKT_public_key *pk );
961
void free_public_key( PKT_public_key *key );
962
963
void free_attributes(PKT_user_id *uid);
964
void free_user_id( PKT_user_id *uid );
965
void free_comment( PKT_comment *rem );
966
void free_packet (PACKET *pkt, parse_packet_ctx_t parsectx);
967
prefitem_t *copy_prefs (const prefitem_t *prefs);
968
969
PKT_public_key *copy_public_key_basics (PKT_public_key *d, PKT_public_key *s);
970
PKT_public_key *copy_public_key( PKT_public_key *d, PKT_public_key *s );
971
972
PKT_signature *copy_signature( PKT_signature *d, PKT_signature *s );
973
PKT_user_id *scopy_user_id (PKT_user_id *sd );
974
975
void free_seskey_enc_list (struct seskey_enc_list *sesenc_list);
976
977
int cmp_public_keys( PKT_public_key *a, PKT_public_key *b );
978
int cmp_signatures( PKT_signature *a, PKT_signature *b );
979
int cmp_user_ids( PKT_user_id *a, PKT_user_id *b );
980
981
982
/*-- sig-check.c --*/
983
/* Check a signature.  Looks up the public key from the key db.  (If
984
 * R_PK is not NULL, it is stored at RET_PK.)  DIGEST contains a
985
 * valid hash context that already includes the signed data.  This
986
 * function adds the relevant meta-data to the hash before finalizing
987
 * it and verifying the signature.  FOCRED_PK is usually NULL. */
988
gpg_error_t check_signature (ctrl_t ctrl,
989
                              PKT_signature *sig, gcry_md_hd_t digest,
990
                              const void *extrahash, size_t extrahashlen,
991
                              PKT_public_key *forced_pk,
992
                              u32 *r_expiredate, int *r_expired, int *r_revoked,
993
                             PKT_public_key **r_pk, kbnode_t *r_keyblock);
994
995
996
/*-- pubkey-enc.c --*/
997
gpg_error_t get_session_key (ctrl_t ctrl, struct seskey_enc_list *k, DEK *dek);
998
gpg_error_t get_override_session_key (DEK *dek, const char *string);
999
1000
/*-- compress.c --*/
1001
int handle_compressed (ctrl_t ctrl, void *ctx, PKT_compressed *cd,
1002
           int (*callback)(iobuf_t, void *), void *passthru );
1003
1004
/*-- decrypt-data.c --*/
1005
int decrypt_data (ctrl_t ctrl, void *ctx, PKT_encrypted *ed, DEK *dek,
1006
                  int *compliance_error);
1007
1008
/*-- plaintext.c --*/
1009
struct pfg { /* structure for PatialFileGuard */
1010
  unsigned int using_file : 1;  /* FP is for a file, not from FD.  */
1011
  char *fname_part;
1012
  char *fname;
1013
  estream_t fp;
1014
};
1015
gpg_error_t pfg_open_file (const byte *embedded_name, int embedded_namelen,
1016
                           iobuf_t data, struct pfg *pfg);
1017
void pfg_close_file (struct pfg *pfg, gpg_error_t err);
1018
int handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
1019
          int nooutput, int clearsig );
1020
int ask_for_detached_datafile( gcry_md_hd_t md, gcry_md_hd_t md2,
1021
             const char *inname, int textmode );
1022
1023
/*-- sign.c --*/
1024
int make_keysig_packet (ctrl_t ctrl,
1025
                        PKT_signature **ret_sig, PKT_public_key *pk,
1026
      PKT_user_id *uid, PKT_public_key *subpk,
1027
      PKT_public_key *pksk, int sigclass,
1028
      u32 timestamp, u32 duration,
1029
      int (*mksubpkt)(PKT_signature *, void *),
1030
      void *opaque,
1031
                        const char *cache_nonce);
1032
gpg_error_t update_keysig_packet (ctrl_t ctrl,
1033
                      PKT_signature **ret_sig,
1034
                      PKT_signature *orig_sig,
1035
                      PKT_public_key *pk,
1036
                      PKT_user_id *uid,
1037
                      PKT_public_key *subpk,
1038
                      PKT_public_key *pksk,
1039
                      int (*mksubpkt)(PKT_signature *, void *),
1040
                      void *opaque   );
1041
1042
/*-- keygen.c --*/
1043
PKT_user_id *generate_user_id (kbnode_t keyblock, const char *uidstr);
1044
1045
#endif /*G10_PACKET_H*/