rpmio/rpmpgp.h

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

Generated on Wed Jan 28 12:45:25 2009 for rpm by  doxygen 1.4.7