rpm 5.2.1

- 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 #include <rpmiotypes.h>
    00016 #include <yarn.h>
    00017
    00018 #if defined(_RPMPGP_INTERNAL)
    00019 #include <rpmsw.h>
    00020
    00024 struct pgpDigParams_s {
    00025 /*@only@*/ /*@null@*/
    00026     const char * userid;
    00027 /*@only@*/ /*@null@*/
    00028     const rpmuint8_t * hash;
    00029     const char * params[4];
    00030     rpmuint8_t tag;
    00031
    00032     rpmuint8_t version;
    00033     rpmuint8_t time[4];
    00034     rpmuint8_t pubkey_algo;
    00036     rpmuint8_t hash_algo;
    00037     rpmuint8_t sigtype;
    00038     size_t hashlen;
    00039     rpmuint8_t signhash16[2];
    00040     rpmuint8_t signid[8];
    00041     rpmuint8_t saved;
    00042 #define PGPDIG_SAVED_TIME       (1 << 0)
    00043 #define PGPDIG_SAVED_ID         (1 << 1)
    00044
    00045 };
    00046
    00050 struct pgpDig_s {
    00051     struct rpmioItem_s _item;
    00052     struct pgpDigParams_s signature;
    00053     struct pgpDigParams_s pubkey;
    00054
    00055     rpmuint32_t sigtag;
    00056     rpmuint32_t sigtype;
    00057 /*@relnull@*/
    00058     const void * sig;
    00059     rpmuint32_t siglen;
    00061     pgpVSFlags vsflags;
    00062     struct rpmop_s dops;
    00063     struct rpmop_s sops;
    00065     int (*findPubkey) (void * _ts, /*@null@*/ void * _dig)
    00066         /*@modifies *_ts, *_dig @*/;
    00067 /*@null@*/
    00068     void * _ts;
    00070     rpmuint8_t ** ppkts;
    00071     int npkts;
    00072     size_t nbytes;
    00074 /*@only@*/ /*@null@*/
    00075     DIGEST_CTX sha1ctx;
    00076 /*@only@*/ /*@null@*/
    00077     DIGEST_CTX hdrsha1ctx;
    00078 /*@only@*/ /*@null@*/
    00079     void * sha1;
    00080     size_t sha1len;
    00082 /*@only@*/ /*@null@*/
    00083     DIGEST_CTX md5ctx;
    00084 /*@only@*/ /*@null@*/
    00085     DIGEST_CTX hdrctx;
    00086 /*@only@*/ /*@null@*/
    00087     void * md5;
    00088     size_t md5len;
    00089 /*@owned@*/ /*@relnull@*/
    00090     void * impl;
    00091 #if defined(__LCLINT__)
    00092 /*@refs@*/
    00093     int nrefs;
    00094 #endif
    00095 };
    00096 #endif
    00097
    00100 typedef const struct pgpValTbl_s {
    00101     int val;
    00102 /*@observer@*/
    00103     const char * str;
    00104 } * pgpValTbl;
    00105
    00113 typedef enum pgpTag_e {
    00114     PGPTAG_RESERVED             =  0,
    00115     PGPTAG_PUBLIC_SESSION_KEY   =  1,
    00116     PGPTAG_SIGNATURE            =  2,
    00117     PGPTAG_SYMMETRIC_SESSION_KEY=  3,
    00118     PGPTAG_ONEPASS_SIGNATURE    =  4,
    00119     PGPTAG_SECRET_KEY           =  5,
    00120     PGPTAG_PUBLIC_KEY           =  6,
    00121     PGPTAG_SECRET_SUBKEY        =  7,
    00122     PGPTAG_COMPRESSED_DATA      =  8,
    00123     PGPTAG_SYMMETRIC_DATA       =  9,
    00124     PGPTAG_MARKER               = 10,
    00125     PGPTAG_LITERAL_DATA         = 11,
    00126     PGPTAG_TRUST                = 12,
    00127     PGPTAG_USER_ID              = 13,
    00128     PGPTAG_PUBLIC_SUBKEY        = 14,
    00129     PGPTAG_COMMENT_OLD          = 16,
    00130     PGPTAG_PHOTOID              = 17,
    00131     PGPTAG_ENCRYPTED_MDC        = 18,
    00132     PGPTAG_MDC                  = 19,
    00133     PGPTAG_PRIVATE_60           = 60,
    00134     PGPTAG_COMMENT              = 61,
    00135     PGPTAG_PRIVATE_62           = 62,
    00136     PGPTAG_CONTROL              = 63
    00137 } pgpTag;
    00138
    00141 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    00142 extern struct pgpValTbl_s pgpTagTbl[];
    00143
    00178 typedef struct pgpPktPubkey_s {
    00179     rpmuint8_t version;
    00180     rpmuint8_t keyid[8];
    00181     rpmuint8_t algo;
    00182 } pgpPktPubkey;
    00183
    00190 /*@-typeuse@*/
    00191 typedef enum pgpSigType_e {
    00192     PGPSIGTYPE_BINARY            = 0x00,
    00193     PGPSIGTYPE_TEXT              = 0x01,
    00194     PGPSIGTYPE_STANDALONE        = 0x02,
    00195     PGPSIGTYPE_GENERIC_CERT      = 0x10,
    00197     PGPSIGTYPE_PERSONA_CERT      = 0x11,
    00199     PGPSIGTYPE_CASUAL_CERT       = 0x12,
    00201     PGPSIGTYPE_POSITIVE_CERT     = 0x13,
    00203     PGPSIGTYPE_SUBKEY_BINDING    = 0x18,
    00204     PGPSIGTYPE_SIGNED_KEY        = 0x1F,
    00205     PGPSIGTYPE_KEY_REVOKE        = 0x20,
    00206     PGPSIGTYPE_SUBKEY_REVOKE     = 0x28,
    00207     PGPSIGTYPE_CERT_REVOKE       = 0x30,
    00208     PGPSIGTYPE_TIMESTAMP         = 0x40,
    00209     PGPSIGTYPE_CONFIRM           = 0x50
    00210 } pgpSigType;
    00211 /*@=typeuse@*/
    00212
    00215 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    00216 extern struct pgpValTbl_s pgpSigTypeTbl[];
    00217
    00241 /*@-typeuse@*/
    00242 typedef enum pgpPubkeyAlgo_e {
    00243     PGPPUBKEYALGO_RSA           =  1,
    00244     PGPPUBKEYALGO_RSA_ENCRYPT   =  2,
    00245     PGPPUBKEYALGO_RSA_SIGN      =  3,
    00246     PGPPUBKEYALGO_ELGAMAL_ENCRYPT = 16,
    00247     PGPPUBKEYALGO_DSA           = 17,
    00248     PGPPUBKEYALGO_EC            = 18,
    00249     PGPPUBKEYALGO_ECDSA         = 19,
    00250     PGPPUBKEYALGO_ELGAMAL       = 20,
    00251     PGPPUBKEYALGO_DH            = 21
    00252 } pgpPubkeyAlgo;
    00253 /*@=typeuse@*/
    00254
    00257 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    00258 extern struct pgpValTbl_s pgpPubkeyTbl[];
    00259
    00285 /*@-typeuse@*/
    00286 typedef enum pgpSymkeyAlgo_e {
    00287     PGPSYMKEYALGO_PLAINTEXT     =  0,
    00288     PGPSYMKEYALGO_IDEA          =  1,
    00289     PGPSYMKEYALGO_TRIPLE_DES    =  2,
    00290     PGPSYMKEYALGO_CAST5         =  3,
    00291     PGPSYMKEYALGO_BLOWFISH      =  4,
    00292     PGPSYMKEYALGO_SAFER         =  5,
    00293     PGPSYMKEYALGO_DES_SK        =  6,
    00294     PGPSYMKEYALGO_AES_128       =  7,
    00295     PGPSYMKEYALGO_AES_192       =  8,
    00296     PGPSYMKEYALGO_AES_256       =  9,
    00297     PGPSYMKEYALGO_TWOFISH       = 10,
    00298     PGPSYMKEYALGO_NOENCRYPT     = 110
    00299 } pgpSymkeyAlgo;
    00300 /*@=typeuse@*/
    00301
    00305 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    00306 extern struct pgpValTbl_s pgpSymkeyTbl[];
    00307
    00323 /*@-typeuse@*/
    00324 typedef enum pgpCompressAlgo_e {
    00325     PGPCOMPRESSALGO_NONE        =  0,
    00326     PGPCOMPRESSALGO_ZIP         =  1,
    00327     PGPCOMPRESSALGO_ZLIB        =  2,
    00328     PGPCOMPRESSALGO_BZIP2       =  3
    00329 } pgpCompressAlgo;
    00330 /*@=typeuse@*/
    00331
    00335 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    00336 extern struct pgpValTbl_s pgpCompressionTbl[];
    00337
    00341 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    00342 extern struct pgpValTbl_s pgpHashTbl[];
    00343
    00365 typedef struct pgpPktSigV3_s {
    00366     rpmuint8_t version;
    00367     rpmuint8_t hashlen;
    00368     rpmuint8_t sigtype;
    00369     rpmuint8_t time[4];
    00370     rpmuint8_t signid[8];
    00371     rpmuint8_t pubkey_algo;
    00372     rpmuint8_t hash_algo;
    00373     rpmuint8_t signhash16[2];
    00374 } * pgpPktSigV3;
    00375
    00397 typedef struct pgpPktSigV4_s {
    00398     rpmuint8_t version;
    00399     rpmuint8_t sigtype;
    00400     rpmuint8_t pubkey_algo;
    00401     rpmuint8_t hash_algo;
    00402     rpmuint8_t hashlen[2];
    00403 } * pgpPktSigV4;
    00404
    00483 /*@-typeuse@*/
    00484 typedef enum pgpSubType_e {
    00485     PGPSUBTYPE_NONE             =   0,
    00486     PGPSUBTYPE_SIG_CREATE_TIME  =   2,
    00487     PGPSUBTYPE_SIG_EXPIRE_TIME  =   3,
    00488     PGPSUBTYPE_EXPORTABLE_CERT  =   4,
    00489     PGPSUBTYPE_TRUST_SIG        =   5,
    00490     PGPSUBTYPE_REGEX            =   6,
    00491     PGPSUBTYPE_REVOCABLE        =   7,
    00492     PGPSUBTYPE_KEY_EXPIRE_TIME  =   9,
    00493     PGPSUBTYPE_ARR              =  10,
    00494     PGPSUBTYPE_PREFER_SYMKEY    =  11,
    00495     PGPSUBTYPE_REVOKE_KEY       =  12,
    00496     PGPSUBTYPE_ISSUER_KEYID     =  16,
    00497     PGPSUBTYPE_NOTATION         =  20,
    00498     PGPSUBTYPE_PREFER_HASH      =  21,
    00499     PGPSUBTYPE_PREFER_COMPRESS  =  22,
    00500     PGPSUBTYPE_KEYSERVER_PREFERS=  23,
    00501     PGPSUBTYPE_PREFER_KEYSERVER =  24,
    00502     PGPSUBTYPE_PRIMARY_USERID   =  25,
    00503     PGPSUBTYPE_POLICY_URL       =  26,
    00504     PGPSUBTYPE_KEY_FLAGS        =  27,
    00505     PGPSUBTYPE_SIGNER_USERID    =  28,
    00506     PGPSUBTYPE_REVOKE_REASON    =  29,
    00507     PGPSUBTYPE_FEATURES         =  30,
    00508     PGPSUBTYPE_SIG_TARGET       =  31,
    00509     PGPSUBTYPE_EMBEDDED_SIG     =  32,
    00511     PGPSUBTYPE_INTERNAL_100     = 100,
    00512     PGPSUBTYPE_INTERNAL_101     = 101,
    00513     PGPSUBTYPE_INTERNAL_102     = 102,
    00514     PGPSUBTYPE_INTERNAL_103     = 103,
    00515     PGPSUBTYPE_INTERNAL_104     = 104,
    00516     PGPSUBTYPE_INTERNAL_105     = 105,
    00517     PGPSUBTYPE_INTERNAL_106     = 106,
    00518     PGPSUBTYPE_INTERNAL_107     = 107,
    00519     PGPSUBTYPE_INTERNAL_108     = 108,
    00520     PGPSUBTYPE_INTERNAL_109     = 109,
    00521     PGPSUBTYPE_INTERNAL_110     = 110,
    00523     PGPSUBTYPE_CRITICAL         = 128
    00524 } pgpSubType;
    00525 /*@=typeuse@*/
    00526
    00530 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    00531 extern struct pgpValTbl_s pgpSubTypeTbl[];
    00532
    00553 typedef union pgpPktSig_u {
    00554     struct pgpPktSigV3_s v3;
    00555     struct pgpPktSigV4_s v4;
    00556 } * pgpPktSig;
    00557
    00586 typedef struct pgpPktSymkey_s {
    00587     rpmuint8_t version;
    00588     rpmuint8_t symkey_algo;
    00589     rpmuint8_t s2k[1];
    00590 } pgpPktSymkey;
    00591
    00621 typedef struct pgpPktOnepass_s {
    00622     rpmuint8_t version;
    00623     rpmuint8_t sigtype;
    00624     rpmuint8_t hash_algo;
    00625     rpmuint8_t pubkey_algo;
    00626     rpmuint8_t signid[8];
    00627     rpmuint8_t nested;
    00628 } * pgpPktOnepass;
    00629
    00702 typedef struct pgpPktKeyV3_s {
    00703     rpmuint8_t version;
    00704     rpmuint8_t time[4];
    00705     rpmuint8_t valid[2];
    00706     rpmuint8_t pubkey_algo;
    00707 } * pgpPktKeyV3;
    00708
    00740 typedef struct pgpPktKeyV4_s {
    00741     rpmuint8_t version;
    00742     rpmuint8_t time[4];
    00743     rpmuint8_t pubkey_algo;
    00744 } * pgpPktKeyV4;
    00745
    00810 typedef union pgpPktKey_u {
    00811     struct pgpPktKeyV3_s v3;
    00812     struct pgpPktKeyV4_s v4;
    00813 } pgpPktKey;
    00814
    00839 typedef struct pgpPktCdata_s {
    00840     rpmuint8_t compressalgo;
    00841     rpmuint8_t data[1];
    00842 } pgpPktCdata;
    00843
    00878 typedef struct pgpPktEdata_s {
    00879     rpmuint8_t data[1];
    00880 } pgpPktEdata;
    00881
    00898 /*
    00899  * 5.9. Literal Data Packet (Tag 11)
    00900  *
    00901  * A Literal Data packet contains the body of a message; data that is
    00902  * not to be further interpreted.
    00903  *
    00904  * The body of this packet consists of:
    00905  *   - A one-octet field that describes how the data is formatted.
    00906  *
    00907  * If it is a 'b' (0x62), then the literal packet contains binary data.
    00908  * If it is a 't' (0x74), then it contains text data, and thus may need
    00909  * line ends converted to local form, or other text-mode changes.  RFC
    00910  * 1991 also defined a value of 'l' as a 'local' mode for machine-local
    00911  * conversions.  This use is now deprecated.
    00912  *   - File name as a string (one-octet length, followed by file name),
    00913  *     if the encrypted data should be saved as a file.
    00914  *
    00915  * If the special name "_CONSOLE" is used, the message is considered to
    00916  * be "for your eyes only".  This advises that the message data is
    00917  * unusually sensitive, and the receiving program should process it more
    00918  * carefully, perhaps avoiding storing the received data to disk, for
    00919  * example.
    00920  *   - A four-octet number that indicates the modification date of the
    00921  *     file, or the creation time of the packet, or a zero that
    00922  *     indicates the present time.
    00923  *   - The remainder of the packet is literal data.
    00924  *
    00925  * Text data is stored with <CR><LF> text endings (i.e. network-normal
    00926  * line endings).  These should be converted to native line endings by
    00927  * the receiving software.
    00928  */
    00929 typedef struct pgpPktLdata_s {
    00930     rpmuint8_t format;
    00931     rpmuint8_t filenamelen;
    00932     rpmuint8_t filename[1];
    00933 } pgpPktLdata;
    00934
    00948 typedef struct pgpPktTrust_s {
    00949     rpmuint8_t flag;
    00950 } pgpPktTrust;
    00951
    00962 typedef struct pgpPktUid_s {
    00963     rpmuint8_t userid[1];
    00964 } pgpPktUid;
    00965
    00968 union pgpPktPre_u {
    00969     pgpPktPubkey pubkey;
    00970     pgpPktSig sig;
    00971     pgpPktSymkey symkey;
    00972     pgpPktOnepass onepass;
    00973     pgpPktKey key;
    00974     pgpPktCdata cdata;
    00975     pgpPktEdata edata;
    00977     pgpPktLdata ldata;
    00978     pgpPktTrust tdata;
    00979     pgpPktUid uid;
    00980 };
    00981
    00984 /*@-typeuse@*/
    00985 typedef enum pgpArmor_e {
    00986     PGPARMOR_ERR_CRC_CHECK              = -7,
    00987     PGPARMOR_ERR_BODY_DECODE            = -6,
    00988     PGPARMOR_ERR_CRC_DECODE             = -5,
    00989     PGPARMOR_ERR_NO_END_PGP             = -4,
    00990     PGPARMOR_ERR_UNKNOWN_PREAMBLE_TAG   = -3,
    00991     PGPARMOR_ERR_UNKNOWN_ARMOR_TYPE     = -2,
    00992     PGPARMOR_ERR_NO_BEGIN_PGP           = -1,
    00993 #define PGPARMOR_ERROR  PGPARMOR_ERR_NO_BEGIN_PGP
    00994     PGPARMOR_NONE               =  0,
    00995     PGPARMOR_MESSAGE            =  1,
    00996     PGPARMOR_PUBKEY             =  2,
    00997     PGPARMOR_SIGNATURE          =  3,
    00998     PGPARMOR_SIGNED_MESSAGE     =  4,
    00999     PGPARMOR_FILE               =  5,
    01000     PGPARMOR_PRIVKEY            =  6,
    01001     PGPARMOR_SECKEY             =  7
    01002 } pgpArmor;
    01003 /*@=typeuse@*/
    01004
    01008 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    01009 extern struct pgpValTbl_s pgpArmorTbl[];
    01010
    01013 /*@-typeuse@*/
    01014 typedef enum pgpArmorKey_e {
    01015     PGPARMORKEY_VERSION         = 1,
    01016     PGPARMORKEY_COMMENT         = 2,
    01017     PGPARMORKEY_MESSAGEID       = 3,
    01018     PGPARMORKEY_HASH            = 4,
    01019     PGPARMORKEY_CHARSET         = 5
    01020 } pgpArmorKey;
    01021 /*@=typeuse@*/
    01022
    01026 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
    01027 extern struct pgpValTbl_s pgpArmorKeyTbl[];
    01028
    01029 /*@-fcnuse@*/
    01030 #ifdef __cplusplus
    01031 extern "C" {
    01032 #endif
    01033
    01040 /*@unused@*/ static inline
    01041 unsigned int pgpGrab(const rpmuint8_t * s, size_t nbytes)
    01042         /*@*/
    01043 {
    01044     unsigned int i = 0;
    01045     size_t nb = (nbytes <= sizeof(i) ? nbytes : sizeof(i));
    01046     while (nb--)
    01047         i = (i << 8) | *s++;
    01048     return i;
    01049 }
    01050
    01057 /*@unused@*/ static inline
    01058 unsigned int pgpLen(const rpmuint8_t * s, /*@out@*/ unsigned int * lenp)
    01059         /*@modifies *lenp @*/
    01060 {
    01061     if (*s < (rpmuint8_t)192) {
    01062         *lenp = (unsigned int) *s++;
    01063         return 1;
    01064     } else if (*s < (rpmuint8_t)255) {
    01065         *lenp = (unsigned int) ((((unsigned)s[0]) - 192) << 8) + (unsigned)s[1] + 192;
    01066         return 2;
    01067     } else {
    01068         *lenp = pgpGrab(s+1, 4);
    01069         return 5;
    01070     }
    01071 }
    01072
    01078 /*@unused@*/ static inline
    01079 unsigned int pgpMpiBits(const rpmuint8_t * p)
    01080         /*@requires maxRead(p) >= 1 @*/
    01081         /*@*/
    01082 {
    01083     return (unsigned int) ((p[0] << 8) | p[1]);
    01084 }
    01085
    01091 /*@unused@*/ static inline
    01092 unsigned int pgpMpiLen(const rpmuint8_t * p)
    01093         /*@requires maxRead(p) >= 1 @*/
    01094         /*@*/
    01095 {
    01096     return (2 + ((pgpMpiBits(p)+7)>>3));
    01097 }
    01098
    01106 /*@unused@*/ static inline
    01107 char * pgpHexCvt(/*@returned@*/ char * t, const rpmuint8_t * s, size_t nbytes)
    01108         /*@modifies *t @*/
    01109 {
    01110     static char hex[] = "0123456789abcdef";
    01111     while (nbytes-- > 0) {
    01112         unsigned int i;
    01113         i = (unsigned int) *s++;
    01114         *t++ = hex[ (i >> 4) & 0xf ];
    01115         *t++ = hex[ (i     ) & 0xf ];
    01116     }
    01117     *t = '\0';
    01118     return t;
    01119 }
    01120
    01128 /*@unused@*/ static inline /*@observer@*/
    01129 char * pgpHexStr(const rpmuint8_t * p, size_t plen)
    01130         /*@*/
    01131 {
    01132     static char prbuf[8*BUFSIZ];        /* XXX ick */
    01133     char *t = prbuf;
    01134     t = pgpHexCvt(t, p, plen);
    01135     return prbuf;
    01136 }
    01137
    01144 /*@unused@*/ static inline /*@observer@*/
    01145 const char * pgpMpiStr(const rpmuint8_t * p)
    01146         /*@requires maxRead(p) >= 3 @*/
    01147         /*@*/
    01148 {
    01149     static char prbuf[8*BUFSIZ];        /* XXX ick */
    01150     char *t = prbuf;
    01151     sprintf(t, "[%4u]: ", pgpGrab(p, 2));
    01152     t += strlen(t);
    01153     t = pgpHexCvt(t, p+2, pgpMpiLen(p)-2);
    01154     return prbuf;
    01155 }
    01156
    01163 /*@unused@*/ static inline /*@observer@*/
    01164 const char * pgpValStr(pgpValTbl vs, rpmuint8_t val)
    01165         /*@*/
    01166 {
    01167     do {
    01168         if (vs->val == (int)val)
    01169             break;
    01170     } while ((++vs)->val != -1);
    01171     return vs->str;
    01172 }
    01173
    01181 /*@unused@*/ static inline
    01182 int pgpValTok(pgpValTbl vs, const char * s, const char * se)
    01183         /*@*/
    01184 {
    01185     do {
    01186         size_t vlen = strlen(vs->str);
    01187         if (vlen <= (size_t)(se-s) && !strncmp(s, vs->str, vlen))
    01188             break;
    01189     } while ((++vs)->val != -1);
    01190     return vs->val;
    01191 }
    01192
    01199 /*@-exportlocal@*/
    01200 void pgpPrtVal(const char * pre, pgpValTbl vs, rpmuint8_t val)
    01201         /*@globals fileSystem @*/
    01202         /*@modifies fileSystem @*/;
    01203 /*@=exportlocal@*/
    01204
    01212 /*@-exportlocal@*/
    01213 int pgpPrtSubType(const rpmuint8_t * h, size_t hlen, pgpSigType sigtype)
    01214         /*@globals fileSystem @*/
    01215         /*@modifies fileSystem @*/;
    01216 /*@=exportlocal@*/
    01217
    01223 /*@-exportlocal@*/
    01224 int pgpPrtSig(const pgpPkt pp)
    01225         /*@globals fileSystem, internalState @*/
    01226         /*@modifies fileSystem, internalState @*/;
    01227 /*@=exportlocal@*/
    01228
    01234 int pgpPrtKey(const pgpPkt pp)
    01235         /*@globals fileSystem, internalState @*/
    01236         /*@modifies fileSystem, internalState @*/;
    01237
    01243 /*@-exportlocal@*/
    01244 int pgpPrtUserID(const pgpPkt pp)
    01245         /*@globals fileSystem, internalState @*/
    01246         /*@modifies fileSystem, internalState @*/;
    01247 /*@=exportlocal@*/
    01248
    01254 /*@-exportlocal@*/
    01255 int pgpPrtComment(const pgpPkt pp)
    01256         /*@globals fileSystem @*/
    01257         /*@modifies fileSystem @*/;
    01258 /*@=exportlocal@*/
    01259
    01268 /*@-exportlocal@*/
    01269 int pgpPubkeyFingerprint(const rpmuint8_t * pkt, size_t pktlen,
    01270                 /*@out@*/ rpmuint8_t * keyid)
    01271         /*@modifies *keyid @*/;
    01272 /*@=exportlocal@*/
    01273
    01281 int pgpExtractPubkeyFingerprint(const char * b64pkt,
    01282                 /*@out@*/ rpmuint8_t * keyid)
    01283         /*@modifies *keyid @*/;
    01284
    01292 int pgpPktLen(const rpmuint8_t * pkt, size_t pleft, /*@out@*/ pgpPkt pp)
    01293         /*@modifies pp @*/;
    01294
    01301 /*@-exportlocal@*/
    01302 int pgpPrtPkt(const rpmuint8_t * pkt, size_t pleft)
    01303         /*@globals fileSystem, internalState @*/
    01304         /*@modifies fileSystem, internalState @*/;
    01305 /*@=exportlocal@*/
    01306
    01315 int pgpPrtPkts(const rpmuint8_t * pkts, size_t pktlen, pgpDig dig, int printing)
    01316         /*@globals fileSystem, internalState @*/
    01317         /*@modifies dig, fileSystem, internalState @*/;
    01318
    01326 pgpArmor pgpReadPkts(const char * fn,
    01327                 /*@out@*/ rpmuint8_t ** pkt, /*@out@*/ size_t * pktlen)
    01328         /*@globals h_errno, fileSystem, internalState @*/
    01329         /*@modifies *pkt, *pktlen, fileSystem, internalState @*/;
    01330
    01338 char * pgpArmorWrap(rpmuint8_t atype, const unsigned char * s, size_t ns)
    01339         /*@*/;
    01340
    01347 pgpHashAlgo pgpHashAlgoStringToNumber(const char *name, size_t name_len)
    01348         /*@*/;
    01349
    01353 /*@unchecked@*/
    01354 extern pgpVSFlags pgpDigVSFlags;
    01355
    01362 /*@unused@*/ /*@null@*/
    01363 pgpDig pgpDigUnlink (/*@killref@*/ /*@only@*/ /*@null@*/ pgpDig dig,
    01364                 /*@null@*/ const char * msg)
    01365         /*@modifies dig @*/;
    01366 #define pgpDigUnlink(_dig, _msg)        \
    01367     ((pgpDig)rpmioUnlinkPoolItem((rpmioItem)(_dig), _msg, __FILE__, __LINE__))
    01368
    01375 /*@unused@*/ /*@newref@*/ /*@null@*/
    01376 pgpDig pgpDigLink (/*@null@*/ pgpDig dig, /*@null@*/ const char * msg)
    01377         /*@modifies dig @*/;
    01378 #define pgpDigLink(_dig, _msg)  \
    01379     ((pgpDig)rpmioLinkPoolItem((rpmioItem)(_dig), _msg, __FILE__, __LINE__))
    01380
    01386 /*@unused@*/ /*@null@*/
    01387 pgpDig pgpDigFree(/*@killref@*/ /*@only@*/ /*@null@*/ pgpDig dig)
    01388         /*@modifies dig @*/;
    01389 #define pgpDigFree(_dig, _msg)       \
    01390     ((pgpDig)rpmioFreePoolItem((rpmioItem)(_dig), _msg, __FILE__, __LINE__))
    01391
    01396 /*@relnull@*/
    01397 pgpDig pgpDigNew(/*@unused@*/ pgpVSFlags vsflags)
    01398         /*@globals fileSystem @*/
    01399         /*@modifies fileSystem @*/;
    01400
    01405 void pgpDigClean(/*@null@*/ pgpDig dig)
    01406         /*@modifies dig @*/;
    01407
    01413 /*@exposed@*/
    01414 pgpDigParams pgpGetPubkey(const pgpDig dig)
    01415         /*@*/;
    01416
    01422 /*@exposed@*/
    01423 pgpDigParams pgpGetSignature(const pgpDig dig)
    01424         /*@*/;
    01425
    01431 rpmuint32_t pgpGetSigtag(const pgpDig dig)
    01432         /*@*/;
    01433
    01439 rpmuint32_t pgpGetSigtype(const pgpDig dig)
    01440         /*@*/;
    01441
    01447 /*@observer@*/ /*@null@*/
    01448 extern const void * pgpGetSig(const pgpDig dig)
    01449         /*@*/;
    01450
    01456 rpmuint32_t pgpGetSiglen(const pgpDig dig)
    01457         /*@*/;
    01458
    01468 int pgpSetSig(pgpDig dig,
    01469                 rpmuint32_t sigtag, rpmuint32_t sigtype,
    01470                 /*@kept@*/ /*@null@*/ const void * sig, rpmuint32_t siglen)
    01471         /*@modifies dig @*/;
    01472
    01479 /*@null@*/
    01480 void * pgpStatsAccumulator(pgpDig dig, int opx)
    01481         /*@*/;
    01482
    01490 int pgpSetFindPubkey(pgpDig dig,
    01491                 /*@null@*/ int (*findPubkey) (void *ts, /*@null@*/ void *dig),
    01492                 /*@exposed@*/ /*@null@*/ void * _ts)
    01493         /*@modifies dig @*/;
    01494
    01500 int pgpFindPubkey(pgpDig dig)
    01501         /*@modifies dig @*/;
    01502
    01509 /*@unused@*/ static inline
    01510 int pgpIsPkt(const rpmuint8_t * p, /*@null@*/ pgpTag * tagp)
    01511         /*@modifies *tagp @*/
    01512 {
    01513     unsigned int val = (unsigned int) *p++;
    01514     pgpTag tag;
    01515     int rc;
    01516
    01517     /* XXX can't deal with these. */
    01518     if (!(val & 0x80))
    01519         return 0;
    01520
    01521     if (val & 0x40)
    01522         tag = (pgpTag)(val & 0x3f);
    01523     else
    01524         tag = (pgpTag)((val >> 2) & 0xf);
    01525
    01526     switch (tag) {
    01527     case PGPTAG_MARKER:
    01528     case PGPTAG_SYMMETRIC_SESSION_KEY:
    01529     case PGPTAG_ONEPASS_SIGNATURE:
    01530     case PGPTAG_PUBLIC_KEY:
    01531     case PGPTAG_SECRET_KEY:
    01532     case PGPTAG_PUBLIC_SESSION_KEY:
    01533     case PGPTAG_SIGNATURE:
    01534     case PGPTAG_COMMENT:
    01535     case PGPTAG_COMMENT_OLD:
    01536     case PGPTAG_LITERAL_DATA:
    01537     case PGPTAG_COMPRESSED_DATA:
    01538     case PGPTAG_SYMMETRIC_DATA:
    01539         rc = 1;
    01540         break;
    01541     case PGPTAG_PUBLIC_SUBKEY:
    01542     case PGPTAG_SECRET_SUBKEY:
    01543     case PGPTAG_USER_ID:
    01544     case PGPTAG_RESERVED:
    01545     case PGPTAG_TRUST:
    01546     case PGPTAG_PHOTOID:
    01547     case PGPTAG_ENCRYPTED_MDC:
    01548     case PGPTAG_MDC:
    01549     case PGPTAG_PRIVATE_60:
    01550     case PGPTAG_PRIVATE_62:
    01551     case PGPTAG_CONTROL:
    01552     default:
    01553         rc = 0;
    01554         break;
    01555     }
    01556     if (tagp != NULL)
    01557         *tagp = tag;
    01558     return rc;
    01559 }
    01560
    01561 #define CRC24_INIT      0xb704ce
    01562 #define CRC24_POLY      0x1864cfb
    01563
    01570 /*@unused@*/ static inline
    01571 unsigned int pgpCRC(const rpmuint8_t * octets, size_t len)
    01572         /*@*/
    01573 {
    01574     unsigned int crc = CRC24_INIT;
    01575     int i;
    01576
    01577     while (len--) {
    01578         crc ^= (*octets++) << 16;
    01579         for (i = 0; i < 8; i++) {
    01580             crc <<= 1;
    01581             if (crc & 0x1000000)
    01582                 crc ^= CRC24_POLY;
    01583         }
    01584     }
    01585     return crc & 0xffffff;
    01586 }
    01587
    01590 typedef int (*pgpImplSet_t) (/*@only@*/ DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
    01591         /*@modifies ctx, dig @*/;
    01592
    01595 typedef int (*pgpImplVerify_t) (pgpDig dig)
    01596         /*@*/;
    01597
    01600 typedef int (*pgpImplMpiItem_t) (const char * pre, pgpDig dig, int itemno,
    01601                 const rpmuint8_t * p, /*@null@*/ const rpmuint8_t * pend)
    01602         /*@globals fileSystem @*/
    01603         /*@modifies dig, fileSystem @*/;
    01604
    01607 typedef void (*pgpImplClean_t) (void * impl)
    01608         /*@modifies impl @*/;
    01609
    01612 typedef void * (*pgpImplFree_t) (/*@only@*/ void * impl)
    01613         /*@modifies impl @*/;
    01614
    01617 typedef void * (*pgpImplInit_t) (void)
    01618         /*@*/;
    01619
    01620
    01623 typedef struct pgpImplVecs_s {
    01624     pgpImplSet_t        _pgpSetRSA;
    01625     pgpImplVerify_t     _pgpVerifyRSA;
    01626     pgpImplSet_t        _pgpSetDSA;
    01627     pgpImplVerify_t     _pgpVerifyDSA;
    01628     pgpImplSet_t        _pgpSetECDSA;
    01629     pgpImplVerify_t     _pgpVerifyECDSA;
    01630     pgpImplMpiItem_t    _pgpMpiItem;
    01631     pgpImplClean_t      _pgpClean;
    01632     pgpImplFree_t       _pgpFree;
    01633     pgpImplInit_t       _pgpInit;
    01634 } pgpImplVecs_t;
    01635
    01638 /*@unchecked@*/
    01639 extern pgpImplVecs_t * pgpImplVecs;
    01640
    01641 /*@-mustmod@*/
    01644 /*@unused@*/ static inline
    01645 int pgpImplSetRSA(/*@only@*/ DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
    01646         /*@modifies ctx, dig @*/
    01647 {
    01648     return (*pgpImplVecs->_pgpSetRSA) (ctx, dig, sigp);
    01649 }
    01650
    01653 /*@unused@*/ static inline
    01654 int pgpImplVerifyRSA(pgpDig dig)
    01655         /*@*/
    01656 {
    01657     return (*pgpImplVecs->_pgpVerifyRSA) (dig);
    01658 }
    01659
    01662 /*@unused@*/ static inline
    01663 int pgpImplSetDSA(/*@only@*/ DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
    01664         /*@modifies ctx, dig @*/
    01665 {
    01666     return (*pgpImplVecs->_pgpSetDSA) (ctx, dig, sigp);
    01667 }
    01668
    01671 /*@unused@*/ static inline
    01672 int pgpImplVerifyDSA(pgpDig dig)
    01673         /*@*/
    01674 {
    01675     return (*pgpImplVecs->_pgpVerifyDSA) (dig);
    01676 }
    01677
    01680 /*@unused@*/ static inline
    01681 int pgpImplSetECDSA(/*@only@*/ DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
    01682         /*@modifies ctx, dig @*/
    01683 {
    01684     return (*pgpImplVecs->_pgpSetECDSA) (ctx, dig, sigp);
    01685 }
    01686
    01689 /*@unused@*/ static inline
    01690 int pgpImplVerifyECDSA(pgpDig dig)
    01691         /*@*/
    01692 {
    01693     return (*pgpImplVecs->_pgpVerifyECDSA) (dig);
    01694 }
    01695
    01698 /*@unused@*/ static inline
    01699 int pgpImplMpiItem(const char * pre, pgpDig dig, int itemno,
    01700                 const rpmuint8_t * p, /*@null@*/ const rpmuint8_t * pend)
    01701         /*@modifies dig @*/
    01702 {
    01703     return (*pgpImplVecs->_pgpMpiItem) (pre, dig, itemno, p, pend);
    01704 }
    01705
    01708 /*@unused@*/ static inline
    01709 void pgpImplClean(void * impl)
    01710         /*@modifies impl @*/
    01711 {
    01712 /*@-noeffectuncon@*/
    01713     (*pgpImplVecs->_pgpClean) (impl);
    01714 /*@=noeffectuncon@*/
    01715 }
    01716
    01719 /*@unused@*/ static inline
    01720 /*@null@*/
    01721 void * pgpImplFree(/*@only@*/ void * impl)
    01722         /*@modifies impl @*/
    01723 {
    01724     return (*pgpImplVecs->_pgpFree) (impl);
    01725 }
    01726
    01729 /*@unused@*/ static inline
    01730 void * pgpImplInit(void)
    01731         /*@*/
    01732 {
    01733     return (*pgpImplVecs->_pgpInit) ();
    01734 }
    01735 /*@=mustmod@*/
    01736
    01737 #ifdef __cplusplus
    01738 }
    01739 #endif
    01740 /*@=fcnuse@*/
    01741
    01742 #endif  /* H_RPMPGP */