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 <beecrypt/base64.h>
00014 #include <beecrypt/dsa.h>
00015 #include <beecrypt/endianness.h>
00016 #include <beecrypt/mp32.h>
00017 #include <beecrypt/rsa.h>
00018 #include <beecrypt/rsapk.h>
00019 
00022 typedef /*@abstract@*/ struct DIGEST_CTX_s * DIGEST_CTX;
00023 
00026 typedef const struct pgpValTbl_s {
00027     int val;
00028 /*@observer@*/ const char * str;
00029 } * pgpValTbl;
00030  
00038 typedef enum pgpTag_e {
00039     PGPTAG_RESERVED             =  0, 
00040     PGPTAG_PUBLIC_SESSION_KEY   =  1, 
00041     PGPTAG_SIGNATURE            =  2, 
00042     PGPTAG_SYMMETRIC_SESSION_KEY=  3, 
00043     PGPTAG_ONEPASS_SIGNATURE    =  4, 
00044     PGPTAG_SECRET_KEY           =  5, 
00045     PGPTAG_PUBLIC_KEY           =  6, 
00046     PGPTAG_SECRET_SUBKEY        =  7, 
00047     PGPTAG_COMPRESSED_DATA      =  8, 
00048     PGPTAG_SYMMETRIC_DATA       =  9, 
00049     PGPTAG_MARKER               = 10, 
00050     PGPTAG_LITERAL_DATA         = 11, 
00051     PGPTAG_TRUST                = 12, 
00052     PGPTAG_USER_ID              = 13, 
00053     PGPTAG_PUBLIC_SUBKEY        = 14, 
00054     PGPTAG_COMMENT_OLD          = 16, 
00055     PGPTAG_PHOTOID              = 17, 
00056     PGPTAG_ENCRYPTED_MDC        = 18, 
00057     PGPTAG_MDC                  = 19, 
00058     PGPTAG_PRIVATE_60           = 60, 
00059     PGPTAG_COMMENT              = 61, 
00060     PGPTAG_PRIVATE_62           = 62, 
00061     PGPTAG_CONTROL              = 63 
00062 } pgpTag;
00063 
00066 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00067 extern struct pgpValTbl_s pgpTagTbl[];
00068 
00103 typedef struct pgpPktPubkey_s {
00104     byte version;       
00105     byte keyid[8];      
00106     byte algo;          
00107 } pgpPktPubkey;
00108 
00109 
00116 /*@-typeuse@*/
00117 typedef enum pgpSigType_e {
00118     PGPSIGTYPE_BINARY            = 0x00, 
00119     PGPSIGTYPE_TEXT              = 0x01, 
00120     PGPSIGTYPE_STANDALONE        = 0x02, 
00121     PGPSIGTYPE_GENERIC_CERT      = 0x10,
00123     PGPSIGTYPE_PERSONA_CERT      = 0x11,
00125     PGPSIGTYPE_CASUAL_CERT       = 0x12,
00127     PGPSIGTYPE_POSITIVE_CERT     = 0x13,
00129     PGPSIGTYPE_SUBKEY_BINDING    = 0x18, 
00130     PGPSIGTYPE_SIGNED_KEY        = 0x1F, 
00131     PGPSIGTYPE_KEY_REVOKE        = 0x20, 
00132     PGPSIGTYPE_SUBKEY_REVOKE     = 0x28, 
00133     PGPSIGTYPE_CERT_REVOKE       = 0x30, 
00134     PGPSIGTYPE_TIMESTAMP         = 0x40  
00135 } pgpSigType;
00136 /*@=typeuse@*/
00137 
00140 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00141 extern struct pgpValTbl_s pgpSigTypeTbl[];
00142 
00166 /*@-typeuse@*/
00167 typedef enum pgpPubkeyAlgo_e {
00168     PGPPUBKEYALGO_RSA           =  1,   
00169     PGPPUBKEYALGO_RSA_ENCRYPT   =  2,   
00170     PGPPUBKEYALGO_RSA_SIGN      =  3,   
00171     PGPPUBKEYALGO_ELGAMAL_ENCRYPT= 16,  
00172     PGPPUBKEYALGO_DSA           = 17,   
00173     PGPPUBKEYALGO_EC            = 18,   
00174     PGPPUBKEYALGO_ECDSA         = 19,   
00175     PGPPUBKEYALGO_ELGAMAL       = 20,   
00176     PGPPUBKEYALGO_DH            = 21    
00177 } pgpPubkeyAlgo;
00178 /*@=typeuse@*/
00179 
00182 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00183 extern struct pgpValTbl_s pgpPubkeyTbl[];
00184 
00209 /*@-typeuse@*/
00210 typedef enum pgpSymkeyAlgo_e {
00211     PGPSYMKEYALGO_PLAINTEXT     =  0,   
00212     PGPSYMKEYALGO_IDEA          =  1,   
00213     PGPSYMKEYALGO_TRIPLE_DES    =  2,   
00214     PGPSYMKEYALGO_CAST5         =  3,   
00215     PGPSYMKEYALGO_BLOWFISH      =  4,   
00216     PGPSYMKEYALGO_SAFER         =  5,   
00217     PGPSYMKEYALGO_DES_SK        =  6,   
00218     PGPSYMKEYALGO_AES_128       =  7,   
00219     PGPSYMKEYALGO_AES_192       =  8,   
00220     PGPSYMKEYALGO_AES_256       =  9,   
00221     PGPSYMKEYALGO_TWOFISH       = 10    
00222 } pgpSymkeyAlgo;
00223 /*@=typeuse@*/
00224 
00227 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00228 extern struct pgpValTbl_s pgpSymkeyTbl[];
00229 
00245 /*@-typeuse@*/
00246 typedef enum pgpCompressAlgo_e {
00247     PGPCOMPRESSALGO_NONE        =  0,   
00248     PGPCOMPRESSALGO_ZIP         =  1,   
00249     PGPCOMPRESSALGO_ZLIB        =  2    
00250 } pgpCompressAlgo;
00251 /*@=typeuse@*/
00252 
00255 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00256 extern struct pgpValTbl_s pgpCompressionTbl[];
00257 
00279 typedef enum pgpHashAlgo_e {
00280     PGPHASHALGO_MD5             = 1,    
00281     PGPHASHALGO_SHA1            = 2,    
00282     PGPHASHALGO_RIPEMD160       = 3,    
00283     PGPHASHALGO_MD2             = 5,    
00284     PGPHASHALGO_TIGER192        = 6,    
00285     PGPHASHALGO_HAVAL_5_160     = 7     
00286 } pgpHashAlgo;
00287 
00290 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00291 extern struct pgpValTbl_s pgpHashTbl[];
00292 
00314 typedef struct pgpPktSigV3_s {
00315     byte version;       
00316     byte hashlen;       
00317     byte sigtype;       
00318     byte time[4];       
00319     byte signid[8];     
00320     byte pubkey_algo;   
00321     byte hash_algo;     
00322     byte signhash16[2]; 
00323 } * pgpPktSigV3;
00324 
00346 typedef struct pgpPktSigV4_s {
00347     byte version;       
00348     byte sigtype;       
00349     byte pubkey_algo;   
00350     byte hash_algo;     
00351     byte hashlen[2];    
00352 } * pgpPktSigV4;
00353 
00420 /*@-typeuse@*/
00421 typedef enum pgpSubType_e {
00422     PGPSUBTYPE_SIG_CREATE_TIME  =   2, 
00423     PGPSUBTYPE_SIG_EXPIRE_TIME  =   3, 
00424     PGPSUBTYPE_EXPORTABLE_CERT  =   4, 
00425     PGPSUBTYPE_TRUST_SIG        =   5, 
00426     PGPSUBTYPE_REGEX            =   6, 
00427     PGPSUBTYPE_REVOCABLE        =   7, 
00428     PGPSUBTYPE_KEY_EXPIRE_TIME  =   9, 
00429     PGPSUBTYPE_BACKWARD_COMPAT  =  10, 
00430     PGPSUBTYPE_PREFER_SYMKEY    =  11, 
00431     PGPSUBTYPE_REVOKE_KEY       =  12, 
00432     PGPSUBTYPE_ISSUER_KEYID     =  16, 
00433     PGPSUBTYPE_NOTATION         =  20, 
00434     PGPSUBTYPE_PREFER_HASH      =  21, 
00435     PGPSUBTYPE_PREFER_COMPRESS  =  22, 
00436     PGPSUBTYPE_KEYSERVER_PREFERS=  23, 
00437     PGPSUBTYPE_PREFER_KEYSERVER =  24, 
00438     PGPSUBTYPE_PRIMARY_USERID   =  25, 
00439     PGPSUBTYPE_POLICY_URL       =  26, 
00440     PGPSUBTYPE_KEY_FLAGS        =  27, 
00441     PGPSUBTYPE_SIGNER_USERID    =  28, 
00442     PGPSUBTYPE_REVOKE_REASON    =  29, 
00443     PGPSUBTYPE_INTERNAL_100     = 100, 
00444     PGPSUBTYPE_INTERNAL_101     = 101, 
00445     PGPSUBTYPE_INTERNAL_102     = 102, 
00446     PGPSUBTYPE_INTERNAL_103     = 103, 
00447     PGPSUBTYPE_INTERNAL_104     = 104, 
00448     PGPSUBTYPE_INTERNAL_105     = 105, 
00449     PGPSUBTYPE_INTERNAL_106     = 106, 
00450     PGPSUBTYPE_INTERNAL_107     = 107, 
00451     PGPSUBTYPE_INTERNAL_108     = 108, 
00452     PGPSUBTYPE_INTERNAL_109     = 109, 
00453     PGPSUBTYPE_INTERNAL_110     = 110 
00454 } pgpSubType;
00455 /*@=typeuse@*/
00456 
00459 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00460 extern struct pgpValTbl_s pgpSubTypeTbl[];
00461 
00482 typedef union pgpPktSig_u {
00483     struct pgpPktSigV3_s v3;
00484     struct pgpPktSigV4_s v4;
00485 } * pgpPktSig;
00486 
00515 typedef struct pgpPktSymkey_s {
00516     byte version;       
00517     byte symkey_algo;
00518     byte s2k[1];
00519 } pgpPktSymkey;
00520 
00550 typedef struct pgpPktOnepass_s {
00551     byte version;       
00552     byte sigtype;       
00553     byte hash_algo;     
00554     byte pubkey_algo;   
00555     byte signid[8];     
00556     byte nested;
00557 } * pgpPktOnepass;
00558 
00631 typedef struct pgpPktKeyV3_s {
00632     byte version;       
00633     byte time[4];       
00634     byte valid[2];      
00635     byte pubkey_algo;   
00636 } * pgpPktKeyV3;
00637 
00669 typedef struct pgpPktKeyV4_s {
00670     byte version;       
00671     byte time[4];       
00672     byte pubkey_algo;   
00673 } * pgpPktKeyV4;
00674 
00739 typedef union pgpPktKey_u {
00740     struct pgpPktKeyV3_s v3;
00741     struct pgpPktKeyV4_s v4;
00742 } pgpPktKey;
00743 
00744 /*
00745  * 5.6. Compressed Data Packet (Tag 8)
00746  *
00747  * The Compressed Data packet contains compressed data. Typically, this
00748  * packet is found as the contents of an encrypted packet, or following
00749  * a Signature or One-Pass Signature packet, and contains literal data
00750  * packets.
00751  *
00752  * The body of this packet consists of:
00753  *   - One octet that gives the algorithm used to compress the packet.
00754  *   - The remainder of the packet is compressed data.
00755  *
00756  * A Compressed Data Packet's body contains an block that compresses
00757  * some set of packets. See section "Packet Composition" for details on
00758  * how messages are formed.
00759  *
00760  * ZIP-compressed packets are compressed with raw RFC 1951 DEFLATE
00761  * blocks. Note that PGP V2.6 uses 13 bits of compression. If an
00762  * implementation uses more bits of compression, PGP V2.6 cannot
00763  * decompress it.
00764  *
00765  * ZLIB-compressed packets are compressed with RFC 1950 ZLIB-style
00766  * blocks.
00767  */
00768 typedef struct pgpPktCdata_s {
00769     byte compressalgo;
00770     byte data[1];
00771 } pgpPktCdata;
00772 
00773 /*
00774  * 5.7. Symmetrically Encrypted Data Packet (Tag 9)
00775  *
00776  * The Symmetrically Encrypted Data packet contains data encrypted with
00777  * a symmetric-key algorithm. When it has been decrypted, it will
00778  * typically contain other packets (often literal data packets or
00779  * compressed data packets).
00780  *
00781  * The body of this packet consists of:
00782  *   - Encrypted data, the output of the selected symmetric-key cipher
00783  *     operating in PGP's variant of Cipher Feedback (CFB) mode.
00784  *
00785  * The symmetric cipher used may be specified in an Public-Key or
00786  * Symmetric-Key Encrypted Session Key packet that precedes the
00787  * Symmetrically Encrypted Data Packet.  In that case, the cipher
00788  * algorithm octet is prefixed to the session key before it is
00789  * encrypted.  If no packets of these types precede the encrypted data,
00790  * the IDEA algorithm is used with the session key calculated as the MD5
00791  * hash of the passphrase.
00792  *
00793  * The data is encrypted in CFB mode, with a CFB shift size equal to the
00794  * cipher's block size.  The Initial Vector (IV) is specified as all
00795  * zeros.  Instead of using an IV, OpenPGP prefixes a 10-octet string to
00796  * the data before it is encrypted.  The first eight octets are random,
00797  * and the 9th and 10th octets are copies of the 7th and 8th octets,
00798  * respectively. After encrypting the first 10 octets, the CFB state is
00799  * resynchronized if the cipher block size is 8 octets or less.  The
00800  * last 8 octets of ciphertext are passed through the cipher and the
00801  * block boundary is reset.
00802  *
00803  * The repetition of 16 bits in the 80 bits of random data prefixed to
00804  * the message allows the receiver to immediately check whether the
00805  * session key is incorrect.
00806  */
00807 typedef struct pgpPktEdata_s {
00808     byte data[1];
00809 } pgpPktEdata;
00810 
00811 /*
00812  * 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10)
00813  *
00814  * An experimental version of PGP used this packet as the Literal
00815  * packet, but no released version of PGP generated Literal packets with
00816  * this tag. With PGP 5.x, this packet has been re-assigned and is
00817  * reserved for use as the Marker packet.
00818  *
00819  * The body of this packet consists of:
00820  *   - The three octets 0x50, 0x47, 0x50 (which spell "PGP" in UTF-8).
00821  *
00822  * Such a packet MUST be ignored when received.  It may be placed at the
00823  * beginning of a message that uses features not available in PGP 2.6.x
00824  * in order to cause that version to report that newer software is
00825  * necessary to process the message.
00826  */
00827 /*
00828  * 5.9. Literal Data Packet (Tag 11)
00829  *
00830  * A Literal Data packet contains the body of a message; data that is
00831  * not to be further interpreted.
00832  *
00833  * The body of this packet consists of:
00834  *   - A one-octet field that describes how the data is formatted.
00835  *
00836  * If it is a 'b' (0x62), then the literal packet contains binary data.
00837  * If it is a 't' (0x74), then it contains text data, and thus may need
00838  * line ends converted to local form, or other text-mode changes.  RFC
00839  * 1991 also defined a value of 'l' as a 'local' mode for machine-local
00840  * conversions.  This use is now deprecated.
00841  *   - File name as a string (one-octet length, followed by file name),
00842  *     if the encrypted data should be saved as a file.
00843  *
00844  * If the special name "_CONSOLE" is used, the message is considered to
00845  * be "for your eyes only".  This advises that the message data is
00846  * unusually sensitive, and the receiving program should process it more
00847  * carefully, perhaps avoiding storing the received data to disk, for
00848  * example.
00849  *   - A four-octet number that indicates the modification date of the
00850  *     file, or the creation time of the packet, or a zero that
00851  *     indicates the present time.
00852  *   - The remainder of the packet is literal data.
00853  *
00854  * Text data is stored with <CR><LF> text endings (i.e. network-normal
00855  * line endings).  These should be converted to native line endings by
00856  * the receiving software.
00857  */
00858 typedef struct pgpPktLdata_s {
00859     byte format;
00860     byte filenamelen;
00861     byte filename[1];
00862 } pgpPktLdata;
00863 
00864 /*
00865  * 5.10. Trust Packet (Tag 12)
00866  *
00867  * The Trust packet is used only within keyrings and is not normally
00868  * exported.  Trust packets contain data that record the user's
00869  * specifications of which key holders are trustworthy introducers,
00870  * along with other information that implementing software uses for
00871  * trust information.
00872  *
00873  * Trust packets SHOULD NOT be emitted to output streams that are
00874  * transferred to other users, and they SHOULD be ignored on any input
00875  * other than local keyring files.
00876  */
00877 typedef struct pgpPktTrust_s {
00878     byte flag;
00879 } pgpPktTrust;
00880 
00881 /*
00882  * 5.11. User ID Packet (Tag 13)
00883  *
00884  * A User ID packet consists of data that is intended to represent the
00885  * name and email address of the key holder.  By convention, it includes
00886  * an RFC 822 mail name, but there are no restrictions on its content.
00887  * The packet length in the header specifies the length of the user id.
00888  * If it is text, it is encoded in UTF-8.
00889  *
00890  */
00891 typedef struct pgpPktUid_s {
00892     byte userid[1];
00893 } pgpPktUid;
00894 
00897 union pgpPktPre_u {
00898     pgpPktPubkey pubkey;        
00899     pgpPktSig sig;              
00900     pgpPktSymkey symkey;        
00901     pgpPktOnepass onepass;      
00902     pgpPktKey key;              
00903     pgpPktCdata cdata;          
00904     pgpPktEdata edata;          
00906     pgpPktLdata ldata;          
00907     pgpPktTrust tdata;          
00908     pgpPktUid uid;              
00909 };
00910 
00913 /*@-typeuse@*/
00914 typedef enum pgpArmor_e {
00915     PGPARMOR_ERROR              = -1,
00916     PGPARMOR_NONE               =  0,
00917     PGPARMOR_MESSAGE            =  1, 
00918     PGPARMOR_PUBKEY             =  2, 
00919     PGPARMOR_SIGNATURE          =  3, 
00920     PGPARMOR_SIGNED_MESSAGE     =  4, 
00921     PGPARMOR_FILE               =  5, 
00922     PGPARMOR_PRIVKEY            =  6, 
00923     PGPARMOR_SECKEY             =  7 
00924 } pgpArmor;
00925 /*@=typeuse@*/
00926 
00929 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00930 extern struct pgpValTbl_s pgpArmorTbl[];
00931 
00934 /*@-typeuse@*/
00935 typedef enum pgpArmorKey_e {
00936     PGPARMORKEY_VERSION         = 1, 
00937     PGPARMORKEY_COMMENT         = 2, 
00938     PGPARMORKEY_MESSAGEID       = 3, 
00939     PGPARMORKEY_HASH            = 4, 
00940     PGPARMORKEY_CHARSET         = 5 
00941 } pgpArmorKey;
00942 /*@=typeuse@*/
00943 
00946 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
00947 extern struct pgpValTbl_s pgpArmorKeyTbl[];
00948 
00951 struct pgpDigParams_s {
00952 /*@only@*/ /*@null@*/
00953     const char * userid;
00954 /*@only@*/ /*@null@*/
00955     const byte * hash;
00956     const char * params[4];
00957     byte tag;
00958 
00959     byte version;       
00960     byte time[4];       
00961     byte pubkey_algo;   
00963     byte hash_algo;
00964     byte sigtype;
00965     byte hashlen;
00966     byte signhash16[2];
00967     byte signid[8];
00968     byte saved;
00969 #define PGPDIG_SAVED_TIME       (1 << 0)
00970 #define PGPDIG_SAVED_ID         (1 << 1)
00971 
00972 };
00973 
00976 struct pgpDig_s {
00977     struct pgpDigParams_s signature;
00978     struct pgpDigParams_s pubkey;
00979 
00980     size_t nbytes;              
00982 /*@only@*/ /*@null@*/
00983     DIGEST_CTX sha1ctx;         
00984 /*@only@*/ /*@null@*/
00985     DIGEST_CTX hdrsha1ctx;      
00986 /*@only@*/ /*@null@*/
00987     void * sha1;                
00988     size_t sha1len;             
00990 /*@only@*/ /*@null@*/
00991     DIGEST_CTX md5ctx;          
00992 /*@only@*/ /*@null@*/
00993     void * md5;                 
00994     size_t md5len;              
00996     /* DSA parameters. */
00997     mp32barrett p;
00998     mp32barrett q;
00999     mp32number g;
01000     mp32number y;
01001     mp32number hm;
01002     mp32number r;
01003     mp32number s;
01004 
01005     /* RSA parameters. */
01006     rsapk rsa_pk;
01007     mp32number m;
01008     mp32number c;
01009     mp32number rsahm;
01010 };
01011 
01012 
01013 /*@-fcnuse@*/
01014 #ifdef __cplusplus
01015 extern "C" {
01016 #endif
01017 
01020 /*@unused@*/ static inline
01021 unsigned int pgpGrab(const byte *s, int nbytes)
01022         /*@*/
01023 {
01024     unsigned int i = 0;
01025     int nb = (nbytes <= sizeof(i) ? nbytes : sizeof(i));
01026     while (nb--)
01027         i = (i << 8) | *s++;
01028     return i;
01029 }
01030 
01033 /*@unused@*/ static inline
01034 int pgpLen(const byte *s, /*@out@*/ unsigned int *lenp)
01035         /*@modifies *lenp @*/
01036 {
01037     if (*s < 192) {
01038         (*lenp) = *s++;
01039         return 1;
01040     } else if (*s < 255) {
01041         (*lenp) = ((((unsigned)s[0]) - 192) << 8) + s[1] + 192;
01042         return 2;
01043     } else {
01044         (*lenp) = pgpGrab(s+1, 4);
01045         return 5;
01046     }
01047 }
01048 
01051 /*@unused@*/ static inline
01052 unsigned int pgpMpiBits(const byte *p)
01053         /*@*/
01054 {
01055     return ((p[0] << 8) | p[1]);
01056 }
01057 
01060 /*@unused@*/ static inline
01061 unsigned int pgpMpiLen(const byte *p)
01062         /*@*/
01063 {
01064     return (2 + ((pgpMpiBits(p)+7)>>3));
01065 }
01066         
01069 /*@unused@*/ static inline
01070 char * pgpHexCvt(/*@returned@*/ char *t, const byte *s, int nbytes)
01071         /*@modifies *t @*/
01072 {
01073     static char hex[] = "0123456789abcdef";
01074     while (nbytes-- > 0) {
01075         unsigned int i;
01076         i = *s++;
01077         *t++ = hex[ (i >> 4) & 0xf ];
01078         *t++ = hex[ (i     ) & 0xf ];
01079     }
01080     *t = '\0';
01081     return t;
01082 }
01083 
01086 /*@unused@*/ static inline /*@observer@*/
01087 char * pgpHexStr(const byte *p, unsigned int plen)
01088         /*@*/
01089 {
01090     static char prbuf[2048];
01091     char *t = prbuf;
01092     t = pgpHexCvt(t, p, plen);
01093     return prbuf;
01094 }
01095 
01098 /*@unused@*/ static inline /*@observer@*/
01099 const char * pgpMpiStr(const byte *p)
01100         /*@*/
01101 {
01102     static char prbuf[2048];
01103     char *t = prbuf;
01104     sprintf(t, "[%4u]: ", pgpGrab(p, 2));
01105     t += strlen(t);
01106     t = pgpHexCvt(t, p+2, pgpMpiLen(p)-2);
01107     return prbuf;
01108 }
01109 
01112 /*@unused@*/ static inline /*@observer@*/
01113 const char * pgpValStr(pgpValTbl vs, byte val)
01114         /*@*/
01115 {
01116     do {
01117         if (vs->val == val)
01118             break;
01119     } while ((++vs)->val != -1);
01120     return vs->str;
01121 }
01122 
01125 /*@unused@*/ static inline
01126 int pgpValTok(pgpValTbl vs, const char * s, const char * se)
01127         /*@*/
01128 {
01129     do {
01130         int vlen = strlen(vs->str);
01131         if (vlen <= (se-s) && !strncmp(s, vs->str, vlen))
01132             break;
01133     } while ((++vs)->val != -1);
01134     return vs->val;
01135 }
01136 
01137 /*@-exportlocal@*/
01140 void pgpPrtVal(const char * pre, pgpValTbl vs, byte val)
01141         /*@globals fileSystem @*/
01142         /*@modifies fileSystem @*/;
01143 
01146 int pgpPrtSubType(const byte *h, unsigned int hlen)
01147         /*@globals fileSystem @*/
01148         /*@modifies fileSystem @*/;
01149 
01152 int pgpPrtSig(pgpTag tag, const byte *h, unsigned int hlen)
01153         /*@globals fileSystem @*/
01154         /*@modifies fileSystem @*/;
01155 
01158 int pgpPrtKey(pgpTag tag, const byte *h, unsigned int hlen)
01159         /*@globals fileSystem @*/
01160         /*@modifies fileSystem @*/;
01161 
01164 int pgpPrtUserID(pgpTag tag, const byte *h, unsigned int hlen)
01165         /*@globals fileSystem @*/
01166         /*@modifies fileSystem @*/;
01167 
01170 int pgpPrtComment(pgpTag tag, const byte *h, unsigned int hlen)
01171         /*@globals fileSystem @*/
01172         /*@modifies fileSystem @*/;
01173 
01176 int pgpPrtPkt(const byte *pkt)
01177         /*@globals fileSystem @*/
01178         /*@modifies fileSystem @*/;
01179 /*@=exportlocal@*/
01180 
01183 int pgpPrtPkts(const byte *pkts, unsigned int plen, struct pgpDig_s *dig, int printing)
01184         /*@globals fileSystem @*/
01185         /*@modifies fileSystem @*/;
01186 
01189 pgpArmor pgpReadPkts(const char * fn,
01190                 /*@out@*/ const byte ** pkt, /*@out@*/ size_t * pktlen)
01191         /*@globals fileSystem @*/
01192         /*@modifies *pkt, *pktlen, fileSystem @*/;
01193 
01196 /*@only@*/
01197 struct pgpDig_s * pgpNewDig(void)
01198         /*@*/;
01199 
01202 void pgpCleanDig(/*@null@*/ struct pgpDig_s * dig)
01203         /*@modifies *dig @*/;
01204 
01207 /*@only@*/ /*@null@*/
01208 struct pgpDig_s * pgpFreeDig(/*@only@*/ /*@null@*/ struct pgpDig_s * dig)
01209         /*@modifies *dig @*/;
01210 
01213 /*@unused@*/ static inline
01214 int pgpIsPkt(const byte * p)
01215         /*@*/
01216 {
01217     unsigned int val = *p++;
01218     pgpTag tag;
01219     int rc;
01220 
01221     /* XXX can't deal with these. */
01222     if (!(val & 0x80))
01223         return 0;
01224 
01225     if (val & 0x40)
01226         tag = (val & 0x3f);
01227     else
01228         tag = (val >> 2) & 0xf;
01229 
01230     switch (tag) {
01231     case PGPTAG_MARKER:
01232     case PGPTAG_SYMMETRIC_SESSION_KEY:
01233     case PGPTAG_ONEPASS_SIGNATURE:
01234     case PGPTAG_PUBLIC_KEY:
01235     case PGPTAG_SECRET_KEY:
01236     case PGPTAG_PUBLIC_SESSION_KEY:
01237     case PGPTAG_SIGNATURE:
01238     case PGPTAG_COMMENT:
01239     case PGPTAG_COMMENT_OLD:
01240     case PGPTAG_LITERAL_DATA:
01241     case PGPTAG_COMPRESSED_DATA:
01242     case PGPTAG_SYMMETRIC_DATA:
01243         rc = 1;
01244         break;
01245     case PGPTAG_PUBLIC_SUBKEY:
01246     case PGPTAG_SECRET_SUBKEY:
01247     case PGPTAG_USER_ID:
01248     case PGPTAG_RESERVED:
01249     case PGPTAG_TRUST:
01250     case PGPTAG_PHOTOID:
01251     case PGPTAG_ENCRYPTED_MDC:
01252     case PGPTAG_MDC:
01253     case PGPTAG_PRIVATE_60:
01254     case PGPTAG_PRIVATE_62:
01255     case PGPTAG_CONTROL:
01256     default:
01257         rc = 0;
01258         break;
01259     }
01260 
01261     return rc;
01262 }
01263 
01264 #define CRC24_INIT      0xb704ce
01265 #define CRC24_POLY      0x1864cfb
01266 
01269 /*@unused@*/ static inline
01270 uint32 pgpCRC(const byte *octets, size_t len)
01271         /*@*/
01272 {
01273     uint32 crc = CRC24_INIT;
01274     int i;
01275 
01276     while (len--) {
01277         crc ^= (*octets++) << 16;
01278         for (i = 0; i < 8; i++) {
01279             crc <<= 1;
01280             if (crc & 0x1000000)
01281                 crc ^= CRC24_POLY;
01282         }
01283     }
01284     return crc & 0xffffff;
01285 }
01286 
01287 #ifdef __cplusplus
01288 }
01289 #endif
01290 /*@=fcnuse@*/
01291 
01292 #endif  /* H_RPMPGP */

Generated on Sun Feb 2 23:32:06 2003 for rpm by doxygen1.2.18