- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

# rpmio/rpmpgp.h

Go to the documentation of this file.

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