Main Page Modules Data Structures File List Data Fields Globals Related Pages

# rpmio/rpmpgp.h

Go to the documentation of this file.

    00001 #ifndef H_RPMPGP
    00002 #define H_RPMPGP
    00003
    00013 #include "base64.h"
    00014 #include "dsa.h"
    00015 #include "endianness.h"
    00016 #include "mp32.h"
    00017 #include "rsa.h"
    00018 #include "rsapk.h"
    00019
    00020
    00023 typedef /*@abstract@*/ struct DIGEST_CTX_s * DIGEST_CTX;
    00024
    00027 typedef const struct pgpValTbl_s {
    00028     int val;
    00029 /*@observer@*/ const char * str;
    00030 } * pgpValTbl;
    00031
    00039 typedef enum pgpTag_e {
    00040     PGPTAG_RESERVED             =  0,
    00041     PGPTAG_PUBLIC_SESSION_KEY   =  1,
    00042     PGPTAG_SIGNATURE            =  2,
    00043     PGPTAG_SYMMETRIC_SESSION_KEY=  3,
    00044     PGPTAG_ONEPASS_SIGNATURE    =  4,
    00045     PGPTAG_SECRET_KEY           =  5,
    00046     PGPTAG_PUBLIC_KEY           =  6,
    00047     PGPTAG_SECRET_SUBKEY        =  7,
    00048     PGPTAG_COMPRESSED_DATA      =  8,
    00049     PGPTAG_SYMMETRIC_DATA       =  9,
    00050     PGPTAG_MARKER               = 10,
    00051     PGPTAG_LITERAL_DATA         = 11,
    00052     PGPTAG_TRUST                = 12,
    00053     PGPTAG_USER_ID              = 13,
    00054     PGPTAG_PUBLIC_SUBKEY        = 14,
    00055     PGPTAG_COMMENT_OLD          = 16,
    00056     PGPTAG_PHOTOID              = 17,
    00057     PGPTAG_ENCRYPTED_MDC        = 18,
    00058     PGPTAG_MDC                  = 19,
    00059     PGPTAG_PRIVATE_60           = 60,
    00060     PGPTAG_COMMENT              = 61,
    00061     PGPTAG_PRIVATE_62           = 62,
    00062     PGPTAG_CONTROL              = 63,
    00063 } pgpTag;
    00064
    00067 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    00068 extern struct pgpValTbl_s pgpTagTbl[];
    00069
    00104 typedef struct pgpPktPubkey_s {
    00105     byte version;
    00106     byte keyid[8];
    00107     byte algo;
    00108 } pgpPktPubkey;
    00109
    00110
    00117 /*@-typeuse@*/
    00118 typedef enum pgpSigType_e {
    00119     PGPSIGTYPE_BINARY            = 0x00,
    00120     PGPSIGTYPE_TEXT              = 0x01,
    00121     PGPSIGTYPE_STANDALONE        = 0x02,
    00122     PGPSIGTYPE_GENERIC_CERT      = 0x10,
    00124     PGPSIGTYPE_PERSONA_CERT      = 0x11,
    00126     PGPSIGTYPE_CASUAL_CERT       = 0x12,
    00128     PGPSIGTYPE_POSITIVE_CERT     = 0x13,
    00130     PGPSIGTYPE_SUBKEY_BINDING    = 0x18,
    00131     PGPSIGTYPE_SIGNED_KEY        = 0x1F,
    00132     PGPSIGTYPE_KEY_REVOKE        = 0x20,
    00133     PGPSIGTYPE_SUBKEY_REVOKE     = 0x28,
    00134     PGPSIGTYPE_CERT_REVOKE       = 0x30,
    00135     PGPSIGTYPE_TIMESTAMP         = 0x40
    00136 } pgpSigType;
    00137 /*@=typeuse@*/
    00138
    00141 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    00142 extern struct pgpValTbl_s pgpSigTypeTbl[];
    00143
    00167 /*@-typeuse@*/
    00168 typedef enum pgpPubkeyAlgo_e {
    00169     PGPPUBKEYALGO_RSA           =  1,
    00170     PGPPUBKEYALGO_RSA_ENCRYPT   =  2,
    00171     PGPPUBKEYALGO_RSA_SIGN      =  3,
    00172     PGPPUBKEYALGO_ELGAMAL_ENCRYPT= 16,
    00173     PGPPUBKEYALGO_DSA           = 17,
    00174     PGPPUBKEYALGO_EC            = 18,
    00175     PGPPUBKEYALGO_ECDSA         = 19,
    00176     PGPPUBKEYALGO_ELGAMAL       = 20,
    00177     PGPPUBKEYALGO_DH            = 21,
    00178 } pgpPubkeyAlgo;
    00179 /*@=typeuse@*/
    00180
    00183 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    00184 extern struct pgpValTbl_s pgpPubkeyTbl[];
    00185
    00210 /*@-typeuse@*/
    00211 typedef enum pgpSymkeyAlgo_e {
    00212     PGPSYMKEYALGO_PLAINTEXT     =  0,
    00213     PGPSYMKEYALGO_IDEA          =  1,
    00214     PGPSYMKEYALGO_TRIPLE_DES    =  2,
    00215     PGPSYMKEYALGO_CAST5         =  3,
    00216     PGPSYMKEYALGO_BLOWFISH      =  4,
    00217     PGPSYMKEYALGO_SAFER         =  5,
    00218     PGPSYMKEYALGO_DES_SK        =  6,
    00219     PGPSYMKEYALGO_AES_128       =  7,
    00220     PGPSYMKEYALGO_AES_192       =  8,
    00221     PGPSYMKEYALGO_AES_256       =  9,
    00222     PGPSYMKEYALGO_TWOFISH       = 10
    00223 } pgpSymkeyAlgo;
    00224 /*@=typeuse@*/
    00225
    00228 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    00229 extern struct pgpValTbl_s pgpSymkeyTbl[];
    00230
    00246 /*@-typeuse@*/
    00247 typedef enum pgpCompressAlgo_e {
    00248     PGPCOMPRESSALGO_NONE        =  0,
    00249     PGPCOMPRESSALGO_ZIP         =  1,
    00250     PGPCOMPRESSALGO_ZLIB        =  2
    00251 } pgpCompressAlgo;
    00252 /*@=typeuse@*/
    00253
    00256 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    00257 extern struct pgpValTbl_s pgpCompressionTbl[];
    00258
    00280 typedef enum pgpHashAlgo_e {
    00281     PGPHASHALGO_MD5             = 1,
    00282     PGPHASHALGO_SHA1            = 2,
    00283     PGPHASHALGO_RIPEMD160       = 3,
    00284     PGPHASHALGO_MD2             = 5,
    00285     PGPHASHALGO_TIGER192        = 6,
    00286     PGPHASHALGO_HAVAL_5_160     = 7
    00287 } pgpHashAlgo;
    00288
    00291 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    00292 extern struct pgpValTbl_s pgpHashTbl[];
    00293
    00315 typedef struct pgpPktSigV3_s {
    00316     byte version;
    00317     byte hashlen;
    00318     byte sigtype;
    00319     byte time[4];
    00320     byte signid[8];
    00321     byte pubkey_algo;
    00322     byte hash_algo;
    00323     byte signhash16[2];
    00324 } * pgpPktSigV3;
    00325
    00347 typedef struct pgpPktSigV4_s {
    00348     byte version;
    00349     byte sigtype;
    00350     byte pubkey_algo;
    00351     byte hash_algo;
    00352     byte hashlen[2];
    00353 } * pgpPktSigV4;
    00354
    00421 /*@-typeuse@*/
    00422 typedef enum pgpSubType_e {
    00423     PGPSUBTYPE_SIG_CREATE_TIME  =   2,
    00424     PGPSUBTYPE_SIG_EXPIRE_TIME  =   3,
    00425     PGPSUBTYPE_EXPORTABLE_CERT  =   4,
    00426     PGPSUBTYPE_TRUST_SIG        =   5,
    00427     PGPSUBTYPE_REGEX            =   6,
    00428     PGPSUBTYPE_REVOCABLE        =   7,
    00429     PGPSUBTYPE_KEY_EXPIRE_TIME  =   9,
    00430     PGPSUBTYPE_BACKWARD_COMPAT  =  10,
    00431     PGPSUBTYPE_PREFER_SYMKEY    =  11,
    00432     PGPSUBTYPE_REVOKE_KEY       =  12,
    00433     PGPSUBTYPE_ISSUER_KEYID     =  16,
    00434     PGPSUBTYPE_NOTATION         =  20,
    00435     PGPSUBTYPE_PREFER_HASH      =  21,
    00436     PGPSUBTYPE_PREFER_COMPRESS  =  22,
    00437     PGPSUBTYPE_KEYSERVER_PREFERS=  23,
    00438     PGPSUBTYPE_PREFER_KEYSERVER =  24,
    00439     PGPSUBTYPE_PRIMARY_USERID   =  25,
    00440     PGPSUBTYPE_POLICY_URL       =  26,
    00441     PGPSUBTYPE_KEY_FLAGS        =  27,
    00442     PGPSUBTYPE_SIGNER_USERID    =  28,
    00443     PGPSUBTYPE_REVOKE_REASON    =  29,
    00444     PGPSUBTYPE_INTERNAL_100     = 100,
    00445     PGPSUBTYPE_INTERNAL_101     = 101,
    00446     PGPSUBTYPE_INTERNAL_102     = 102,
    00447     PGPSUBTYPE_INTERNAL_103     = 103,
    00448     PGPSUBTYPE_INTERNAL_104     = 104,
    00449     PGPSUBTYPE_INTERNAL_105     = 105,
    00450     PGPSUBTYPE_INTERNAL_106     = 106,
    00451     PGPSUBTYPE_INTERNAL_107     = 107,
    00452     PGPSUBTYPE_INTERNAL_108     = 108,
    00453     PGPSUBTYPE_INTERNAL_109     = 109,
    00454     PGPSUBTYPE_INTERNAL_110     = 110,
    00455 } pgpSubType;
    00456 /*@=typeuse@*/
    00457
    00460 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    00461 extern struct pgpValTbl_s pgpSubTypeTbl[];
    00462
    00483 typedef union pgpPktSig_u {
    00484     struct pgpPktSigV3_s v3;
    00485     struct pgpPktSigV4_s v4;
    00486 } * pgpPktSig;
    00487
    00516 typedef struct pgpPktSymkey_s {
    00517     byte version;
    00518     byte symkey_algo;
    00519     byte s2k[1];
    00520 } pgpPktSymkey;
    00521
    00551 typedef struct pgpPktOnepass_s {
    00552     byte version;
    00553     byte sigtype;
    00554     byte hash_algo;
    00555     byte pubkey_algo;
    00556     byte signid[8];
    00557     byte nested;
    00558 } * pgpPktOnepass;
    00559
    00632 typedef struct pgpPktKeyV3_s {
    00633     byte version;
    00634     byte time[4];
    00635     byte valid[2];
    00636     byte pubkey_algo;
    00637 } * pgpPktKeyV3;
    00638
    00670 typedef struct pgpPktKeyV4_s {
    00671     byte version;
    00672     byte time[4];
    00673     byte pubkey_algo;
    00674 } * pgpPktKeyV4;
    00675
    00740 typedef union pgpPktKey_u {
    00741     struct pgpPktKeyV3_s v3;
    00742     struct pgpPktKeyV4_s v4;
    00743 } pgpPktKey;
    00744
    00745 /*
    00746  * 5.6. Compressed Data Packet (Tag 8)
    00747  *
    00748  * The Compressed Data packet contains compressed data. Typically, this
    00749  * packet is found as the contents of an encrypted packet, or following
    00750  * a Signature or One-Pass Signature packet, and contains literal data
    00751  * packets.
    00752  *
    00753  * The body of this packet consists of:
    00754  *   - One octet that gives the algorithm used to compress the packet.
    00755  *   - The remainder of the packet is compressed data.
    00756  *
    00757  * A Compressed Data Packet's body contains an block that compresses
    00758  * some set of packets. See section "Packet Composition" for details on
    00759  * how messages are formed.
    00760  *
    00761  * ZIP-compressed packets are compressed with raw RFC 1951 DEFLATE
    00762  * blocks. Note that PGP V2.6 uses 13 bits of compression. If an
    00763  * implementation uses more bits of compression, PGP V2.6 cannot
    00764  * decompress it.
    00765  *
    00766  * ZLIB-compressed packets are compressed with RFC 1950 ZLIB-style
    00767  * blocks.
    00768  */
    00769 typedef struct pgpPktCdata_s {
    00770     byte compressalgo;
    00771     byte data[1];
    00772 } pgpPktCdata;
    00773
    00774 /*
    00775  * 5.7. Symmetrically Encrypted Data Packet (Tag 9)
    00776  *
    00777  * The Symmetrically Encrypted Data packet contains data encrypted with
    00778  * a symmetric-key algorithm. When it has been decrypted, it will
    00779  * typically contain other packets (often literal data packets or
    00780  * compressed data packets).
    00781  *
    00782  * The body of this packet consists of:
    00783  *   - Encrypted data, the output of the selected symmetric-key cipher
    00784  *     operating in PGP's variant of Cipher Feedback (CFB) mode.
    00785  *
    00786  * The symmetric cipher used may be specified in an Public-Key or
    00787  * Symmetric-Key Encrypted Session Key packet that precedes the
    00788  * Symmetrically Encrypted Data Packet.  In that case, the cipher
    00789  * algorithm octet is prefixed to the session key before it is
    00790  * encrypted.  If no packets of these types precede the encrypted data,
    00791  * the IDEA algorithm is used with the session key calculated as the MD5
    00792  * hash of the passphrase.
    00793  *
    00794  * The data is encrypted in CFB mode, with a CFB shift size equal to the
    00795  * cipher's block size.  The Initial Vector (IV) is specified as all
    00796  * zeros.  Instead of using an IV, OpenPGP prefixes a 10-octet string to
    00797  * the data before it is encrypted.  The first eight octets are random,
    00798  * and the 9th and 10th octets are copies of the 7th and 8th octets,
    00799  * respectively. After encrypting the first 10 octets, the CFB state is
    00800  * resynchronized if the cipher block size is 8 octets or less.  The
    00801  * last 8 octets of ciphertext are passed through the cipher and the
    00802  * block boundary is reset.
    00803  *
    00804  * The repetition of 16 bits in the 80 bits of random data prefixed to
    00805  * the message allows the receiver to immediately check whether the
    00806  * session key is incorrect.
    00807  */
    00808 typedef struct pgpPktEdata_s {
    00809     byte data[1];
    00810 } pgpPktEdata;
    00811
    00812 /*
    00813  * 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10)
    00814  *
    00815  * An experimental version of PGP used this packet as the Literal
    00816  * packet, but no released version of PGP generated Literal packets with
    00817  * this tag. With PGP 5.x, this packet has been re-assigned and is
    00818  * reserved for use as the Marker packet.
    00819  *
    00820  * The body of this packet consists of:
    00821  *   - The three octets 0x50, 0x47, 0x50 (which spell "PGP" in UTF-8).
    00822  *
    00823  * Such a packet MUST be ignored when received.  It may be placed at the
    00824  * beginning of a message that uses features not available in PGP 2.6.x
    00825  * in order to cause that version to report that newer software is
    00826  * necessary to process the message.
    00827  */
    00828 /*
    00829  * 5.9. Literal Data Packet (Tag 11)
    00830  *
    00831  * A Literal Data packet contains the body of a message; data that is
    00832  * not to be further interpreted.
    00833  *
    00834  * The body of this packet consists of:
    00835  *   - A one-octet field that describes how the data is formatted.
    00836  *
    00837  * If it is a 'b' (0x62), then the literal packet contains binary data.
    00838  * If it is a 't' (0x74), then it contains text data, and thus may need
    00839  * line ends converted to local form, or other text-mode changes.  RFC
    00840  * 1991 also defined a value of 'l' as a 'local' mode for machine-local
    00841  * conversions.  This use is now deprecated.
    00842  *   - File name as a string (one-octet length, followed by file name),
    00843  *     if the encrypted data should be saved as a file.
    00844  *
    00845  * If the special name "_CONSOLE" is used, the message is considered to
    00846  * be "for your eyes only".  This advises that the message data is
    00847  * unusually sensitive, and the receiving program should process it more
    00848  * carefully, perhaps avoiding storing the received data to disk, for
    00849  * example.
    00850  *   - A four-octet number that indicates the modification date of the
    00851  *     file, or the creation time of the packet, or a zero that
    00852  *     indicates the present time.
    00853  *   - The remainder of the packet is literal data.
    00854  *
    00855  * Text data is stored with <CR><LF> text endings (i.e. network-normal
    00856  * line endings).  These should be converted to native line endings by
    00857  * the receiving software.
    00858  */
    00859 typedef struct pgpPktLdata_s {
    00860     byte format;
    00861     byte filenamelen;
    00862     byte filename[1];
    00863 } pgpPktLdata;
    00864
    00865 /*
    00866  * 5.10. Trust Packet (Tag 12)
    00867  *
    00868  * The Trust packet is used only within keyrings and is not normally
    00869  * exported.  Trust packets contain data that record the user's
    00870  * specifications of which key holders are trustworthy introducers,
    00871  * along with other information that implementing software uses for
    00872  * trust information.
    00873  *
    00874  * Trust packets SHOULD NOT be emitted to output streams that are
    00875  * transferred to other users, and they SHOULD be ignored on any input
    00876  * other than local keyring files.
    00877  */
    00878 typedef struct pgpPktTrust_s {
    00879     byte flag;
    00880 } pgpPktTrust;
    00881
    00882 /*
    00883  * 5.11. User ID Packet (Tag 13)
    00884  *
    00885  * A User ID packet consists of data that is intended to represent the
    00886  * name and email address of the key holder.  By convention, it includes
    00887  * an RFC 822 mail name, but there are no restrictions on its content.
    00888  * The packet length in the header specifies the length of the user id.
    00889  * If it is text, it is encoded in UTF-8.
    00890  *
    00891  */
    00892 typedef struct pgpPktUid_s {
    00893     byte userid[1];
    00894 } pgpPktUid;
    00895
    00898 union pgpPktPre_u {
    00899     pgpPktPubkey pubkey;
    00900     pgpPktSig sig;
    00901     pgpPktSymkey symkey;
    00902     pgpPktOnepass onepass;
    00903     pgpPktKey key;
    00904     pgpPktCdata cdata;
    00905     pgpPktEdata edata;
    00907     pgpPktLdata ldata;
    00908     pgpPktTrust tdata;
    00909     pgpPktUid uid;
    00910 };
    00911
    00914 /*@-typeuse@*/
    00915 typedef enum pgpArmor_e {
    00916     PGPARMOR_ERROR              = -1,
    00917     PGPARMOR_NONE               =  0,
    00918     PGPARMOR_MESSAGE            =  1,
    00919     PGPARMOR_PUBKEY             =  2,
    00920     PGPARMOR_SIGNATURE          =  3,
    00921     PGPARMOR_SIGNED_MESSAGE     =  4,
    00922     PGPARMOR_FILE               =  5,
    00923     PGPARMOR_PRIVKEY            =  6,
    00924     PGPARMOR_SECKEY             =  7,
    00925 } pgpArmor;
    00926 /*@=typeuse@*/
    00927
    00930 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    00931 extern struct pgpValTbl_s pgpArmorTbl[];
    00932
    00935 /*@-typeuse@*/
    00936 typedef enum pgpArmorKey_e {
    00937     PGPARMORKEY_VERSION         = 1,
    00938     PGPARMORKEY_COMMENT         = 2,
    00939     PGPARMORKEY_MESSAGEID       = 3,
    00940     PGPARMORKEY_HASH            = 4,
    00941     PGPARMORKEY_CHARSET         = 5,
    00942 } pgpArmorKey;
    00943 /*@=typeuse@*/
    00944
    00947 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    00948 extern struct pgpValTbl_s pgpArmorKeyTbl[];
    00949
    00952 struct pgpDigParams_s {
    00953 /*@only@*/ /*@null@*/
    00954     const char * userid;
    00955 /*@only@*/ /*@null@*/
    00956     const byte * hash;
    00957     const char * params[4];
    00958     byte tag;
    00959
    00960     byte version;
    00961     byte time[4];
    00962     byte pubkey_algo;
    00964     byte hash_algo;
    00965     byte sigtype;
    00966     byte hashlen;
    00967     byte signhash16[2];
    00968     byte signid[8];
    00969 };
    00970
    00973 struct pgpDig_s {
    00974     struct pgpDigParams_s signature;
    00975     struct pgpDigParams_s pubkey;
    00976
    00977     size_t nbytes;
    00979 /*@only@*/ /*@null@*/ DIGEST_CTX sha1ctx;
    00980 /*@only@*/ /*@null@*/ void * sha1;
    00981     size_t sha1len;
    00983 /*@only@*/ /*@null@*/ DIGEST_CTX md5ctx;
    00984 /*@only@*/ /*@null@*/ void * md5;
    00985     size_t md5len;
    00987     /* DSA parameters. */
    00988     mp32barrett p;
    00989     mp32barrett q;
    00990     mp32number g;
    00991     mp32number y;
    00992     mp32number hm;
    00993     mp32number r;
    00994     mp32number s;
    00995
    00996     /* RSA parameters. */
    00997     rsapk rsa_pk;
    00998     mp32number m;
    00999     mp32number c;
    01000     mp32number rsahm;
    01001 };
    01002
    01003
    01004 /*@-fcnuse@*/
    01005 #ifdef __cplusplus
    01006 extern "C" {
    01007 #endif
    01008
    01011 /*@unused@*/ static inline
    01012 unsigned int pgpGrab(const byte *s, int nbytes)
    01013         /*@*/
    01014 {
    01015     unsigned int i = 0;
    01016     int nb = (nbytes <= sizeof(i) ? nbytes : sizeof(i));
    01017     while (nb--)
    01018         i = (i << 8) | *s++;
    01019     return i;
    01020 }
    01021
    01024 /*@unused@*/ static inline
    01025 int pgpLen(const byte *s, /*@out@*/ unsigned int *lenp)
    01026         /*@modifies *lenp @*/
    01027 {
    01028     if (*s < 192) {
    01029         (*lenp) = *s++;
    01030         return 1;
    01031     } else if (*s < 255) {
    01032         (*lenp) = ((((unsigned)s[0]) - 192) << 8) + s[1] + 192;
    01033         return 2;
    01034     } else {
    01035         (*lenp) = pgpGrab(s+1, 4);
    01036         return 5;
    01037     }
    01038 }
    01039
    01042 /*@unused@*/ static inline
    01043 unsigned int pgpMpiBits(const byte *p)
    01044         /*@*/
    01045 {
    01046     return ((p[0] << 8) | p[1]);
    01047 }
    01048
    01051 /*@unused@*/ static inline
    01052 unsigned int pgpMpiLen(const byte *p)
    01053         /*@*/
    01054 {
    01055     return (2 + ((pgpMpiBits(p)+7)>>3));
    01056 }
    01057
    01060 /*@unused@*/ static inline
    01061 char * pgpHexCvt(/*@returned@*/ char *t, const byte *s, int nbytes)
    01062         /*@modifies *t @*/
    01063 {
    01064     static char hex[] = "0123456789abcdef";
    01065     while (nbytes-- > 0) {
    01066         unsigned int i;
    01067         i = *s++;
    01068         *t++ = hex[ (i >> 4) & 0xf ];
    01069         *t++ = hex[ (i     ) & 0xf ];
    01070     }
    01071     *t = '\0';
    01072     return t;
    01073 }
    01074
    01077 /*@unused@*/ static inline /*@observer@*/
    01078 char * pgpHexStr(const byte *p, unsigned int plen)
    01079         /*@*/
    01080 {
    01081     static char prbuf[2048];
    01082     char *t = prbuf;
    01083     t = pgpHexCvt(t, p, plen);
    01084     return prbuf;
    01085 }
    01086
    01089 /*@unused@*/ static inline /*@observer@*/
    01090 const char * pgpMpiStr(const byte *p)
    01091         /*@*/
    01092 {
    01093     static char prbuf[2048];
    01094     char *t = prbuf;
    01095     sprintf(t, "[%4u]: ", pgpGrab(p, 2));
    01096     t += strlen(t);
    01097     t = pgpHexCvt(t, p+2, pgpMpiLen(p)-2);
    01098     return prbuf;
    01099 }
    01100
    01103 /*@unused@*/ static inline /*@observer@*/
    01104 const char * pgpValStr(pgpValTbl vs, byte val)
    01105         /*@*/
    01106 {
    01107     do {
    01108         if (vs->val == val)
    01109             break;
    01110     } while ((++vs)->val != -1);
    01111     return vs->str;
    01112 }
    01113
    01116 /*@unused@*/ static inline
    01117 int pgpValTok(pgpValTbl vs, const char * s, const char * se)
    01118         /*@*/
    01119 {
    01120     do {
    01121         int vlen = strlen(vs->str);
    01122         if (vlen <= (se-s) && !strncmp(s, vs->str, vlen))
    01123             break;
    01124     } while ((++vs)->val != -1);
    01125     return vs->val;
    01126 }
    01127
    01128 /*@-exportlocal@*/
    01131 void pgpPrtVal(const char * pre, pgpValTbl vs, byte val)
    01132         /*@globals fileSystem @*/
    01133         /*@modifies fileSystem @*/;
    01134
    01137 int pgpPrtSubType(const byte *h, unsigned int hlen)
    01138         /*@globals fileSystem @*/
    01139         /*@modifies fileSystem @*/;
    01140
    01143 int pgpPrtSig(pgpTag tag, const byte *h, unsigned int hlen)
    01144         /*@globals fileSystem @*/
    01145         /*@modifies fileSystem @*/;
    01146
    01149 int pgpPrtKey(pgpTag tag, const byte *h, unsigned int hlen)
    01150         /*@globals fileSystem @*/
    01151         /*@modifies fileSystem @*/;
    01152
    01155 int pgpPrtUserID(pgpTag tag, const byte *h, unsigned int hlen)
    01156         /*@globals fileSystem @*/
    01157         /*@modifies fileSystem @*/;
    01158
    01161 int pgpPrtComment(pgpTag tag, const byte *h, unsigned int hlen)
    01162         /*@globals fileSystem @*/
    01163         /*@modifies fileSystem @*/;
    01164
    01167 int pgpPrtPkt(const byte *pkt)
    01168         /*@globals fileSystem @*/
    01169         /*@modifies fileSystem @*/;
    01170 /*@=exportlocal@*/
    01171
    01174 int pgpPrtPkts(const byte *pkts, unsigned int plen, struct pgpDig_s *dig, int printing)
    01175         /*@globals fileSystem @*/
    01176         /*@modifies fileSystem @*/;
    01177
    01180 pgpArmor pgpReadPkts(const char * fn,
    01181                 /*@out@*/ const byte ** pkt, /*@out@*/ size_t * pktlen)
    01182         /*@globals fileSystem @*/
    01183         /*@modifies *pkt, *pktlen, fileSystem @*/;
    01184
    01187 /*@only@*/
    01188 struct pgpDig_s * pgpNewDig(void)
    01189         /*@*/;
    01190
    01193 /*@only@*/ /*@null@*/
    01194 struct pgpDig_s * pgpFreeDig(/*@only@*/ /*@null@*/ struct pgpDig_s * dig)
    01195         /*@modifies dig @*/;
    01196
    01199 /*@unused@*/ static inline
    01200 int pgpIsPkt(const byte * p)
    01201         /*@*/
    01202 {
    01203     unsigned int val = *p++;
    01204     pgpTag tag;
    01205     int rc;
    01206
    01207     /* XXX can't deal with these. */
    01208     if (!(val & 0x80))
    01209         return 0;
    01210
    01211     if (val & 0x40)
    01212         tag = (val & 0x3f);
    01213     else
    01214         tag = (val >> 2) & 0xf;
    01215
    01216     switch (tag) {
    01217     case PGPTAG_MARKER:
    01218     case PGPTAG_SYMMETRIC_SESSION_KEY:
    01219     case PGPTAG_ONEPASS_SIGNATURE:
    01220     case PGPTAG_PUBLIC_KEY:
    01221     case PGPTAG_SECRET_KEY:
    01222     case PGPTAG_PUBLIC_SESSION_KEY:
    01223     case PGPTAG_SIGNATURE:
    01224     case PGPTAG_COMMENT:
    01225     case PGPTAG_COMMENT_OLD:
    01226     case PGPTAG_LITERAL_DATA:
    01227     case PGPTAG_COMPRESSED_DATA:
    01228     case PGPTAG_SYMMETRIC_DATA:
    01229         rc = 1;
    01230         break;
    01231     case PGPTAG_PUBLIC_SUBKEY:
    01232     case PGPTAG_SECRET_SUBKEY:
    01233     case PGPTAG_USER_ID:
    01234     case PGPTAG_RESERVED:
    01235     case PGPTAG_TRUST:
    01236     case PGPTAG_PHOTOID:
    01237     case PGPTAG_ENCRYPTED_MDC:
    01238     case PGPTAG_MDC:
    01239     case PGPTAG_PRIVATE_60:
    01240     case PGPTAG_PRIVATE_62:
    01241     case PGPTAG_CONTROL:
    01242     default:
    01243         rc = 0;
    01244         break;
    01245     }
    01246
    01247     return rc;
    01248 }
    01249
    01250 #define CRC24_INIT      0xb704ce
    01251 #define CRC24_POLY      0x1864cfb
    01252
    01255 /*@unused@*/ static inline
    01256 uint32 pgpCRC(const byte *octets, size_t len)
    01257         /*@*/
    01258 {
    01259     uint32 crc = CRC24_INIT;
    01260     int i;
    01261
    01262     while (len--) {
    01263         crc ^= (*octets++) << 16;
    01264         for (i = 0; i < 8; i++) {
    01265             crc <<= 1;
    01266             if (crc & 0x1000000)
    01267                 crc ^= CRC24_POLY;
    01268         }
    01269     }
    01270     return crc & 0xffffff;
    01271 }
    01272
    01273 #ifdef __cplusplus
    01274 }
    01275 #endif
    01276 /*@=fcnuse@*/
    01277
    01278 #endif  /* H_RPMPGP */