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

Generated on Fri Oct 12 08:44:54 2007 for rpm by  doxygen 1.5.2