00001 #ifndef H_RPMPGP
00002 #define H_RPMPGP
00003
00013 #include <string.h>
00014 #include <popt.h>
00015
00018 typedef struct DIGEST_CTX_s * DIGEST_CTX;
00019
00022 typedef struct pgpPkt_s * pgpPkt;
00023
00026 typedef struct pgpDig_s * pgpDig;
00027
00030 typedef struct pgpDigParams_s * pgpDigParams;
00031
00035 typedef enum pgpVSFlags_e {
00036 RPMVSF_DEFAULT = 0,
00037 RPMVSF_NOHDRCHK = (1 << 0),
00038 RPMVSF_NEEDPAYLOAD = (1 << 1),
00039
00040 RPMVSF_NOSHA1HEADER = (1 << 8),
00041 RPMVSF_NOMD5HEADER = (1 << 9),
00042 RPMVSF_NODSAHEADER = (1 << 10),
00043 RPMVSF_NORSAHEADER = (1 << 11),
00044
00045 RPMVSF_NOSHA1 = (1 << 16),
00046 RPMVSF_NOMD5 = (1 << 17),
00047 RPMVSF_NODSA = (1 << 18),
00048 RPMVSF_NORSA = (1 << 19)
00049
00050 } pgpVSFlags;
00051
00052 #define _RPMVSF_NODIGESTS \
00053 ( RPMVSF_NOSHA1HEADER | \
00054 RPMVSF_NOMD5HEADER | \
00055 RPMVSF_NOSHA1 | \
00056 RPMVSF_NOMD5 )
00057
00058 #define _RPMVSF_NOSIGNATURES \
00059 ( RPMVSF_NODSAHEADER | \
00060 RPMVSF_NORSAHEADER | \
00061 RPMVSF_NODSA | \
00062 RPMVSF_NORSA )
00063
00064 #define _RPMVSF_NOHEADER \
00065 ( RPMVSF_NOSHA1HEADER | \
00066 RPMVSF_NOMD5HEADER | \
00067 RPMVSF_NODSAHEADER | \
00068 RPMVSF_NORSAHEADER )
00069
00070 #define _RPMVSF_NOPAYLOAD \
00071 ( RPMVSF_NOSHA1 | \
00072 RPMVSF_NOMD5 | \
00073 RPMVSF_NODSA | \
00074 RPMVSF_NORSA )
00075
00076 #if defined(_RPMPGP_INTERNAL)
00077 #include <rpmsw.h>
00078
00082 struct pgpDigParams_s {
00083
00084 const char * userid;
00085
00086 const uint8_t * hash;
00087 const char * params[4];
00088 uint8_t tag;
00089
00090 uint8_t version;
00091 uint8_t time[4];
00092 uint8_t pubkey_algo;
00094 uint8_t hash_algo;
00095 uint8_t sigtype;
00096 uint8_t hashlen;
00097 uint8_t signhash16[2];
00098 uint8_t signid[8];
00099 uint8_t saved;
00100 #define PGPDIG_SAVED_TIME (1 << 0)
00101 #define PGPDIG_SAVED_ID (1 << 1)
00102
00103 };
00104
00108 struct pgpDig_s {
00109 struct pgpDigParams_s signature;
00110 struct pgpDigParams_s pubkey;
00111
00112 uint32_t sigtag;
00113 uint32_t sigtype;
00114
00115 const void * sig;
00116 uint32_t siglen;
00118 pgpVSFlags vsflags;
00119 struct rpmop_s dops;
00120 struct rpmop_s sops;
00122 int (*findPubkey) (void * _ts, void * _dig)
00123 ;
00124
00125 void * _ts;
00126
00127 int nrefs;
00129 uint8_t ** ppkts;
00130 int npkts;
00131 size_t nbytes;
00133
00134 DIGEST_CTX sha1ctx;
00135
00136 DIGEST_CTX hdrsha1ctx;
00137
00138 void * sha1;
00139 size_t sha1len;
00141
00142 DIGEST_CTX md5ctx;
00143
00144 DIGEST_CTX hdrmd5ctx;
00145
00146 void * md5;
00147 size_t md5len;
00148
00149 void * impl;
00150 };
00151 #endif
00152
00155 typedef const struct pgpValTbl_s {
00156 int val;
00157 const char * str;
00158 } * pgpValTbl;
00159
00167 typedef enum pgpTag_e {
00168 PGPTAG_RESERVED = 0,
00169 PGPTAG_PUBLIC_SESSION_KEY = 1,
00170 PGPTAG_SIGNATURE = 2,
00171 PGPTAG_SYMMETRIC_SESSION_KEY= 3,
00172 PGPTAG_ONEPASS_SIGNATURE = 4,
00173 PGPTAG_SECRET_KEY = 5,
00174 PGPTAG_PUBLIC_KEY = 6,
00175 PGPTAG_SECRET_SUBKEY = 7,
00176 PGPTAG_COMPRESSED_DATA = 8,
00177 PGPTAG_SYMMETRIC_DATA = 9,
00178 PGPTAG_MARKER = 10,
00179 PGPTAG_LITERAL_DATA = 11,
00180 PGPTAG_TRUST = 12,
00181 PGPTAG_USER_ID = 13,
00182 PGPTAG_PUBLIC_SUBKEY = 14,
00183 PGPTAG_COMMENT_OLD = 16,
00184 PGPTAG_PHOTOID = 17,
00185 PGPTAG_ENCRYPTED_MDC = 18,
00186 PGPTAG_MDC = 19,
00187 PGPTAG_PRIVATE_60 = 60,
00188 PGPTAG_COMMENT = 61,
00189 PGPTAG_PRIVATE_62 = 62,
00190 PGPTAG_CONTROL = 63
00191 } pgpTag;
00192
00195
00196 extern struct pgpValTbl_s pgpTagTbl[];
00197
00232 typedef struct pgpPktPubkey_s {
00233 uint8_t version;
00234 uint8_t keyid[8];
00235 uint8_t algo;
00236 } pgpPktPubkey;
00237
00238
00245
00246 typedef enum pgpSigType_e {
00247 PGPSIGTYPE_BINARY = 0x00,
00248 PGPSIGTYPE_TEXT = 0x01,
00249 PGPSIGTYPE_STANDALONE = 0x02,
00250 PGPSIGTYPE_GENERIC_CERT = 0x10,
00252 PGPSIGTYPE_PERSONA_CERT = 0x11,
00254 PGPSIGTYPE_CASUAL_CERT = 0x12,
00256 PGPSIGTYPE_POSITIVE_CERT = 0x13,
00258 PGPSIGTYPE_SUBKEY_BINDING = 0x18,
00259 PGPSIGTYPE_SIGNED_KEY = 0x1F,
00260 PGPSIGTYPE_KEY_REVOKE = 0x20,
00261 PGPSIGTYPE_SUBKEY_REVOKE = 0x28,
00262 PGPSIGTYPE_CERT_REVOKE = 0x30,
00263 PGPSIGTYPE_TIMESTAMP = 0x40
00264 } pgpSigType;
00265
00266
00269
00270 extern struct pgpValTbl_s pgpSigTypeTbl[];
00271
00295
00296 typedef enum pgpPubkeyAlgo_e {
00297 PGPPUBKEYALGO_RSA = 1,
00298 PGPPUBKEYALGO_RSA_ENCRYPT = 2,
00299 PGPPUBKEYALGO_RSA_SIGN = 3,
00300 PGPPUBKEYALGO_ELGAMAL_ENCRYPT = 16,
00301 PGPPUBKEYALGO_DSA = 17,
00302 PGPPUBKEYALGO_EC = 18,
00303 PGPPUBKEYALGO_ECDSA = 19,
00304 PGPPUBKEYALGO_ELGAMAL = 20,
00305 PGPPUBKEYALGO_DH = 21
00306 } pgpPubkeyAlgo;
00307
00308
00311
00312 extern struct pgpValTbl_s pgpPubkeyTbl[];
00313
00338
00339 typedef enum pgpSymkeyAlgo_e {
00340 PGPSYMKEYALGO_PLAINTEXT = 0,
00341 PGPSYMKEYALGO_IDEA = 1,
00342 PGPSYMKEYALGO_TRIPLE_DES = 2,
00343 PGPSYMKEYALGO_CAST5 = 3,
00344 PGPSYMKEYALGO_BLOWFISH = 4,
00345 PGPSYMKEYALGO_SAFER = 5,
00346 PGPSYMKEYALGO_DES_SK = 6,
00347 PGPSYMKEYALGO_AES_128 = 7,
00348 PGPSYMKEYALGO_AES_192 = 8,
00349 PGPSYMKEYALGO_AES_256 = 9,
00350 PGPSYMKEYALGO_TWOFISH = 10,
00351 PGPSYMKEYALGO_NOENCRYPT = 110
00352 } pgpSymkeyAlgo;
00353
00354
00358
00359 extern struct pgpValTbl_s pgpSymkeyTbl[];
00360
00376
00377 typedef enum pgpCompressAlgo_e {
00378 PGPCOMPRESSALGO_NONE = 0,
00379 PGPCOMPRESSALGO_ZIP = 1,
00380 PGPCOMPRESSALGO_ZLIB = 2,
00381 PGPCOMPRESSALGO_BZIP2 = 3
00382 } pgpCompressAlgo;
00383
00384
00388
00389 extern struct pgpValTbl_s pgpCompressionTbl[];
00390
00412 typedef enum pgpHashAlgo_e {
00413 PGPHASHALGO_MD5 = 1,
00414 PGPHASHALGO_SHA1 = 2,
00415 PGPHASHALGO_RIPEMD160 = 3,
00416 PGPHASHALGO_MD2 = 5,
00417 PGPHASHALGO_TIGER192 = 6,
00418 PGPHASHALGO_HAVAL_5_160 = 7,
00419 PGPHASHALGO_SHA256 = 8,
00420 PGPHASHALGO_SHA384 = 9,
00421 PGPHASHALGO_SHA512 = 10,
00423 PGPHASHALGO_MD4 = 104,
00424 PGPHASHALGO_RIPEMD128 = 105,
00425 PGPHASHALGO_CRC32 = 106,
00426 PGPHASHALGO_ADLER32 = 107,
00427 PGPHASHALGO_CRC64 = 108,
00428 PGPHASHALGO_JLU32 = 109,
00429 PGPHASHALGO_SHA224 = 110,
00430 PGPHASHALGO_RIPEMD256 = 111,
00431 PGPHASHALGO_RIPEMD320 = 112,
00432 PGPHASHALGO_SALSA10 = 113,
00433 PGPHASHALGO_SALSA20 = 114,
00435 } pgpHashAlgo;
00436
00440
00441 extern struct pgpValTbl_s pgpHashTbl[];
00442
00464 typedef struct pgpPktSigV3_s {
00465 uint8_t version;
00466 uint8_t hashlen;
00467 uint8_t sigtype;
00468 uint8_t time[4];
00469 uint8_t signid[8];
00470 uint8_t pubkey_algo;
00471 uint8_t hash_algo;
00472 uint8_t signhash16[2];
00473 } * pgpPktSigV3;
00474
00496 typedef struct pgpPktSigV4_s {
00497 uint8_t version;
00498 uint8_t sigtype;
00499 uint8_t pubkey_algo;
00500 uint8_t hash_algo;
00501 uint8_t hashlen[2];
00502 } * pgpPktSigV4;
00503
00570
00571 typedef enum pgpSubType_e {
00572 PGPSUBTYPE_NONE = 0,
00573 PGPSUBTYPE_SIG_CREATE_TIME = 2,
00574 PGPSUBTYPE_SIG_EXPIRE_TIME = 3,
00575 PGPSUBTYPE_EXPORTABLE_CERT = 4,
00576 PGPSUBTYPE_TRUST_SIG = 5,
00577 PGPSUBTYPE_REGEX = 6,
00578 PGPSUBTYPE_REVOCABLE = 7,
00579 PGPSUBTYPE_KEY_EXPIRE_TIME = 9,
00580 PGPSUBTYPE_ARR = 10,
00581 PGPSUBTYPE_PREFER_SYMKEY = 11,
00582 PGPSUBTYPE_REVOKE_KEY = 12,
00583 PGPSUBTYPE_ISSUER_KEYID = 16,
00584 PGPSUBTYPE_NOTATION = 20,
00585 PGPSUBTYPE_PREFER_HASH = 21,
00586 PGPSUBTYPE_PREFER_COMPRESS = 22,
00587 PGPSUBTYPE_KEYSERVER_PREFERS= 23,
00588 PGPSUBTYPE_PREFER_KEYSERVER = 24,
00589 PGPSUBTYPE_PRIMARY_USERID = 25,
00590 PGPSUBTYPE_POLICY_URL = 26,
00591 PGPSUBTYPE_KEY_FLAGS = 27,
00592 PGPSUBTYPE_SIGNER_USERID = 28,
00593 PGPSUBTYPE_REVOKE_REASON = 29,
00594 PGPSUBTYPE_FEATURES = 30,
00595 PGPSUBTYPE_EMBEDDED_SIG = 32,
00597 PGPSUBTYPE_INTERNAL_100 = 100,
00598 PGPSUBTYPE_INTERNAL_101 = 101,
00599 PGPSUBTYPE_INTERNAL_102 = 102,
00600 PGPSUBTYPE_INTERNAL_103 = 103,
00601 PGPSUBTYPE_INTERNAL_104 = 104,
00602 PGPSUBTYPE_INTERNAL_105 = 105,
00603 PGPSUBTYPE_INTERNAL_106 = 106,
00604 PGPSUBTYPE_INTERNAL_107 = 107,
00605 PGPSUBTYPE_INTERNAL_108 = 108,
00606 PGPSUBTYPE_INTERNAL_109 = 109,
00607 PGPSUBTYPE_INTERNAL_110 = 110,
00609 PGPSUBTYPE_CRITICAL = 128
00610 } pgpSubType;
00611
00612
00616
00617 extern struct pgpValTbl_s pgpSubTypeTbl[];
00618
00639 typedef union pgpPktSig_u {
00640 struct pgpPktSigV3_s v3;
00641 struct pgpPktSigV4_s v4;
00642 } * pgpPktSig;
00643
00672 typedef struct pgpPktSymkey_s {
00673 uint8_t version;
00674 uint8_t symkey_algo;
00675 uint8_t s2k[1];
00676 } pgpPktSymkey;
00677
00707 typedef struct pgpPktOnepass_s {
00708 uint8_t version;
00709 uint8_t sigtype;
00710 uint8_t hash_algo;
00711 uint8_t pubkey_algo;
00712 uint8_t signid[8];
00713 uint8_t nested;
00714 } * pgpPktOnepass;
00715
00788 typedef struct pgpPktKeyV3_s {
00789 uint8_t version;
00790 uint8_t time[4];
00791 uint8_t valid[2];
00792 uint8_t pubkey_algo;
00793 } * pgpPktKeyV3;
00794
00826 typedef struct pgpPktKeyV4_s {
00827 uint8_t version;
00828 uint8_t time[4];
00829 uint8_t pubkey_algo;
00830 } * pgpPktKeyV4;
00831
00896 typedef union pgpPktKey_u {
00897 struct pgpPktKeyV3_s v3;
00898 struct pgpPktKeyV4_s v4;
00899 } pgpPktKey;
00900
00925 typedef struct pgpPktCdata_s {
00926 uint8_t compressalgo;
00927 uint8_t data[1];
00928 } pgpPktCdata;
00929
00964 typedef struct pgpPktEdata_s {
00965 uint8_t data[1];
00966 } pgpPktEdata;
00967
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015 typedef struct pgpPktLdata_s {
01016 uint8_t format;
01017 uint8_t filenamelen;
01018 uint8_t filename[1];
01019 } pgpPktLdata;
01020
01034 typedef struct pgpPktTrust_s {
01035 uint8_t flag;
01036 } pgpPktTrust;
01037
01048 typedef struct pgpPktUid_s {
01049 uint8_t userid[1];
01050 } pgpPktUid;
01051
01054 union pgpPktPre_u {
01055 pgpPktPubkey pubkey;
01056 pgpPktSig sig;
01057 pgpPktSymkey symkey;
01058 pgpPktOnepass onepass;
01059 pgpPktKey key;
01060 pgpPktCdata cdata;
01061 pgpPktEdata edata;
01063 pgpPktLdata ldata;
01064 pgpPktTrust tdata;
01065 pgpPktUid uid;
01066 };
01067
01070
01071 typedef enum pgpArmor_e {
01072 PGPARMOR_ERR_CRC_CHECK = -7,
01073 PGPARMOR_ERR_BODY_DECODE = -6,
01074 PGPARMOR_ERR_CRC_DECODE = -5,
01075 PGPARMOR_ERR_NO_END_PGP = -4,
01076 PGPARMOR_ERR_UNKNOWN_PREAMBLE_TAG = -3,
01077 PGPARMOR_ERR_UNKNOWN_ARMOR_TYPE = -2,
01078 PGPARMOR_ERR_NO_BEGIN_PGP = -1,
01079 #define PGPARMOR_ERROR PGPARMOR_ERR_NO_BEGIN_PGP
01080 PGPARMOR_NONE = 0,
01081 PGPARMOR_MESSAGE = 1,
01082 PGPARMOR_PUBKEY = 2,
01083 PGPARMOR_SIGNATURE = 3,
01084 PGPARMOR_SIGNED_MESSAGE = 4,
01085 PGPARMOR_FILE = 5,
01086 PGPARMOR_PRIVKEY = 6,
01087 PGPARMOR_SECKEY = 7
01088 } pgpArmor;
01089
01090
01094
01095 extern struct pgpValTbl_s pgpArmorTbl[];
01096
01099
01100 typedef enum pgpArmorKey_e {
01101 PGPARMORKEY_VERSION = 1,
01102 PGPARMORKEY_COMMENT = 2,
01103 PGPARMORKEY_MESSAGEID = 3,
01104 PGPARMORKEY_HASH = 4,
01105 PGPARMORKEY_CHARSET = 5
01106 } pgpArmorKey;
01107
01108
01112
01113 extern struct pgpValTbl_s pgpArmorKeyTbl[];
01114
01118 typedef enum rpmDigestFlags_e {
01119 RPMDIGEST_NONE = 0
01120 } rpmDigestFlags;
01121
01124
01125 extern pgpHashAlgo rpmDigestHashAlgo;
01126
01129
01130 extern struct poptOption rpmDigestPoptTable[];
01131
01132
01133 #ifdef __cplusplus
01134 extern "C" {
01135 #endif
01136
01143 static inline
01144 unsigned int pgpGrab(const uint8_t * s, size_t nbytes)
01145
01146 {
01147 unsigned int i = 0;
01148 size_t nb = (nbytes <= sizeof(i) ? nbytes : sizeof(i));
01149 while (nb--)
01150 i = (i << 8) | *s++;
01151 return i;
01152 }
01153
01160 static inline
01161 int pgpLen(const uint8_t * s, unsigned int * lenp)
01162
01163 {
01164 if (*s < 192) {
01165 *lenp = (unsigned int) *s++;
01166 return 1;
01167 } else if (*s < 255) {
01168 *lenp = (unsigned int) ((((unsigned)s[0]) - 192) << 8) + s[1] + 192;
01169 return 2;
01170 } else {
01171 *lenp = pgpGrab(s+1, 4);
01172 return 5;
01173 }
01174 }
01175
01181 static inline
01182 unsigned int pgpMpiBits(const uint8_t * p)
01183
01184
01185 {
01186 return (unsigned int) ((p[0] << 8) | p[1]);
01187 }
01188
01194 static inline
01195 unsigned int pgpMpiLen(const uint8_t * p)
01196
01197
01198 {
01199 return (2 + ((pgpMpiBits(p)+7)>>3));
01200 }
01201
01209 static inline
01210 char * pgpHexCvt( char * t, const uint8_t * s, size_t nbytes)
01211
01212 {
01213 static char hex[] = "0123456789abcdef";
01214 while (nbytes-- > 0) {
01215 unsigned int i;
01216 i = (unsigned int) *s++;
01217 *t++ = hex[ (i >> 4) & 0xf ];
01218 *t++ = hex[ (i ) & 0xf ];
01219 }
01220 *t = '\0';
01221 return t;
01222 }
01223
01231 static inline
01232 char * pgpHexStr(const uint8_t * p, size_t plen)
01233
01234 {
01235 static char prbuf[8*BUFSIZ];
01236 char *t = prbuf;
01237 t = pgpHexCvt(t, p, plen);
01238 return prbuf;
01239 }
01240
01247 static inline
01248 const char * pgpMpiStr(const uint8_t * p)
01249
01250
01251 {
01252 static char prbuf[8*BUFSIZ];
01253 char *t = prbuf;
01254 sprintf(t, "[%4u]: ", pgpGrab(p, 2));
01255 t += strlen(t);
01256 t = pgpHexCvt(t, p+2, pgpMpiLen(p)-2);
01257 return prbuf;
01258 }
01259
01266 static inline
01267 const char * pgpValStr(pgpValTbl vs, uint8_t val)
01268
01269 {
01270 do {
01271 if (vs->val == (int)val)
01272 break;
01273 } while ((++vs)->val != -1);
01274 return vs->str;
01275 }
01276
01284 static inline
01285 int pgpValTok(pgpValTbl vs, const char * s, const char * se)
01286
01287 {
01288 do {
01289 size_t vlen = strlen(vs->str);
01290 if (vlen <= (se-s) && !strncmp(s, vs->str, vlen))
01291 break;
01292 } while ((++vs)->val != -1);
01293 return vs->val;
01294 }
01295
01302
01303 void pgpPrtVal(const char * pre, pgpValTbl vs, uint8_t val)
01304
01305 ;
01306
01307
01315
01316 int pgpPrtSubType(const uint8_t * h, size_t hlen, pgpSigType sigtype)
01317
01318 ;
01319
01320
01326
01327 int pgpPrtSig(const pgpPkt pp)
01328
01329 ;
01330
01331
01337 int pgpPrtKey(const pgpPkt pp)
01338
01339 ;
01340
01346
01347 int pgpPrtUserID(const pgpPkt pp)
01348
01349 ;
01350
01351
01357
01358 int pgpPrtComment(const pgpPkt pp)
01359
01360 ;
01361
01362
01371
01372 int pgpPubkeyFingerprint(const uint8_t * pkt, size_t pktlen,
01373 uint8_t * keyid)
01374 ;
01375
01376
01384 int pgpExtractPubkeyFingerprint(const char * b64pkt, uint8_t * keyid)
01385 ;
01386
01394 int pgpPktLen(const uint8_t * pkt, size_t pleft, pgpPkt pp)
01395 ;
01396
01403
01404 int pgpPrtPkt(const uint8_t * pkt, size_t pleft)
01405
01406 ;
01407
01408
01417 int pgpPrtPkts(const uint8_t * pkts, size_t pktlen, pgpDig dig, int printing)
01418
01419 ;
01420
01428 pgpArmor pgpReadPkts(const char * fn,
01429 const uint8_t ** pkt, size_t * pktlen)
01430
01431 ;
01432
01440 char * pgpArmorWrap(int atype, const unsigned char * s, size_t ns)
01441 ;
01442
01449 int pgpHashAlgoStringToNumber(const char *name, size_t name_len)
01450 ;
01451
01455
01456 extern pgpVSFlags pgpDigVSFlags;
01457
01464
01465 pgpDig pgpDigUnlink ( pgpDig dig,
01466 const char * msg)
01467 ;
01468
01470
01471
01472 pgpDig XpgpDigUnlink ( pgpDig dig,
01473 const char * msg, const char * fn, unsigned ln)
01474 ;
01475
01476 #define pgpDigUnlink(_dig, _msg) XpgpDigUnlink(_dig, _msg, __FILE__, __LINE__)
01477
01484
01485 pgpDig pgpDigLink ( pgpDig dig, const char * msg)
01486 ;
01487
01489
01490 pgpDig XpgpDigLink ( pgpDig dig, const char * msg,
01491 const char * fn, unsigned ln)
01492 ;
01493 #define pgpDigLink(_dig, _msg) XpgpDigLink(_dig, _msg, __FILE__, __LINE__)
01494
01500
01501 pgpDig pgpDigFree( pgpDig dig)
01502 ;
01503
01508
01509 pgpDig pgpDigNew( pgpVSFlags vsflags)
01510 ;
01511
01516 void pgpDigClean( pgpDig dig)
01517 ;
01518
01524
01525 pgpDigParams pgpGetPubkey(const pgpDig dig)
01526 ;
01527
01533
01534 pgpDigParams pgpGetSignature(const pgpDig dig)
01535 ;
01536
01542 uint32_t pgpGetSigtag(const pgpDig dig)
01543 ;
01544
01551 uint32_t pgpGetSigtype(const pgpDig dig)
01552 ;
01553
01559
01560 extern const void * pgpGetSig(const pgpDig dig)
01561 ;
01562
01568 uint32_t pgpGetSiglen(const pgpDig dig)
01569 ;
01570
01580 int pgpSetSig(pgpDig dig,
01581 uint32_t sigtag, uint32_t sigtype,
01582 const void * sig, uint32_t siglen)
01583 ;
01584
01591 void * pgpStatsAccumulator(pgpDig dig, int opx)
01592 ;
01593
01601 int pgpSetFindPubkey(pgpDig dig,
01602 int (*findPubkey) (void *ts, void *dig),
01603 void * _ts)
01604 ;
01605
01611 int pgpFindPubkey(pgpDig dig)
01612 ;
01613
01619 static inline
01620 int pgpIsPkt(const uint8_t * p, pgpTag * tagp)
01621
01622 {
01623 unsigned int val = (unsigned int) *p++;
01624 pgpTag tag;
01625 int rc;
01626
01627
01628 if (!(val & 0x80))
01629 return 0;
01630
01631 if (val & 0x40)
01632 tag = (pgpTag)(val & 0x3f);
01633 else
01634 tag = (pgpTag)((val >> 2) & 0xf);
01635
01636 switch (tag) {
01637 case PGPTAG_MARKER:
01638 case PGPTAG_SYMMETRIC_SESSION_KEY:
01639 case PGPTAG_ONEPASS_SIGNATURE:
01640 case PGPTAG_PUBLIC_KEY:
01641 case PGPTAG_SECRET_KEY:
01642 case PGPTAG_PUBLIC_SESSION_KEY:
01643 case PGPTAG_SIGNATURE:
01644 case PGPTAG_COMMENT:
01645 case PGPTAG_COMMENT_OLD:
01646 case PGPTAG_LITERAL_DATA:
01647 case PGPTAG_COMPRESSED_DATA:
01648 case PGPTAG_SYMMETRIC_DATA:
01649 rc = 1;
01650 break;
01651 case PGPTAG_PUBLIC_SUBKEY:
01652 case PGPTAG_SECRET_SUBKEY:
01653 case PGPTAG_USER_ID:
01654 case PGPTAG_RESERVED:
01655 case PGPTAG_TRUST:
01656 case PGPTAG_PHOTOID:
01657 case PGPTAG_ENCRYPTED_MDC:
01658 case PGPTAG_MDC:
01659 case PGPTAG_PRIVATE_60:
01660 case PGPTAG_PRIVATE_62:
01661 case PGPTAG_CONTROL:
01662 default:
01663 rc = 0;
01664 break;
01665 }
01666 if (tagp)
01667 *tagp = tag;
01668 return rc;
01669 }
01670
01671 #define CRC24_INIT 0xb704ce
01672 #define CRC24_POLY 0x1864cfb
01673
01680 static inline
01681 unsigned int pgpCRC(const uint8_t * octets, size_t len)
01682
01683 {
01684 unsigned int crc = CRC24_INIT;
01685 int i;
01686
01687 while (len--) {
01688 crc ^= (*octets++) << 16;
01689 for (i = 0; i < 8; i++) {
01690 crc <<= 1;
01691 if (crc & 0x1000000)
01692 crc ^= CRC24_POLY;
01693 }
01694 }
01695 return crc & 0xffffff;
01696 }
01697
01703
01704 DIGEST_CTX rpmDigestDup(DIGEST_CTX octx)
01705 ;
01706
01714
01715 DIGEST_CTX rpmDigestInit(pgpHashAlgo hashalgo, rpmDigestFlags flags)
01716 ;
01717
01725 int rpmDigestUpdate( DIGEST_CTX ctx, const void * data, size_t len)
01726 ;
01727
01739 int rpmDigestFinal( DIGEST_CTX ctx,
01740 void * datap,
01741 size_t * lenp, int asAscii)
01742 ;
01743
01746 typedef int (*pgpImplSet_t) ( DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
01747 ;
01748
01751 typedef int (*pgpImplVerify_t) (pgpDig dig)
01752 ;
01753
01756 typedef int (*pgpImplMpiItem_t) (const char * pre, pgpDig dig, int itemno,
01757 const uint8_t * p, const uint8_t * pend)
01758
01759 ;
01760
01763 typedef void (*pgpImplClean_t) (void * impl)
01764 ;
01765
01768 typedef void * (*pgpImplFree_t) ( void * impl)
01769 ;
01770
01773 typedef void * (*pgpImplInit_t) (void)
01774 ;
01775
01776
01779 typedef struct pgpImplVecs_s {
01780 pgpImplSet_t _pgpSetRSA;
01781 pgpImplVerify_t _pgpVerifyRSA;
01782 pgpImplSet_t _pgpSetDSA;
01783 pgpImplVerify_t _pgpVerifyDSA;
01784 pgpImplMpiItem_t _pgpMpiItem;
01785 pgpImplClean_t _pgpClean;
01786 pgpImplFree_t _pgpFree;
01787 pgpImplInit_t _pgpInit;
01788 } pgpImplVecs_t;
01789
01792
01793 extern pgpImplVecs_t * pgpImplVecs;
01794
01795
01798 static inline
01799 int pgpImplSetRSA( DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
01800
01801 {
01802 return (*pgpImplVecs->_pgpSetRSA) (ctx, dig, sigp);
01803 }
01804
01807 static inline
01808 int pgpImplVerifyRSA(pgpDig dig)
01809
01810 {
01811 return (*pgpImplVecs->_pgpVerifyRSA) (dig);
01812 }
01813
01816 static inline
01817 int pgpImplSetDSA( DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
01818
01819 {
01820 return (*pgpImplVecs->_pgpSetDSA) (ctx, dig, sigp);
01821 }
01822
01825 static inline
01826 int pgpImplVerifyDSA(pgpDig dig)
01827
01828 {
01829 return (*pgpImplVecs->_pgpVerifyDSA) (dig);
01830 }
01831
01834 static inline
01835 int pgpImplMpiItem(const char * pre, pgpDig dig, int itemno,
01836 const uint8_t * p, const uint8_t * pend)
01837
01838 {
01839 return (*pgpImplVecs->_pgpMpiItem) (pre, dig, itemno, p, pend);
01840 }
01841
01844 static inline
01845 void pgpImplClean(void * impl)
01846
01847 {
01848
01849 (*pgpImplVecs->_pgpClean) (impl);
01850
01851 }
01852
01855 static inline
01856
01857 void * pgpImplFree( void * impl)
01858
01859 {
01860 return (*pgpImplVecs->_pgpFree) (impl);
01861 }
01862
01865 static inline
01866 void * pgpImplInit(void)
01867
01868 {
01869 return (*pgpImplVecs->_pgpInit) ();
01870 }
01871
01872
01873 #ifdef __cplusplus
01874 }
01875 #endif
01876
01877
01878 #endif