rpmio/rpmpgp.h

Go to the documentation of this file.
00001 #ifndef H_RPMPGP
00002 #define H_RPMPGP
00003 
00013 #include <popt.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 /*@abstract@*/ struct pgpPkt_s * pgpPkt;
00028 
00031 typedef const struct pgpValTbl_s {
00032     int val;
00033 /*@observer@*/ const char * str;
00034 } * pgpValTbl;
00035  
00043 typedef enum pgpTag_e {
00044     PGPTAG_RESERVED             =  0, 
00045     PGPTAG_PUBLIC_SESSION_KEY   =  1, 
00046     PGPTAG_SIGNATURE            =  2, 
00047     PGPTAG_SYMMETRIC_SESSION_KEY=  3, 
00048     PGPTAG_ONEPASS_SIGNATURE    =  4, 
00049     PGPTAG_SECRET_KEY           =  5, 
00050     PGPTAG_PUBLIC_KEY           =  6, 
00051     PGPTAG_SECRET_SUBKEY        =  7, 
00052     PGPTAG_COMPRESSED_DATA      =  8, 
00053     PGPTAG_SYMMETRIC_DATA       =  9, 
00054     PGPTAG_MARKER               = 10, 
00055     PGPTAG_LITERAL_DATA         = 11, 
00056     PGPTAG_TRUST                = 12, 
00057     PGPTAG_USER_ID              = 13, 
00058     PGPTAG_PUBLIC_SUBKEY        = 14, 
00059     PGPTAG_COMMENT_OLD          = 16, 
00060     PGPTAG_PHOTOID              = 17, 
00061     PGPTAG_ENCRYPTED_MDC        = 18, 
00062     PGPTAG_MDC                  = 19, 
00063     PGPTAG_PRIVATE_60           = 60, 
00064     PGPTAG_COMMENT              = 61, 
00065     PGPTAG_PRIVATE_62           = 62, 
00066     PGPTAG_CONTROL              = 63  
00067 } pgpTag;
00068 
00071 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00072 extern struct pgpValTbl_s pgpTagTbl[];
00073 
00108 typedef struct pgpPktPubkey_s {
00109     byte version;       
00110     byte keyid[8];      
00111     byte algo;          
00112 } pgpPktPubkey;
00113 
00114 
00121 /*@-typeuse@*/
00122 typedef enum pgpSigType_e {
00123     PGPSIGTYPE_BINARY            = 0x00, 
00124     PGPSIGTYPE_TEXT              = 0x01, 
00125     PGPSIGTYPE_STANDALONE        = 0x02, 
00126     PGPSIGTYPE_GENERIC_CERT      = 0x10,
00128     PGPSIGTYPE_PERSONA_CERT      = 0x11,
00130     PGPSIGTYPE_CASUAL_CERT       = 0x12,
00132     PGPSIGTYPE_POSITIVE_CERT     = 0x13,
00134     PGPSIGTYPE_SUBKEY_BINDING    = 0x18, 
00135     PGPSIGTYPE_SIGNED_KEY        = 0x1F, 
00136     PGPSIGTYPE_KEY_REVOKE        = 0x20, 
00137     PGPSIGTYPE_SUBKEY_REVOKE     = 0x28, 
00138     PGPSIGTYPE_CERT_REVOKE       = 0x30, 
00139     PGPSIGTYPE_TIMESTAMP         = 0x40  
00140 } pgpSigType;
00141 /*@=typeuse@*/
00142 
00145 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00146 extern struct pgpValTbl_s pgpSigTypeTbl[];
00147 
00171 /*@-typeuse@*/
00172 typedef enum pgpPubkeyAlgo_e {
00173     PGPPUBKEYALGO_RSA           =  1,   
00174     PGPPUBKEYALGO_RSA_ENCRYPT   =  2,   
00175     PGPPUBKEYALGO_RSA_SIGN      =  3,   
00176     PGPPUBKEYALGO_ELGAMAL_ENCRYPT = 16, 
00177     PGPPUBKEYALGO_DSA           = 17,   
00178     PGPPUBKEYALGO_EC            = 18,   
00179     PGPPUBKEYALGO_ECDSA         = 19,   
00180     PGPPUBKEYALGO_ELGAMAL       = 20,   
00181     PGPPUBKEYALGO_DH            = 21    
00182 } pgpPubkeyAlgo;
00183 /*@=typeuse@*/
00184 
00187 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00188 extern struct pgpValTbl_s pgpPubkeyTbl[];
00189 
00214 /*@-typeuse@*/
00215 typedef enum pgpSymkeyAlgo_e {
00216     PGPSYMKEYALGO_PLAINTEXT     =  0,   
00217     PGPSYMKEYALGO_IDEA          =  1,   
00218     PGPSYMKEYALGO_TRIPLE_DES    =  2,   
00219     PGPSYMKEYALGO_CAST5         =  3,   
00220     PGPSYMKEYALGO_BLOWFISH      =  4,   
00221     PGPSYMKEYALGO_SAFER         =  5,   
00222     PGPSYMKEYALGO_DES_SK        =  6,   
00223     PGPSYMKEYALGO_AES_128       =  7,   
00224     PGPSYMKEYALGO_AES_192       =  8,   
00225     PGPSYMKEYALGO_AES_256       =  9,   
00226     PGPSYMKEYALGO_TWOFISH       = 10,   
00227     PGPSYMKEYALGO_NOENCRYPT     = 110   
00228 } pgpSymkeyAlgo;
00229 /*@=typeuse@*/
00230 
00234 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00235 extern struct pgpValTbl_s pgpSymkeyTbl[];
00236 
00252 /*@-typeuse@*/
00253 typedef enum pgpCompressAlgo_e {
00254     PGPCOMPRESSALGO_NONE        =  0,   
00255     PGPCOMPRESSALGO_ZIP         =  1,   
00256     PGPCOMPRESSALGO_ZLIB        =  2,   
00257     PGPCOMPRESSALGO_BZIP2       =  3    
00258 } pgpCompressAlgo;
00259 /*@=typeuse@*/
00260 
00264 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00265 extern struct pgpValTbl_s pgpCompressionTbl[];
00266 
00288 typedef enum pgpHashAlgo_e {
00289     PGPHASHALGO_MD5             =  1,   
00290     PGPHASHALGO_SHA1            =  2,   
00291     PGPHASHALGO_RIPEMD160       =  3,   
00292     PGPHASHALGO_MD2             =  5,   
00293     PGPHASHALGO_TIGER192        =  6,   
00294     PGPHASHALGO_HAVAL_5_160     =  7,   
00295     PGPHASHALGO_SHA256          =  8,   
00296     PGPHASHALGO_SHA384          =  9,   
00297     PGPHASHALGO_SHA512          = 10,   
00299     PGPHASHALGO_MD4             = 104,  
00300     PGPHASHALGO_RIPEMD128       = 105,  
00301     PGPHASHALGO_CRC32           = 106,  
00302     PGPHASHALGO_ADLER32         = 107,  
00303     PGPHASHALGO_CRC64           = 108,  
00304     PGPHASHALGO_JLU32           = 109,  
00305     PGPHASHALGO_SHA224          = 110,  
00306     PGPHASHALGO_RIPEMD256       = 111,  
00307     PGPHASHALGO_RIPEMD320       = 112,  
00308     PGPHASHALGO_SALSA10         = 113,  
00309     PGPHASHALGO_SALSA20         = 114,  
00311 } pgpHashAlgo;
00312 
00316 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00317 extern struct pgpValTbl_s pgpHashTbl[];
00318 
00340 typedef struct pgpPktSigV3_s {
00341     byte version;       
00342     byte hashlen;       
00343     byte sigtype;       
00344     byte time[4];       
00345     byte signid[8];     
00346     byte pubkey_algo;   
00347     byte hash_algo;     
00348     byte signhash16[2]; 
00349 } * pgpPktSigV3;
00350 
00372 typedef struct pgpPktSigV4_s {
00373     byte version;       
00374     byte sigtype;       
00375     byte pubkey_algo;   
00376     byte hash_algo;     
00377     byte hashlen[2];    
00378 } * pgpPktSigV4;
00379 
00446 /*@-typeuse@*/
00447 typedef enum pgpSubType_e {
00448     PGPSUBTYPE_NONE             =   0, 
00449     PGPSUBTYPE_SIG_CREATE_TIME  =   2, 
00450     PGPSUBTYPE_SIG_EXPIRE_TIME  =   3, 
00451     PGPSUBTYPE_EXPORTABLE_CERT  =   4, 
00452     PGPSUBTYPE_TRUST_SIG        =   5, 
00453     PGPSUBTYPE_REGEX            =   6, 
00454     PGPSUBTYPE_REVOCABLE        =   7, 
00455     PGPSUBTYPE_KEY_EXPIRE_TIME  =   9, 
00456     PGPSUBTYPE_ARR              =  10, 
00457     PGPSUBTYPE_PREFER_SYMKEY    =  11, 
00458     PGPSUBTYPE_REVOKE_KEY       =  12, 
00459     PGPSUBTYPE_ISSUER_KEYID     =  16, 
00460     PGPSUBTYPE_NOTATION         =  20, 
00461     PGPSUBTYPE_PREFER_HASH      =  21, 
00462     PGPSUBTYPE_PREFER_COMPRESS  =  22, 
00463     PGPSUBTYPE_KEYSERVER_PREFERS=  23, 
00464     PGPSUBTYPE_PREFER_KEYSERVER =  24, 
00465     PGPSUBTYPE_PRIMARY_USERID   =  25, 
00466     PGPSUBTYPE_POLICY_URL       =  26, 
00467     PGPSUBTYPE_KEY_FLAGS        =  27, 
00468     PGPSUBTYPE_SIGNER_USERID    =  28, 
00469     PGPSUBTYPE_REVOKE_REASON    =  29, 
00470     PGPSUBTYPE_FEATURES         =  30, 
00471     PGPSUBTYPE_EMBEDDED_SIG     =  32, 
00473     PGPSUBTYPE_INTERNAL_100     = 100, 
00474     PGPSUBTYPE_INTERNAL_101     = 101, 
00475     PGPSUBTYPE_INTERNAL_102     = 102, 
00476     PGPSUBTYPE_INTERNAL_103     = 103, 
00477     PGPSUBTYPE_INTERNAL_104     = 104, 
00478     PGPSUBTYPE_INTERNAL_105     = 105, 
00479     PGPSUBTYPE_INTERNAL_106     = 106, 
00480     PGPSUBTYPE_INTERNAL_107     = 107, 
00481     PGPSUBTYPE_INTERNAL_108     = 108, 
00482     PGPSUBTYPE_INTERNAL_109     = 109, 
00483     PGPSUBTYPE_INTERNAL_110     = 110, 
00485     PGPSUBTYPE_CRITICAL         = 128  
00486 } pgpSubType;
00487 /*@=typeuse@*/
00488 
00492 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00493 extern struct pgpValTbl_s pgpSubTypeTbl[];
00494 
00515 typedef union pgpPktSig_u {
00516     struct pgpPktSigV3_s v3;
00517     struct pgpPktSigV4_s v4;
00518 } * pgpPktSig;
00519 
00548 typedef struct pgpPktSymkey_s {
00549     byte version;       
00550     byte symkey_algo;
00551     byte s2k[1];
00552 } pgpPktSymkey;
00553 
00583 typedef struct pgpPktOnepass_s {
00584     byte version;       
00585     byte sigtype;       
00586     byte hash_algo;     
00587     byte pubkey_algo;   
00588     byte signid[8];     
00589     byte nested;
00590 } * pgpPktOnepass;
00591 
00664 typedef struct pgpPktKeyV3_s {
00665     byte version;       
00666     byte time[4];       
00667     byte valid[2];      
00668     byte pubkey_algo;   
00669 } * pgpPktKeyV3;
00670 
00702 typedef struct pgpPktKeyV4_s {
00703     byte version;       
00704     byte time[4];       
00705     byte pubkey_algo;   
00706 } * pgpPktKeyV4;
00707 
00772 typedef union pgpPktKey_u {
00773     struct pgpPktKeyV3_s v3;
00774     struct pgpPktKeyV4_s v4;
00775 } pgpPktKey;
00776 
00777 /*
00778  * 5.6. Compressed Data Packet (Tag 8)
00779  *
00780  * The Compressed Data packet contains compressed data. Typically, this
00781  * packet is found as the contents of an encrypted packet, or following
00782  * a Signature or One-Pass Signature packet, and contains literal data
00783  * packets.
00784  *
00785  * The body of this packet consists of:
00786  *   - One octet that gives the algorithm used to compress the packet.
00787  *   - The remainder of the packet is compressed data.
00788  *
00789  * A Compressed Data Packet's body contains an block that compresses
00790  * some set of packets. See section "Packet Composition" for details on
00791  * how messages are formed.
00792  *
00793  * ZIP-compressed packets are compressed with raw RFC 1951 DEFLATE
00794  * blocks. Note that PGP V2.6 uses 13 bits of compression. If an
00795  * implementation uses more bits of compression, PGP V2.6 cannot
00796  * decompress it.
00797  *
00798  * ZLIB-compressed packets are compressed with RFC 1950 ZLIB-style
00799  * blocks.
00800  */
00801 typedef struct pgpPktCdata_s {
00802     byte compressalgo;
00803     byte data[1];
00804 } pgpPktCdata;
00805 
00806 /*
00807  * 5.7. Symmetrically Encrypted Data Packet (Tag 9)
00808  *
00809  * The Symmetrically Encrypted Data packet contains data encrypted with
00810  * a symmetric-key algorithm. When it has been decrypted, it will
00811  * typically contain other packets (often literal data packets or
00812  * compressed data packets).
00813  *
00814  * The body of this packet consists of:
00815  *   - Encrypted data, the output of the selected symmetric-key cipher
00816  *     operating in PGP's variant of Cipher Feedback (CFB) mode.
00817  *
00818  * The symmetric cipher used may be specified in an Public-Key or
00819  * Symmetric-Key Encrypted Session Key packet that precedes the
00820  * Symmetrically Encrypted Data Packet.  In that case, the cipher
00821  * algorithm octet is prefixed to the session key before it is
00822  * encrypted.  If no packets of these types precede the encrypted data,
00823  * the IDEA algorithm is used with the session key calculated as the MD5
00824  * hash of the passphrase.
00825  *
00826  * The data is encrypted in CFB mode, with a CFB shift size equal to the
00827  * cipher's block size.  The Initial Vector (IV) is specified as all
00828  * zeros.  Instead of using an IV, OpenPGP prefixes a 10-octet string to
00829  * the data before it is encrypted.  The first eight octets are random,
00830  * and the 9th and 10th octets are copies of the 7th and 8th octets,
00831  * respectively. After encrypting the first 10 octets, the CFB state is
00832  * resynchronized if the cipher block size is 8 octets or less.  The
00833  * last 8 octets of ciphertext are passed through the cipher and the
00834  * block boundary is reset.
00835  *
00836  * The repetition of 16 bits in the 80 bits of random data prefixed to
00837  * the message allows the receiver to immediately check whether the
00838  * session key is incorrect.
00839  */
00840 typedef struct pgpPktEdata_s {
00841     byte data[1];
00842 } pgpPktEdata;
00843 
00844 /*
00845  * 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10)
00846  *
00847  * An experimental version of PGP used this packet as the Literal
00848  * packet, but no released version of PGP generated Literal packets with
00849  * this tag. With PGP 5.x, this packet has been re-assigned and is
00850  * reserved for use as the Marker packet.
00851  *
00852  * The body of this packet consists of:
00853  *   - The three octets 0x50, 0x47, 0x50 (which spell "PGP" in UTF-8).
00854  *
00855  * Such a packet MUST be ignored when received.  It may be placed at the
00856  * beginning of a message that uses features not available in PGP 2.6.x
00857  * in order to cause that version to report that newer software is
00858  * necessary to process the message.
00859  */
00860 /*
00861  * 5.9. Literal Data Packet (Tag 11)
00862  *
00863  * A Literal Data packet contains the body of a message; data that is
00864  * not to be further interpreted.
00865  *
00866  * The body of this packet consists of:
00867  *   - A one-octet field that describes how the data is formatted.
00868  *
00869  * If it is a 'b' (0x62), then the literal packet contains binary data.
00870  * If it is a 't' (0x74), then it contains text data, and thus may need
00871  * line ends converted to local form, or other text-mode changes.  RFC
00872  * 1991 also defined a value of 'l' as a 'local' mode for machine-local
00873  * conversions.  This use is now deprecated.
00874  *   - File name as a string (one-octet length, followed by file name),
00875  *     if the encrypted data should be saved as a file.
00876  *
00877  * If the special name "_CONSOLE" is used, the message is considered to
00878  * be "for your eyes only".  This advises that the message data is
00879  * unusually sensitive, and the receiving program should process it more
00880  * carefully, perhaps avoiding storing the received data to disk, for
00881  * example.
00882  *   - A four-octet number that indicates the modification date of the
00883  *     file, or the creation time of the packet, or a zero that
00884  *     indicates the present time.
00885  *   - The remainder of the packet is literal data.
00886  *
00887  * Text data is stored with <CR><LF> text endings (i.e. network-normal
00888  * line endings).  These should be converted to native line endings by
00889  * the receiving software.
00890  */
00891 typedef struct pgpPktLdata_s {
00892     byte format;
00893     byte filenamelen;
00894     byte filename[1];
00895 } pgpPktLdata;
00896 
00897 /*
00898  * 5.10. Trust Packet (Tag 12)
00899  *
00900  * The Trust packet is used only within keyrings and is not normally
00901  * exported.  Trust packets contain data that record the user's
00902  * specifications of which key holders are trustworthy introducers,
00903  * along with other information that implementing software uses for
00904  * trust information.
00905  *
00906  * Trust packets SHOULD NOT be emitted to output streams that are
00907  * transferred to other users, and they SHOULD be ignored on any input
00908  * other than local keyring files.
00909  */
00910 typedef struct pgpPktTrust_s {
00911     byte flag;
00912 } pgpPktTrust;
00913 
00914 /*
00915  * 5.11. User ID Packet (Tag 13)
00916  *
00917  * A User ID packet consists of data that is intended to represent the
00918  * name and email address of the key holder.  By convention, it includes
00919  * an RFC 822 mail name, but there are no restrictions on its content.
00920  * The packet length in the header specifies the length of the user id.
00921  * If it is text, it is encoded in UTF-8.
00922  *
00923  */
00924 typedef struct pgpPktUid_s {
00925     byte userid[1];
00926 } pgpPktUid;
00927 
00930 union pgpPktPre_u {
00931     pgpPktPubkey pubkey;        
00932     pgpPktSig sig;              
00933     pgpPktSymkey symkey;        
00934     pgpPktOnepass onepass;      
00935     pgpPktKey key;              
00936     pgpPktCdata cdata;          
00937     pgpPktEdata edata;          
00939     pgpPktLdata ldata;          
00940     pgpPktTrust tdata;          
00941     pgpPktUid uid;              
00942 };
00943 
00946 /*@-typeuse@*/
00947 typedef enum pgpArmor_e {
00948     PGPARMOR_ERR_CRC_CHECK              = -7,
00949     PGPARMOR_ERR_BODY_DECODE            = -6,
00950     PGPARMOR_ERR_CRC_DECODE             = -5,
00951     PGPARMOR_ERR_NO_END_PGP             = -4,
00952     PGPARMOR_ERR_UNKNOWN_PREAMBLE_TAG   = -3,
00953     PGPARMOR_ERR_UNKNOWN_ARMOR_TYPE     = -2,
00954     PGPARMOR_ERR_NO_BEGIN_PGP           = -1,
00955 #define PGPARMOR_ERROR  PGPARMOR_ERR_NO_BEGIN_PGP
00956     PGPARMOR_NONE               =  0,
00957     PGPARMOR_MESSAGE            =  1, 
00958     PGPARMOR_PUBKEY             =  2, 
00959     PGPARMOR_SIGNATURE          =  3, 
00960     PGPARMOR_SIGNED_MESSAGE     =  4, 
00961     PGPARMOR_FILE               =  5, 
00962     PGPARMOR_PRIVKEY            =  6, 
00963     PGPARMOR_SECKEY             =  7  
00964 } pgpArmor;
00965 /*@=typeuse@*/
00966 
00970 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00971 extern struct pgpValTbl_s pgpArmorTbl[];
00972 
00975 /*@-typeuse@*/
00976 typedef enum pgpArmorKey_e {
00977     PGPARMORKEY_VERSION         = 1, 
00978     PGPARMORKEY_COMMENT         = 2, 
00979     PGPARMORKEY_MESSAGEID       = 3, 
00980     PGPARMORKEY_HASH            = 4, 
00981     PGPARMORKEY_CHARSET         = 5  
00982 } pgpArmorKey;
00983 /*@=typeuse@*/
00984 
00988 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00989 extern struct pgpValTbl_s pgpArmorKeyTbl[];
00990 
00994 typedef enum rpmDigestFlags_e {
00995     RPMDIGEST_NONE      = 0
00996 } rpmDigestFlags;
00997 
00998 /*@unchecked@*/
00999 extern pgpHashAlgo rpmDigestHashAlgo;
01000 
01001 /*@unchecked@*/ /*@observer@*/
01002 extern struct poptOption rpmDigestPoptTable[];
01003 
01004 /*@-fcnuse@*/
01005 #ifdef __cplusplus
01006 extern "C" {
01007 #endif
01008 
01015 /*@unused@*/ static inline
01016 unsigned int pgpGrab(const byte *s, int nbytes)
01017         /*@*/
01018 {
01019     unsigned int i = 0;
01020     int nb = (nbytes <= sizeof(i) ? nbytes : sizeof(i));
01021 /*@-boundsread@*/
01022     while (nb--)
01023         i = (i << 8) | *s++;
01024 /*@=boundsread@*/
01025     return i;
01026 }
01027 
01034 /*@unused@*/ static inline
01035 int pgpLen(const byte *s, /*@out@*/ unsigned int *lenp)
01036         /*@modifies *lenp @*/
01037 {
01038 /*@-boundswrite@*/
01039     if (*s < 192) {
01040         (*lenp) = *s++;
01041         return 1;
01042     } else if (*s < 255) {
01043         (*lenp) = ((((unsigned)s[0]) - 192) << 8) + s[1] + 192;
01044         return 2;
01045     } else {
01046         (*lenp) = pgpGrab(s+1, 4);
01047         return 5;
01048     }
01049 /*@=boundswrite@*/
01050 }
01051 
01057 /*@unused@*/ static inline
01058 unsigned int pgpMpiBits(const byte *p)
01059         /*@requires maxRead(p) >= 1 @*/
01060         /*@*/
01061 {
01062     return ((p[0] << 8) | p[1]);
01063 }
01064 
01070 /*@unused@*/ static inline
01071 unsigned int pgpMpiLen(const byte *p)
01072         /*@requires maxRead(p) >= 1 @*/
01073         /*@*/
01074 {
01075     return (2 + ((pgpMpiBits(p)+7)>>3));
01076 }
01077         
01085 /*@unused@*/ static inline
01086 char * pgpHexCvt(/*@returned@*/ char *t, const byte *s, int nbytes)
01087         /*@modifies *t @*/
01088 {
01089     static char hex[] = "0123456789abcdef";
01090 /*@-boundswrite@*/
01091     while (nbytes-- > 0) {
01092         unsigned int i;
01093         i = *s++;
01094         *t++ = hex[ (i >> 4) & 0xf ];
01095         *t++ = hex[ (i     ) & 0xf ];
01096     }
01097     *t = '\0';
01098 /*@=boundswrite@*/
01099     return t;
01100 }
01101 
01109 /*@unused@*/ static inline /*@observer@*/
01110 char * pgpHexStr(const byte *p, unsigned int plen)
01111         /*@*/
01112 {
01113     static char prbuf[8*BUFSIZ];        /* XXX ick */
01114     char *t = prbuf;
01115     t = pgpHexCvt(t, p, plen);
01116     return prbuf;
01117 }
01118 
01125 /*@unused@*/ static inline /*@observer@*/
01126 const char * pgpMpiStr(const byte *p)
01127         /*@requires maxRead(p) >= 3 @*/
01128         /*@*/
01129 {
01130     static char prbuf[8*BUFSIZ];        /* XXX ick */
01131     char *t = prbuf;
01132     sprintf(t, "[%4u]: ", pgpGrab(p, 2));
01133     t += strlen(t);
01134     t = pgpHexCvt(t, p+2, pgpMpiLen(p)-2);
01135     return prbuf;
01136 }
01137 
01144 /*@unused@*/ static inline /*@observer@*/
01145 const char * pgpValStr(pgpValTbl vs, byte val)
01146         /*@*/
01147 {
01148     do {
01149         if (vs->val == val)
01150             break;
01151     } while ((++vs)->val != -1);
01152     return vs->str;
01153 }
01154 
01162 /*@unused@*/ static inline
01163 int pgpValTok(pgpValTbl vs, const char * s, const char * se)
01164         /*@*/
01165 {
01166     do {
01167         int vlen = strlen(vs->str);
01168         if (vlen <= (se-s) && !strncmp(s, vs->str, vlen))
01169             break;
01170     } while ((++vs)->val != -1);
01171     return vs->val;
01172 }
01173 
01180 /*@-exportlocal@*/
01181 void pgpPrtVal(const char * pre, pgpValTbl vs, byte val)
01182         /*@globals fileSystem @*/
01183         /*@modifies fileSystem @*/;
01184 /*@=exportlocal@*/
01185 
01193 /*@-exportlocal@*/
01194 int pgpPrtSubType(const byte *h, unsigned int hlen, pgpSigType sigtype)
01195         /*@globals fileSystem @*/
01196         /*@modifies fileSystem @*/;
01197 /*@=exportlocal@*/
01198 
01204 /*@-exportlocal@*/
01205 int pgpPrtSig(const pgpPkt pp)
01206         /*@globals fileSystem, internalState @*/
01207         /*@modifies fileSystem, internalState @*/;
01208 /*@=exportlocal@*/
01209 
01215 int pgpPrtKey(const pgpPkt pp)
01216         /*@globals fileSystem, internalState @*/
01217         /*@modifies fileSystem, internalState @*/;
01218 
01224 /*@-exportlocal@*/
01225 int pgpPrtUserID(const pgpPkt pp)
01226         /*@globals fileSystem, internalState @*/
01227         /*@modifies fileSystem, internalState @*/;
01228 /*@=exportlocal@*/
01229 
01235 /*@-exportlocal@*/
01236 int pgpPrtComment(const pgpPkt pp)
01237         /*@globals fileSystem @*/
01238         /*@modifies fileSystem @*/;
01239 /*@=exportlocal@*/
01240 
01249 /*@-exportlocal@*/
01250 int pgpPubkeyFingerprint(const byte * pkt, unsigned int pktlen,
01251                 /*@out@*/ byte * keyid)
01252         /*@modifies *keyid @*/;
01253 /*@=exportlocal@*/
01254 
01262 int pgpExtractPubkeyFingerprint(const char * b64pkt, /*@out@*/ byte * keyid)
01263         /*@modifies *keyid @*/;
01264 
01272 int pgpPktLen(const byte *pkt, unsigned int pleft, /*@out@*/ pgpPkt pp)
01273         /*@modifies pp @*/;
01274 
01281 /*@-exportlocal@*/
01282 int pgpPrtPkt(const byte *pkt, unsigned int pleft)
01283         /*@globals fileSystem, internalState @*/
01284         /*@modifies fileSystem, internalState @*/;
01285 /*@=exportlocal@*/
01286 
01295 int pgpPrtPkts(const byte *pkts, unsigned int pktlen, pgpDig dig, int printing)
01296         /*@globals fileSystem, internalState @*/
01297         /*@modifies dig, fileSystem, internalState @*/;
01298 
01306 pgpArmor pgpReadPkts(const char * fn,
01307                 /*@out@*/ const byte ** pkt, /*@out@*/ size_t * pktlen)
01308         /*@globals h_errno, fileSystem, internalState @*/
01309         /*@modifies *pkt, *pktlen, fileSystem, internalState @*/;
01310 
01318 char * pgpArmorWrap(int atype, const unsigned char * s, size_t ns)
01319         /*@*/;
01320 
01325 /*@only@*/
01326 pgpDig pgpNewDig(void)
01327         /*@*/;
01328 
01333 void pgpCleanDig(/*@null@*/ pgpDig dig)
01334         /*@modifies dig @*/;
01335 
01341 /*@only@*/ /*@null@*/
01342 pgpDig pgpFreeDig(/*@only@*/ /*@null@*/ pgpDig dig)
01343         /*@modifies dig @*/;
01344 
01350 /*@unused@*/ static inline
01351 int pgpIsPkt(const byte * p)
01352         /*@*/
01353 {
01354 /*@-boundsread@*/
01355     unsigned int val = *p++;
01356 /*@=boundsread@*/
01357     pgpTag tag;
01358     int rc;
01359 
01360     /* XXX can't deal with these. */
01361     if (!(val & 0x80))
01362         return 0;
01363 
01364     if (val & 0x40)
01365         tag = (val & 0x3f);
01366     else
01367         tag = (val >> 2) & 0xf;
01368 
01369     switch (tag) {
01370     case PGPTAG_MARKER:
01371     case PGPTAG_SYMMETRIC_SESSION_KEY:
01372     case PGPTAG_ONEPASS_SIGNATURE:
01373     case PGPTAG_PUBLIC_KEY:
01374     case PGPTAG_SECRET_KEY:
01375     case PGPTAG_PUBLIC_SESSION_KEY:
01376     case PGPTAG_SIGNATURE:
01377     case PGPTAG_COMMENT:
01378     case PGPTAG_COMMENT_OLD:
01379     case PGPTAG_LITERAL_DATA:
01380     case PGPTAG_COMPRESSED_DATA:
01381     case PGPTAG_SYMMETRIC_DATA:
01382         rc = 1;
01383         break;
01384     case PGPTAG_PUBLIC_SUBKEY:
01385     case PGPTAG_SECRET_SUBKEY:
01386     case PGPTAG_USER_ID:
01387     case PGPTAG_RESERVED:
01388     case PGPTAG_TRUST:
01389     case PGPTAG_PHOTOID:
01390     case PGPTAG_ENCRYPTED_MDC:
01391     case PGPTAG_MDC:
01392     case PGPTAG_PRIVATE_60:
01393     case PGPTAG_PRIVATE_62:
01394     case PGPTAG_CONTROL:
01395     default:
01396         rc = 0;
01397         break;
01398     }
01399 
01400     return rc;
01401 }
01402 
01403 #define CRC24_INIT      0xb704ce
01404 #define CRC24_POLY      0x1864cfb
01405 
01412 /*@unused@*/ static inline
01413 unsigned int pgpCRC(const byte *octets, size_t len)
01414         /*@*/
01415 {
01416     unsigned int crc = CRC24_INIT;
01417     int i;
01418 
01419     while (len--) {
01420 /*@-boundsread@*/
01421         crc ^= (*octets++) << 16;
01422 /*@=boundsread@*/
01423         for (i = 0; i < 8; i++) {
01424             crc <<= 1;
01425             if (crc & 0x1000000)
01426                 crc ^= CRC24_POLY;
01427         }
01428     }
01429     return crc & 0xffffff;
01430 }
01431 
01437 /*@only@*/
01438 DIGEST_CTX rpmDigestDup(DIGEST_CTX octx)
01439         /*@*/;
01440 
01448 /*@only@*/ /*@null@*/
01449 DIGEST_CTX rpmDigestInit(pgpHashAlgo hashalgo, rpmDigestFlags flags)
01450         /*@*/;
01451 
01459 int rpmDigestUpdate(/*@null@*/ DIGEST_CTX ctx, const void * data, size_t len)
01460         /*@modifies ctx @*/;
01461 
01473 int rpmDigestFinal(/*@only@*/ /*@null@*/ DIGEST_CTX ctx,
01474         /*@null@*/ /*@out@*/ void ** datap,
01475         /*@null@*/ /*@out@*/ size_t * lenp, int asAscii)
01476                 /*@modifies *datap, *lenp @*/;
01477 
01478 #ifdef __cplusplus
01479 }
01480 #endif
01481 /*@=fcnuse@*/
01482 
01483 #endif  /* H_RPMPGP */

Generated on Mon Aug 3 15:21:49 2009 for rpm by  doxygen 1.5.1