rpm 5.3.7

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 
00021 /*@unchecked@*/
00022 extern int _pgp_error_count;
00023 
00027 struct pgpDigParams_s {
00028 /*@only@*/ /*@null@*/
00029     const char * userid;
00030 /*@dependent@*/ /*@null@*/
00031     const rpmuint8_t * hash;
00032     rpmuint8_t tag;
00033 
00034     rpmuint8_t version;         
00035     rpmuint8_t time[4];         
00036     rpmuint8_t pubkey_algo;     
00038     rpmuint8_t hash_algo;
00039     rpmuint8_t sigtype;
00040     size_t hashlen;
00041     rpmuint8_t signhash16[2];
00042     rpmuint8_t signid[8];
00043     rpmuint8_t expire[4];       
00044     rpmuint8_t keyexpire[4];    
00046     rpmuint8_t saved;
00047 #define PGPDIG_SAVED_TIME       (1 << 0)
00048 #define PGPDIG_SAVED_ID         (1 << 1)
00049 
00050 };
00051 
00055 struct pgpDig_s {
00056     struct rpmioItem_s _item;   
00057     struct pgpDigParams_s signature;
00058     struct pgpDigParams_s pubkey;
00059 
00060 /*@observer@*/ /*@null@*/
00061     const char * pubkey_algoN;
00062 /*@observer@*/ /*@null@*/
00063     const char * hash_algoN;
00064 
00065     rpmuint32_t sigtag;         
00066     rpmuint32_t sigtype;        
00067 /*@relnull@*/
00068     const void * sig;           
00069     size_t siglen;              
00070     const void * pub;           
00071     size_t publen;              
00073     pgpVSFlags vsflags;         
00074     struct rpmop_s dops;        
00075     struct rpmop_s sops;        
00077     int (*findPubkey) (void * _ts, /*@null@*/ void * _dig)
00078         /*@modifies *_ts, *_dig @*/;
00079 /*@null@*/
00080     void * _ts;                 
00082     rpmuint8_t ** ppkts;
00083     int npkts;
00084     size_t nbytes;              
00086 /*@only@*/ /*@null@*/
00087     DIGEST_CTX sha1ctx;         
00088 /*@only@*/ /*@null@*/
00089     DIGEST_CTX hdrsha1ctx;      
00090 /*@only@*/ /*@null@*/
00091     void * sha1;                
00092     size_t sha1len;             
00094 /*@only@*/ /*@null@*/
00095     DIGEST_CTX md5ctx;          
00096 /*@only@*/ /*@null@*/
00097     DIGEST_CTX hdrctx;          
00098 /*@only@*/ /*@null@*/
00099     void * md5;                 
00100     size_t md5len;              
00102 /*@owned@*/ /*@relnull@*/
00103     void * impl;                
00105 #if defined(__LCLINT__)
00106 /*@refs@*/
00107     int nrefs;                  
00108 #endif
00109 };
00110 #endif  /* _RPMPGP_INTERNAL */
00111 
00114 typedef const struct pgpValTbl_s {
00115     int val;
00116 /*@observer@*/
00117     const char * str;
00118 } * pgpValTbl;
00119  
00127 typedef enum pgpTag_e {
00128     PGPTAG_RESERVED             =  0, 
00129     PGPTAG_PUBLIC_SESSION_KEY   =  1, 
00130     PGPTAG_SIGNATURE            =  2, 
00131     PGPTAG_SYMMETRIC_SESSION_KEY=  3, 
00132     PGPTAG_ONEPASS_SIGNATURE    =  4, 
00133     PGPTAG_SECRET_KEY           =  5, 
00134     PGPTAG_PUBLIC_KEY           =  6, 
00135     PGPTAG_SECRET_SUBKEY        =  7, 
00136     PGPTAG_COMPRESSED_DATA      =  8, 
00137     PGPTAG_SYMMETRIC_DATA       =  9, 
00138     PGPTAG_MARKER               = 10, 
00139     PGPTAG_LITERAL_DATA         = 11, 
00140     PGPTAG_TRUST                = 12, 
00141     PGPTAG_USER_ID              = 13, 
00142     PGPTAG_PUBLIC_SUBKEY        = 14, 
00143     PGPTAG_COMMENT_OLD          = 16, 
00144     PGPTAG_PHOTOID              = 17, 
00145     PGPTAG_ENCRYPTED_MDC        = 18, 
00146     PGPTAG_MDC                  = 19, 
00147     PGPTAG_PRIVATE_60           = 60, 
00148     PGPTAG_COMMENT              = 61, 
00149     PGPTAG_PRIVATE_62           = 62, 
00150     PGPTAG_CONTROL              = 63  
00151 } pgpTag;
00152 
00155 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00156 extern struct pgpValTbl_s pgpTagTbl[];
00157 
00192 typedef struct pgpPktPubkey_s {
00193     rpmuint8_t version;         
00194     rpmuint8_t keyid[8];        
00195     rpmuint8_t algo;            
00196 } pgpPktPubkey;
00197 
00204 /*@-typeuse@*/
00205 typedef enum pgpSigType_e {
00206     PGPSIGTYPE_BINARY            = 0x00, 
00207     PGPSIGTYPE_TEXT              = 0x01, 
00208     PGPSIGTYPE_STANDALONE        = 0x02, 
00209     PGPSIGTYPE_GENERIC_CERT      = 0x10,
00211     PGPSIGTYPE_PERSONA_CERT      = 0x11,
00213     PGPSIGTYPE_CASUAL_CERT       = 0x12,
00215     PGPSIGTYPE_POSITIVE_CERT     = 0x13,
00217     PGPSIGTYPE_SUBKEY_BINDING    = 0x18, 
00218     PGPSIGTYPE_KEY_BINDING       = 0x19, 
00219     PGPSIGTYPE_SIGNED_KEY        = 0x1F, 
00220     PGPSIGTYPE_KEY_REVOKE        = 0x20, 
00221     PGPSIGTYPE_SUBKEY_REVOKE     = 0x28, 
00222     PGPSIGTYPE_CERT_REVOKE       = 0x30, 
00223     PGPSIGTYPE_TIMESTAMP         = 0x40, 
00224     PGPSIGTYPE_CONFIRM           = 0x50  
00225 } pgpSigType;
00226 /*@=typeuse@*/
00227 
00230 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00231 extern struct pgpValTbl_s pgpSigTypeTbl[];
00232 
00256 /*@-typeuse@*/
00257 typedef enum pgpPubkeyAlgo_e {
00258     PGPPUBKEYALGO_RSA           =  1,   
00259     PGPPUBKEYALGO_RSA_ENCRYPT   =  2,   
00260     PGPPUBKEYALGO_RSA_SIGN      =  3,   
00261     PGPPUBKEYALGO_ELGAMAL_ENCRYPT = 16, 
00262     PGPPUBKEYALGO_DSA           = 17,   
00263     PGPPUBKEYALGO_EC            = 18,   
00264     PGPPUBKEYALGO_ECDSA         = 19,   
00265     PGPPUBKEYALGO_ELGAMAL       = 20,   
00266     PGPPUBKEYALGO_DH            = 21,   
00267     PGPPUBKEYALGO_ECDH          = 22    
00268 } pgpPubkeyAlgo;
00269 /*@=typeuse@*/
00270 
00273 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00274 extern struct pgpValTbl_s pgpPubkeyTbl[];
00275 
00301 /*@-typeuse@*/
00302 typedef enum pgpSymkeyAlgo_e {
00303     PGPSYMKEYALGO_PLAINTEXT     =  0,   
00304     PGPSYMKEYALGO_IDEA          =  1,   
00305     PGPSYMKEYALGO_TRIPLE_DES    =  2,   
00306     PGPSYMKEYALGO_CAST5         =  3,   
00307     PGPSYMKEYALGO_BLOWFISH      =  4,   
00308     PGPSYMKEYALGO_SAFER         =  5,   
00309     PGPSYMKEYALGO_DES_SK        =  6,   
00310     PGPSYMKEYALGO_AES_128       =  7,   
00311     PGPSYMKEYALGO_AES_192       =  8,   
00312     PGPSYMKEYALGO_AES_256       =  9,   
00313     PGPSYMKEYALGO_TWOFISH       = 10,   
00314     PGPSYMKEYALGO_CAMELLIA_128  = 11,   
00315     PGPSYMKEYALGO_CAMELLIA_192  = 12,   
00316     PGPSYMKEYALGO_CAMELLIA_256  = 13,   
00317     PGPSYMKEYALGO_NOENCRYPT     = 110   
00318 } pgpSymkeyAlgo;
00319 /*@=typeuse@*/
00320 
00324 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00325 extern struct pgpValTbl_s pgpSymkeyTbl[];
00326 
00342 /*@-typeuse@*/
00343 typedef enum pgpCompressAlgo_e {
00344     PGPCOMPRESSALGO_NONE        =  0,   
00345     PGPCOMPRESSALGO_ZIP         =  1,   
00346     PGPCOMPRESSALGO_ZLIB        =  2,   
00347     PGPCOMPRESSALGO_BZIP2       =  3    
00348 } pgpCompressAlgo;
00349 /*@=typeuse@*/
00350 
00354 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00355 extern struct pgpValTbl_s pgpCompressionTbl[];
00356 
00360 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00361 extern struct pgpValTbl_s pgpHashTbl[];
00362 
00384 typedef struct pgpPktSigV3_s {
00385     rpmuint8_t version; 
00386     rpmuint8_t hashlen; 
00387     rpmuint8_t sigtype; 
00388     rpmuint8_t time[4]; 
00389     rpmuint8_t signid[8];       
00390     rpmuint8_t pubkey_algo;     
00391     rpmuint8_t hash_algo;       
00392     rpmuint8_t signhash16[2];   
00393 } * pgpPktSigV3;
00394 
00416 typedef struct pgpPktSigV4_s {
00417     rpmuint8_t version;         
00418     rpmuint8_t sigtype;         
00419     rpmuint8_t pubkey_algo;     
00420     rpmuint8_t hash_algo;       
00421     rpmuint8_t hashlen[2];      
00422 } * pgpPktSigV4;
00423 
00502 /*@-typeuse@*/
00503 typedef enum pgpSubType_e {
00504     PGPSUBTYPE_NONE             =   0, 
00505     PGPSUBTYPE_SIG_CREATE_TIME  =   2, 
00506     PGPSUBTYPE_SIG_EXPIRE_TIME  =   3, 
00507     PGPSUBTYPE_EXPORTABLE_CERT  =   4, 
00508     PGPSUBTYPE_TRUST_SIG        =   5, 
00509     PGPSUBTYPE_REGEX            =   6, 
00510     PGPSUBTYPE_REVOCABLE        =   7, 
00511     PGPSUBTYPE_KEY_EXPIRE_TIME  =   9, 
00512     PGPSUBTYPE_ARR              =  10, 
00513     PGPSUBTYPE_PREFER_SYMKEY    =  11, 
00514     PGPSUBTYPE_REVOKE_KEY       =  12, 
00515     PGPSUBTYPE_ISSUER_KEYID     =  16, 
00516     PGPSUBTYPE_NOTATION         =  20, 
00517     PGPSUBTYPE_PREFER_HASH      =  21, 
00518     PGPSUBTYPE_PREFER_COMPRESS  =  22, 
00519     PGPSUBTYPE_KEYSERVER_PREFERS=  23, 
00520     PGPSUBTYPE_PREFER_KEYSERVER =  24, 
00521     PGPSUBTYPE_PRIMARY_USERID   =  25, 
00522     PGPSUBTYPE_POLICY_URL       =  26, 
00523     PGPSUBTYPE_KEY_FLAGS        =  27, 
00524     PGPSUBTYPE_SIGNER_USERID    =  28, 
00525     PGPSUBTYPE_REVOKE_REASON    =  29, 
00526     PGPSUBTYPE_FEATURES         =  30, 
00527     PGPSUBTYPE_SIG_TARGET       =  31, 
00528     PGPSUBTYPE_EMBEDDED_SIG     =  32, 
00530     PGPSUBTYPE_INTERNAL_100     = 100, 
00531     PGPSUBTYPE_INTERNAL_101     = 101, 
00532     PGPSUBTYPE_INTERNAL_102     = 102, 
00533     PGPSUBTYPE_INTERNAL_103     = 103, 
00534     PGPSUBTYPE_INTERNAL_104     = 104, 
00535     PGPSUBTYPE_INTERNAL_105     = 105, 
00536     PGPSUBTYPE_INTERNAL_106     = 106, 
00537     PGPSUBTYPE_INTERNAL_107     = 107, 
00538     PGPSUBTYPE_INTERNAL_108     = 108, 
00539     PGPSUBTYPE_INTERNAL_109     = 109, 
00540     PGPSUBTYPE_INTERNAL_110     = 110, 
00542     PGPSUBTYPE_CRITICAL         = 128  
00543 } pgpSubType;
00544 /*@=typeuse@*/
00545 
00549 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00550 extern struct pgpValTbl_s pgpSubTypeTbl[];
00551 
00572 typedef union pgpPktSig_u {
00573     struct pgpPktSigV3_s v3;
00574     struct pgpPktSigV4_s v4;
00575 } * pgpPktSig;
00576 
00605 typedef struct pgpPktSymkey_s {
00606     rpmuint8_t version; 
00607     rpmuint8_t symkey_algo;
00608     rpmuint8_t s2k[1];
00609 } pgpPktSymkey;
00610 
00640 typedef struct pgpPktOnepass_s {
00641     rpmuint8_t version;         
00642     rpmuint8_t sigtype;         
00643     rpmuint8_t hash_algo;       
00644     rpmuint8_t pubkey_algo;     
00645     rpmuint8_t signid[8];       
00646     rpmuint8_t nested;
00647 } * pgpPktOnepass;
00648 
00721 typedef struct pgpPktKeyV3_s {
00722     rpmuint8_t version;         
00723     rpmuint8_t time[4];         
00724     rpmuint8_t valid[2];        
00725     rpmuint8_t pubkey_algo;     
00726 } * pgpPktKeyV3;
00727 
00759 typedef struct pgpPktKeyV4_s {
00760     rpmuint8_t version;         
00761     rpmuint8_t time[4];         
00762     rpmuint8_t pubkey_algo;     
00763 } * pgpPktKeyV4;
00764 
00829 typedef union pgpPktKey_u {
00830     struct pgpPktKeyV3_s v3;
00831     struct pgpPktKeyV4_s v4;
00832 } pgpPktKey;
00833 
00858 typedef struct pgpPktCdata_s {
00859     rpmuint8_t compressalgo;
00860     rpmuint8_t data[1];
00861 } pgpPktCdata;
00862 
00897 typedef struct pgpPktEdata_s {
00898     rpmuint8_t data[1];
00899 } pgpPktEdata;
00900 
00917 /*
00918  * 5.9. Literal Data Packet (Tag 11)
00919  *
00920  * A Literal Data packet contains the body of a message; data that is
00921  * not to be further interpreted.
00922  *
00923  * The body of this packet consists of:
00924  *   - A one-octet field that describes how the data is formatted.
00925  *
00926  * If it is a 'b' (0x62), then the literal packet contains binary data.
00927  * If it is a 't' (0x74), then it contains text data, and thus may need
00928  * line ends converted to local form, or other text-mode changes.  RFC
00929  * 1991 also defined a value of 'l' as a 'local' mode for machine-local
00930  * conversions.  This use is now deprecated.
00931  *   - File name as a string (one-octet length, followed by file name),
00932  *     if the encrypted data should be saved as a file.
00933  *
00934  * If the special name "_CONSOLE" is used, the message is considered to
00935  * be "for your eyes only".  This advises that the message data is
00936  * unusually sensitive, and the receiving program should process it more
00937  * carefully, perhaps avoiding storing the received data to disk, for
00938  * example.
00939  *   - A four-octet number that indicates the modification date of the
00940  *     file, or the creation time of the packet, or a zero that
00941  *     indicates the present time.
00942  *   - The remainder of the packet is literal data.
00943  *
00944  * Text data is stored with <CR><LF> text endings (i.e. network-normal
00945  * line endings).  These should be converted to native line endings by
00946  * the receiving software.
00947  */
00948 typedef struct pgpPktLdata_s {
00949     rpmuint8_t format;
00950     rpmuint8_t filenamelen;
00951     rpmuint8_t filename[1];
00952 } pgpPktLdata;
00953 
00967 typedef struct pgpPktTrust_s {
00968     rpmuint8_t flag;
00969 } pgpPktTrust;
00970 
00981 typedef struct pgpPktUid_s {
00982     rpmuint8_t userid[1];
00983 } pgpPktUid;
00984 
00987 /*@-typeuse@*/
00988 typedef enum pgpArmor_e {
00989     PGPARMOR_ERR_CRC_CHECK              = -7,
00990     PGPARMOR_ERR_BODY_DECODE            = -6,
00991     PGPARMOR_ERR_CRC_DECODE             = -5,
00992     PGPARMOR_ERR_NO_END_PGP             = -4,
00993     PGPARMOR_ERR_UNKNOWN_PREAMBLE_TAG   = -3,
00994     PGPARMOR_ERR_UNKNOWN_ARMOR_TYPE     = -2,
00995     PGPARMOR_ERR_NO_BEGIN_PGP           = -1,
00996 #define PGPARMOR_ERROR  PGPARMOR_ERR_NO_BEGIN_PGP
00997     PGPARMOR_NONE               =  0,
00998     PGPARMOR_MESSAGE            =  1, 
00999     PGPARMOR_PUBKEY             =  2, 
01000     PGPARMOR_SIGNATURE          =  3, 
01001     PGPARMOR_SIGNED_MESSAGE     =  4, 
01002     PGPARMOR_FILE               =  5, 
01003     PGPARMOR_PRIVKEY            =  6, 
01004     PGPARMOR_SECKEY             =  7  
01005 } pgpArmor;
01006 /*@=typeuse@*/
01007 
01011 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
01012 extern struct pgpValTbl_s pgpArmorTbl[];
01013 
01016 /*@-typeuse@*/
01017 typedef enum pgpArmorKey_e {
01018     PGPARMORKEY_VERSION         = 1, 
01019     PGPARMORKEY_COMMENT         = 2, 
01020     PGPARMORKEY_MESSAGEID       = 3, 
01021     PGPARMORKEY_HASH            = 4, 
01022     PGPARMORKEY_CHARSET         = 5  
01023 } pgpArmorKey;
01024 /*@=typeuse@*/
01025 
01029 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
01030 extern struct pgpValTbl_s pgpArmorKeyTbl[];
01031 
01032 #if defined(_RPMPGP_INTERNAL)
01033 
01035 union pgpPktPre_u {
01036     pgpPktPubkey pubkey;        
01037     pgpPktSig sig;              
01038     pgpPktSymkey symkey;        
01039     pgpPktOnepass onepass;      
01040     pgpPktKey key;              
01041     pgpPktCdata cdata;          
01042     pgpPktEdata edata;          
01044     pgpPktLdata ldata;          
01045     pgpPktTrust tdata;          
01046     pgpPktUid uid;              
01047 };
01048 
01049 struct pgpPkt_s {
01050     pgpTag tag;
01051     unsigned int pktlen;
01052     union {
01053         const rpmuint8_t * h;
01054         const pgpPktKeyV3 j;
01055         const pgpPktKeyV4 k;
01056         const pgpPktSigV3 r;
01057         const pgpPktSigV4 s;
01058         const pgpPktUid * u;
01059     } u;
01060     unsigned int hlen;
01061 };
01062 #endif  /* _RPMPGP_INTERNAL */
01063 
01064 /*@-fcnuse@*/
01065 #ifdef __cplusplus
01066 extern "C" {
01067 #endif
01068 
01075 /*@unused@*/ static inline
01076 unsigned int pgpGrab(const rpmuint8_t * s, size_t nbytes)
01077         /*@*/
01078 {
01079     unsigned int i = 0;
01080     size_t nb = (nbytes <= sizeof(i) ? nbytes : sizeof(i));
01081     while (nb--)
01082         i = (i << 8) | *s++;
01083     return i;
01084 }
01085 
01092 /*@unused@*/ static inline
01093 unsigned int pgpLen(const rpmuint8_t * s, /*@out@*/ unsigned int * lenp)
01094         /*@modifies *lenp @*/
01095 {
01096     if (*s < (rpmuint8_t)192) {
01097         *lenp = (unsigned int) *s++;
01098         return 1;
01099     } else if (*s < (rpmuint8_t)255) {
01100         *lenp = (unsigned int) ((((unsigned)s[0]) - 192) << 8) + (unsigned)s[1] + 192;
01101         return 2;
01102     } else {
01103         *lenp = pgpGrab(s+1, 4);
01104         return 5;
01105     }
01106 }
01107 
01113 /*@unused@*/ static inline
01114 unsigned int pgpMpiBits(const rpmuint8_t * p)
01115         /*@requires maxRead(p) >= 1 @*/
01116         /*@*/
01117 {
01118     return (unsigned int) ((p[0] << 8) | p[1]);
01119 }
01120 
01126 /*@unused@*/ static inline
01127 unsigned int pgpMpiLen(const rpmuint8_t * p)
01128         /*@requires maxRead(p) >= 1 @*/
01129         /*@*/
01130 {
01131     return (2 + ((pgpMpiBits(p)+7)>>3));
01132 }
01133         
01141 /*@unused@*/ static inline
01142 char * pgpHexCvt(/*@returned@*/ char * t, const rpmuint8_t * s, size_t nbytes)
01143         /*@modifies *t @*/
01144 {
01145     static char hex[] = "0123456789abcdef";
01146     while (nbytes-- > 0) {
01147         unsigned int i;
01148         i = (unsigned int) *s++;
01149         *t++ = hex[ (i >> 4) & 0xf ];
01150         *t++ = hex[ (i     ) & 0xf ];
01151     }
01152     *t = '\0';
01153     return t;
01154 }
01155 
01163 /*@unused@*/ static inline /*@observer@*/
01164 char * pgpHexStr(const rpmuint8_t * p, size_t plen)
01165         /*@*/
01166 {
01167     static char prbuf[8*BUFSIZ];        /* XXX ick */
01168     char *t = prbuf;
01169     t = pgpHexCvt(t, p, plen);
01170     return prbuf;
01171 }
01172 
01179 /*@unused@*/ static inline /*@observer@*/
01180 const char * pgpMpiStr(const rpmuint8_t * p)
01181         /*@requires maxRead(p) >= 3 @*/
01182         /*@*/
01183 {
01184     static char prbuf[8*BUFSIZ];        /* XXX ick */
01185     char *t = prbuf;
01186     sprintf(t, "[%4u]: ", pgpGrab(p, 2));
01187     t += strlen(t);
01188     t = pgpHexCvt(t, p+2, pgpMpiLen(p)-2);
01189     return prbuf;
01190 }
01191 
01198 /*@unused@*/ static inline /*@observer@*/
01199 const char * pgpValStr(pgpValTbl vs, rpmuint8_t val)
01200         /*@*/
01201 {
01202     do {
01203         if (vs->val == (int)val)
01204             break;
01205     } while ((++vs)->val != -1);
01206     return vs->str;
01207 }
01208 
01216 /*@unused@*/ static inline
01217 int pgpValTok(pgpValTbl vs, const char * s, const char * se)
01218         /*@*/
01219 {
01220     do {
01221         size_t vlen = strlen(vs->str);
01222         if (vlen <= (size_t)(se-s) && !strncmp(s, vs->str, vlen))
01223             break;
01224     } while ((++vs)->val != -1);
01225     return vs->val;
01226 }
01227 
01234 /*@-exportlocal@*/
01235 void pgpPrtVal(const char * pre, pgpValTbl vs, rpmuint8_t val)
01236         /*@globals fileSystem @*/
01237         /*@modifies fileSystem @*/;
01238 /*@=exportlocal@*/
01239 
01247 #if defined(_RPMPGP_INTERNAL)
01248 /*@-exportlocal@*/
01249 int pgpPrtSubType(const rpmuint8_t * h, size_t hlen, pgpSigType sigtype)
01250         /*@globals fileSystem @*/
01251         /*@modifies fileSystem @*/;
01252 /*@=exportlocal@*/
01253 #endif
01254 
01260 #if defined(_RPMPGP_INTERNAL)
01261 /*@-exportlocal@*/
01262 int pgpPrtSig(const pgpPkt pp)
01263         /*@globals fileSystem, internalState @*/
01264         /*@modifies fileSystem, internalState @*/;
01265 
01266 int pgpPrtSigParams(pgpDig dig, const pgpPkt pp, pgpPubkeyAlgo pubkey_algo,
01267                 pgpSigType sigtype, const rpmuint8_t * p)
01268         /*@globals fileSystem @*/
01269         /*@modifies fileSystem @*/;
01270 
01271 const rpmuint8_t * pgpPrtPubkeyParams(pgpDig dig, const pgpPkt pp,
01272                 pgpPubkeyAlgo pubkey_algo, /*@returned@*/ const rpmuint8_t * p)
01273         /*@globals fileSystem, internalState @*/
01274         /*@modifies fileSystem, internalState @*/;
01275 
01276 /*@=exportlocal@*/
01277 #endif
01278 
01284 #if defined(_RPMPGP_INTERNAL)
01285 int pgpPrtKey(const pgpPkt pp)
01286         /*@globals fileSystem, internalState @*/
01287         /*@modifies fileSystem, internalState @*/;
01288 #endif
01289 
01295 #if defined(_RPMPGP_INTERNAL)
01296 /*@-exportlocal@*/
01297 int pgpPrtUserID(const pgpPkt pp)
01298         /*@globals fileSystem, internalState @*/
01299         /*@modifies fileSystem, internalState @*/;
01300 /*@=exportlocal@*/
01301 #endif
01302 
01308 #if defined(_RPMPGP_INTERNAL)
01309 /*@-exportlocal@*/
01310 int pgpPrtComment(const pgpPkt pp)
01311         /*@globals fileSystem @*/
01312         /*@modifies fileSystem @*/;
01313 /*@=exportlocal@*/
01314 #endif
01315 
01324 /*@-exportlocal@*/
01325 int pgpPubkeyFingerprint(const rpmuint8_t * pkt, size_t pktlen,
01326                 /*@out@*/ rpmuint8_t * keyid)
01327         /*@modifies *keyid @*/;
01328 /*@=exportlocal@*/
01329 
01337 int pgpExtractPubkeyFingerprint(const char * b64pkt,
01338                 /*@out@*/ rpmuint8_t * keyid)
01339         /*@modifies *keyid @*/;
01340 
01348 #if defined(_RPMPGP_INTERNAL)
01349 int pgpPktLen(const rpmuint8_t * pkt, size_t pleft, /*@out@*/ pgpPkt pp)
01350         /*@modifies pp @*/;
01351 #endif
01352 
01359 /*@-exportlocal@*/
01360 int pgpPrtPkt(const rpmuint8_t * pkt, size_t pleft)
01361         /*@globals fileSystem, internalState @*/
01362         /*@modifies fileSystem, internalState @*/;
01363 /*@=exportlocal@*/
01364 
01373 int pgpGrabPkts(const rpmuint8_t * pkts, size_t pktlen,
01374                 /*@out@*/ rpmuint8_t *** pppkts, /*@out@*/ int * pnpkts)
01375         /*@modifies *pppkts, *pnpkts @*/;
01376 
01385 int pgpPrtPkts(const rpmuint8_t * pkts, size_t pktlen, pgpDig dig, int printing)
01386         /*@globals fileSystem, internalState @*/
01387         /*@modifies dig, fileSystem, internalState @*/;
01388 
01396 pgpArmor pgpArmorUnwrap(rpmiob iob,
01397                 /*@out@*/ rpmuint8_t ** pkt, /*@out@*/ size_t * pktlen)
01398         /*@globals h_errno, fileSystem, internalState @*/
01399         /*@modifies *pkt, *pktlen, fileSystem, internalState @*/;
01400 
01408 pgpArmor pgpReadPkts(const char * fn,
01409                 /*@out@*/ rpmuint8_t ** pkt, /*@out@*/ size_t * pktlen)
01410         /*@globals h_errno, fileSystem, internalState @*/
01411         /*@modifies *pkt, *pktlen, fileSystem, internalState @*/;
01412 
01420 char * pgpArmorWrap(rpmuint8_t atype, const unsigned char * s, size_t ns)
01421         /*@*/;
01422 
01429 pgpHashAlgo pgpHashAlgoStringToNumber(const char *name, size_t name_len)
01430         /*@*/;
01431 
01435 /*@unchecked@*/
01436 extern pgpVSFlags pgpDigVSFlags;
01437 
01443 /*@unused@*/ /*@null@*/
01444 pgpDig pgpDigUnlink (/*@killref@*/ /*@only@*/ /*@null@*/ pgpDig dig)
01445         /*@modifies dig @*/;
01446 #define pgpDigUnlink(_dig)      \
01447     ((pgpDig)rpmioUnlinkPoolItem((rpmioItem)(_dig), __FUNCTION__, __FILE__, __LINE__))
01448 
01454 /*@unused@*/ /*@newref@*/ /*@null@*/
01455 pgpDig pgpDigLink (/*@null@*/ pgpDig dig)
01456         /*@modifies dig @*/;
01457 #define pgpDigLink(_dig)        \
01458     ((pgpDig)rpmioLinkPoolItem((rpmioItem)(_dig), __FUNCTION__, __FILE__, __LINE__))
01459 
01465 /*@unused@*/ /*@null@*/
01466 pgpDig pgpDigFree(/*@killref@*/ /*@only@*/ /*@null@*/ pgpDig dig)
01467         /*@modifies dig @*/;
01468 #define pgpDigFree(_dig)        \
01469     ((pgpDig)rpmioFreePoolItem((rpmioItem)(_dig), __FUNCTION__, __FILE__, __LINE__))
01470 
01478 /*@relnull@*/
01479 pgpDig pgpDigNew(pgpVSFlags vsflags, pgpPubkeyAlgo pubkey_algo)
01480         /*@globals fileSystem @*/
01481         /*@modifies fileSystem @*/;
01482 int rpmbcExportPubkey(pgpDig dig)
01483         /*@*/;
01484 int rpmbcExportSignature(pgpDig dig, /*@only@*/ DIGEST_CTX ctx)
01485         /*@*/;
01486 
01491 void pgpDigClean(/*@null@*/ pgpDig dig)
01492         /*@modifies dig @*/;
01493 
01499 /*@exposed@*/
01500 pgpDigParams pgpGetPubkey(const pgpDig dig)
01501         /*@*/;
01502 
01508 /*@exposed@*/
01509 pgpDigParams pgpGetSignature(const pgpDig dig)
01510         /*@*/;
01511 
01517 rpmuint32_t pgpGetSigtag(const pgpDig dig)
01518         /*@*/;
01519 
01525 rpmuint32_t pgpGetSigtype(const pgpDig dig)
01526         /*@*/;
01527 
01533 /*@observer@*/ /*@null@*/
01534 extern const void * pgpGetSig(const pgpDig dig)
01535         /*@*/;
01536 
01542 rpmuint32_t pgpGetSiglen(const pgpDig dig)
01543         /*@*/;
01544 
01554 int pgpSetSig(pgpDig dig,
01555                 rpmuint32_t sigtag, rpmuint32_t sigtype,
01556                 /*@kept@*/ /*@null@*/ const void * sig, rpmuint32_t siglen)
01557         /*@modifies dig @*/;
01558 
01565 /*@null@*/
01566 void * pgpStatsAccumulator(pgpDig dig, int opx)
01567         /*@*/;
01568 
01576 int pgpSetFindPubkey(pgpDig dig,
01577                 /*@null@*/ int (*findPubkey) (void *ts, /*@null@*/ void *dig),
01578                 /*@exposed@*/ /*@null@*/ void * _ts)
01579         /*@modifies dig @*/;
01580 
01586 int pgpFindPubkey(pgpDig dig)
01587         /*@modifies dig @*/;
01588 
01595 /*@unused@*/ static inline
01596 int pgpIsPkt(const rpmuint8_t * p, /*@null@*/ pgpTag * tagp)
01597         /*@modifies *tagp @*/
01598 {
01599     unsigned int val = (unsigned int) *p++;
01600     pgpTag tag;
01601     int rc;
01602 
01603     /* XXX can't deal with these. */
01604     if (!(val & 0x80))
01605         return 0;
01606 
01607     if (val & 0x40)
01608         tag = (pgpTag)(val & 0x3f);
01609     else
01610         tag = (pgpTag)((val >> 2) & 0xf);
01611 
01612     switch (tag) {
01613     case PGPTAG_MARKER:
01614     case PGPTAG_SYMMETRIC_SESSION_KEY:
01615     case PGPTAG_ONEPASS_SIGNATURE:
01616     case PGPTAG_PUBLIC_KEY:
01617     case PGPTAG_SECRET_KEY:
01618     case PGPTAG_PUBLIC_SESSION_KEY:
01619     case PGPTAG_SIGNATURE:
01620     case PGPTAG_COMMENT:
01621     case PGPTAG_COMMENT_OLD:
01622     case PGPTAG_LITERAL_DATA:
01623     case PGPTAG_COMPRESSED_DATA:
01624     case PGPTAG_SYMMETRIC_DATA:
01625         rc = 1;
01626         break;
01627     case PGPTAG_PUBLIC_SUBKEY:
01628     case PGPTAG_SECRET_SUBKEY:
01629     case PGPTAG_USER_ID:
01630     case PGPTAG_RESERVED:
01631     case PGPTAG_TRUST:
01632     case PGPTAG_PHOTOID:
01633     case PGPTAG_ENCRYPTED_MDC:
01634     case PGPTAG_MDC:
01635     case PGPTAG_PRIVATE_60:
01636     case PGPTAG_PRIVATE_62:
01637     case PGPTAG_CONTROL:
01638     default:
01639         rc = 0;
01640         break;
01641     }
01642     if (tagp != NULL)
01643         *tagp = tag;
01644     return rc;
01645 }
01646 
01647 #define CRC24_INIT      0xb704ce
01648 #define CRC24_POLY      0x1864cfb
01649 
01656 /*@unused@*/ static inline
01657 unsigned int pgpCRC(const rpmuint8_t * octets, size_t len)
01658         /*@*/
01659 {
01660     unsigned int crc = CRC24_INIT;
01661     int i;
01662 
01663     while (len--) {
01664         crc ^= (*octets++) << 16;
01665         for (i = 0; i < 8; i++) {
01666             crc <<= 1;
01667             if (crc & 0x1000000)
01668                 crc ^= CRC24_POLY;
01669         }
01670     }
01671     return crc & 0xffffff;
01672 }
01673 
01676 typedef int (*pgpImplSet_t) (/*@only@*/ DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
01677         /*@modifies ctx, dig @*/;
01678 
01681 typedef int (*pgpImplErrChk_t) (pgpDig dig, const char * msg, int rc, unsigned expected)
01682         /*@*/;
01683 
01686 typedef int (*pgpImplAvailable_t) (pgpDig dig, int algo)
01687         /*@*/;
01688 
01691 typedef int (*pgpImplGenerate_t) (pgpDig dig)
01692         /*@*/;
01693 
01696 typedef int (*pgpImplSign_t) (pgpDig dig)
01697         /*@*/;
01698 
01701 typedef int (*pgpImplVerify_t) (pgpDig dig)
01702         /*@*/;
01703 
01706 typedef int (*pgpImplMpiItem_t) (const char * pre, pgpDig dig, int itemno,
01707                 const rpmuint8_t * p, /*@null@*/ const rpmuint8_t * pend)
01708         /*@globals fileSystem @*/
01709         /*@modifies dig, fileSystem @*/;
01710 
01713 typedef void (*pgpImplClean_t) (void * impl)
01714         /*@modifies impl @*/;
01715 
01718 typedef void * (*pgpImplFree_t) (/*@only@*/ void * impl)
01719         /*@modifies impl @*/;
01720 
01723 typedef void * (*pgpImplInit_t) (void)
01724         /*@*/;
01725 
01726 
01729 typedef struct pgpImplVecs_s {
01730     pgpImplSet_t        _pgpSetRSA;
01731     pgpImplSet_t        _pgpSetDSA;
01732     pgpImplSet_t        _pgpSetELG;
01733     pgpImplSet_t        _pgpSetECDSA;
01734 
01735     pgpImplErrChk_t     _pgpErrChk;
01736     pgpImplAvailable_t  _pgpAvailableCipher;
01737     pgpImplAvailable_t  _pgpAvailableDigest;
01738     pgpImplAvailable_t  _pgpAvailablePubkey;
01739 
01740     pgpImplVerify_t     _pgpVerify;
01741     pgpImplSign_t       _pgpSign;
01742     pgpImplGenerate_t   _pgpGenerate;
01743 
01744     pgpImplMpiItem_t    _pgpMpiItem;
01745     pgpImplClean_t      _pgpClean;
01746     pgpImplFree_t       _pgpFree;
01747     pgpImplInit_t       _pgpInit;
01748 } pgpImplVecs_t;
01749 
01752 /*@unchecked@*/
01753 extern pgpImplVecs_t * pgpImplVecs;
01754 
01755 /*@-mustmod@*/
01758 /*@unused@*/ static inline
01759 int pgpImplSetRSA(/*@only@*/ DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
01760         /*@modifies ctx, dig @*/
01761 {
01762     return (*pgpImplVecs->_pgpSetRSA) (ctx, dig, sigp);
01763 }
01764 
01767 /*@unused@*/ static inline
01768 int pgpImplSetDSA(/*@only@*/ DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
01769         /*@modifies ctx, dig @*/
01770 {
01771     return (*pgpImplVecs->_pgpSetDSA) (ctx, dig, sigp);
01772 }
01773 
01776 /*@unused@*/ static inline
01777 int pgpImplSetELG(/*@only@*/ DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
01778         /*@modifies ctx, dig @*/
01779 {
01780     return (*pgpImplVecs->_pgpSetELG) (ctx, dig, sigp);
01781 }
01782 
01785 /*@unused@*/ static inline
01786 int pgpImplSetECDSA(/*@only@*/ DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
01787         /*@modifies ctx, dig @*/
01788 {
01789     return (*pgpImplVecs->_pgpSetECDSA) (ctx, dig, sigp);
01790 }
01791 
01794 /*@unused@*/ static inline
01795 int pgpImplErrChk(pgpDig dig, const char * msg, int rc, unsigned expected)
01796         /*@*/
01797 {
01798     return (pgpImplVecs->_pgpErrChk
01799         ? (*pgpImplVecs->_pgpErrChk) (dig, msg, rc, expected)
01800         : rc);
01801 }
01802 
01805 /*@unused@*/ static inline
01806 int pgpImplAvailableCipher(pgpDig dig, int algo)
01807         /*@*/
01808 {
01809     return (pgpImplVecs->_pgpAvailableCipher
01810         ? (*pgpImplVecs->_pgpAvailableCipher) (dig, algo)
01811         : 0);
01812 }
01813 
01816 /*@unused@*/ static inline
01817 int pgpImplAvailableDigest(pgpDig dig, int algo)
01818         /*@*/
01819 {
01820     return (pgpImplVecs->_pgpAvailableDigest
01821         ? (*pgpImplVecs->_pgpAvailableDigest) (dig, algo)
01822         : 0);
01823 }
01824 
01827 /*@unused@*/ static inline
01828 int pgpImplAvailablePubkey(pgpDig dig, int algo)
01829         /*@*/
01830 {
01831     return (pgpImplVecs->_pgpAvailablePubkey
01832         ? (*pgpImplVecs->_pgpAvailablePubkey) (dig, algo)
01833         : 0);
01834 }
01835 
01838 /*@unused@*/ static inline
01839 int pgpImplVerify(pgpDig dig)
01840         /*@*/
01841 {
01842     return (pgpImplVecs->_pgpVerify
01843         ? (*pgpImplVecs->_pgpVerify) (dig)
01844         : 0);
01845 }
01846 
01849 /*@unused@*/ static inline
01850 int pgpImplSign(pgpDig dig)
01851         /*@*/
01852 {
01853     return (pgpImplVecs->_pgpSign
01854         ? (*pgpImplVecs->_pgpSign) (dig)
01855         : 0);
01856 }
01857 
01860 /*@unused@*/ static inline
01861 int pgpImplGenerate(pgpDig dig)
01862         /*@*/
01863 {
01864     return (pgpImplVecs->_pgpGenerate
01865         ? (*pgpImplVecs->_pgpGenerate) (dig)
01866         : 0);
01867 }
01868 
01871 /*@unused@*/ static inline
01872 int pgpImplMpiItem(const char * pre, pgpDig dig, int itemno,
01873                 const rpmuint8_t * p, /*@null@*/ const rpmuint8_t * pend)
01874         /*@modifies dig @*/
01875 {
01876     return (*pgpImplVecs->_pgpMpiItem) (pre, dig, itemno, p, pend);
01877 }
01878 
01881 /*@unused@*/ static inline
01882 void pgpImplClean(void * impl)
01883         /*@modifies impl @*/
01884 {
01885 /*@-noeffectuncon@*/
01886     (*pgpImplVecs->_pgpClean) (impl);
01887 /*@=noeffectuncon@*/
01888 }
01889 
01892 /*@unused@*/ static inline
01893 /*@null@*/
01894 void * pgpImplFree(/*@only@*/ void * impl)
01895         /*@modifies impl @*/
01896 {
01897     return (*pgpImplVecs->_pgpFree) (impl);
01898 }
01899 
01902 /*@unused@*/ static inline
01903 void * pgpImplInit(void)
01904         /*@*/
01905 {
01906     return (*pgpImplVecs->_pgpInit) ();
01907 }
01908 /*@=mustmod@*/
01909 
01910 
01911 #ifdef __cplusplus
01912 }
01913 #endif
01914 /*@=fcnuse@*/
01915 
01916 #endif  /* H_RPMPGP */