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

- File List
- Globals

# rpmio/rpmpgp.h

Go to the documentation of this file.

    00001 #ifndef H_RPMPGP
    00002 #define H_RPMPGP
    00003
    00013 #include <string.h>
    00014 #include <popt.h>
    00015
    00018 typedef /*@abstract@*/ struct DIGEST_CTX_s * DIGEST_CTX;
    00019
    00022 typedef /*@abstract@*/ struct pgpPkt_s * pgpPkt;
    00023
    00026 typedef /*@abstract@*/ /*@refcounted@*/ struct pgpDig_s * pgpDig;
    00027
    00030 typedef /*@abstract@*/ struct pgpDigParams_s * pgpDigParams;
    00031
    00035 typedef enum pgpVSFlags_e {
    00036     RPMVSF_DEFAULT      = 0,
    00037     RPMVSF_NOHDRCHK     = (1 <<  0),
    00038     RPMVSF_NEEDPAYLOAD  = (1 <<  1),
    00039     /* bit(s) 2-7 unused */
    00040     RPMVSF_NOSHA1HEADER = (1 <<  8),
    00041     RPMVSF_NOMD5HEADER  = (1 <<  9),    /* unimplemented */
    00042     RPMVSF_NODSAHEADER  = (1 << 10),
    00043     RPMVSF_NORSAHEADER  = (1 << 11),
    00044     /* bit(s) 12-15 unused */
    00045     RPMVSF_NOSHA1       = (1 << 16),    /* unimplemented */
    00046     RPMVSF_NOMD5        = (1 << 17),
    00047     RPMVSF_NODSA        = (1 << 18),
    00048     RPMVSF_NORSA        = (1 << 19)
    00049     /* bit(s) 20-31 unused */
    00050 } pgpVSFlags;
    00051
    00052 #define _RPMVSF_NODIGESTS       \
    00053   ( RPMVSF_NOSHA1HEADER |       \
    00054     RPMVSF_NOMD5HEADER |        \
    00055     RPMVSF_NOSHA1 |             \
    00056     RPMVSF_NOMD5 )
    00057
    00058 #define _RPMVSF_NOSIGNATURES    \
    00059   ( RPMVSF_NODSAHEADER |        \
    00060     RPMVSF_NORSAHEADER |        \
    00061     RPMVSF_NODSA |              \
    00062     RPMVSF_NORSA )
    00063
    00064 #define _RPMVSF_NOHEADER        \
    00065   ( RPMVSF_NOSHA1HEADER |       \
    00066     RPMVSF_NOMD5HEADER |        \
    00067     RPMVSF_NODSAHEADER |        \
    00068     RPMVSF_NORSAHEADER )
    00069
    00070 #define _RPMVSF_NOPAYLOAD       \
    00071   ( RPMVSF_NOSHA1 |             \
    00072     RPMVSF_NOMD5 |              \
    00073     RPMVSF_NODSA |              \
    00074     RPMVSF_NORSA )
    00075
    00076 #if defined(_RPMPGP_INTERNAL)
    00077 #include <rpmsw.h>
    00078
    00082 struct pgpDigParams_s {
    00083 /*@only@*/ /*@null@*/
    00084     const char * userid;
    00085 /*@only@*/ /*@null@*/
    00086     const uint8_t * hash;
    00087     const char * params[4];
    00088     uint8_t tag;
    00089
    00090     uint8_t version;
    00091     uint8_t time[4];
    00092     uint8_t pubkey_algo;
    00094     uint8_t hash_algo;
    00095     uint8_t sigtype;
    00096     uint8_t hashlen;
    00097     uint8_t signhash16[2];
    00098     uint8_t signid[8];
    00099     uint8_t saved;
    00100 #define PGPDIG_SAVED_TIME       (1 << 0)
    00101 #define PGPDIG_SAVED_ID         (1 << 1)
    00102
    00103 };
    00104
    00108 struct pgpDig_s {
    00109     struct pgpDigParams_s signature;
    00110     struct pgpDigParams_s pubkey;
    00111
    00112     uint32_t sigtag;
    00113     uint32_t sigtype;
    00114 /*@relnull@*/
    00115     const void * sig;
    00116     uint32_t siglen;
    00118     pgpVSFlags vsflags;
    00119     struct rpmop_s dops;
    00120     struct rpmop_s sops;
    00122     int (*findPubkey) (void * _ts, /*@null@*/ void * _dig)
    00123         /*@modifies *_ts, *_dig @*/;
    00124 /*@null@*/
    00125     void * _ts;
    00126 /*@refs@*/
    00127     int nrefs;
    00129     uint8_t ** ppkts;
    00130     int npkts;
    00131     size_t nbytes;
    00133 /*@only@*/ /*@null@*/
    00134     DIGEST_CTX sha1ctx;
    00135 /*@only@*/ /*@null@*/
    00136     DIGEST_CTX hdrsha1ctx;
    00137 /*@only@*/ /*@null@*/
    00138     void * sha1;
    00139     size_t sha1len;
    00141 /*@only@*/ /*@null@*/
    00142     DIGEST_CTX md5ctx;
    00143 /*@only@*/ /*@null@*/
    00144     DIGEST_CTX hdrmd5ctx;
    00145 /*@only@*/ /*@null@*/
    00146     void * md5;
    00147     size_t md5len;
    00148 /*@owned@*/ /*@relnull@*/
    00149     void * impl;
    00150 };
    00151 #endif
    00152
    00155 typedef const struct pgpValTbl_s {
    00156     int val;
    00157 /*@observer@*/ const char * str;
    00158 } * pgpValTbl;
    00159
    00167 typedef enum pgpTag_e {
    00168     PGPTAG_RESERVED             =  0,
    00169     PGPTAG_PUBLIC_SESSION_KEY   =  1,
    00170     PGPTAG_SIGNATURE            =  2,
    00171     PGPTAG_SYMMETRIC_SESSION_KEY=  3,
    00172     PGPTAG_ONEPASS_SIGNATURE    =  4,
    00173     PGPTAG_SECRET_KEY           =  5,
    00174     PGPTAG_PUBLIC_KEY           =  6,
    00175     PGPTAG_SECRET_SUBKEY        =  7,
    00176     PGPTAG_COMPRESSED_DATA      =  8,
    00177     PGPTAG_SYMMETRIC_DATA       =  9,
    00178     PGPTAG_MARKER               = 10,
    00179     PGPTAG_LITERAL_DATA         = 11,
    00180     PGPTAG_TRUST                = 12,
    00181     PGPTAG_USER_ID              = 13,
    00182     PGPTAG_PUBLIC_SUBKEY        = 14,
    00183     PGPTAG_COMMENT_OLD          = 16,
    00184     PGPTAG_PHOTOID              = 17,
    00185     PGPTAG_ENCRYPTED_MDC        = 18,
    00186     PGPTAG_MDC                  = 19,
    00187     PGPTAG_PRIVATE_60           = 60,
    00188     PGPTAG_COMMENT              = 61,
    00189     PGPTAG_PRIVATE_62           = 62,
    00190     PGPTAG_CONTROL              = 63
    00191 } pgpTag;
    00192
    00195 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    00196 extern struct pgpValTbl_s pgpTagTbl[];
    00197
    00232 typedef struct pgpPktPubkey_s {
    00233     uint8_t version;
    00234     uint8_t keyid[8];
    00235     uint8_t algo;
    00236 } pgpPktPubkey;
    00237
    00238
    00245 /*@-typeuse@*/
    00246 typedef enum pgpSigType_e {
    00247     PGPSIGTYPE_BINARY            = 0x00,
    00248     PGPSIGTYPE_TEXT              = 0x01,
    00249     PGPSIGTYPE_STANDALONE        = 0x02,
    00250     PGPSIGTYPE_GENERIC_CERT      = 0x10,
    00252     PGPSIGTYPE_PERSONA_CERT      = 0x11,
    00254     PGPSIGTYPE_CASUAL_CERT       = 0x12,
    00256     PGPSIGTYPE_POSITIVE_CERT     = 0x13,
    00258     PGPSIGTYPE_SUBKEY_BINDING    = 0x18,
    00259     PGPSIGTYPE_SIGNED_KEY        = 0x1F,
    00260     PGPSIGTYPE_KEY_REVOKE        = 0x20,
    00261     PGPSIGTYPE_SUBKEY_REVOKE     = 0x28,
    00262     PGPSIGTYPE_CERT_REVOKE       = 0x30,
    00263     PGPSIGTYPE_TIMESTAMP         = 0x40
    00264 } pgpSigType;
    00265 /*@=typeuse@*/
    00266
    00269 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    00270 extern struct pgpValTbl_s pgpSigTypeTbl[];
    00271
    00295 /*@-typeuse@*/
    00296 typedef enum pgpPubkeyAlgo_e {
    00297     PGPPUBKEYALGO_RSA           =  1,
    00298     PGPPUBKEYALGO_RSA_ENCRYPT   =  2,
    00299     PGPPUBKEYALGO_RSA_SIGN      =  3,
    00300     PGPPUBKEYALGO_ELGAMAL_ENCRYPT = 16,
    00301     PGPPUBKEYALGO_DSA           = 17,
    00302     PGPPUBKEYALGO_EC            = 18,
    00303     PGPPUBKEYALGO_ECDSA         = 19,
    00304     PGPPUBKEYALGO_ELGAMAL       = 20,
    00305     PGPPUBKEYALGO_DH            = 21
    00306 } pgpPubkeyAlgo;
    00307 /*@=typeuse@*/
    00308
    00311 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    00312 extern struct pgpValTbl_s pgpPubkeyTbl[];
    00313
    00338 /*@-typeuse@*/
    00339 typedef enum pgpSymkeyAlgo_e {
    00340     PGPSYMKEYALGO_PLAINTEXT     =  0,
    00341     PGPSYMKEYALGO_IDEA          =  1,
    00342     PGPSYMKEYALGO_TRIPLE_DES    =  2,
    00343     PGPSYMKEYALGO_CAST5         =  3,
    00344     PGPSYMKEYALGO_BLOWFISH      =  4,
    00345     PGPSYMKEYALGO_SAFER         =  5,
    00346     PGPSYMKEYALGO_DES_SK        =  6,
    00347     PGPSYMKEYALGO_AES_128       =  7,
    00348     PGPSYMKEYALGO_AES_192       =  8,
    00349     PGPSYMKEYALGO_AES_256       =  9,
    00350     PGPSYMKEYALGO_TWOFISH       = 10,
    00351     PGPSYMKEYALGO_NOENCRYPT     = 110
    00352 } pgpSymkeyAlgo;
    00353 /*@=typeuse@*/
    00354
    00358 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    00359 extern struct pgpValTbl_s pgpSymkeyTbl[];
    00360
    00376 /*@-typeuse@*/
    00377 typedef enum pgpCompressAlgo_e {
    00378     PGPCOMPRESSALGO_NONE        =  0,
    00379     PGPCOMPRESSALGO_ZIP         =  1,
    00380     PGPCOMPRESSALGO_ZLIB        =  2,
    00381     PGPCOMPRESSALGO_BZIP2       =  3
    00382 } pgpCompressAlgo;
    00383 /*@=typeuse@*/
    00384
    00388 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    00389 extern struct pgpValTbl_s pgpCompressionTbl[];
    00390
    00412 typedef enum pgpHashAlgo_e {
    00413     PGPHASHALGO_MD5             =  1,
    00414     PGPHASHALGO_SHA1            =  2,
    00415     PGPHASHALGO_RIPEMD160       =  3,
    00416     PGPHASHALGO_MD2             =  5,
    00417     PGPHASHALGO_TIGER192        =  6,
    00418     PGPHASHALGO_HAVAL_5_160     =  7,
    00419     PGPHASHALGO_SHA256          =  8,
    00420     PGPHASHALGO_SHA384          =  9,
    00421     PGPHASHALGO_SHA512          = 10,
    00423     PGPHASHALGO_MD4             = 104,
    00424     PGPHASHALGO_RIPEMD128       = 105,
    00425     PGPHASHALGO_CRC32           = 106,
    00426     PGPHASHALGO_ADLER32         = 107,
    00427     PGPHASHALGO_CRC64           = 108,
    00428     PGPHASHALGO_JLU32           = 109,
    00429     PGPHASHALGO_SHA224          = 110,
    00430     PGPHASHALGO_RIPEMD256       = 111,
    00431     PGPHASHALGO_RIPEMD320       = 112,
    00432     PGPHASHALGO_SALSA10         = 113,
    00433     PGPHASHALGO_SALSA20         = 114,
    00435 } pgpHashAlgo;
    00436
    00440 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    00441 extern struct pgpValTbl_s pgpHashTbl[];
    00442
    00464 typedef struct pgpPktSigV3_s {
    00465     uint8_t version;
    00466     uint8_t hashlen;
    00467     uint8_t sigtype;
    00468     uint8_t time[4];
    00469     uint8_t signid[8];
    00470     uint8_t pubkey_algo;
    00471     uint8_t hash_algo;
    00472     uint8_t signhash16[2];
    00473 } * pgpPktSigV3;
    00474
    00496 typedef struct pgpPktSigV4_s {
    00497     uint8_t version;
    00498     uint8_t sigtype;
    00499     uint8_t pubkey_algo;
    00500     uint8_t hash_algo;
    00501     uint8_t hashlen[2];
    00502 } * pgpPktSigV4;
    00503
    00570 /*@-typeuse@*/
    00571 typedef enum pgpSubType_e {
    00572     PGPSUBTYPE_NONE             =   0,
    00573     PGPSUBTYPE_SIG_CREATE_TIME  =   2,
    00574     PGPSUBTYPE_SIG_EXPIRE_TIME  =   3,
    00575     PGPSUBTYPE_EXPORTABLE_CERT  =   4,
    00576     PGPSUBTYPE_TRUST_SIG        =   5,
    00577     PGPSUBTYPE_REGEX            =   6,
    00578     PGPSUBTYPE_REVOCABLE        =   7,
    00579     PGPSUBTYPE_KEY_EXPIRE_TIME  =   9,
    00580     PGPSUBTYPE_ARR              =  10,
    00581     PGPSUBTYPE_PREFER_SYMKEY    =  11,
    00582     PGPSUBTYPE_REVOKE_KEY       =  12,
    00583     PGPSUBTYPE_ISSUER_KEYID     =  16,
    00584     PGPSUBTYPE_NOTATION         =  20,
    00585     PGPSUBTYPE_PREFER_HASH      =  21,
    00586     PGPSUBTYPE_PREFER_COMPRESS  =  22,
    00587     PGPSUBTYPE_KEYSERVER_PREFERS=  23,
    00588     PGPSUBTYPE_PREFER_KEYSERVER =  24,
    00589     PGPSUBTYPE_PRIMARY_USERID   =  25,
    00590     PGPSUBTYPE_POLICY_URL       =  26,
    00591     PGPSUBTYPE_KEY_FLAGS        =  27,
    00592     PGPSUBTYPE_SIGNER_USERID    =  28,
    00593     PGPSUBTYPE_REVOKE_REASON    =  29,
    00594     PGPSUBTYPE_FEATURES         =  30,
    00595     PGPSUBTYPE_EMBEDDED_SIG     =  32,
    00597     PGPSUBTYPE_INTERNAL_100     = 100,
    00598     PGPSUBTYPE_INTERNAL_101     = 101,
    00599     PGPSUBTYPE_INTERNAL_102     = 102,
    00600     PGPSUBTYPE_INTERNAL_103     = 103,
    00601     PGPSUBTYPE_INTERNAL_104     = 104,
    00602     PGPSUBTYPE_INTERNAL_105     = 105,
    00603     PGPSUBTYPE_INTERNAL_106     = 106,
    00604     PGPSUBTYPE_INTERNAL_107     = 107,
    00605     PGPSUBTYPE_INTERNAL_108     = 108,
    00606     PGPSUBTYPE_INTERNAL_109     = 109,
    00607     PGPSUBTYPE_INTERNAL_110     = 110,
    00609     PGPSUBTYPE_CRITICAL         = 128
    00610 } pgpSubType;
    00611 /*@=typeuse@*/
    00612
    00616 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    00617 extern struct pgpValTbl_s pgpSubTypeTbl[];
    00618
    00639 typedef union pgpPktSig_u {
    00640     struct pgpPktSigV3_s v3;
    00641     struct pgpPktSigV4_s v4;
    00642 } * pgpPktSig;
    00643
    00672 typedef struct pgpPktSymkey_s {
    00673     uint8_t version;
    00674     uint8_t symkey_algo;
    00675     uint8_t s2k[1];
    00676 } pgpPktSymkey;
    00677
    00707 typedef struct pgpPktOnepass_s {
    00708     uint8_t version;
    00709     uint8_t sigtype;
    00710     uint8_t hash_algo;
    00711     uint8_t pubkey_algo;
    00712     uint8_t signid[8];
    00713     uint8_t nested;
    00714 } * pgpPktOnepass;
    00715
    00788 typedef struct pgpPktKeyV3_s {
    00789     uint8_t version;
    00790     uint8_t time[4];
    00791     uint8_t valid[2];
    00792     uint8_t pubkey_algo;
    00793 } * pgpPktKeyV3;
    00794
    00826 typedef struct pgpPktKeyV4_s {
    00827     uint8_t version;
    00828     uint8_t time[4];
    00829     uint8_t pubkey_algo;
    00830 } * pgpPktKeyV4;
    00831
    00896 typedef union pgpPktKey_u {
    00897     struct pgpPktKeyV3_s v3;
    00898     struct pgpPktKeyV4_s v4;
    00899 } pgpPktKey;
    00900
    00925 typedef struct pgpPktCdata_s {
    00926     uint8_t compressalgo;
    00927     uint8_t data[1];
    00928 } pgpPktCdata;
    00929
    00964 typedef struct pgpPktEdata_s {
    00965     uint8_t data[1];
    00966 } pgpPktEdata;
    00967
    00984 /*
    00985  * 5.9. Literal Data Packet (Tag 11)
    00986  *
    00987  * A Literal Data packet contains the body of a message; data that is
    00988  * not to be further interpreted.
    00989  *
    00990  * The body of this packet consists of:
    00991  *   - A one-octet field that describes how the data is formatted.
    00992  *
    00993  * If it is a 'b' (0x62), then the literal packet contains binary data.
    00994  * If it is a 't' (0x74), then it contains text data, and thus may need
    00995  * line ends converted to local form, or other text-mode changes.  RFC
    00996  * 1991 also defined a value of 'l' as a 'local' mode for machine-local
    00997  * conversions.  This use is now deprecated.
    00998  *   - File name as a string (one-octet length, followed by file name),
    00999  *     if the encrypted data should be saved as a file.
    01000  *
    01001  * If the special name "_CONSOLE" is used, the message is considered to
    01002  * be "for your eyes only".  This advises that the message data is
    01003  * unusually sensitive, and the receiving program should process it more
    01004  * carefully, perhaps avoiding storing the received data to disk, for
    01005  * example.
    01006  *   - A four-octet number that indicates the modification date of the
    01007  *     file, or the creation time of the packet, or a zero that
    01008  *     indicates the present time.
    01009  *   - The remainder of the packet is literal data.
    01010  *
    01011  * Text data is stored with <CR><LF> text endings (i.e. network-normal
    01012  * line endings).  These should be converted to native line endings by
    01013  * the receiving software.
    01014  */
    01015 typedef struct pgpPktLdata_s {
    01016     uint8_t format;
    01017     uint8_t filenamelen;
    01018     uint8_t filename[1];
    01019 } pgpPktLdata;
    01020
    01034 typedef struct pgpPktTrust_s {
    01035     uint8_t flag;
    01036 } pgpPktTrust;
    01037
    01048 typedef struct pgpPktUid_s {
    01049     uint8_t userid[1];
    01050 } pgpPktUid;
    01051
    01054 union pgpPktPre_u {
    01055     pgpPktPubkey pubkey;
    01056     pgpPktSig sig;
    01057     pgpPktSymkey symkey;
    01058     pgpPktOnepass onepass;
    01059     pgpPktKey key;
    01060     pgpPktCdata cdata;
    01061     pgpPktEdata edata;
    01063     pgpPktLdata ldata;
    01064     pgpPktTrust tdata;
    01065     pgpPktUid uid;
    01066 };
    01067
    01070 /*@-typeuse@*/
    01071 typedef enum pgpArmor_e {
    01072     PGPARMOR_ERR_CRC_CHECK              = -7,
    01073     PGPARMOR_ERR_BODY_DECODE            = -6,
    01074     PGPARMOR_ERR_CRC_DECODE             = -5,
    01075     PGPARMOR_ERR_NO_END_PGP             = -4,
    01076     PGPARMOR_ERR_UNKNOWN_PREAMBLE_TAG   = -3,
    01077     PGPARMOR_ERR_UNKNOWN_ARMOR_TYPE     = -2,
    01078     PGPARMOR_ERR_NO_BEGIN_PGP           = -1,
    01079 #define PGPARMOR_ERROR  PGPARMOR_ERR_NO_BEGIN_PGP
    01080     PGPARMOR_NONE               =  0,
    01081     PGPARMOR_MESSAGE            =  1,
    01082     PGPARMOR_PUBKEY             =  2,
    01083     PGPARMOR_SIGNATURE          =  3,
    01084     PGPARMOR_SIGNED_MESSAGE     =  4,
    01085     PGPARMOR_FILE               =  5,
    01086     PGPARMOR_PRIVKEY            =  6,
    01087     PGPARMOR_SECKEY             =  7
    01088 } pgpArmor;
    01089 /*@=typeuse@*/
    01090
    01094 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    01095 extern struct pgpValTbl_s pgpArmorTbl[];
    01096
    01099 /*@-typeuse@*/
    01100 typedef enum pgpArmorKey_e {
    01101     PGPARMORKEY_VERSION         = 1,
    01102     PGPARMORKEY_COMMENT         = 2,
    01103     PGPARMORKEY_MESSAGEID       = 3,
    01104     PGPARMORKEY_HASH            = 4,
    01105     PGPARMORKEY_CHARSET         = 5
    01106 } pgpArmorKey;
    01107 /*@=typeuse@*/
    01108
    01112 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    01113 extern struct pgpValTbl_s pgpArmorKeyTbl[];
    01114
    01118 typedef enum rpmDigestFlags_e {
    01119     RPMDIGEST_NONE      = 0
    01120 } rpmDigestFlags;
    01121
    01124 /*@unchecked@*/
    01125 extern pgpHashAlgo rpmDigestHashAlgo;
    01126
    01129 /*@unchecked@*/ /*@observer@*/
    01130 extern struct poptOption rpmDigestPoptTable[];
    01131
    01132 /*@-fcnuse@*/
    01133 #ifdef __cplusplus
    01134 extern "C" {
    01135 #endif
    01136
    01143 /*@unused@*/ static inline
    01144 unsigned int pgpGrab(const uint8_t * s, size_t nbytes)
    01145         /*@*/
    01146 {
    01147     unsigned int i = 0;
    01148     size_t nb = (nbytes <= sizeof(i) ? nbytes : sizeof(i));
    01149     while (nb--)
    01150         i = (i << 8) | *s++;
    01151     return i;
    01152 }
    01153
    01160 /*@unused@*/ static inline
    01161 int pgpLen(const uint8_t * s, /*@out@*/ unsigned int * lenp)
    01162         /*@modifies *lenp @*/
    01163 {
    01164     if (*s < 192) {
    01165         *lenp = (unsigned int) *s++;
    01166         return 1;
    01167     } else if (*s < 255) {
    01168         *lenp = (unsigned int) ((((unsigned)s[0]) - 192) << 8) + s[1] + 192;
    01169         return 2;
    01170     } else {
    01171         *lenp = pgpGrab(s+1, 4);
    01172         return 5;
    01173     }
    01174 }
    01175
    01181 /*@unused@*/ static inline
    01182 unsigned int pgpMpiBits(const uint8_t * p)
    01183         /*@requires maxRead(p) >= 1 @*/
    01184         /*@*/
    01185 {
    01186     return (unsigned int) ((p[0] << 8) | p[1]);
    01187 }
    01188
    01194 /*@unused@*/ static inline
    01195 unsigned int pgpMpiLen(const uint8_t * p)
    01196         /*@requires maxRead(p) >= 1 @*/
    01197         /*@*/
    01198 {
    01199     return (2 + ((pgpMpiBits(p)+7)>>3));
    01200 }
    01201
    01209 /*@unused@*/ static inline
    01210 char * pgpHexCvt(/*@returned@*/ char * t, const uint8_t * s, size_t nbytes)
    01211         /*@modifies *t @*/
    01212 {
    01213     static char hex[] = "0123456789abcdef";
    01214     while (nbytes-- > 0) {
    01215         unsigned int i;
    01216         i = (unsigned int) *s++;
    01217         *t++ = hex[ (i >> 4) & 0xf ];
    01218         *t++ = hex[ (i     ) & 0xf ];
    01219     }
    01220     *t = '\0';
    01221     return t;
    01222 }
    01223
    01231 /*@unused@*/ static inline /*@observer@*/
    01232 char * pgpHexStr(const uint8_t * p, size_t plen)
    01233         /*@*/
    01234 {
    01235     static char prbuf[8*BUFSIZ];        /* XXX ick */
    01236     char *t = prbuf;
    01237     t = pgpHexCvt(t, p, plen);
    01238     return prbuf;
    01239 }
    01240
    01247 /*@unused@*/ static inline /*@observer@*/
    01248 const char * pgpMpiStr(const uint8_t * p)
    01249         /*@requires maxRead(p) >= 3 @*/
    01250         /*@*/
    01251 {
    01252     static char prbuf[8*BUFSIZ];        /* XXX ick */
    01253     char *t = prbuf;
    01254     sprintf(t, "[%4u]: ", pgpGrab(p, 2));
    01255     t += strlen(t);
    01256     t = pgpHexCvt(t, p+2, pgpMpiLen(p)-2);
    01257     return prbuf;
    01258 }
    01259
    01266 /*@unused@*/ static inline /*@observer@*/
    01267 const char * pgpValStr(pgpValTbl vs, uint8_t val)
    01268         /*@*/
    01269 {
    01270     do {
    01271         if (vs->val == (int)val)
    01272             break;
    01273     } while ((++vs)->val != -1);
    01274     return vs->str;
    01275 }
    01276
    01284 /*@unused@*/ static inline
    01285 int pgpValTok(pgpValTbl vs, const char * s, const char * se)
    01286         /*@*/
    01287 {
    01288     do {
    01289         size_t vlen = strlen(vs->str);
    01290         if (vlen <= (se-s) && !strncmp(s, vs->str, vlen))
    01291             break;
    01292     } while ((++vs)->val != -1);
    01293     return vs->val;
    01294 }
    01295
    01302 /*@-exportlocal@*/
    01303 void pgpPrtVal(const char * pre, pgpValTbl vs, uint8_t val)
    01304         /*@globals fileSystem @*/
    01305         /*@modifies fileSystem @*/;
    01306 /*@=exportlocal@*/
    01307
    01315 /*@-exportlocal@*/
    01316 int pgpPrtSubType(const uint8_t * h, size_t hlen, pgpSigType sigtype)
    01317         /*@globals fileSystem @*/
    01318         /*@modifies fileSystem @*/;
    01319 /*@=exportlocal@*/
    01320
    01326 /*@-exportlocal@*/
    01327 int pgpPrtSig(const pgpPkt pp)
    01328         /*@globals fileSystem, internalState @*/
    01329         /*@modifies fileSystem, internalState @*/;
    01330 /*@=exportlocal@*/
    01331
    01337 int pgpPrtKey(const pgpPkt pp)
    01338         /*@globals fileSystem, internalState @*/
    01339         /*@modifies fileSystem, internalState @*/;
    01340
    01346 /*@-exportlocal@*/
    01347 int pgpPrtUserID(const pgpPkt pp)
    01348         /*@globals fileSystem, internalState @*/
    01349         /*@modifies fileSystem, internalState @*/;
    01350 /*@=exportlocal@*/
    01351
    01357 /*@-exportlocal@*/
    01358 int pgpPrtComment(const pgpPkt pp)
    01359         /*@globals fileSystem @*/
    01360         /*@modifies fileSystem @*/;
    01361 /*@=exportlocal@*/
    01362
    01371 /*@-exportlocal@*/
    01372 int pgpPubkeyFingerprint(const uint8_t * pkt, size_t pktlen,
    01373                 /*@out@*/ uint8_t * keyid)
    01374         /*@modifies *keyid @*/;
    01375 /*@=exportlocal@*/
    01376
    01384 int pgpExtractPubkeyFingerprint(const char * b64pkt, /*@out@*/ uint8_t * keyid)
    01385         /*@modifies *keyid @*/;
    01386
    01394 int pgpPktLen(const uint8_t * pkt, size_t pleft, /*@out@*/ pgpPkt pp)
    01395         /*@modifies pp @*/;
    01396
    01403 /*@-exportlocal@*/
    01404 int pgpPrtPkt(const uint8_t * pkt, size_t pleft)
    01405         /*@globals fileSystem, internalState @*/
    01406         /*@modifies fileSystem, internalState @*/;
    01407 /*@=exportlocal@*/
    01408
    01417 int pgpPrtPkts(const uint8_t * pkts, size_t pktlen, pgpDig dig, int printing)
    01418         /*@globals fileSystem, internalState @*/
    01419         /*@modifies dig, fileSystem, internalState @*/;
    01420
    01428 pgpArmor pgpReadPkts(const char * fn,
    01429                 /*@out@*/ const uint8_t ** pkt, /*@out@*/ size_t * pktlen)
    01430         /*@globals h_errno, fileSystem, internalState @*/
    01431         /*@modifies *pkt, *pktlen, fileSystem, internalState @*/;
    01432
    01440 char * pgpArmorWrap(int atype, const unsigned char * s, size_t ns)
    01441         /*@*/;
    01442
    01449 int pgpHashAlgoStringToNumber(const char *name, size_t name_len)
    01450         /*@*/;
    01451
    01455 /*@unchecked@*/
    01456 extern pgpVSFlags pgpDigVSFlags;
    01457
    01464 /*@unused@*/ /*@null@*/
    01465 pgpDig pgpDigUnlink (/*@killref@*/ /*@only@*/ /*@null@*/ pgpDig dig,
    01466                 /*@null@*/ const char * msg)
    01467         /*@modifies dig @*/;
    01468
    01470 /*@-exportlocal@*/
    01471 /*@null@*/
    01472 pgpDig XpgpDigUnlink (/*@killref@*/ /*@only@*/ /*@null@*/ pgpDig dig,
    01473                 /*@null@*/ const char * msg, const char * fn, unsigned ln)
    01474         /*@modifies dig @*/;
    01475 /*@=exportlocal@*/
    01476 #define pgpDigUnlink(_dig, _msg) XpgpDigUnlink(_dig, _msg, __FILE__, __LINE__)
    01477
    01484 /*@unused@*/ /*@newref@*/ /*@null@*/
    01485 pgpDig pgpDigLink (/*@null@*/ pgpDig dig, /*@null@*/ const char * msg)
    01486         /*@modifies dig @*/;
    01487
    01489 /*@newref@*/ /*@null@*/
    01490 pgpDig XpgpDigLink (/*@null@*/ pgpDig dig, /*@null@*/ const char * msg,
    01491                 const char * fn, unsigned ln)
    01492         /*@modifies dig @*/;
    01493 #define pgpDigLink(_dig, _msg)  XpgpDigLink(_dig, _msg, __FILE__, __LINE__)
    01494
    01500 /*@null@*/
    01501 pgpDig pgpDigFree(/*@killref@*/ /*@only@*/ /*@null@*/ pgpDig dig)
    01502         /*@modifies dig @*/;
    01503
    01508 /*@relnull@*/
    01509 pgpDig pgpDigNew(/*@unused@*/ pgpVSFlags vsflags)
    01510         /*@*/;
    01511
    01516 void pgpDigClean(/*@null@*/ pgpDig dig)
    01517         /*@modifies dig @*/;
    01518
    01524 /*@exposed@*/
    01525 pgpDigParams pgpGetPubkey(const pgpDig dig)
    01526         /*@*/;
    01527
    01533 /*@exposed@*/
    01534 pgpDigParams pgpGetSignature(const pgpDig dig)
    01535         /*@*/;
    01536
    01542 uint32_t pgpGetSigtag(const pgpDig dig)
    01543         /*@*/;
    01544
    01551 uint32_t pgpGetSigtype(const pgpDig dig)
    01552         /*@*/;
    01553
    01559 /*@observer@*/ /*@null@*/
    01560 extern const void * pgpGetSig(const pgpDig dig)
    01561         /*@*/;
    01562
    01568 uint32_t pgpGetSiglen(const pgpDig dig)
    01569         /*@*/;
    01570
    01580 int pgpSetSig(pgpDig dig,
    01581                 uint32_t sigtag, uint32_t sigtype,
    01582                 /*@kept@*/ /*@null@*/ const void * sig, uint32_t siglen)
    01583         /*@modifies dig @*/;
    01584
    01591 void * pgpStatsAccumulator(pgpDig dig, int opx)
    01592         /*@*/;
    01593
    01601 int pgpSetFindPubkey(pgpDig dig,
    01602                 /*@null@*/ int (*findPubkey) (void *ts, /*@null@*/ void *dig),
    01603                 /*@exposed@*/ /*@null@*/ void * _ts)
    01604         /*@modifies dig @*/;
    01605
    01611 int pgpFindPubkey(pgpDig dig)
    01612         /*@modifies dig @*/;
    01613
    01619 /*@unused@*/ static inline
    01620 int pgpIsPkt(const uint8_t * p, /*@null@*/ pgpTag * tagp)
    01621         /*@modifies *tagp @*/
    01622 {
    01623     unsigned int val = (unsigned int) *p++;
    01624     pgpTag tag;
    01625     int rc;
    01626
    01627     /* XXX can't deal with these. */
    01628     if (!(val & 0x80))
    01629         return 0;
    01630
    01631     if (val & 0x40)
    01632         tag = (pgpTag)(val & 0x3f);
    01633     else
    01634         tag = (pgpTag)((val >> 2) & 0xf);
    01635
    01636     switch (tag) {
    01637     case PGPTAG_MARKER:
    01638     case PGPTAG_SYMMETRIC_SESSION_KEY:
    01639     case PGPTAG_ONEPASS_SIGNATURE:
    01640     case PGPTAG_PUBLIC_KEY:
    01641     case PGPTAG_SECRET_KEY:
    01642     case PGPTAG_PUBLIC_SESSION_KEY:
    01643     case PGPTAG_SIGNATURE:
    01644     case PGPTAG_COMMENT:
    01645     case PGPTAG_COMMENT_OLD:
    01646     case PGPTAG_LITERAL_DATA:
    01647     case PGPTAG_COMPRESSED_DATA:
    01648     case PGPTAG_SYMMETRIC_DATA:
    01649         rc = 1;
    01650         break;
    01651     case PGPTAG_PUBLIC_SUBKEY:
    01652     case PGPTAG_SECRET_SUBKEY:
    01653     case PGPTAG_USER_ID:
    01654     case PGPTAG_RESERVED:
    01655     case PGPTAG_TRUST:
    01656     case PGPTAG_PHOTOID:
    01657     case PGPTAG_ENCRYPTED_MDC:
    01658     case PGPTAG_MDC:
    01659     case PGPTAG_PRIVATE_60:
    01660     case PGPTAG_PRIVATE_62:
    01661     case PGPTAG_CONTROL:
    01662     default:
    01663         rc = 0;
    01664         break;
    01665     }
    01666     if (tagp)
    01667         *tagp = tag;
    01668     return rc;
    01669 }
    01670
    01671 #define CRC24_INIT      0xb704ce
    01672 #define CRC24_POLY      0x1864cfb
    01673
    01680 /*@unused@*/ static inline
    01681 unsigned int pgpCRC(const uint8_t * octets, size_t len)
    01682         /*@*/
    01683 {
    01684     unsigned int crc = CRC24_INIT;
    01685     int i;
    01686
    01687     while (len--) {
    01688         crc ^= (*octets++) << 16;
    01689         for (i = 0; i < 8; i++) {
    01690             crc <<= 1;
    01691             if (crc & 0x1000000)
    01692                 crc ^= CRC24_POLY;
    01693         }
    01694     }
    01695     return crc & 0xffffff;
    01696 }
    01697
    01703 /*@only@*/
    01704 DIGEST_CTX rpmDigestDup(DIGEST_CTX octx)
    01705         /*@*/;
    01706
    01714 /*@only@*/ /*@null@*/
    01715 DIGEST_CTX rpmDigestInit(pgpHashAlgo hashalgo, rpmDigestFlags flags)
    01716         /*@*/;
    01717
    01725 int rpmDigestUpdate(/*@null@*/ DIGEST_CTX ctx, const void * data, size_t len)
    01726         /*@modifies ctx @*/;
    01727
    01739 int rpmDigestFinal(/*@only@*/ /*@null@*/ DIGEST_CTX ctx,
    01740         /*@null@*/ /*@out@*/ void * datap,
    01741         /*@null@*/ /*@out@*/ size_t * lenp, int asAscii)
    01742                 /*@modifies *datap, *lenp @*/;
    01743
    01746 typedef int (*pgpImplSet_t) (/*@only@*/ DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
    01747         /*@modifies ctx, dig @*/;
    01748
    01751 typedef int (*pgpImplVerify_t) (pgpDig dig)
    01752         /*@*/;
    01753
    01756 typedef int (*pgpImplMpiItem_t) (const char * pre, pgpDig dig, int itemno,
    01757                 const uint8_t * p, /*@null@*/ const uint8_t * pend)
    01758         /*@globals fileSystem @*/
    01759         /*@modifies dig, fileSystem @*/;
    01760
    01763 typedef void (*pgpImplClean_t) (void * impl)
    01764         /*@modifies impl @*/;
    01765
    01768 typedef void * (*pgpImplFree_t) (/*@only@*/ void * impl)
    01769         /*@modifies impl @*/;
    01770
    01773 typedef void * (*pgpImplInit_t) (void)
    01774         /*@*/;
    01775
    01776
    01779 typedef struct pgpImplVecs_s {
    01780     pgpImplSet_t        _pgpSetRSA;
    01781     pgpImplVerify_t     _pgpVerifyRSA;
    01782     pgpImplSet_t        _pgpSetDSA;
    01783     pgpImplVerify_t     _pgpVerifyDSA;
    01784     pgpImplMpiItem_t    _pgpMpiItem;
    01785     pgpImplClean_t      _pgpClean;
    01786     pgpImplFree_t       _pgpFree;
    01787     pgpImplInit_t       _pgpInit;
    01788 } pgpImplVecs_t;
    01789
    01792 /*@unchecked@*/
    01793 extern pgpImplVecs_t * pgpImplVecs;
    01794
    01795 /*@-mustmod@*/
    01798 /*@unused@*/ static inline
    01799 int pgpImplSetRSA(/*@only@*/ DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
    01800         /*@modifies ctx, dig @*/
    01801 {
    01802     return (*pgpImplVecs->_pgpSetRSA) (ctx, dig, sigp);
    01803 }
    01804
    01807 /*@unused@*/ static inline
    01808 int pgpImplVerifyRSA(pgpDig dig)
    01809         /*@*/
    01810 {
    01811     return (*pgpImplVecs->_pgpVerifyRSA) (dig);
    01812 }
    01813
    01816 /*@unused@*/ static inline
    01817 int pgpImplSetDSA(/*@only@*/ DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
    01818         /*@modifies ctx, dig @*/
    01819 {
    01820     return (*pgpImplVecs->_pgpSetDSA) (ctx, dig, sigp);
    01821 }
    01822
    01825 /*@unused@*/ static inline
    01826 int pgpImplVerifyDSA(pgpDig dig)
    01827         /*@*/
    01828 {
    01829     return (*pgpImplVecs->_pgpVerifyDSA) (dig);
    01830 }
    01831
    01834 /*@unused@*/ static inline
    01835 int pgpImplMpiItem(const char * pre, pgpDig dig, int itemno,
    01836                 const uint8_t * p, /*@null@*/ const uint8_t * pend)
    01837         /*@modifies dig @*/
    01838 {
    01839     return (*pgpImplVecs->_pgpMpiItem) (pre, dig, itemno, p, pend);
    01840 }
    01841
    01844 /*@unused@*/ static inline
    01845 void pgpImplClean(void * impl)
    01846         /*@modifies impl @*/
    01847 {
    01848 /*@-noeffectuncon@*/
    01849     (*pgpImplVecs->_pgpClean) (impl);
    01850 /*@=noeffectuncon@*/
    01851 }
    01852
    01855 /*@unused@*/ static inline
    01856 /*@null@*/
    01857 void * pgpImplFree(/*@only@*/ void * impl)
    01858         /*@modifies impl @*/
    01859 {
    01860     return (*pgpImplVecs->_pgpFree) (impl);
    01861 }
    01862
    01865 /*@unused@*/ static inline
    01866 void * pgpImplInit(void)
    01867         /*@*/
    01868 {
    01869     return (*pgpImplVecs->_pgpInit) ();
    01870 }
    01871 /*@=mustmod@*/
    01872
    01873 #ifdef __cplusplus
    01874 }
    01875 #endif
    01876 /*@=fcnuse@*/
    01877
    01878 #endif  /* H_RPMPGP */