Converging on lclint-3.0.17 strict level.
[platform/upstream/rpm.git] / rpmio / rpmpgp.c
1 /** \ingroup rpmio signature
2  * \file rpmio/rpmpgp.c
3  * Routines to handle RFC-2440 detached signatures.
4  */
5
6 #include "system.h"
7 #include "rpmpgp.h"
8 #include "debug.h"
9
10 /*@unchecked@*/
11 static int _debug = 0;
12 /*@unchecked@*/
13 static int _print = 0;
14 /*@unchecked@*/
15 /*@null@*/ static struct pgpSig_s * _dig = NULL;
16
17 /* This is the unarmored RPM-GPG-KEY public key. */
18 const char * redhatPubKeyDSA = "\
19 mQGiBDfqVDgRBADBKr3Bl6PO8BQ0H8sJoD6p9U7Yyl7pjtZqioviPwXP+DCWd4u8\n\
20 HQzcxAZ57m8ssA1LK1Fx93coJhDzM130+p5BG9mYSWShLabR3N1KXdXQYYcowTOM\n\
21 GxdwYRGr1Spw8QydLhjVfU1VSl4xt6bupPbWJbyjkg5Z3P7BlUOUJmrx3wCgobNV\n\
22 EDGaWYJcch5z5B1of/41G8kEAKii6q7Gu/vhXXnLS6m15oNnPVybyngiw/23dKjS\n\
23 ZVG7rKANEK2mxg1VB+vc/uUc4k49UxJJfCZg1gu1sPFV3GSa+Y/7jsiLktQvCiLP\n\
24 lncQt1dV+ENmHR5BdIDPWDzKBVbgWnSDnqQ6KrZ7T6AlZ74VMpjGxxkWU6vV2xsW\n\
25 XCLPA/9P/vtImA8CZN3jxGgtK5GGtDNJ/cMhhuv5tnfwFg4b/VGo2Jr8mhLUqoIb\n\
26 E6zeGAmZbUpdckDco8D5fiFmqTf5+++pCEpJLJkkzel/32N2w4qzPrcRMCiBURES\n\
27 PjCLd4Y5rPoU8E4kOHc/4BuHN903tiCsCPloCrWsQZ7UdxfQ5LQiUmVkIEhhdCwg\n\
28 SW5jIDxzZWN1cml0eUByZWRoYXQuY29tPohVBBMRAgAVBQI36lQ4AwsKAwMVAwID\n\
29 FgIBAheAAAoJECGRgM3bQqYOsBQAnRVtg7B25Hm11PHcpa8FpeddKiq2AJ9aO8sB\n\
30 XmLDmPOEFI75mpTrKYHF6rkCDQQ36lRyEAgAokgI2xJ+3bZsk8jRA8ORIX8DH05U\n\
31 lMH27qFYzLbT6npXwXYIOtVn0K2/iMDj+oEB1Aa2au4OnddYaLWp06v3d+XyS0t+\n\
32 5ab2ZfIQzdh7wCwxqRkzR+/H5TLYbMG+hvtTdylfqIX0WEfoOXMtWEGSVwyUsnM3\n\
33 Jy3LOi48rQQSCKtCAUdV20FoIGWhwnb/gHU1BnmES6UdQujFBE6EANqPhp0coYoI\n\
34 hHJ2oIO8ujQItvvNaU88j/s/izQv5e7MXOgVSjKe/WX3s2JtB/tW7utpy12wh1J+\n\
35 JsFdbLV/t8CozUTpJgx5mVA3RKlxjTA+On+1IEUWioB+iVfT7Ov/0kcAzwADBQf9\n\
36 E4SKCWRand8K0XloMYgmipxMhJNnWDMLkokvbMNTUoNpSfRoQJ9EheXDxwMpTPwK\n\
37 ti/PYrrL2J11P2ed0x7zm8v3gLrY0cue1iSba+8glY+p31ZPOr5ogaJw7ZARgoS8\n\
38 BwjyRymXQp+8Dete0TELKOL2/itDOPGHW07SsVWOR6cmX4VlRRcWB5KejaNvdrE5\n\
39 4XFtOd04NMgWI63uqZc4zkRa+kwEZtmbz3tHSdRCCE+Y7YVP6IUf/w6YPQFQriWY\n\
40 FiA6fD10eB+BlIUqIw80VgjsBKmCwvKkn4jg8kibXgj4/TzQSx77uYokw1EqQ2wk\n\
41 OZoaEtcubsNMquuLCMWijYhGBBgRAgAGBQI36lRyAAoJECGRgM3bQqYOhyYAnj7h\n\
42 VDY/FJAGqmtZpwVp9IlitW5tAJ4xQApr/jNFZCTksnI+4O1765F7tA==\n\
43 ";
44
45 /* This is the unarmored RPM-PGP-KEY public key. */
46 const char * redhatPubKeyRSA = "\
47 mQCNAzEpXjUAAAEEAKG4/V9oUSiDc9wIge6Bmg6erDGCLzmFyioAho8kDIJSrcmi\n\
48 F9qTdPq+fj726pgW1iSb0Y7syZn9Y2lgQm5HkPODfNi8eWyTFSxbr8ygosLRClTP\n\
49 xqHVhtInGrfZNLoSpv1LdWOme0yOpOQJnghdOMzKXpgf5g84vaUg6PHLopv5AAUR\n\
50 tCpSZWQgSGF0IFNvZnR3YXJlLCBJbmMuIDxyZWRoYXRAcmVkaGF0LmNvbT6JAJUD\n\
51 BRAyA5tUoyDApfg4JKEBAUzSA/9QdcVsu955vVyZDk8uvOXWV0X3voT9B3aYMFvj\n\
52 UNHUD6F1VFruwQHVKbGJEq1o5MOA6OXKR3vJZStXEMF47TWXJfQaflgl8ywZTH5W\n\
53 +eMlKau6Nr0labUV3lmsAE4Vsgu8NCkzIrp2wNVbeW2ZAXtrKswV+refLquUhp7l\n\
54 wMpH9IkAdQMFEDGttkRNdXhbO1TgGQEBAGoC/j6C22PqXIyqZc6fG6J6Jl/T5kFG\n\
55 xH1pKIzua5WCDDugAgnuOJgywa4pegT4UqwEZiMTAlwT6dmG1CXgKB+5V7lnCjDc\n\
56 JZLni0iztoe08ig6fJrjNGXljf7KYXzgwBftQokAlQMFEDMQzo2MRVM9rfPulQEB\n\
57 pLoD/1/MWv3u0Paiu14XRvDrBaJ7BmG2/48bA5vKOzpvvoNRO95YS7ZEtqErXA7Y\n\
58 DRO8+C8f6PAILMk7kCk4lNMscS/ZRzu5+J8cv4ejsFvxgJBBU3Zgp8AWdWOpvZ0I\n\
59 wW//HoDUGhOxlEtymljIMFBkj4SysHWhCBUfA9Xy86kouTJQiQCVAwUQMxDOQ50a\n\
60 feTWLUSJAQFnYQQAkt9nhMTeioREB1DvJt+vsFyOj//o3ThqK5ySEP3dgj62iaQp\n\
61 JrBmAe5XZPw25C/TXAf+x27H8h2QbKgq49VtsElFexc6wO+uq85fAPDdyE+2XyNE\n\
62 njGZkY/TP2F/jTB0sAwJO+xFCHmSYkcBjzxK/2LMD+O7rwp2UCUhhl9QhhqJAJUD\n\
63 BRAx5na6pSDo8cuim/kBARmjA/4lDVnV2h9KiNabp9oE38wmGgu5m5XgUHW8L6du\n\
64 iQDnwO5IgXN2vDpKGxbgtwv6iYYmGd8IRQ66uJvOsxSv3OR7J7LkCHuI2b/s0AZn\n\
65 c79DZaJ2ChUCZlbNQBMeEdrFWif9NopY+d5+2tby1onu9XOFMMvomxL3NhctElYR\n\
66 HC8Xw4kAlQMFEDHmdTtURTdEKY1MpQEBEtEEAMZbp1ZFrjiHkj2aLFC1S8dGRbSH\n\
67 GUdnLP9qLPFgmWekp9E0o8ZztALGVdqPfPF3N/JJ+AL4IMrfojd7+eZKw36Mdvtg\n\
68 dPI+Oz4sxHDbDynZ2qspD9Om5yYuxuz/Xq+9nO2IlsAnEYw3ag3cxat0kvxpOPRe\n\
69 Yy+vFpgfDNizr3MgiQBVAwUQMXNMXCjtrosVMemRAQEDnwH7BsJrnnh91nI54LAK\n\
70 Gcq3pr8ld0PAtWJmNRGQvUlpEMXUSnu59j2P1ogPNjL3PqKdVxk5Jqgcr8TPQMf3\n\
71 V4fqXokAlQMFEDFy+8YiEmsRQ3LyzQEB+TwD/03QDslXLg5F3zj4zf0yI6ikT0be\n\
72 5OhZv2pnkb80qgdHzFRxBOYmSoueRKdQJASd8F9ue4b3bmf/Y7ikiY0DblvxcXB2\n\
73 sz1Pu8i2Zn9u8SKuxNIoVvM8/STRVkgPfvL5QjAWMHT9Wvg81XcI2yXJzrt/2f2g\n\
74 mNpWIvVOOT85rVPIiQCVAwUQMVPRlBlzviMjNHElAQG1nwP/fpVX6nKRWJCSFeB7\n\
75 leZ4lb+y1uMsMVv0n7agjJVw13SXaA267y7VWCBlnhsCemxEugqEIkI4lu/1mgtw\n\
76 WPWSE0BOIVjj0AA8zp2T0H3ZCCMbiFAFJ1P2Gq2rKr8QrOb/08oH1lEzyz0j/jKh\n\
77 qiXAxdlB1wojQB6yLbHvTIe3rZGJAHUDBRAxKetfzauiKSJ6LJEBAed/AvsEiGgj\n\
78 TQzhsZcUuRNrQpV0cDGH9Mpril7P7K7yFIzju8biB+Cu6nEknSOHlMLl8usObVlk\n\
79 d8Wf14soHC7SjItiGSKtI8JhauzBJPl6fDDeyHGsJKo9f9adKeBMCipCFOuJAJUD\n\
80 BRAxKeqWRHFTaIK/x+0BAY6eA/4m5X4gs1UwOUIRnljo9a0cVs6ITL554J9vSCYH\n\
81 Zzd87kFwdf5W1Vd82HIkRzcr6cp33E3IDkRzaQCMVw2me7HePP7+4Ry2q3EeZMbm\n\
82 NE++VzkxjikzpRb2+F5nGB2UdsElkgbXinswebiuOwOrocLbz6JFdDsJPcT5gVfi\n\
83 z15FuA==\n\
84 ";
85
86 struct pgpValTbl_s pgpSigTypeTbl[] = {
87     { PGPSIGTYPE_BINARY,        "Binary document signature" },
88     { PGPSIGTYPE_TEXT,          "Text document signature" },
89     { PGPSIGTYPE_STANDALONE,    "Standalone signature" },
90     { PGPSIGTYPE_GENERIC_CERT,  "Generic certification of a User ID and Public Key" },
91     { PGPSIGTYPE_PERSONA_CERT,  "Persona certification of a User ID and Public Key" },
92     { PGPSIGTYPE_CASUAL_CERT,   "Casual certification of a User ID and Public Key" },
93     { PGPSIGTYPE_POSITIVE_CERT, "Positive certification of a User ID and Public Key" },
94     { PGPSIGTYPE_SUBKEY_BINDING,"Subkey Binding Signature" },
95     { PGPSIGTYPE_SIGNED_KEY,    "Signature directly on a key" },
96     { PGPSIGTYPE_KEY_REVOKE,    "Key revocation signature" },
97     { PGPSIGTYPE_SUBKEY_REVOKE, "Subkey revocation signature" },
98     { PGPSIGTYPE_CERT_REVOKE,   "Certification revocation signature" },
99     { PGPSIGTYPE_TIMESTAMP,     "Timestamp signature" },
100     { -1,                       "Unknown signature type" },
101 };
102
103 struct pgpValTbl_s pgpPubkeyTbl[] = {
104     { PGPPUBKEYALGO_RSA,        "RSA" },
105     { PGPPUBKEYALGO_RSA_ENCRYPT,"RSA(Encrypt-Only)" },
106     { PGPPUBKEYALGO_RSA_SIGN,   "RSA(Sign-Only)" },
107     { PGPPUBKEYALGO_ELGAMAL_ENCRYPT,"Elgamal(Encrypt-Only)" },
108     { PGPPUBKEYALGO_DSA,        "DSA" },
109     { PGPPUBKEYALGO_EC,         "Elliptic Curve" },
110     { PGPPUBKEYALGO_ECDSA,      "ECDSA" },
111     { PGPPUBKEYALGO_ELGAMAL,    "Elgamal" },
112     { PGPPUBKEYALGO_DH,         "Diffie-Hellman (X9.42)" },
113     { -1,                       "Unknown public key algorithm" },
114 };
115
116 struct pgpValTbl_s pgpSymkeyTbl[] = {
117     { PGPSYMKEYALGO_PLAINTEXT,  "Plaintext" },
118     { PGPSYMKEYALGO_IDEA,       "IDEA" },
119     { PGPSYMKEYALGO_TRIPLE_DES, "3DES" },
120     { PGPSYMKEYALGO_CAST5,      "CAST5" },
121     { PGPSYMKEYALGO_BLOWFISH,   "BLOWFISH" },
122     { PGPSYMKEYALGO_SAFER,      "SAFER" },
123     { PGPSYMKEYALGO_DES_SK,     "DES/SK" },
124     { PGPSYMKEYALGO_AES_128,    "AES(128-bit key)" },
125     { PGPSYMKEYALGO_AES_192,    "AES(192-bit key)" },
126     { PGPSYMKEYALGO_AES_256,    "AES(256-bit key)" },
127     { PGPSYMKEYALGO_TWOFISH,    "TWOFISH" },
128     { -1,                       "Unknown symmetric key algorithm" },
129 };
130
131 struct pgpValTbl_s pgpCompressionTbl[] = {
132     { PGPCOMPRESSALGO_NONE,     "Uncompressed" },
133     { PGPCOMPRESSALGO_ZIP,      "ZIP" },
134     { PGPCOMPRESSALGO_ZLIB,     "ZLIB" },
135     { -1,                       "Unknown compression algorithm" },
136 };
137
138 struct pgpValTbl_s pgpHashTbl[] = {
139     { PGPHASHALGO_MD5,          "MD5" },
140     { PGPHASHALGO_SHA1,         "SHA1" },
141     { PGPHASHALGO_RIPEMD160,    "RIPEMD160" },
142     { PGPHASHALGO_MD2,          "MD2" },
143     { PGPHASHALGO_TIGER192,     "TIGER192" },
144     { PGPHASHALGO_HAVAL_5_160,  "HAVAL-5-160" },
145     { -1,                       "Unknown hash algorithm" },
146 };
147
148 /*@-exportlocal -exportheadervar@*/
149 /*@observer@*/ /*@unchecked@*/
150 struct pgpValTbl_s pgpKeyServerPrefsTbl[] = {
151     { 0x80,                     "No-modify" },
152     { -1,                       "Unknown key server preference" },
153 };
154 /*@=exportlocal =exportheadervar@*/
155
156 struct pgpValTbl_s pgpSubTypeTbl[] = {
157     { PGPSUBTYPE_SIG_CREATE_TIME,"signature creation time" },
158     { PGPSUBTYPE_SIG_EXPIRE_TIME,"signature expiration time" },
159     { PGPSUBTYPE_EXPORTABLE_CERT,"exportable certification" },
160     { PGPSUBTYPE_TRUST_SIG,     "trust signature" },
161     { PGPSUBTYPE_REGEX,         "regular expression" },
162     { PGPSUBTYPE_REVOCABLE,     "revocable" },
163     { PGPSUBTYPE_KEY_EXPIRE_TIME,"key expiration time" },
164     { PGPSUBTYPE_BACKWARD_COMPAT,"placeholder for backward compatibility" },
165     { PGPSUBTYPE_PREFER_SYMKEY, "preferred symmetric algorithms" },
166     { PGPSUBTYPE_REVOKE_KEY,    "revocation key" },
167     { PGPSUBTYPE_ISSUER_KEYID,  "issuer key ID" },
168     { PGPSUBTYPE_NOTATION,      "notation data" },
169     { PGPSUBTYPE_PREFER_HASH,   "preferred hash algorithms" },
170     { PGPSUBTYPE_PREFER_COMPRESS,"preferred compression algorithms" },
171     { PGPSUBTYPE_KEYSERVER_PREFERS,"key server preferences" },
172     { PGPSUBTYPE_PREFER_KEYSERVER,"preferred key server" },
173     { PGPSUBTYPE_PRIMARY_USERID,"primary user id" },
174     { PGPSUBTYPE_POLICY_URL,    "policy URL" },
175     { PGPSUBTYPE_KEY_FLAGS,     "key flags" },
176     { PGPSUBTYPE_SIGNER_USERID, "signer's user id" },
177     { PGPSUBTYPE_REVOKE_REASON, "reason for revocation" },
178     { PGPSUBTYPE_INTERNAL_100,  "internal subpkt type 100" },
179     { PGPSUBTYPE_INTERNAL_101,  "internal subpkt type 101" },
180     { PGPSUBTYPE_INTERNAL_102,  "internal subpkt type 102" },
181     { PGPSUBTYPE_INTERNAL_103,  "internal subpkt type 103" },
182     { PGPSUBTYPE_INTERNAL_104,  "internal subpkt type 104" },
183     { PGPSUBTYPE_INTERNAL_105,  "internal subpkt type 105" },
184     { PGPSUBTYPE_INTERNAL_106,  "internal subpkt type 106" },
185     { PGPSUBTYPE_INTERNAL_107,  "internal subpkt type 107" },
186     { PGPSUBTYPE_INTERNAL_108,  "internal subpkt type 108" },
187     { PGPSUBTYPE_INTERNAL_109,  "internal subpkt type 109" },
188     { PGPSUBTYPE_INTERNAL_110,  "internal subpkt type 110" },
189     { -1,                       "Unknown signature subkey type" },
190 };
191
192 struct pgpValTbl_s pgpPktTbl[] = {
193     { PGPPKT_PUBLIC_SESSION_KEY,"Public-Key Encrypted Session Key" },
194     { PGPPKT_SIGNATURE,         "Signature" },
195     { PGPPKT_SYMMETRIC_SESSION_KEY,"Symmetric-Key Encrypted Session Key" },
196     { PGPPKT_ONEPASS_SIGNATURE, "One-Pass Signature" },
197     { PGPPKT_SECRET_KEY,        "Secret Key" },
198     { PGPPKT_PUBLIC_KEY,        "Public Key" },
199     { PGPPKT_SECRET_SUBKEY,     "Secret Subkey" },
200     { PGPPKT_COMPRESSED_DATA,   "Compressed Data" },
201     { PGPPKT_SYMMETRIC_DATA,    "Symmetrically Encrypted Data" },
202     { PGPPKT_MARKER,            "Marker" },
203     { PGPPKT_LITERAL_DATA,      "Literal Data" },
204     { PGPPKT_TRUST,             "Trust" },
205     { PGPPKT_USER_ID,           "User ID" },
206     { PGPPKT_PUBLIC_SUBKEY,     "Public Subkey" },
207     { PGPPKT_COMMENT_OLD,       "Comment (from OpenPGP draft)" },
208     { PGPPKT_PHOTOID,           "PGP's pgoto ID" },
209     { PGPPKT_ENCRYPTED_MDC,     "Integrity protected encrypted data" },
210     { PGPPKT_MDC,               "Manipulaion detection code packet" },
211     { PGPPKT_PRIVATE_60,        "Private #60" },
212     { PGPPKT_COMMENT,           "Comment" },
213     { PGPPKT_PRIVATE_62,        "Private #62" },
214     { PGPPKT_CONTROL,           "Control (GPG)" },
215     { -1,                       "Unknown packet tag" },
216 };
217
218 static void pgpPrtNL(void)
219         /*@globals fileSystem @*/
220         /*@modifies fileSystem @*/
221 {
222     if (!_print) return;
223     fprintf(stderr, "\n");
224 }
225
226 static void pgpPrtInt(const char *pre, int i)
227         /*@globals fileSystem @*/
228         /*@modifies fileSystem @*/
229 {
230     if (!_print) return;
231     if (pre && *pre)
232         fprintf(stderr, "%s", pre);
233     fprintf(stderr, " %d", i);
234 }
235
236 static void pgpPrtStr(const char *pre, const char *s)
237         /*@globals fileSystem @*/
238         /*@modifies fileSystem @*/
239 {
240     if (!_print) return;
241     if (pre && *pre)
242         fprintf(stderr, "%s", pre);
243     fprintf(stderr, " %s", s);
244 }
245
246 static void pgpPrtHex(const char *pre, const byte *p, unsigned int plen)
247         /*@globals fileSystem @*/
248         /*@modifies fileSystem @*/
249 {
250     if (!_print) return;
251     if (pre && *pre)
252         fprintf(stderr, "%s", pre);
253     fprintf(stderr, " %s", pgpHexStr(p, plen));
254 }
255
256 void pgpPrtVal(const char * pre, pgpValTbl vs, byte val)
257         /*@globals fileSystem @*/
258         /*@modifies fileSystem @*/
259 {
260     if (!_print) return;
261     if (pre && *pre)
262         fprintf(stderr, "%s", pre);
263     fprintf(stderr, "%s(%u)", pgpValStr(vs, val), (unsigned)val);
264 }
265
266 static void pgpHexSet(const char * pre, int lbits,
267                 /*@out@*/ mp32number * mpn, const byte * p)
268         /*@globals fileSystem @*/
269         /*@modifies *mpn, fileSystem @*/
270 {
271     unsigned int mbits = pgpMpiBits(p);
272     unsigned int nbits = (lbits > mbits ? lbits : mbits);
273     unsigned int nbytes = ((nbits + 7) >> 3);
274     char * t = xmalloc(2*nbytes+1);
275     unsigned int ix = 2 * ((nbits - mbits) >> 3);
276
277 if (_debug)
278 fprintf(stderr, "*** mbits %u nbits %u nbytes %u t %p[%d] ix %u\n", mbits, nbits, nbytes, t, (2*nbytes+1), ix);
279     if (ix > 0) memset(t, (int)'0', ix);
280     strcpy(t+ix, pgpMpiHex(p));
281 if (_debug)
282 fprintf(stderr, "*** %s %s\n", pre, t);
283     mp32nsethex(mpn, t);
284     free(t);
285 if (_debug && _print)
286 printf("\t %s ", pre), mp32println(mpn->size, mpn->data);
287 }
288
289 /*@-varuse =readonlytrans @*/
290 /*@observer@*/ /*@unchecked@*/
291 static const char * pgpSigRSA[] = {
292     " m**d =",
293     NULL,
294 };
295
296 /*@observer@*/ /*@unchecked@*/
297 static const char * pgpSigDSA[] = {
298     "    r =",
299     "    s =",
300     NULL,
301 };
302 /*@=varuse =readonlytrans @*/
303
304 int pgpPrtPktSigV3(pgpPkt pkt, const byte *h, unsigned int hlen)
305 {
306     pgpPktSigV3 v = (pgpPktSigV3)h;
307     byte *p;
308     unsigned plen;
309     time_t t;
310     int i;
311
312     if (v->version != 3) {
313         fprintf(stderr, " version(%u) != 3\n", (unsigned)v->version);
314         return 1;
315     }
316     if (v->hashlen != 5) {
317         fprintf(stderr, " hashlen(%u) != 5\n", (unsigned)v->hashlen);
318         return 1;
319     }
320
321     /*@-mods@*/
322     if (_dig) memcpy(&_dig->sig.v3, v, sizeof(_dig->sig.v3));
323     /*@=mods@*/
324
325     pgpPrtVal("V3 ", pgpPktTbl, pkt);
326
327     pgpPrtVal(" ", pgpPubkeyTbl, v->pubkey_algo);
328     pgpPrtVal(" ", pgpHashTbl, v->hash_algo);
329
330     pgpPrtVal(" ", pgpSigTypeTbl, v->sigtype);
331     pgpPrtNL();
332
333     t = pgpGrab(v->time, sizeof(v->time));
334     if (_print)
335         fprintf(stderr, " %-24.24s(0x%08x)", ctime(&t), (unsigned)t);
336     pgpPrtNL();
337     pgpPrtHex(" signer keyid", v->signer, sizeof(v->signer));
338     plen = pgpGrab(v->signhash16, sizeof(v->signhash16));
339     pgpPrtHex(" signhash16", v->signhash16, sizeof(v->signhash16));
340     pgpPrtNL();
341
342     p = ((byte *)v) + sizeof(*v);
343     for (i = 0; p < &h[hlen]; i++, p += pgpMpiLen(p)) {
344         if (v->pubkey_algo == PGPPUBKEYALGO_RSA) {
345             if (pgpSigRSA[i] == NULL) break;
346             /*@-mods@*/
347             if (_dig &&
348         (v->sigtype == PGPSIGTYPE_BINARY || v->sigtype == PGPSIGTYPE_TEXT))
349             {
350                 switch (i) {
351                 case 0:         /* m**d */
352                     mp32nsethex(&_dig->c, pgpMpiHex(p));
353 if (_debug && _print)
354 printf("\t  m**d = "),  mp32println(_dig->c.size, _dig->c.data);
355                     /*@switchbreak@*/ break;
356                 default:
357                     /*@switchbreak@*/ break;
358                 }
359             }
360             /*@=mods@*/
361             pgpPrtStr("", pgpSigRSA[i]);
362         } else if (v->pubkey_algo == PGPPUBKEYALGO_DSA) {
363             if (pgpSigDSA[i] == NULL) break;
364             /*@-mods@*/
365             if (_dig &&
366         (v->sigtype == PGPSIGTYPE_BINARY || v->sigtype == PGPSIGTYPE_TEXT))
367             {
368                 switch (i) {
369                 case 0:         /* r */
370                     pgpHexSet(pgpSigDSA[i], 160, &_dig->r, p);
371                     /*@switchbreak@*/ break;
372                 case 1:         /* s */
373                     pgpHexSet(pgpSigDSA[i], 160, &_dig->s, p);
374                     /*@switchbreak@*/ break;
375                 default:
376                     /*@switchbreak@*/ break;
377                 }
378             }
379             /*@=mods@*/
380             pgpPrtStr("", pgpSigDSA[i]);
381         } else {
382             if (_print)
383                 fprintf(stderr, "%7d", i);
384         }
385         pgpPrtStr("", pgpMpiStr(p));
386         pgpPrtNL();
387     }
388
389     return 0;
390 }
391
392 int pgpPrtSubType(const byte *h, unsigned int hlen)
393 {
394     const byte *p = h;
395     unsigned plen;
396     int i;
397
398     while (hlen > 0) {
399         i = pgpLen(p, &plen);
400         p += i;
401         hlen -= i;
402
403         pgpPrtVal("    ", pgpSubTypeTbl, p[0]);
404         switch (*p) {
405         case PGPSUBTYPE_PREFER_SYMKEY:  /* preferred symmetric algorithms */
406             for (i = 1; i < plen; i++)
407                 pgpPrtVal(" ", pgpSymkeyTbl, p[i]);
408             pgpPrtNL();
409             /*@switchbreak@*/ break;
410         case PGPSUBTYPE_PREFER_HASH:    /* preferred hash algorithms */
411             for (i = 1; i < plen; i++)
412                 pgpPrtVal(" ", pgpHashTbl, p[i]);
413             pgpPrtNL();
414             /*@switchbreak@*/ break;
415         case PGPSUBTYPE_PREFER_COMPRESS:/* preferred compression algorithms */
416             for (i = 1; i < plen; i++)
417                 pgpPrtVal(" ", pgpCompressionTbl, p[i]);
418             pgpPrtNL();
419             /*@switchbreak@*/ break;
420         case PGPSUBTYPE_KEYSERVER_PREFERS:/* key server preferences */
421             for (i = 1; i < plen; i++)
422                 pgpPrtVal(" ", pgpKeyServerPrefsTbl, p[i]);
423             pgpPrtNL();
424             /*@switchbreak@*/ break;
425         case PGPSUBTYPE_SIG_CREATE_TIME:
426         case PGPSUBTYPE_SIG_EXPIRE_TIME:
427         case PGPSUBTYPE_KEY_EXPIRE_TIME:
428             if ((plen - 1) == 4) {
429                 time_t t = pgpGrab(p+1, plen-1);
430                 if (_print)
431                    fprintf(stderr, " %-24.24s(0x%08x)", ctime(&t), (unsigned)t);
432             } else
433                 pgpPrtHex("", p+1, plen-1);
434             pgpPrtNL();
435             /*@switchbreak@*/ break;
436
437         case PGPSUBTYPE_ISSUER_KEYID:   /* issuer key ID */
438         case PGPSUBTYPE_EXPORTABLE_CERT:
439         case PGPSUBTYPE_TRUST_SIG:
440         case PGPSUBTYPE_REGEX:
441         case PGPSUBTYPE_REVOCABLE:
442         case PGPSUBTYPE_BACKWARD_COMPAT:
443         case PGPSUBTYPE_REVOKE_KEY:
444         case PGPSUBTYPE_NOTATION:
445         case PGPSUBTYPE_PREFER_KEYSERVER:
446         case PGPSUBTYPE_PRIMARY_USERID:
447         case PGPSUBTYPE_POLICY_URL:
448         case PGPSUBTYPE_KEY_FLAGS:
449         case PGPSUBTYPE_SIGNER_USERID:
450         case PGPSUBTYPE_REVOKE_REASON:
451         case PGPSUBTYPE_INTERNAL_100:
452         case PGPSUBTYPE_INTERNAL_101:
453         case PGPSUBTYPE_INTERNAL_102:
454         case PGPSUBTYPE_INTERNAL_103:
455         case PGPSUBTYPE_INTERNAL_104:
456         case PGPSUBTYPE_INTERNAL_105:
457         case PGPSUBTYPE_INTERNAL_106:
458         case PGPSUBTYPE_INTERNAL_107:
459         case PGPSUBTYPE_INTERNAL_108:
460         case PGPSUBTYPE_INTERNAL_109:
461         case PGPSUBTYPE_INTERNAL_110:
462         default:
463             pgpPrtHex("", p+1, plen-1);
464             pgpPrtNL();
465             /*@switchbreak@*/ break;
466         }
467         p += plen;
468         hlen -= plen;
469     }
470     return 0;
471 }
472
473 int pgpPrtPktSigV4(pgpPkt pkt, const byte *h, unsigned int hlen)
474 {
475     pgpPktSigV4 v = (pgpPktSigV4)h;
476     byte * p;
477     unsigned plen;
478     int i;
479
480     if (v->version != 4) {
481         fprintf(stderr, " version(%u) != 4\n", (unsigned)v->version);
482         return 1;
483     }
484
485     /*@-mods@*/
486     if (_dig) memcpy(&_dig->sig.v4, v, sizeof(_dig->sig.v4));
487     /*@=mods@*/
488
489     pgpPrtVal("V4 ", pgpPktTbl, pkt);
490     pgpPrtVal(" ", pgpPubkeyTbl, v->pubkey_algo);
491     pgpPrtVal(" ", pgpHashTbl, v->hash_algo);
492
493     pgpPrtVal(" ", pgpSigTypeTbl, v->sigtype);
494     pgpPrtNL();
495
496     p = &v->hashlen[0];
497     plen = pgpGrab(v->hashlen, sizeof(v->hashlen));
498     p += sizeof(v->hashlen);
499
500 if (_debug && _print)
501 fprintf(stderr, "   hash[%u] -- %s\n", plen, pgpHexStr(p, plen));
502     /*@-mods@*/
503     if (_dig) {
504         _dig->hash_datalen = plen;
505         _dig->hash_data = xmalloc(_dig->hash_datalen);
506         memcpy(_dig->hash_data, p, plen);
507     }
508     /*@=mods@*/
509     (void) pgpPrtSubType(p, plen);
510     p += plen;
511
512     plen = pgpGrab(p,2);
513     p += 2;
514
515 if (_debug && _print)
516 fprintf(stderr, " unhash[%u] -- %s\n", plen, pgpHexStr(p, plen));
517     (void) pgpPrtSubType(p, plen);
518     p += plen;
519
520     plen = pgpGrab(p,2);
521     pgpPrtHex(" signhash16", p, 2);
522     pgpPrtNL();
523     p += 2;
524
525     for (i = 0; p < &h[hlen]; i++, p += pgpMpiLen(p)) {
526         if (v->pubkey_algo == PGPPUBKEYALGO_RSA) {
527             if (pgpSigRSA[i] == NULL) break;
528             /*@-mods@*/
529             if (_dig &&
530         (v->sigtype == PGPSIGTYPE_BINARY || v->sigtype == PGPSIGTYPE_TEXT))
531             {
532                 switch (i) {
533                 case 0:         /* m**d */
534                     mp32nsethex(&_dig->c, pgpMpiHex(p));
535 if (_debug && _print)
536 printf("\t  m**d = "),  mp32println(_dig->c.size, _dig->c.data);
537                     /*@switchbreak@*/ break;
538                 default:
539                     /*@switchbreak@*/ break;
540                 }
541             }
542             /*@=mods@*/
543             pgpPrtStr("", pgpSigRSA[i]);
544         } else if (v->pubkey_algo == PGPPUBKEYALGO_DSA) {
545             if (pgpSigDSA[i] == NULL) break;
546             /*@-mods@*/
547             if (_dig &&
548         (v->sigtype == PGPSIGTYPE_BINARY || v->sigtype == PGPSIGTYPE_TEXT))
549             {
550                 switch (i) {
551                 case 0:         /* r */
552                     pgpHexSet(pgpSigDSA[i], 160, &_dig->r, p);
553                     /*@switchbreak@*/ break;
554                 case 1:         /* s */
555                     pgpHexSet(pgpSigDSA[i], 160, &_dig->s, p);
556                     /*@switchbreak@*/ break;
557                 default:
558                     /*@switchbreak@*/ break;
559                 }
560             }
561             /*@=mods@*/
562             pgpPrtStr("", pgpSigDSA[i]);
563         } else {
564             if (_print)
565                 fprintf(stderr, "%7d", i);
566         }
567         pgpPrtStr("", pgpMpiStr(p));
568         pgpPrtNL();
569     }
570
571     return 0;
572 }
573
574 int pgpPrtPktSig(pgpPkt pkt, const byte *h, unsigned int hlen)
575 {
576     byte version = *h;
577     switch (version) {
578     case 3:
579         (void) pgpPrtPktSigV3(pkt, h, hlen);
580         break;
581     case 4:
582         (void) pgpPrtPktSigV4(pkt, h, hlen);
583         break;
584     }
585     return 0;
586 }
587
588 /*@-varuse =readonlytrans @*/
589 /*@observer@*/ /*@unchecked@*/
590 static const char * pgpPublicRSA[] = {
591     "    n =",
592     "    e =",
593     NULL,
594 };
595
596 /*@observer@*/ /*@unchecked@*/
597 static const char * pgpSecretRSA[] = {
598     "    d =",
599     "    p =",
600     "    q =",
601     "    u =",
602     NULL,
603 };
604
605 /*@observer@*/ /*@unchecked@*/
606 static const char * pgpPublicDSA[] = {
607     "    p =",
608     "    q =",
609     "    g =",
610     "    y =",
611     NULL,
612 };
613
614 /*@observer@*/ /*@unchecked@*/
615 static const char * pgpSecretDSA[] = {
616     "    x =",
617     NULL,
618 };
619
620 /*@observer@*/ /*@unchecked@*/
621 static const char * pgpPublicELGAMAL[] = {
622     "    p =",
623     "    g =",
624     "    y =",
625     NULL,
626 };
627
628 /*@observer@*/ /*@unchecked@*/
629 static const char * pgpSecretELGAMAL[] = {
630     "    x =",
631     NULL,
632 };
633 /*@=varuse =readonlytrans @*/
634
635 int pgpPrtKeyV3(pgpPkt pkt, const byte *h, unsigned int hlen)
636 {
637     pgpPktKeyV3 v = (pgpPktKeyV3)h;
638     byte * p;
639     unsigned plen;
640     time_t t;
641     int i;
642
643     pgpPrtVal("", pgpPktTbl, pkt);
644     if (v->version != 3) {
645         fprintf(stderr, " version(%u) != 3\n", (unsigned)v->version);
646         return 1;
647     }
648     pgpPrtVal(" ", pgpPubkeyTbl, v->pubkey_algo);
649     t = pgpGrab(v->time, sizeof(v->time));
650     if (_print)
651         fprintf(stderr, " %-24.24s(0x%08x)", ctime(&t), (unsigned)t);
652
653     plen = pgpGrab(v->valid, sizeof(v->valid));
654     if (plen != 0)
655         fprintf(stderr, " valid %u days", plen);
656
657     pgpPrtNL();
658
659     p = ((byte *)v) + sizeof(*v);
660     for (i = 0; p < &h[hlen]; i++, p += pgpMpiLen(p)) {
661         if (v->pubkey_algo == PGPPUBKEYALGO_RSA) {
662             if (pgpPublicRSA[i] == NULL) break;
663             /*@-mods@*/
664             if (_dig) {
665                 switch (i) {
666                 case 0:         /* n */
667                     mp32bsethex(&_dig->rsa_pk.n, pgpMpiHex(p));
668 if (_debug && _print)
669 printf("\t     n = "),  mp32println(_dig->rsa_pk.n.size, _dig->rsa_pk.n.modl);
670                     /*@switchbreak@*/ break;
671                 case 1:         /* e */
672                     mp32nsethex(&_dig->rsa_pk.e, pgpMpiHex(p));
673 if (_debug && _print)
674 printf("\t     e = "),  mp32println(_dig->rsa_pk.e.size, _dig->rsa_pk.e.data);
675                     /*@switchbreak@*/ break;
676                 default:
677                     /*@switchbreak@*/ break;
678                 }
679             }
680             /*@=mods@*/
681             pgpPrtStr("", pgpPublicRSA[i]);
682         } else if (v->pubkey_algo == PGPPUBKEYALGO_DSA) {
683             if (pgpPublicDSA[i] == NULL) break;
684             /*@-mods@*/
685             if (_dig) {
686                 switch (i) {
687                 case 0:         /* p */
688                     mp32bsethex(&_dig->p, pgpMpiHex(p));
689 if (_debug && _print)
690 printf("\t     p = "),  mp32println(_dig->p.size, _dig->p.modl);
691                     /*@switchbreak@*/ break;
692                 case 1:         /* q */
693                     mp32bsethex(&_dig->q, pgpMpiHex(p));
694 if (_debug && _print)
695 printf("\t     q = "),  mp32println(_dig->q.size, _dig->q.modl);
696                     /*@switchbreak@*/ break;
697                 case 2:         /* g */
698                     mp32nsethex(&_dig->g, pgpMpiHex(p));
699 if (_debug && _print)
700 printf("\t     g = "),  mp32println(_dig->g.size, _dig->g.data);
701                     /*@switchbreak@*/ break;
702                 case 3:         /* y */
703                     mp32nsethex(&_dig->y, pgpMpiHex(p));
704 if (_debug && _print)
705 printf("\t     y = "),  mp32println(_dig->y.size, _dig->y.data);
706                     /*@switchbreak@*/ break;
707                 default:
708                     /*@switchbreak@*/ break;
709                 }
710             }
711             /*@=mods@*/
712             pgpPrtStr("", pgpPublicDSA[i]);
713         } else if (v->pubkey_algo == PGPPUBKEYALGO_ELGAMAL_ENCRYPT) {
714             if (pgpPublicELGAMAL[i] == NULL) break;
715             pgpPrtStr("", pgpPublicELGAMAL[i]);
716         } else {
717             if (_print)
718                 fprintf(stderr, "%7d", i);
719         }
720     /*@=mods@*/
721         pgpPrtStr("", pgpMpiStr(p));
722         pgpPrtNL();
723     }
724
725     return 0;
726 }
727
728 int pgpPrtKeyV4(pgpPkt pkt, const byte *h, unsigned int hlen)
729 {
730     pgpPktKeyV4 v = (pgpPktKeyV4)h;
731     byte * p;
732     time_t t;
733     int i;
734
735     pgpPrtVal("", pgpPktTbl, pkt);
736     if (v->version != 4) {
737         fprintf(stderr, " version(%u) != 4\n", (unsigned)v->version);
738         return 1;
739     }
740     pgpPrtVal(" ", pgpPubkeyTbl, v->pubkey_algo);
741     t = pgpGrab(v->time, sizeof(v->time));
742     if (_print)
743         fprintf(stderr, " %-24.24s(0x%08x)", ctime(&t), (unsigned)t);
744     pgpPrtNL();
745
746     p = ((byte *)v) + sizeof(*v);
747     for (i = 0; p < &h[hlen]; i++, p += pgpMpiLen(p)) {
748         if (v->pubkey_algo == PGPPUBKEYALGO_RSA) {
749             if (pgpPublicRSA[i] == NULL) break;
750             /*@-mods@*/
751             if (_dig) {
752                 switch (i) {
753                 case 0:         /* n */
754                     mp32bsethex(&_dig->rsa_pk.n, pgpMpiHex(p));
755 if (_debug && _print)
756 printf("\t     n = "),  mp32println(_dig->rsa_pk.n.size, _dig->rsa_pk.n.modl);
757                     /*@switchbreak@*/ break;
758                 case 1:         /* e */
759                     mp32nsethex(&_dig->rsa_pk.e, pgpMpiHex(p));
760 if (_debug && _print)
761 printf("\t     e = "),  mp32println(_dig->rsa_pk.e.size, _dig->rsa_pk.e.data);
762                     /*@switchbreak@*/ break;
763                 default:
764                     /*@switchbreak@*/ break;
765                 }
766             }
767             /*@=mods@*/
768             pgpPrtStr("", pgpPublicRSA[i]);
769         } else if (v->pubkey_algo == PGPPUBKEYALGO_DSA) {
770             if (pgpPublicDSA[i] == NULL) break;
771             /*@-mods@*/
772             if (_dig) {
773                 switch (i) {
774                 case 0:         /* p */
775                     mp32bsethex(&_dig->p, pgpMpiHex(p));
776 if (_debug && _print)
777 printf("\t     p = "),  mp32println(_dig->p.size, _dig->p.modl);
778                     /*@switchbreak@*/ break;
779                 case 1:         /* q */
780                     mp32bsethex(&_dig->q, pgpMpiHex(p));
781 if (_debug && _print)
782 printf("\t     q = "),  mp32println(_dig->q.size, _dig->q.modl);
783                     /*@switchbreak@*/ break;
784                 case 2:         /* g */
785                     mp32nsethex(&_dig->g, pgpMpiHex(p));
786 if (_debug && _print)
787 printf("\t     g = "),  mp32println(_dig->g.size, _dig->g.data);
788                     /*@switchbreak@*/ break;
789                 case 3:         /* y */
790                     mp32nsethex(&_dig->y, pgpMpiHex(p));
791 if (_debug && _print)
792 printf("\t     y = "),  mp32println(_dig->y.size, _dig->y.data);
793                     /*@switchbreak@*/ break;
794                 default:
795                     /*@switchbreak@*/ break;
796                 }
797             }
798             /*@=mods@*/
799             pgpPrtStr("", pgpPublicDSA[i]);
800         } else if (v->pubkey_algo == PGPPUBKEYALGO_ELGAMAL_ENCRYPT) {
801             if (pgpPublicELGAMAL[i] == NULL) break;
802             if (_print)
803                 fprintf(stderr, "%7.7s", pgpPublicELGAMAL[i]);
804         } else {
805             if (_print)
806                 fprintf(stderr, "%7d", i);
807         }
808         pgpPrtStr("", pgpMpiStr(p));
809         pgpPrtNL();
810     }
811
812     if (pkt == PGPPKT_PUBLIC_KEY || pkt == PGPPKT_PUBLIC_SUBKEY)
813         return 0;
814
815     switch (*p) {
816     case 0:
817         pgpPrtVal(" ", pgpSymkeyTbl, *p);
818         break;
819     case 255:
820         p++;
821         pgpPrtVal(" ", pgpSymkeyTbl, *p);
822         switch (p[1]) {
823         case 0x00:
824             pgpPrtVal(" simple ", pgpHashTbl, p[2]);
825             p += 2;
826             /*@innerbreak@*/ break;
827         case 0x01:
828             pgpPrtVal(" salted ", pgpHashTbl, p[2]);
829             pgpPrtHex("", p+3, 8);
830             p += 10;
831             /*@innerbreak@*/ break;
832         case 0x03:
833             pgpPrtVal(" iterated/salted ", pgpHashTbl, p[2]);
834             /*@-shiftsigned@*/ /* FIX: unsigned cast */
835             i = (16 + (p[11] & 0xf)) << ((p[11] >> 4) + 6);
836             /*@=shiftsigned@*/
837             pgpPrtHex("", p+3, 8);
838             pgpPrtInt(" iter", i);
839             p += 11;
840             /*@innerbreak@*/ break;
841         }
842         break;
843     default:
844         pgpPrtVal(" ", pgpSymkeyTbl, *p);
845         pgpPrtHex(" IV", p+1, 8);
846         p += 8;
847         break;
848     }
849     pgpPrtNL();
850
851     p++;
852
853 #ifdef  NOTYET  /* XXX encrypted MPI's need to be handled. */
854     for (i = 0; p < &h[hlen]; i++, p += pgpMpiLen(p)) {
855         if (v->pubkey_algo == PGPPUBKEYALGO_RSA) {
856             if (pgpSecretRSA[i] == NULL) break;
857             pgpPrtStr("", pgpSecretRSA[i]);
858         } else if (v->pubkey_algo == PGPPUBKEYALGO_DSA) {
859             if (pgpSecretDSA[i] == NULL) break;
860             pgpPrtStr("", pgpSecretDSA[i]);
861         } else if (v->pubkey_algo == PGPPUBKEYALGO_ELGAMAL_ENCRYPT) {
862             if (pgpSecretELGAMAL[i] == NULL) break;
863             pgpPrtStr("", pgpSecretELGAMAL[i]);
864         } else {
865             if (_print)
866                 fprintf(stderr, "%7d", i);
867         }
868         pgpPrtStr("", pgpMpiStr(p));
869         pgpPrtNL();
870     }
871 #else
872     pgpPrtHex(" secret", p, (hlen - (p - h) - 2));
873     pgpPrtNL();
874     p += (hlen - (p - h) - 2);
875 #endif
876     pgpPrtHex(" checksum", p, 2);
877     pgpPrtNL();
878
879     return 0;
880 }
881
882 int pgpPrtKey(pgpPkt pkt, const byte *h, unsigned int hlen)
883 {
884     byte version = *h;
885     switch (version) {
886     case 3:
887         (void) pgpPrtKeyV3(pkt, h, hlen);
888         break;
889     case 4:
890         (void) pgpPrtKeyV4(pkt, h, hlen);
891         break;
892     }
893     return 0;
894 }
895
896 int pgpPrtUserID(pgpPkt pkt, const byte *h, unsigned int hlen)
897 {
898     pgpPrtVal("", pgpPktTbl, pkt);
899     if (_print)
900         fprintf(stderr, " \"%.*s\"", (int)hlen, (const char *)h);
901     pgpPrtNL();
902     return 0;
903 }
904
905 int pgpPrtComment(pgpPkt pkt, const byte *h, unsigned int hlen)
906 {
907     int i = hlen;
908
909     pgpPrtVal("", pgpPktTbl, pkt);
910     if (_print)
911         fprintf(stderr, " ");
912     while (i > 0) {
913         int j;
914         if (*h >= ' ' && *h <= 'z') {
915             if (_print)
916                 fprintf(stderr, "%s", (const char *)h);
917             j = strlen(h);
918             while (h[j] == '\0')
919                 j++;
920         } else {
921             pgpPrtHex("", h, i);
922             j = i;
923         }
924         i -= j;
925         h += j;
926     }
927     pgpPrtNL();
928     return 0;
929 }
930
931 int pgpPrtPkt(const byte *p)
932 {
933     unsigned int val = *p++;
934     pgpPkt pkt;
935     unsigned int plen;
936     const byte *h;
937     unsigned int hlen = 0;
938
939     /* XXX can't deal with these. */
940     if (!(val & 0x80))
941         return -1;
942
943     if (val & 0x40) {
944         pkt = (val & 0x3f);
945         plen = pgpLen(p, &hlen);
946     } else {
947         pkt = (val >> 2) & 0xf;
948         plen = (1 << (val & 0x3));
949         hlen = pgpGrab(p, plen);
950     }
951
952     h = p + plen;
953     switch (pkt) {
954     case PGPPKT_SIGNATURE:
955         (void) pgpPrtPktSig(pkt, h, hlen);
956         break;
957     case PGPPKT_PUBLIC_KEY:
958     case PGPPKT_PUBLIC_SUBKEY:
959     case PGPPKT_SECRET_KEY:
960     case PGPPKT_SECRET_SUBKEY:
961         (void) pgpPrtKey(pkt, h, hlen);
962         break;
963     case PGPPKT_USER_ID:
964 #ifndef DYING
965         (void) pgpPrtUserID(pkt, h, hlen);
966         break;
967 #endif
968     case PGPPKT_COMMENT:
969     case PGPPKT_COMMENT_OLD:
970         (void) pgpPrtComment(pkt, h, hlen);
971         break;
972
973     case PGPPKT_RESERVED:
974     case PGPPKT_PUBLIC_SESSION_KEY:
975     case PGPPKT_SYMMETRIC_SESSION_KEY:
976     case PGPPKT_COMPRESSED_DATA:
977     case PGPPKT_SYMMETRIC_DATA:
978     case PGPPKT_MARKER:
979     case PGPPKT_LITERAL_DATA:
980     case PGPPKT_TRUST:
981     case PGPPKT_PHOTOID:
982     case PGPPKT_ENCRYPTED_MDC:
983     case PGPPKT_MDC:
984     case PGPPKT_PRIVATE_60:
985     case PGPPKT_PRIVATE_62:
986     case PGPPKT_CONTROL:
987     default:
988         pgpPrtVal("", pgpPktTbl, pkt);
989         if (_print)
990             fprintf(stderr, " plen %02x hlen %x", plen, hlen);
991         pgpPrtHex("", h, hlen);
992         pgpPrtNL();
993         break;
994     }
995
996     return plen+hlen+1;
997 }
998
999 int pgpPrtPkts(const byte *pkts, unsigned int plen, struct pgpSig_s * dig, int printing)
1000 {
1001     const byte *p;
1002     int len;
1003
1004 /*@-mods@*/
1005 _print = printing;
1006 _dig = dig;
1007 /*@=mods@*/
1008
1009     for (p = pkts; p < (pkts + plen); p += len) {
1010         len = pgpPrtPkt(p);
1011         if (len <= 0)
1012             return len;
1013     }
1014     return 0;
1015 }