Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

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_ERROR           = -1,
00290     PGPHASHALGO_NONE            = 0,
00291     PGPHASHALGO_MD5             =  1,   
00292     PGPHASHALGO_SHA1            =  2,   
00293     PGPHASHALGO_RIPEMD160       =  3,   
00294     PGPHASHALGO_MD2             =  5,   
00295     PGPHASHALGO_TIGER192        =  6,   
00296     PGPHASHALGO_HAVAL_5_160     =  7,   
00297     PGPHASHALGO_SHA256          =  8,   
00298     PGPHASHALGO_SHA384          =  9,   
00299     PGPHASHALGO_SHA512          = 10,   
00301     PGPHASHALGO_MD4             = 104,  
00302     PGPHASHALGO_RIPEMD128       = 105,  
00303     PGPHASHALGO_CRC32           = 106,  
00304     PGPHASHALGO_ADLER32         = 107,  
00305     PGPHASHALGO_CRC64           = 108,  
00306     PGPHASHALGO_JLU32           = 109,  
00307     PGPHASHALGO_SHA224          = 110,  
00308     PGPHASHALGO_RIPEMD256       = 111,  
00309     PGPHASHALGO_RIPEMD320       = 112,  
00310     PGPHASHALGO_SALSA10         = 113,  
00311     PGPHASHALGO_SALSA20         = 114,  
00313 } pgpHashAlgo;
00314 
00318 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00319 extern struct pgpValTbl_s pgpHashTbl[];
00320 
00342 typedef struct pgpPktSigV3_s {
00343     byte version;       
00344     byte hashlen;       
00345     byte sigtype;       
00346     byte time[4];       
00347     byte signid[8];     
00348     byte pubkey_algo;   
00349     byte hash_algo;     
00350     byte signhash16[2]; 
00351 } * pgpPktSigV3;
00352 
00374 typedef struct pgpPktSigV4_s {
00375     byte version;       
00376     byte sigtype;       
00377     byte pubkey_algo;   
00378     byte hash_algo;     
00379     byte hashlen[2];    
00380 } * pgpPktSigV4;
00381 
00448 /*@-typeuse@*/
00449 typedef enum pgpSubType_e {
00450     PGPSUBTYPE_NONE             =   0, 
00451     PGPSUBTYPE_SIG_CREATE_TIME  =   2, 
00452     PGPSUBTYPE_SIG_EXPIRE_TIME  =   3, 
00453     PGPSUBTYPE_EXPORTABLE_CERT  =   4, 
00454     PGPSUBTYPE_TRUST_SIG        =   5, 
00455     PGPSUBTYPE_REGEX            =   6, 
00456     PGPSUBTYPE_REVOCABLE        =   7, 
00457     PGPSUBTYPE_KEY_EXPIRE_TIME  =   9, 
00458     PGPSUBTYPE_ARR              =  10, 
00459     PGPSUBTYPE_PREFER_SYMKEY    =  11, 
00460     PGPSUBTYPE_REVOKE_KEY       =  12, 
00461     PGPSUBTYPE_ISSUER_KEYID     =  16, 
00462     PGPSUBTYPE_NOTATION         =  20, 
00463     PGPSUBTYPE_PREFER_HASH      =  21, 
00464     PGPSUBTYPE_PREFER_COMPRESS  =  22, 
00465     PGPSUBTYPE_KEYSERVER_PREFERS=  23, 
00466     PGPSUBTYPE_PREFER_KEYSERVER =  24, 
00467     PGPSUBTYPE_PRIMARY_USERID   =  25, 
00468     PGPSUBTYPE_POLICY_URL       =  26, 
00469     PGPSUBTYPE_KEY_FLAGS        =  27, 
00470     PGPSUBTYPE_SIGNER_USERID    =  28, 
00471     PGPSUBTYPE_REVOKE_REASON    =  29, 
00472     PGPSUBTYPE_FEATURES         =  30, 
00473     PGPSUBTYPE_EMBEDDED_SIG     =  32, 
00475     PGPSUBTYPE_INTERNAL_100     = 100, 
00476     PGPSUBTYPE_INTERNAL_101     = 101, 
00477     PGPSUBTYPE_INTERNAL_102     = 102, 
00478     PGPSUBTYPE_INTERNAL_103     = 103, 
00479     PGPSUBTYPE_INTERNAL_104     = 104, 
00480     PGPSUBTYPE_INTERNAL_105     = 105, 
00481     PGPSUBTYPE_INTERNAL_106     = 106, 
00482     PGPSUBTYPE_INTERNAL_107     = 107, 
00483     PGPSUBTYPE_INTERNAL_108     = 108, 
00484     PGPSUBTYPE_INTERNAL_109     = 109, 
00485     PGPSUBTYPE_INTERNAL_110     = 110, 
00487     PGPSUBTYPE_CRITICAL         = 128  
00488 } pgpSubType;
00489 /*@=typeuse@*/
00490 
00494 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00495 extern struct pgpValTbl_s pgpSubTypeTbl[];
00496 
00517 typedef union pgpPktSig_u {
00518     struct pgpPktSigV3_s v3;
00519     struct pgpPktSigV4_s v4;
00520 } * pgpPktSig;
00521 
00550 typedef struct pgpPktSymkey_s {
00551     byte version;       
00552     byte symkey_algo;
00553     byte s2k[1];
00554 } pgpPktSymkey;
00555 
00585 typedef struct pgpPktOnepass_s {
00586     byte version;       
00587     byte sigtype;       
00588     byte hash_algo;     
00589     byte pubkey_algo;   
00590     byte signid[8];     
00591     byte nested;
00592 } * pgpPktOnepass;
00593 
00666 typedef struct pgpPktKeyV3_s {
00667     byte version;       
00668     byte time[4];       
00669     byte valid[2];      
00670     byte pubkey_algo;   
00671 } * pgpPktKeyV3;
00672 
00704 typedef struct pgpPktKeyV4_s {
00705     byte version;       
00706     byte time[4];       
00707     byte pubkey_algo;   
00708 } * pgpPktKeyV4;
00709 
00774 typedef union pgpPktKey_u {
00775     struct pgpPktKeyV3_s v3;
00776     struct pgpPktKeyV4_s v4;
00777 } pgpPktKey;
00778 
00779 /*
00780  * 5.6. Compressed Data Packet (Tag 8)
00781  *
00782  * The Compressed Data packet contains compressed data. Typically, this
00783  * packet is found as the contents of an encrypted packet, or following
00784  * a Signature or One-Pass Signature packet, and contains literal data
00785  * packets.
00786  *
00787  * The body of this packet consists of:
00788  *   - One octet that gives the algorithm used to compress the packet.
00789  *   - The remainder of the packet is compressed data.
00790  *
00791  * A Compressed Data Packet's body contains an block that compresses
00792  * some set of packets. See section "Packet Composition" for details on
00793  * how messages are formed.
00794  *
00795  * ZIP-compressed packets are compressed with raw RFC 1951 DEFLATE
00796  * blocks. Note that PGP V2.6 uses 13 bits of compression. If an
00797  * implementation uses more bits of compression, PGP V2.6 cannot
00798  * decompress it.
00799  *
00800  * ZLIB-compressed packets are compressed with RFC 1950 ZLIB-style
00801  * blocks.
00802  */
00803 typedef struct pgpPktCdata_s {
00804     byte compressalgo;
00805     byte data[1];
00806 } pgpPktCdata;
00807 
00808 /*
00809  * 5.7. Symmetrically Encrypted Data Packet (Tag 9)
00810  *
00811  * The Symmetrically Encrypted Data packet contains data encrypted with
00812  * a symmetric-key algorithm. When it has been decrypted, it will
00813  * typically contain other packets (often literal data packets or
00814  * compressed data packets).
00815  *
00816  * The body of this packet consists of:
00817  *   - Encrypted data, the output of the selected symmetric-key cipher
00818  *     operating in PGP's variant of Cipher Feedback (CFB) mode.
00819  *
00820  * The symmetric cipher used may be specified in an Public-Key or
00821  * Symmetric-Key Encrypted Session Key packet that precedes the
00822  * Symmetrically Encrypted Data Packet.  In that case, the cipher
00823  * algorithm octet is prefixed to the session key before it is
00824  * encrypted.  If no packets of these types precede the encrypted data,
00825  * the IDEA algorithm is used with the session key calculated as the MD5
00826  * hash of the passphrase.
00827  *
00828  * The data is encrypted in CFB mode, with a CFB shift size equal to the
00829  * cipher's block size.  The Initial Vector (IV) is specified as all
00830  * zeros.  Instead of using an IV, OpenPGP prefixes a 10-octet string to
00831  * the data before it is encrypted.  The first eight octets are random,
00832  * and the 9th and 10th octets are copies of the 7th and 8th octets,
00833  * respectively. After encrypting the first 10 octets, the CFB state is
00834  * resynchronized if the cipher block size is 8 octets or less.  The
00835  * last 8 octets of ciphertext are passed through the cipher and the
00836  * block boundary is reset.
00837  *
00838  * The repetition of 16 bits in the 80 bits of random data prefixed to
00839  * the message allows the receiver to immediately check whether the
00840  * session key is incorrect.
00841  */
00842 typedef struct pgpPktEdata_s {
00843     byte data[1];
00844 } pgpPktEdata;
00845 
00846 /*
00847  * 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10)
00848  *
00849  * An experimental version of PGP used this packet as the Literal
00850  * packet, but no released version of PGP generated Literal packets with
00851  * this tag. With PGP 5.x, this packet has been re-assigned and is
00852  * reserved for use as the Marker packet.
00853  *
00854  * The body of this packet consists of:
00855  *   - The three octets 0x50, 0x47, 0x50 (which spell "PGP" in UTF-8).
00856  *
00857  * Such a packet MUST be ignored when received.  It may be placed at the
00858  * beginning of a message that uses features not available in PGP 2.6.x
00859  * in order to cause that version to report that newer software is
00860  * necessary to process the message.
00861  */
00862 /*
00863  * 5.9. Literal Data Packet (Tag 11)
00864  *
00865  * A Literal Data packet contains the body of a message; data that is
00866  * not to be further interpreted.
00867  *
00868  * The body of this packet consists of:
00869  *   - A one-octet field that describes how the data is formatted.
00870  *
00871  * If it is a 'b' (0x62), then the literal packet contains binary data.
00872  * If it is a 't' (0x74), then it contains text data, and thus may need
00873  * line ends converted to local form, or other text-mode changes.  RFC
00874  * 1991 also defined a value of 'l' as a 'local' mode for machine-local
00875  * conversions.  This use is now deprecated.
00876  *   - File name as a string (one-octet length, followed by file name),
00877  *     if the encrypted data should be saved as a file.
00878  *
00879  * If the special name "_CONSOLE" is used, the message is considered to
00880  * be "for your eyes only".  This advises that the message data is
00881  * unusually sensitive, and the receiving program should process it more
00882  * carefully, perhaps avoiding storing the received data to disk, for
00883  * example.
00884  *   - A four-octet number that indicates the modification date of the
00885  *     file, or the creation time of the packet, or a zero that
00886  *     indicates the present time.
00887  *   - The remainder of the packet is literal data.
00888  *
00889  * Text data is stored with <CR><LF> text endings (i.e. network-normal
00890  * line endings).  These should be converted to native line endings by
00891  * the receiving software.
00892  */
00893 typedef struct pgpPktLdata_s {
00894     byte format;
00895     byte filenamelen;
00896     byte filename[1];
00897 } pgpPktLdata;
00898 
00899 /*
00900  * 5.10. Trust Packet (Tag 12)
00901  *
00902  * The Trust packet is used only within keyrings and is not normally
00903  * exported.  Trust packets contain data that record the user's
00904  * specifications of which key holders are trustworthy introducers,
00905  * along with other information that implementing software uses for
00906  * trust information.
00907  *
00908  * Trust packets SHOULD NOT be emitted to output streams that are
00909  * transferred to other users, and they SHOULD be ignored on any input
00910  * other than local keyring files.
00911  */
00912 typedef struct pgpPktTrust_s {
00913     byte flag;
00914 } pgpPktTrust;
00915 
00916 /*
00917  * 5.11. User ID Packet (Tag 13)
00918  *
00919  * A User ID packet consists of data that is intended to represent the
00920  * name and email address of the key holder.  By convention, it includes
00921  * an RFC 822 mail name, but there are no restrictions on its content.
00922  * The packet length in the header specifies the length of the user id.
00923  * If it is text, it is encoded in UTF-8.
00924  *
00925  */
00926 typedef struct pgpPktUid_s {
00927     byte userid[1];
00928 } pgpPktUid;
00929 
00932 union pgpPktPre_u {
00933     pgpPktPubkey pubkey;        
00934     pgpPktSig sig;              
00935     pgpPktSymkey symkey;        
00936     pgpPktOnepass onepass;      
00937     pgpPktKey key;              
00938     pgpPktCdata cdata;          
00939     pgpPktEdata edata;          
00941     pgpPktLdata ldata;          
00942     pgpPktTrust tdata;          
00943     pgpPktUid uid;              
00944 };
00945 
00948 /*@-typeuse@*/
00949 typedef enum pgpArmor_e {
00950     PGPARMOR_ERR_CRC_CHECK              = -7,
00951     PGPARMOR_ERR_BODY_DECODE            = -6,
00952     PGPARMOR_ERR_CRC_DECODE             = -5,
00953     PGPARMOR_ERR_NO_END_PGP             = -4,
00954     PGPARMOR_ERR_UNKNOWN_PREAMBLE_TAG   = -3,
00955     PGPARMOR_ERR_UNKNOWN_ARMOR_TYPE     = -2,
00956     PGPARMOR_ERR_NO_BEGIN_PGP           = -1,
00957 #define PGPARMOR_ERROR  PGPARMOR_ERR_NO_BEGIN_PGP
00958     PGPARMOR_NONE               =  0,
00959     PGPARMOR_MESSAGE            =  1, 
00960     PGPARMOR_PUBKEY             =  2, 
00961     PGPARMOR_SIGNATURE          =  3, 
00962     PGPARMOR_SIGNED_MESSAGE     =  4, 
00963     PGPARMOR_FILE               =  5, 
00964     PGPARMOR_PRIVKEY            =  6, 
00965     PGPARMOR_SECKEY             =  7  
00966 } pgpArmor;
00967 /*@=typeuse@*/
00968 
00972 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00973 extern struct pgpValTbl_s pgpArmorTbl[];
00974 
00977 /*@-typeuse@*/
00978 typedef enum pgpArmorKey_e {
00979     PGPARMORKEY_VERSION         = 1, 
00980     PGPARMORKEY_COMMENT         = 2, 
00981     PGPARMORKEY_MESSAGEID       = 3, 
00982     PGPARMORKEY_HASH            = 4, 
00983     PGPARMORKEY_CHARSET         = 5  
00984 } pgpArmorKey;
00985 /*@=typeuse@*/
00986 
00990 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00991 extern struct pgpValTbl_s pgpArmorKeyTbl[];
00992 
00996 typedef enum rpmDigestFlags_e {
00997     RPMDIGEST_NONE      = 0
00998 } rpmDigestFlags;
00999 
01000 /*@unchecked@*/
01001 extern pgpHashAlgo rpmDigestHashAlgo;
01002 
01003 /*@unchecked@*/ /*@observer@*/
01004 extern struct poptOption rpmDigestPoptTable[];
01005 
01006 /*@-fcnuse@*/
01007 #ifdef __cplusplus
01008 extern "C" {
01009 #endif
01010 
01017 /*@unused@*/ static inline
01018 unsigned int pgpGrab(const byte *s, int nbytes)
01019         /*@*/
01020 {
01021     unsigned int i = 0;
01022     int nb = (nbytes <= sizeof(i) ? nbytes : sizeof(i));
01023 /*@-boundsread@*/
01024     while (nb--)
01025         i = (i << 8) | *s++;
01026 /*@=boundsread@*/
01027     return i;
01028 }
01029 
01036 /*@unused@*/ static inline
01037 int pgpLen(const byte *s, /*@out@*/ unsigned int *lenp)
01038         /*@modifies *lenp @*/
01039 {
01040 /*@-boundswrite@*/
01041     if (*s < 192) {
01042         (*lenp) = *s++;
01043         return 1;
01044     } else if (*s < 255) {
01045         (*lenp) = ((((unsigned)s[0]) - 192) << 8) + s[1] + 192;
01046         return 2;
01047     } else {
01048         (*lenp) = pgpGrab(s+1, 4);
01049         return 5;
01050     }
01051 /*@=boundswrite@*/
01052 }
01053 
01059 /*@unused@*/ static inline
01060 unsigned int pgpMpiBits(const byte *p)
01061         /*@requires maxRead(p) >= 1 @*/
01062         /*@*/
01063 {
01064     return ((p[0] << 8) | p[1]);
01065 }
01066 
01072 /*@unused@*/ static inline
01073 unsigned int pgpMpiLen(const byte *p)
01074         /*@requires maxRead(p) >= 1 @*/
01075         /*@*/
01076 {
01077     return (2 + ((pgpMpiBits(p)+7)>>3));
01078 }
01079         
01087 /*@unused@*/ static inline
01088 char * pgpHexCvt(/*@returned@*/ char *t, const byte *s, int nbytes)
01089         /*@modifies *t @*/
01090 {
01091     static char hex[] = "0123456789abcdef";
01092 /*@-boundswrite@*/
01093     while (nbytes-- > 0) {
01094         unsigned int i;
01095         i = *s++;
01096         *t++ = hex[ (i >> 4) & 0xf ];
01097         *t++ = hex[ (i     ) & 0xf ];
01098     }
01099     *t = '\0';
01100 /*@=boundswrite@*/
01101     return t;
01102 }
01103 
01111 /*@unused@*/ static inline /*@observer@*/
01112 char * pgpHexStr(const byte *p, unsigned int plen)
01113         /*@*/
01114 {
01115     static char prbuf[8*BUFSIZ];        /* XXX ick */
01116     char *t = prbuf;
01117     t = pgpHexCvt(t, p, plen);
01118     return prbuf;
01119 }
01120 
01127 /*@unused@*/ static inline /*@observer@*/
01128 const char * pgpMpiStr(const byte *p)
01129         /*@requires maxRead(p) >= 3 @*/
01130         /*@*/
01131 {
01132     static char prbuf[8*BUFSIZ];        /* XXX ick */
01133     char *t = prbuf;
01134     sprintf(t, "[%4u]: ", pgpGrab(p, 2));
01135     t += strlen(t);
01136     t = pgpHexCvt(t, p+2, pgpMpiLen(p)-2);
01137     return prbuf;
01138 }
01139 
01146 /*@unused@*/ static inline /*@observer@*/
01147 const char * pgpValStr(pgpValTbl vs, byte val)
01148         /*@*/
01149 {
01150     do {
01151         if (vs->val == val)
01152             break;
01153     } while ((++vs)->val != -1);
01154     return vs->str;
01155 }
01156 
01164 /*@unused@*/ static inline
01165 int pgpValTok(pgpValTbl vs, const char * s, const char * se)
01166         /*@*/
01167 {
01168     do {
01169         int vlen = strlen(vs->str);
01170         if (vlen <= (se-s) && !strncmp(s, vs->str, vlen))
01171             break;
01172     } while ((++vs)->val != -1);
01173     return vs->val;
01174 }
01175 
01182 /*@-exportlocal@*/
01183 void pgpPrtVal(const char * pre, pgpValTbl vs, byte val)
01184         /*@globals fileSystem @*/
01185         /*@modifies fileSystem @*/;
01186 /*@=exportlocal@*/
01187 
01195 /*@-exportlocal@*/
01196 int pgpPrtSubType(const byte *h, unsigned int hlen, pgpSigType sigtype)
01197         /*@globals fileSystem @*/
01198         /*@modifies fileSystem @*/;
01199 /*@=exportlocal@*/
01200 
01206 /*@-exportlocal@*/
01207 int pgpPrtSig(const pgpPkt pp)
01208         /*@globals fileSystem, internalState @*/
01209         /*@modifies fileSystem, internalState @*/;
01210 /*@=exportlocal@*/
01211 
01217 int pgpPrtKey(const pgpPkt pp)
01218         /*@globals fileSystem, internalState @*/
01219         /*@modifies fileSystem, internalState @*/;
01220 
01226 /*@-exportlocal@*/
01227 int pgpPrtUserID(const pgpPkt pp)
01228         /*@globals fileSystem, internalState @*/
01229         /*@modifies fileSystem, internalState @*/;
01230 /*@=exportlocal@*/
01231 
01237 /*@-exportlocal@*/
01238 int pgpPrtComment(const pgpPkt pp)
01239         /*@globals fileSystem @*/
01240         /*@modifies fileSystem @*/;
01241 /*@=exportlocal@*/
01242 
01251 /*@-exportlocal@*/
01252 int pgpPubkeyFingerprint(const byte * pkt, unsigned int pktlen,
01253                 /*@out@*/ byte * keyid)
01254         /*@modifies *keyid @*/;
01255 /*@=exportlocal@*/
01256 
01264 int pgpExtractPubkeyFingerprint(const char * b64pkt, /*@out@*/ byte * keyid)
01265         /*@modifies *keyid @*/;
01266 
01274 int pgpPktLen(const byte *pkt, unsigned int pleft, /*@out@*/ pgpPkt pp)
01275         /*@modifies pp @*/;
01276 
01283 /*@-exportlocal@*/
01284 int pgpPrtPkt(const byte *pkt, unsigned int pleft)
01285         /*@globals fileSystem, internalState @*/
01286         /*@modifies fileSystem, internalState @*/;
01287 /*@=exportlocal@*/
01288 
01297 int pgpPrtPkts(const byte *pkts, unsigned int pktlen, pgpDig dig, int printing)
01298         /*@globals fileSystem, internalState @*/
01299         /*@modifies dig, fileSystem, internalState @*/;
01300 
01308 pgpArmor pgpReadPkts(const char * fn,
01309                 /*@out@*/ const byte ** pkt, /*@out@*/ size_t * pktlen)
01310         /*@globals h_errno, fileSystem, internalState @*/
01311         /*@modifies *pkt, *pktlen, fileSystem, internalState @*/;
01312 
01320 char * pgpArmorWrap(int atype, const unsigned char * s, size_t ns)
01321         /*@*/;
01322 
01327 /*@only@*/
01328 pgpDig pgpNewDig(void)
01329         /*@*/;
01330 
01335 void pgpCleanDig(/*@null@*/ pgpDig dig)
01336         /*@modifies dig @*/;
01337 
01343 /*@only@*/ /*@null@*/
01344 pgpDig pgpFreeDig(/*@only@*/ /*@null@*/ pgpDig dig)
01345         /*@modifies dig @*/;
01346 
01352 /*@unused@*/ static inline
01353 int pgpIsPkt(const byte * p)
01354         /*@*/
01355 {
01356 /*@-boundsread@*/
01357     unsigned int val = *p++;
01358 /*@=boundsread@*/
01359     pgpTag tag;
01360     int rc;
01361 
01362     /* XXX can't deal with these. */
01363     if (!(val & 0x80))
01364         return 0;
01365 
01366     if (val & 0x40)
01367         tag = (val & 0x3f);
01368     else
01369         tag = (val >> 2) & 0xf;
01370 
01371     switch (tag) {
01372     case PGPTAG_MARKER:
01373     case PGPTAG_SYMMETRIC_SESSION_KEY:
01374     case PGPTAG_ONEPASS_SIGNATURE:
01375     case PGPTAG_PUBLIC_KEY:
01376     case PGPTAG_SECRET_KEY:
01377     case PGPTAG_PUBLIC_SESSION_KEY:
01378     case PGPTAG_SIGNATURE:
01379     case PGPTAG_COMMENT:
01380     case PGPTAG_COMMENT_OLD:
01381     case PGPTAG_LITERAL_DATA:
01382     case PGPTAG_COMPRESSED_DATA:
01383     case PGPTAG_SYMMETRIC_DATA:
01384         rc = 1;
01385         break;
01386     case PGPTAG_PUBLIC_SUBKEY:
01387     case PGPTAG_SECRET_SUBKEY:
01388     case PGPTAG_USER_ID:
01389     case PGPTAG_RESERVED:
01390     case PGPTAG_TRUST:
01391     case PGPTAG_PHOTOID:
01392     case PGPTAG_ENCRYPTED_MDC:
01393     case PGPTAG_MDC:
01394     case PGPTAG_PRIVATE_60:
01395     case PGPTAG_PRIVATE_62:
01396     case PGPTAG_CONTROL:
01397     default:
01398         rc = 0;
01399         break;
01400     }
01401 
01402     return rc;
01403 }
01404 
01405 #define CRC24_INIT      0xb704ce
01406 #define CRC24_POLY      0x1864cfb
01407 
01414 /*@unused@*/ static inline
01415 unsigned int pgpCRC(const byte *octets, size_t len)
01416         /*@*/
01417 {
01418     unsigned int crc = CRC24_INIT;
01419     int i;
01420 
01421     while (len--) {
01422 /*@-boundsread@*/
01423         crc ^= (*octets++) << 16;
01424 /*@=boundsread@*/
01425         for (i = 0; i < 8; i++) {
01426             crc <<= 1;
01427             if (crc & 0x1000000)
01428                 crc ^= CRC24_POLY;
01429         }
01430     }
01431     return crc & 0xffffff;
01432 }
01433 
01439 /*@only@*/
01440 DIGEST_CTX rpmDigestDup(DIGEST_CTX octx)
01441         /*@*/;
01442 
01450 /*@only@*/ /*@null@*/
01451 DIGEST_CTX rpmDigestInit(pgpHashAlgo hashalgo, rpmDigestFlags flags)
01452         /*@*/;
01453 
01461 int rpmDigestUpdate(/*@null@*/ DIGEST_CTX ctx, const void * data, size_t len)
01462         /*@modifies ctx @*/;
01463 
01475 int rpmDigestFinal(/*@only@*/ /*@null@*/ DIGEST_CTX ctx,
01476         /*@null@*/ /*@out@*/ void * datap,
01477         /*@null@*/ /*@out@*/ size_t * lenp, int asAscii)
01478                 /*@modifies *datap, *lenp @*/;
01479 
01480 #ifdef __cplusplus
01481 }
01482 #endif
01483 /*@=fcnuse@*/
01484 
01485 #endif  /* H_RPMPGP */

Generated on Sun Aug 18 10:48:24 2013 for rpm by  doxygen 1.4.4