rpmio/rpmpgp.h

Go to the documentation of this file.
00001 #ifndef H_RPMPGP
00002 #define H_RPMPGP
00003 
00013 #include <string.h>
00014 
00015 typedef unsigned char byte;
00016 
00019 typedef /*@abstract@*/ struct DIGEST_CTX_s * DIGEST_CTX;
00020 
00023 typedef const struct pgpValTbl_s {
00024     int val;
00025 /*@observer@*/ const char * str;
00026 } * pgpValTbl;
00027  
00035 typedef enum pgpTag_e {
00036     PGPTAG_RESERVED             =  0, 
00037     PGPTAG_PUBLIC_SESSION_KEY   =  1, 
00038     PGPTAG_SIGNATURE            =  2, 
00039     PGPTAG_SYMMETRIC_SESSION_KEY=  3, 
00040     PGPTAG_ONEPASS_SIGNATURE    =  4, 
00041     PGPTAG_SECRET_KEY           =  5, 
00042     PGPTAG_PUBLIC_KEY           =  6, 
00043     PGPTAG_SECRET_SUBKEY        =  7, 
00044     PGPTAG_COMPRESSED_DATA      =  8, 
00045     PGPTAG_SYMMETRIC_DATA       =  9, 
00046     PGPTAG_MARKER               = 10, 
00047     PGPTAG_LITERAL_DATA         = 11, 
00048     PGPTAG_TRUST                = 12, 
00049     PGPTAG_USER_ID              = 13, 
00050     PGPTAG_PUBLIC_SUBKEY        = 14, 
00051     PGPTAG_COMMENT_OLD          = 16, 
00052     PGPTAG_PHOTOID              = 17, 
00053     PGPTAG_ENCRYPTED_MDC        = 18, 
00054     PGPTAG_MDC                  = 19, 
00055     PGPTAG_PRIVATE_60           = 60, 
00056     PGPTAG_COMMENT              = 61, 
00057     PGPTAG_PRIVATE_62           = 62, 
00058     PGPTAG_CONTROL              = 63  
00059 } pgpTag;
00060 
00063 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00064 extern struct pgpValTbl_s pgpTagTbl[];
00065 
00100 typedef struct pgpPktPubkey_s {
00101     byte version;       
00102     byte keyid[8];      
00103     byte algo;          
00104 } pgpPktPubkey;
00105 
00106 
00113 /*@-typeuse@*/
00114 typedef enum pgpSigType_e {
00115     PGPSIGTYPE_BINARY            = 0x00, 
00116     PGPSIGTYPE_TEXT              = 0x01, 
00117     PGPSIGTYPE_STANDALONE        = 0x02, 
00118     PGPSIGTYPE_GENERIC_CERT      = 0x10,
00120     PGPSIGTYPE_PERSONA_CERT      = 0x11,
00122     PGPSIGTYPE_CASUAL_CERT       = 0x12,
00124     PGPSIGTYPE_POSITIVE_CERT     = 0x13,
00126     PGPSIGTYPE_SUBKEY_BINDING    = 0x18, 
00127     PGPSIGTYPE_SIGNED_KEY        = 0x1F, 
00128     PGPSIGTYPE_KEY_REVOKE        = 0x20, 
00129     PGPSIGTYPE_SUBKEY_REVOKE     = 0x28, 
00130     PGPSIGTYPE_CERT_REVOKE       = 0x30, 
00131     PGPSIGTYPE_TIMESTAMP         = 0x40  
00132 } pgpSigType;
00133 /*@=typeuse@*/
00134 
00137 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00138 extern struct pgpValTbl_s pgpSigTypeTbl[];
00139 
00163 /*@-typeuse@*/
00164 typedef enum pgpPubkeyAlgo_e {
00165     PGPPUBKEYALGO_RSA           =  1,   
00166     PGPPUBKEYALGO_RSA_ENCRYPT   =  2,   
00167     PGPPUBKEYALGO_RSA_SIGN      =  3,   
00168     PGPPUBKEYALGO_ELGAMAL_ENCRYPT = 16, 
00169     PGPPUBKEYALGO_DSA           = 17,   
00170     PGPPUBKEYALGO_EC            = 18,   
00171     PGPPUBKEYALGO_ECDSA         = 19,   
00172     PGPPUBKEYALGO_ELGAMAL       = 20,   
00173     PGPPUBKEYALGO_DH            = 21    
00174 } pgpPubkeyAlgo;
00175 /*@=typeuse@*/
00176 
00179 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00180 extern struct pgpValTbl_s pgpPubkeyTbl[];
00181 
00206 /*@-typeuse@*/
00207 typedef enum pgpSymkeyAlgo_e {
00208     PGPSYMKEYALGO_PLAINTEXT     =  0,   
00209     PGPSYMKEYALGO_IDEA          =  1,   
00210     PGPSYMKEYALGO_TRIPLE_DES    =  2,   
00211     PGPSYMKEYALGO_CAST5         =  3,   
00212     PGPSYMKEYALGO_BLOWFISH      =  4,   
00213     PGPSYMKEYALGO_SAFER         =  5,   
00214     PGPSYMKEYALGO_DES_SK        =  6,   
00215     PGPSYMKEYALGO_AES_128       =  7,   
00216     PGPSYMKEYALGO_AES_192       =  8,   
00217     PGPSYMKEYALGO_AES_256       =  9,   
00218     PGPSYMKEYALGO_TWOFISH       = 10,   
00219     PGPSYMKEYALGO_NOENCRYPT     = 110   
00220 } pgpSymkeyAlgo;
00221 /*@=typeuse@*/
00222 
00226 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00227 extern struct pgpValTbl_s pgpSymkeyTbl[];
00228 
00244 /*@-typeuse@*/
00245 typedef enum pgpCompressAlgo_e {
00246     PGPCOMPRESSALGO_NONE        =  0,   
00247     PGPCOMPRESSALGO_ZIP         =  1,   
00248     PGPCOMPRESSALGO_ZLIB        =  2,   
00249     PGPCOMPRESSALGO_BZIP2       =  3    
00250 } pgpCompressAlgo;
00251 /*@=typeuse@*/
00252 
00256 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00257 extern struct pgpValTbl_s pgpCompressionTbl[];
00258 
00280 typedef enum pgpHashAlgo_e {
00281     PGPHASHALGO_MD5             =  1,   
00282     PGPHASHALGO_SHA1            =  2,   
00283     PGPHASHALGO_RIPEMD160       =  3,   
00284     PGPHASHALGO_MD2             =  5,   
00285     PGPHASHALGO_TIGER192        =  6,   
00286     PGPHASHALGO_HAVAL_5_160     =  7,   
00287     PGPHASHALGO_SHA256          =  8,   
00288     PGPHASHALGO_SHA384          =  9,   
00289     PGPHASHALGO_SHA512          = 10,   
00290 } pgpHashAlgo;
00291 
00295 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00296 extern struct pgpValTbl_s pgpHashTbl[];
00297 
00319 typedef struct pgpPktSigV3_s {
00320     byte version;       
00321     byte hashlen;       
00322     byte sigtype;       
00323     byte time[4];       
00324     byte signid[8];     
00325     byte pubkey_algo;   
00326     byte hash_algo;     
00327     byte signhash16[2]; 
00328 } * pgpPktSigV3;
00329 
00351 typedef struct pgpPktSigV4_s {
00352     byte version;       
00353     byte sigtype;       
00354     byte pubkey_algo;   
00355     byte hash_algo;     
00356     byte hashlen[2];    
00357 } * pgpPktSigV4;
00358 
00425 /*@-typeuse@*/
00426 typedef enum pgpSubType_e {
00427     PGPSUBTYPE_NONE             =   0, 
00428     PGPSUBTYPE_SIG_CREATE_TIME  =   2, 
00429     PGPSUBTYPE_SIG_EXPIRE_TIME  =   3, 
00430     PGPSUBTYPE_EXPORTABLE_CERT  =   4, 
00431     PGPSUBTYPE_TRUST_SIG        =   5, 
00432     PGPSUBTYPE_REGEX            =   6, 
00433     PGPSUBTYPE_REVOCABLE        =   7, 
00434     PGPSUBTYPE_KEY_EXPIRE_TIME  =   9, 
00435     PGPSUBTYPE_ARR              =  10, 
00436     PGPSUBTYPE_PREFER_SYMKEY    =  11, 
00437     PGPSUBTYPE_REVOKE_KEY       =  12, 
00438     PGPSUBTYPE_ISSUER_KEYID     =  16, 
00439     PGPSUBTYPE_NOTATION         =  20, 
00440     PGPSUBTYPE_PREFER_HASH      =  21, 
00441     PGPSUBTYPE_PREFER_COMPRESS  =  22, 
00442     PGPSUBTYPE_KEYSERVER_PREFERS=  23, 
00443     PGPSUBTYPE_PREFER_KEYSERVER =  24, 
00444     PGPSUBTYPE_PRIMARY_USERID   =  25, 
00445     PGPSUBTYPE_POLICY_URL       =  26, 
00446     PGPSUBTYPE_KEY_FLAGS        =  27, 
00447     PGPSUBTYPE_SIGNER_USERID    =  28, 
00448     PGPSUBTYPE_REVOKE_REASON    =  29, 
00449     PGPSUBTYPE_FEATURES         =  30, 
00450     PGPSUBTYPE_EMBEDDED_SIG     =  32, 
00452     PGPSUBTYPE_INTERNAL_100     = 100, 
00453     PGPSUBTYPE_INTERNAL_101     = 101, 
00454     PGPSUBTYPE_INTERNAL_102     = 102, 
00455     PGPSUBTYPE_INTERNAL_103     = 103, 
00456     PGPSUBTYPE_INTERNAL_104     = 104, 
00457     PGPSUBTYPE_INTERNAL_105     = 105, 
00458     PGPSUBTYPE_INTERNAL_106     = 106, 
00459     PGPSUBTYPE_INTERNAL_107     = 107, 
00460     PGPSUBTYPE_INTERNAL_108     = 108, 
00461     PGPSUBTYPE_INTERNAL_109     = 109, 
00462     PGPSUBTYPE_INTERNAL_110     = 110, 
00464     PGPSUBTYPE_CRITICAL         = 128  
00465 } pgpSubType;
00466 /*@=typeuse@*/
00467 
00471 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00472 extern struct pgpValTbl_s pgpSubTypeTbl[];
00473 
00494 typedef union pgpPktSig_u {
00495     struct pgpPktSigV3_s v3;
00496     struct pgpPktSigV4_s v4;
00497 } * pgpPktSig;
00498 
00527 typedef struct pgpPktSymkey_s {
00528     byte version;       
00529     byte symkey_algo;
00530     byte s2k[1];
00531 } pgpPktSymkey;
00532 
00562 typedef struct pgpPktOnepass_s {
00563     byte version;       
00564     byte sigtype;       
00565     byte hash_algo;     
00566     byte pubkey_algo;   
00567     byte signid[8];     
00568     byte nested;
00569 } * pgpPktOnepass;
00570 
00643 typedef struct pgpPktKeyV3_s {
00644     byte version;       
00645     byte time[4];       
00646     byte valid[2];      
00647     byte pubkey_algo;   
00648 } * pgpPktKeyV3;
00649 
00681 typedef struct pgpPktKeyV4_s {
00682     byte version;       
00683     byte time[4];       
00684     byte pubkey_algo;   
00685 } * pgpPktKeyV4;
00686 
00751 typedef union pgpPktKey_u {
00752     struct pgpPktKeyV3_s v3;
00753     struct pgpPktKeyV4_s v4;
00754 } pgpPktKey;
00755 
00756 /*
00757  * 5.6. Compressed Data Packet (Tag 8)
00758  *
00759  * The Compressed Data packet contains compressed data. Typically, this
00760  * packet is found as the contents of an encrypted packet, or following
00761  * a Signature or One-Pass Signature packet, and contains literal data
00762  * packets.
00763  *
00764  * The body of this packet consists of:
00765  *   - One octet that gives the algorithm used to compress the packet.
00766  *   - The remainder of the packet is compressed data.
00767  *
00768  * A Compressed Data Packet's body contains an block that compresses
00769  * some set of packets. See section "Packet Composition" for details on
00770  * how messages are formed.
00771  *
00772  * ZIP-compressed packets are compressed with raw RFC 1951 DEFLATE
00773  * blocks. Note that PGP V2.6 uses 13 bits of compression. If an
00774  * implementation uses more bits of compression, PGP V2.6 cannot
00775  * decompress it.
00776  *
00777  * ZLIB-compressed packets are compressed with RFC 1950 ZLIB-style
00778  * blocks.
00779  */
00780 typedef struct pgpPktCdata_s {
00781     byte compressalgo;
00782     byte data[1];
00783 } pgpPktCdata;
00784 
00785 /*
00786  * 5.7. Symmetrically Encrypted Data Packet (Tag 9)
00787  *
00788  * The Symmetrically Encrypted Data packet contains data encrypted with
00789  * a symmetric-key algorithm. When it has been decrypted, it will
00790  * typically contain other packets (often literal data packets or
00791  * compressed data packets).
00792  *
00793  * The body of this packet consists of:
00794  *   - Encrypted data, the output of the selected symmetric-key cipher
00795  *     operating in PGP's variant of Cipher Feedback (CFB) mode.
00796  *
00797  * The symmetric cipher used may be specified in an Public-Key or
00798  * Symmetric-Key Encrypted Session Key packet that precedes the
00799  * Symmetrically Encrypted Data Packet.  In that case, the cipher
00800  * algorithm octet is prefixed to the session key before it is
00801  * encrypted.  If no packets of these types precede the encrypted data,
00802  * the IDEA algorithm is used with the session key calculated as the MD5
00803  * hash of the passphrase.
00804  *
00805  * The data is encrypted in CFB mode, with a CFB shift size equal to the
00806  * cipher's block size.  The Initial Vector (IV) is specified as all
00807  * zeros.  Instead of using an IV, OpenPGP prefixes a 10-octet string to
00808  * the data before it is encrypted.  The first eight octets are random,
00809  * and the 9th and 10th octets are copies of the 7th and 8th octets,
00810  * respectively. After encrypting the first 10 octets, the CFB state is
00811  * resynchronized if the cipher block size is 8 octets or less.  The
00812  * last 8 octets of ciphertext are passed through the cipher and the
00813  * block boundary is reset.
00814  *
00815  * The repetition of 16 bits in the 80 bits of random data prefixed to
00816  * the message allows the receiver to immediately check whether the
00817  * session key is incorrect.
00818  */
00819 typedef struct pgpPktEdata_s {
00820     byte data[1];
00821 } pgpPktEdata;
00822 
00823 /*
00824  * 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10)
00825  *
00826  * An experimental version of PGP used this packet as the Literal
00827  * packet, but no released version of PGP generated Literal packets with
00828  * this tag. With PGP 5.x, this packet has been re-assigned and is
00829  * reserved for use as the Marker packet.
00830  *
00831  * The body of this packet consists of:
00832  *   - The three octets 0x50, 0x47, 0x50 (which spell "PGP" in UTF-8).
00833  *
00834  * Such a packet MUST be ignored when received.  It may be placed at the
00835  * beginning of a message that uses features not available in PGP 2.6.x
00836  * in order to cause that version to report that newer software is
00837  * necessary to process the message.
00838  */
00839 /*
00840  * 5.9. Literal Data Packet (Tag 11)
00841  *
00842  * A Literal Data packet contains the body of a message; data that is
00843  * not to be further interpreted.
00844  *
00845  * The body of this packet consists of:
00846  *   - A one-octet field that describes how the data is formatted.
00847  *
00848  * If it is a 'b' (0x62), then the literal packet contains binary data.
00849  * If it is a 't' (0x74), then it contains text data, and thus may need
00850  * line ends converted to local form, or other text-mode changes.  RFC
00851  * 1991 also defined a value of 'l' as a 'local' mode for machine-local
00852  * conversions.  This use is now deprecated.
00853  *   - File name as a string (one-octet length, followed by file name),
00854  *     if the encrypted data should be saved as a file.
00855  *
00856  * If the special name "_CONSOLE" is used, the message is considered to
00857  * be "for your eyes only".  This advises that the message data is
00858  * unusually sensitive, and the receiving program should process it more
00859  * carefully, perhaps avoiding storing the received data to disk, for
00860  * example.
00861  *   - A four-octet number that indicates the modification date of the
00862  *     file, or the creation time of the packet, or a zero that
00863  *     indicates the present time.
00864  *   - The remainder of the packet is literal data.
00865  *
00866  * Text data is stored with <CR><LF> text endings (i.e. network-normal
00867  * line endings).  These should be converted to native line endings by
00868  * the receiving software.
00869  */
00870 typedef struct pgpPktLdata_s {
00871     byte format;
00872     byte filenamelen;
00873     byte filename[1];
00874 } pgpPktLdata;
00875 
00876 /*
00877  * 5.10. Trust Packet (Tag 12)
00878  *
00879  * The Trust packet is used only within keyrings and is not normally
00880  * exported.  Trust packets contain data that record the user's
00881  * specifications of which key holders are trustworthy introducers,
00882  * along with other information that implementing software uses for
00883  * trust information.
00884  *
00885  * Trust packets SHOULD NOT be emitted to output streams that are
00886  * transferred to other users, and they SHOULD be ignored on any input
00887  * other than local keyring files.
00888  */
00889 typedef struct pgpPktTrust_s {
00890     byte flag;
00891 } pgpPktTrust;
00892 
00893 /*
00894  * 5.11. User ID Packet (Tag 13)
00895  *
00896  * A User ID packet consists of data that is intended to represent the
00897  * name and email address of the key holder.  By convention, it includes
00898  * an RFC 822 mail name, but there are no restrictions on its content.
00899  * The packet length in the header specifies the length of the user id.
00900  * If it is text, it is encoded in UTF-8.
00901  *
00902  */
00903 typedef struct pgpPktUid_s {
00904     byte userid[1];
00905 } pgpPktUid;
00906 
00909 union pgpPktPre_u {
00910     pgpPktPubkey pubkey;        
00911     pgpPktSig sig;              
00912     pgpPktSymkey symkey;        
00913     pgpPktOnepass onepass;      
00914     pgpPktKey key;              
00915     pgpPktCdata cdata;          
00916     pgpPktEdata edata;          
00918     pgpPktLdata ldata;          
00919     pgpPktTrust tdata;          
00920     pgpPktUid uid;              
00921 };
00922 
00925 /*@-typeuse@*/
00926 typedef enum pgpArmor_e {
00927     PGPARMOR_ERR_CRC_CHECK              = -7,
00928     PGPARMOR_ERR_BODY_DECODE            = -6,
00929     PGPARMOR_ERR_CRC_DECODE             = -5,
00930     PGPARMOR_ERR_NO_END_PGP             = -4,
00931     PGPARMOR_ERR_UNKNOWN_PREAMBLE_TAG   = -3,
00932     PGPARMOR_ERR_UNKNOWN_ARMOR_TYPE     = -2,
00933     PGPARMOR_ERR_NO_BEGIN_PGP           = -1,
00934 #define PGPARMOR_ERROR  PGPARMOR_ERR_NO_BEGIN_PGP
00935     PGPARMOR_NONE               =  0,
00936     PGPARMOR_MESSAGE            =  1, 
00937     PGPARMOR_PUBKEY             =  2, 
00938     PGPARMOR_SIGNATURE          =  3, 
00939     PGPARMOR_SIGNED_MESSAGE     =  4, 
00940     PGPARMOR_FILE               =  5, 
00941     PGPARMOR_PRIVKEY            =  6, 
00942     PGPARMOR_SECKEY             =  7  
00943 } pgpArmor;
00944 /*@=typeuse@*/
00945 
00949 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00950 extern struct pgpValTbl_s pgpArmorTbl[];
00951 
00954 /*@-typeuse@*/
00955 typedef enum pgpArmorKey_e {
00956     PGPARMORKEY_VERSION         = 1, 
00957     PGPARMORKEY_COMMENT         = 2, 
00958     PGPARMORKEY_MESSAGEID       = 3, 
00959     PGPARMORKEY_HASH            = 4, 
00960     PGPARMORKEY_CHARSET         = 5  
00961 } pgpArmorKey;
00962 /*@=typeuse@*/
00963 
00967 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00968 extern struct pgpValTbl_s pgpArmorKeyTbl[];
00969 
00973 typedef enum rpmDigestFlags_e {
00974     RPMDIGEST_NONE      = 0
00975 } rpmDigestFlags;
00976 
00977 
00978 /*@-fcnuse@*/
00979 #ifdef __cplusplus
00980 extern "C" {
00981 #endif
00982 
00989 /*@unused@*/ static inline
00990 unsigned int pgpGrab(const byte *s, int nbytes)
00991         /*@*/
00992 {
00993     unsigned int i = 0;
00994     int nb = (nbytes <= sizeof(i) ? nbytes : sizeof(i));
00995 /*@-boundsread@*/
00996     while (nb--)
00997         i = (i << 8) | *s++;
00998 /*@=boundsread@*/
00999     return i;
01000 }
01001 
01008 /*@unused@*/ static inline
01009 int pgpLen(const byte *s, /*@out@*/ unsigned int *lenp)
01010         /*@modifies *lenp @*/
01011 {
01012 /*@-boundswrite@*/
01013     if (*s < 192) {
01014         (*lenp) = *s++;
01015         return 1;
01016     } else if (*s < 255) {
01017         (*lenp) = ((((unsigned)s[0]) - 192) << 8) + s[1] + 192;
01018         return 2;
01019     } else {
01020         (*lenp) = pgpGrab(s+1, 4);
01021         return 5;
01022     }
01023 /*@=boundswrite@*/
01024 }
01025 
01031 /*@unused@*/ static inline
01032 unsigned int pgpMpiBits(const byte *p)
01033         /*@requires maxRead(p) >= 1 @*/
01034         /*@*/
01035 {
01036     return ((p[0] << 8) | p[1]);
01037 }
01038 
01044 /*@unused@*/ static inline
01045 unsigned int pgpMpiLen(const byte *p)
01046         /*@requires maxRead(p) >= 1 @*/
01047         /*@*/
01048 {
01049     return (2 + ((pgpMpiBits(p)+7)>>3));
01050 }
01051         
01059 /*@unused@*/ static inline
01060 char * pgpHexCvt(/*@returned@*/ char *t, const byte *s, int nbytes)
01061         /*@modifies *t @*/
01062 {
01063     static char hex[] = "0123456789abcdef";
01064 /*@-boundswrite@*/
01065     while (nbytes-- > 0) {
01066         unsigned int i;
01067         i = *s++;
01068         *t++ = hex[ (i >> 4) & 0xf ];
01069         *t++ = hex[ (i     ) & 0xf ];
01070     }
01071     *t = '\0';
01072 /*@=boundswrite@*/
01073     return t;
01074 }
01075 
01083 /*@unused@*/ static inline /*@observer@*/
01084 char * pgpHexStr(const byte *p, unsigned int plen)
01085         /*@*/
01086 {
01087     static char prbuf[8*BUFSIZ];        /* XXX ick */
01088     char *t = prbuf;
01089     t = pgpHexCvt(t, p, plen);
01090     return prbuf;
01091 }
01092 
01099 /*@unused@*/ static inline /*@observer@*/
01100 const char * pgpMpiStr(const byte *p)
01101         /*@requires maxRead(p) >= 3 @*/
01102         /*@*/
01103 {
01104     static char prbuf[8*BUFSIZ];        /* XXX ick */
01105     char *t = prbuf;
01106     sprintf(t, "[%4u]: ", pgpGrab(p, 2));
01107     t += strlen(t);
01108     t = pgpHexCvt(t, p+2, pgpMpiLen(p)-2);
01109     return prbuf;
01110 }
01111 
01118 /*@unused@*/ static inline /*@observer@*/
01119 const char * pgpValStr(pgpValTbl vs, byte val)
01120         /*@*/
01121 {
01122     do {
01123         if (vs->val == val)
01124             break;
01125     } while ((++vs)->val != -1);
01126     return vs->str;
01127 }
01128 
01136 /*@unused@*/ static inline
01137 int pgpValTok(pgpValTbl vs, const char * s, const char * se)
01138         /*@*/
01139 {
01140     do {
01141         int vlen = strlen(vs->str);
01142         if (vlen <= (se-s) && !strncmp(s, vs->str, vlen))
01143             break;
01144     } while ((++vs)->val != -1);
01145     return vs->val;
01146 }
01147 
01148 /*@-exportlocal@*/
01155 void pgpPrtVal(const char * pre, pgpValTbl vs, byte val)
01156         /*@globals fileSystem @*/
01157         /*@modifies fileSystem @*/;
01158 
01166 int pgpPrtSubType(const byte *h, unsigned int hlen, pgpSigType sigtype)
01167         /*@globals fileSystem @*/
01168         /*@modifies fileSystem @*/;
01169 
01177 int pgpPrtSig(pgpTag tag, const byte *h, unsigned int hlen)
01178         /*@globals fileSystem, internalState @*/
01179         /*@modifies fileSystem, internalState @*/;
01180 
01188 int pgpPrtKey(pgpTag tag, const byte *h, unsigned int hlen)
01189         /*@globals fileSystem, internalState @*/
01190         /*@modifies fileSystem, internalState @*/;
01191 
01199 int pgpPrtUserID(pgpTag tag, const byte *h, unsigned int hlen)
01200         /*@globals fileSystem, internalState @*/
01201         /*@modifies fileSystem, internalState @*/;
01202 
01210 int pgpPrtComment(pgpTag tag, const byte *h, unsigned int hlen)
01211         /*@globals fileSystem @*/
01212         /*@modifies fileSystem @*/;
01213 
01222 int pgpPubkeyFingerprint(const byte * pkt, unsigned int pktlen,
01223                 /*@out@*/ byte * keyid)
01224         /*@modifies *keyid @*/;
01225 
01232 int pgpPrtPkt(const byte *pkt, unsigned int pleft)
01233         /*@globals fileSystem, internalState @*/
01234         /*@modifies fileSystem, internalState @*/;
01235 /*@=exportlocal@*/
01236 
01245 int pgpPrtPkts(const byte *pkts, unsigned int pktlen, pgpDig dig, int printing)
01246         /*@globals fileSystem, internalState @*/
01247         /*@modifies dig, fileSystem, internalState @*/;
01248 
01256 pgpArmor pgpReadPkts(const char * fn,
01257                 /*@out@*/ const byte ** pkt, /*@out@*/ size_t * pktlen)
01258         /*@globals h_errno, fileSystem, internalState @*/
01259         /*@modifies *pkt, *pktlen, fileSystem, internalState @*/;
01260 
01268 char * pgpArmorWrap(int atype, const unsigned char * s, size_t ns)
01269         /*@*/;
01270 
01275 /*@only@*/
01276 pgpDig pgpNewDig(void)
01277         /*@*/;
01278 
01283 void pgpCleanDig(/*@null@*/ pgpDig dig)
01284         /*@modifies dig @*/;
01285 
01291 /*@only@*/ /*@null@*/
01292 pgpDig pgpFreeDig(/*@only@*/ /*@null@*/ pgpDig dig)
01293         /*@modifies dig @*/;
01294 
01300 /*@unused@*/ static inline
01301 int pgpIsPkt(const byte * p)
01302         /*@*/
01303 {
01304 /*@-boundsread@*/
01305     unsigned int val = *p++;
01306 /*@=boundsread@*/
01307     pgpTag tag;
01308     int rc;
01309 
01310     /* XXX can't deal with these. */
01311     if (!(val & 0x80))
01312         return 0;
01313 
01314     if (val & 0x40)
01315         tag = (pgpTag)(val & 0x3f);
01316     else
01317         tag = (pgpTag)((val >> 2) & 0xf);
01318 
01319     switch (tag) {
01320     case PGPTAG_MARKER:
01321     case PGPTAG_SYMMETRIC_SESSION_KEY:
01322     case PGPTAG_ONEPASS_SIGNATURE:
01323     case PGPTAG_PUBLIC_KEY:
01324     case PGPTAG_SECRET_KEY:
01325     case PGPTAG_PUBLIC_SESSION_KEY:
01326     case PGPTAG_SIGNATURE:
01327     case PGPTAG_COMMENT:
01328     case PGPTAG_COMMENT_OLD:
01329     case PGPTAG_LITERAL_DATA:
01330     case PGPTAG_COMPRESSED_DATA:
01331     case PGPTAG_SYMMETRIC_DATA:
01332         rc = 1;
01333         break;
01334     case PGPTAG_PUBLIC_SUBKEY:
01335     case PGPTAG_SECRET_SUBKEY:
01336     case PGPTAG_USER_ID:
01337     case PGPTAG_RESERVED:
01338     case PGPTAG_TRUST:
01339     case PGPTAG_PHOTOID:
01340     case PGPTAG_ENCRYPTED_MDC:
01341     case PGPTAG_MDC:
01342     case PGPTAG_PRIVATE_60:
01343     case PGPTAG_PRIVATE_62:
01344     case PGPTAG_CONTROL:
01345     default:
01346         rc = 0;
01347         break;
01348     }
01349 
01350     return rc;
01351 }
01352 
01353 #define CRC24_INIT      0xb704ce
01354 #define CRC24_POLY      0x1864cfb
01355 
01362 /*@unused@*/ static inline
01363 unsigned int pgpCRC(const byte *octets, size_t len)
01364         /*@*/
01365 {
01366     unsigned int crc = CRC24_INIT;
01367     int i;
01368 
01369     while (len--) {
01370 /*@-boundsread@*/
01371         crc ^= (*octets++) << 16;
01372 /*@=boundsread@*/
01373         for (i = 0; i < 8; i++) {
01374             crc <<= 1;
01375             if (crc & 0x1000000)
01376                 crc ^= CRC24_POLY;
01377         }
01378     }
01379     return crc & 0xffffff;
01380 }
01381 
01389 int rpmInitCrypto(void);
01390 
01396 /*@only@*/
01397 DIGEST_CTX rpmDigestDup(DIGEST_CTX octx)
01398         /*@*/;
01399 
01405 /*@only@*/ /*@null@*/
01406 size_t rpmDigestLength(pgpHashAlgo hashalgo)
01407         /*@*/;
01408 
01416 /*@only@*/ /*@null@*/
01417 DIGEST_CTX rpmDigestInit(pgpHashAlgo hashalgo, rpmDigestFlags flags)
01418         /*@*/;
01419 
01427 int rpmDigestUpdate(/*@null@*/ DIGEST_CTX ctx, const void * data, size_t len)
01428         /*@modifies ctx @*/;
01429 
01441 int rpmDigestFinal(/*@only@*/ /*@null@*/ DIGEST_CTX ctx,
01442         /*@null@*/ /*@out@*/ void ** datap,
01443         /*@null@*/ /*@out@*/ size_t * lenp, int asAscii)
01444                 /*@modifies *datap, *lenp @*/;
01445 
01446 #ifdef __cplusplus
01447 }
01448 #endif
01449 /*@=fcnuse@*/
01450 
01451 #endif  /* H_RPMPGP */

Generated on 28 Aug 2013 for rpm by  doxygen 1.4.7