rpmpgp.h
Go to the documentation of this file.
#ifndef H_RPMPGP
#define H_RPMPGP
#include <string.h>
#include <popt.h>
#include <rpmiotypes.h>
#include <yarn.h>
#if defined(_RPMPGP_INTERNAL)
#include <rpmsw.h>
struct pgpDigParams_s {
/*@only@*/ /*@null@*/
const char * userid;
/*@only@*/ /*@null@*/
const rpmuint8_t * hash;
const char * params[4];
rpmuint8_t tag;
rpmuint8_t version;
rpmuint8_t time[4];
rpmuint8_t pubkey_algo;
rpmuint8_t hash_algo;
rpmuint8_t sigtype;
size_t hashlen;
rpmuint8_t signhash16[2];
rpmuint8_t signid[8];
rpmuint8_t saved;
#define PGPDIG_SAVED_TIME (1 << 0)
#define PGPDIG_SAVED_ID (1 << 1)
};
struct pgpDig_s {
struct rpmioItem_s _item;
struct pgpDigParams_s signature;
struct pgpDigParams_s pubkey;
rpmuint32_t sigtag;
rpmuint32_t sigtype;
/*@relnull@*/
const void * sig;
rpmuint32_t siglen;
pgpVSFlags vsflags;
struct rpmop_s dops;
struct rpmop_s sops;
int (*findPubkey) (void * _ts, /*@null@*/ void * _dig)
/*@modifies *_ts, *_dig @*/;
/*@null@*/
void * _ts;
rpmuint8_t ** ppkts;
int npkts;
size_t nbytes;
/*@only@*/ /*@null@*/
DIGEST_CTX sha1ctx;
/*@only@*/ /*@null@*/
DIGEST_CTX hdrsha1ctx;
/*@only@*/ /*@null@*/
void * sha1;
size_t sha1len;
/*@only@*/ /*@null@*/
DIGEST_CTX md5ctx;
/*@only@*/ /*@null@*/
DIGEST_CTX hdrctx;
/*@only@*/ /*@null@*/
void * md5;
size_t md5len;
/*@owned@*/ /*@relnull@*/
void * impl;
#if defined(__LCLINT__)
/*@refs@*/
int nrefs;
#endif
};
#endif
typedef const struct pgpValTbl_s {
int val;
/*@observer@*/
const char * str;
} * pgpValTbl;
typedef enum pgpTag_e {
PGPTAG_RESERVED = 0,
PGPTAG_PUBLIC_SESSION_KEY = 1,
PGPTAG_SIGNATURE = 2,
PGPTAG_SYMMETRIC_SESSION_KEY= 3,
PGPTAG_ONEPASS_SIGNATURE = 4,
PGPTAG_SECRET_KEY = 5,
PGPTAG_PUBLIC_KEY = 6,
PGPTAG_SECRET_SUBKEY = 7,
PGPTAG_COMPRESSED_DATA = 8,
PGPTAG_SYMMETRIC_DATA = 9,
PGPTAG_MARKER = 10,
PGPTAG_LITERAL_DATA = 11,
PGPTAG_TRUST = 12,
PGPTAG_USER_ID = 13,
PGPTAG_PUBLIC_SUBKEY = 14,
PGPTAG_COMMENT_OLD = 16,
PGPTAG_PHOTOID = 17,
PGPTAG_ENCRYPTED_MDC = 18,
PGPTAG_MDC = 19,
PGPTAG_PRIVATE_60 = 60,
PGPTAG_COMMENT = 61,
PGPTAG_PRIVATE_62 = 62,
PGPTAG_CONTROL = 63
} pgpTag;
/*@observer@*/ /*@unchecked@*/ /*@unused@*/
extern struct pgpValTbl_s pgpTagTbl[];
typedef struct pgpPktPubkey_s {
rpmuint8_t version;
rpmuint8_t keyid[8];
rpmuint8_t algo;
} pgpPktPubkey;
/*@-typeuse@*/
typedef enum pgpSigType_e {
PGPSIGTYPE_BINARY = 0x00,
PGPSIGTYPE_TEXT = 0x01,
PGPSIGTYPE_STANDALONE = 0x02,
PGPSIGTYPE_GENERIC_CERT = 0x10,
PGPSIGTYPE_PERSONA_CERT = 0x11,
PGPSIGTYPE_CASUAL_CERT = 0x12,
PGPSIGTYPE_POSITIVE_CERT = 0x13,
PGPSIGTYPE_SUBKEY_BINDING = 0x18,
PGPSIGTYPE_SIGNED_KEY = 0x1F,
PGPSIGTYPE_KEY_REVOKE = 0x20,
PGPSIGTYPE_SUBKEY_REVOKE = 0x28,
PGPSIGTYPE_CERT_REVOKE = 0x30,
PGPSIGTYPE_TIMESTAMP = 0x40,
PGPSIGTYPE_CONFIRM = 0x50
} pgpSigType;
/*@=typeuse@*/
/*@observer@*/ /*@unchecked@*/ /*@unused@*/
extern struct pgpValTbl_s pgpSigTypeTbl[];
/*@-typeuse@*/
typedef enum pgpPubkeyAlgo_e {
PGPPUBKEYALGO_RSA = 1,
PGPPUBKEYALGO_RSA_ENCRYPT = 2,
PGPPUBKEYALGO_RSA_SIGN = 3,
PGPPUBKEYALGO_ELGAMAL_ENCRYPT = 16,
PGPPUBKEYALGO_DSA = 17,
PGPPUBKEYALGO_EC = 18,
PGPPUBKEYALGO_ECDSA = 19,
PGPPUBKEYALGO_ELGAMAL = 20,
PGPPUBKEYALGO_DH = 21
} pgpPubkeyAlgo;
/*@=typeuse@*/
/*@observer@*/ /*@unchecked@*/ /*@unused@*/
extern struct pgpValTbl_s pgpPubkeyTbl[];
/*@-typeuse@*/
typedef enum pgpSymkeyAlgo_e {
PGPSYMKEYALGO_PLAINTEXT = 0,
PGPSYMKEYALGO_IDEA = 1,
PGPSYMKEYALGO_TRIPLE_DES = 2,
PGPSYMKEYALGO_CAST5 = 3,
PGPSYMKEYALGO_BLOWFISH = 4,
PGPSYMKEYALGO_SAFER = 5,
PGPSYMKEYALGO_DES_SK = 6,
PGPSYMKEYALGO_AES_128 = 7,
PGPSYMKEYALGO_AES_192 = 8,
PGPSYMKEYALGO_AES_256 = 9,
PGPSYMKEYALGO_TWOFISH = 10,
PGPSYMKEYALGO_NOENCRYPT = 110
} pgpSymkeyAlgo;
/*@=typeuse@*/
/*@observer@*/ /*@unchecked@*/ /*@unused@*/
extern struct pgpValTbl_s pgpSymkeyTbl[];
/*@-typeuse@*/
typedef enum pgpCompressAlgo_e {
PGPCOMPRESSALGO_NONE = 0,
PGPCOMPRESSALGO_ZIP = 1,
PGPCOMPRESSALGO_ZLIB = 2,
PGPCOMPRESSALGO_BZIP2 = 3
} pgpCompressAlgo;
/*@=typeuse@*/
/*@observer@*/ /*@unchecked@*/ /*@unused@*/
extern struct pgpValTbl_s pgpCompressionTbl[];
/*@observer@*/ /*@unchecked@*/ /*@unused@*/
extern struct pgpValTbl_s pgpHashTbl[];
typedef struct pgpPktSigV3_s {
rpmuint8_t version;
rpmuint8_t hashlen;
rpmuint8_t sigtype;
rpmuint8_t time[4];
rpmuint8_t signid[8];
rpmuint8_t pubkey_algo;
rpmuint8_t hash_algo;
rpmuint8_t signhash16[2];
} * pgpPktSigV3;
typedef struct pgpPktSigV4_s {
rpmuint8_t version;
rpmuint8_t sigtype;
rpmuint8_t pubkey_algo;
rpmuint8_t hash_algo;
rpmuint8_t hashlen[2];
} * pgpPktSigV4;
/*@-typeuse@*/
typedef enum pgpSubType_e {
PGPSUBTYPE_NONE = 0,
PGPSUBTYPE_SIG_CREATE_TIME = 2,
PGPSUBTYPE_SIG_EXPIRE_TIME = 3,
PGPSUBTYPE_EXPORTABLE_CERT = 4,
PGPSUBTYPE_TRUST_SIG = 5,
PGPSUBTYPE_REGEX = 6,
PGPSUBTYPE_REVOCABLE = 7,
PGPSUBTYPE_KEY_EXPIRE_TIME = 9,
PGPSUBTYPE_ARR = 10,
PGPSUBTYPE_PREFER_SYMKEY = 11,
PGPSUBTYPE_REVOKE_KEY = 12,
PGPSUBTYPE_ISSUER_KEYID = 16,
PGPSUBTYPE_NOTATION = 20,
PGPSUBTYPE_PREFER_HASH = 21,
PGPSUBTYPE_PREFER_COMPRESS = 22,
PGPSUBTYPE_KEYSERVER_PREFERS= 23,
PGPSUBTYPE_PREFER_KEYSERVER = 24,
PGPSUBTYPE_PRIMARY_USERID = 25,
PGPSUBTYPE_POLICY_URL = 26,
PGPSUBTYPE_KEY_FLAGS = 27,
PGPSUBTYPE_SIGNER_USERID = 28,
PGPSUBTYPE_REVOKE_REASON = 29,
PGPSUBTYPE_FEATURES = 30,
PGPSUBTYPE_SIG_TARGET = 31,
PGPSUBTYPE_EMBEDDED_SIG = 32,
PGPSUBTYPE_INTERNAL_100 = 100,
PGPSUBTYPE_INTERNAL_101 = 101,
PGPSUBTYPE_INTERNAL_102 = 102,
PGPSUBTYPE_INTERNAL_103 = 103,
PGPSUBTYPE_INTERNAL_104 = 104,
PGPSUBTYPE_INTERNAL_105 = 105,
PGPSUBTYPE_INTERNAL_106 = 106,
PGPSUBTYPE_INTERNAL_107 = 107,
PGPSUBTYPE_INTERNAL_108 = 108,
PGPSUBTYPE_INTERNAL_109 = 109,
PGPSUBTYPE_INTERNAL_110 = 110,
PGPSUBTYPE_CRITICAL = 128
} pgpSubType;
/*@=typeuse@*/
/*@observer@*/ /*@unchecked@*/ /*@unused@*/
extern struct pgpValTbl_s pgpSubTypeTbl[];
typedef union pgpPktSig_u {
struct pgpPktSigV3_s v3;
struct pgpPktSigV4_s v4;
} * pgpPktSig;
typedef struct pgpPktSymkey_s {
rpmuint8_t version;
rpmuint8_t symkey_algo;
rpmuint8_t s2k[1];
} pgpPktSymkey;
typedef struct pgpPktOnepass_s {
rpmuint8_t version;
rpmuint8_t sigtype;
rpmuint8_t hash_algo;
rpmuint8_t pubkey_algo;
rpmuint8_t signid[8];
rpmuint8_t nested;
} * pgpPktOnepass;
typedef struct pgpPktKeyV3_s {
rpmuint8_t version;
rpmuint8_t time[4];
rpmuint8_t valid[2];
rpmuint8_t pubkey_algo;
} * pgpPktKeyV3;
typedef struct pgpPktKeyV4_s {
rpmuint8_t version;
rpmuint8_t time[4];
rpmuint8_t pubkey_algo;
} * pgpPktKeyV4;
typedef union pgpPktKey_u {
struct pgpPktKeyV3_s v3;
struct pgpPktKeyV4_s v4;
} pgpPktKey;
typedef struct pgpPktCdata_s {
rpmuint8_t compressalgo;
rpmuint8_t data[1];
} pgpPktCdata;
typedef struct pgpPktEdata_s {
rpmuint8_t data[1];
} pgpPktEdata;
/*
* 5.9. Literal Data Packet (Tag 11)
*
* A Literal Data packet contains the body of a message; data that is
* not to be further interpreted.
*
* The body of this packet consists of:
* - A one-octet field that describes how the data is formatted.
*
* If it is a 'b' (0x62), then the literal packet contains binary data.
* If it is a 't' (0x74), then it contains text data, and thus may need
* line ends converted to local form, or other text-mode changes. RFC
* 1991 also defined a value of 'l' as a 'local' mode for machine-local
* conversions. This use is now deprecated.
* - File name as a string (one-octet length, followed by file name),
* if the encrypted data should be saved as a file.
*
* If the special name "_CONSOLE" is used, the message is considered to
* be "for your eyes only". This advises that the message data is
* unusually sensitive, and the receiving program should process it more
* carefully, perhaps avoiding storing the received data to disk, for
* example.
* - A four-octet number that indicates the modification date of the
* file, or the creation time of the packet, or a zero that
* indicates the present time.
* - The remainder of the packet is literal data.
*
* Text data is stored with <CR><LF> text endings (i.e. network-normal
* line endings). These should be converted to native line endings by
* the receiving software.
*/
typedef struct pgpPktLdata_s {
rpmuint8_t format;
rpmuint8_t filenamelen;
rpmuint8_t filename[1];
} pgpPktLdata;
typedef struct pgpPktTrust_s {
rpmuint8_t flag;
} pgpPktTrust;
typedef struct pgpPktUid_s {
rpmuint8_t userid[1];
} pgpPktUid;
union pgpPktPre_u {
pgpPktPubkey pubkey;
pgpPktSig sig;
pgpPktSymkey symkey;
pgpPktOnepass onepass;
pgpPktKey key;
pgpPktCdata cdata;
pgpPktEdata edata;
pgpPktLdata ldata;
pgpPktTrust tdata;
pgpPktUid uid;
};
/*@-typeuse@*/
typedef enum pgpArmor_e {
PGPARMOR_ERR_CRC_CHECK = -7,
PGPARMOR_ERR_BODY_DECODE = -6,
PGPARMOR_ERR_CRC_DECODE = -5,
PGPARMOR_ERR_NO_END_PGP = -4,
PGPARMOR_ERR_UNKNOWN_PREAMBLE_TAG = -3,
PGPARMOR_ERR_UNKNOWN_ARMOR_TYPE = -2,
PGPARMOR_ERR_NO_BEGIN_PGP = -1,
#define PGPARMOR_ERROR PGPARMOR_ERR_NO_BEGIN_PGP
PGPARMOR_NONE = 0,
PGPARMOR_MESSAGE = 1,
PGPARMOR_PUBKEY = 2,
PGPARMOR_SIGNATURE = 3,
PGPARMOR_SIGNED_MESSAGE = 4,
PGPARMOR_FILE = 5,
PGPARMOR_PRIVKEY = 6,
PGPARMOR_SECKEY = 7
} pgpArmor;
/*@=typeuse@*/
/*@observer@*/ /*@unchecked@*/ /*@unused@*/
extern struct pgpValTbl_s pgpArmorTbl[];
/*@-typeuse@*/
typedef enum pgpArmorKey_e {
PGPARMORKEY_VERSION = 1,
PGPARMORKEY_COMMENT = 2,
PGPARMORKEY_MESSAGEID = 3,
PGPARMORKEY_HASH = 4,
PGPARMORKEY_CHARSET = 5
} pgpArmorKey;
/*@=typeuse@*/
/*@observer@*/ /*@unchecked@*/ /*@unused@*/
extern struct pgpValTbl_s pgpArmorKeyTbl[];
/*@-fcnuse@*/
#ifdef __cplusplus
extern "C" {
#endif
/*@unused@*/ static inline
unsigned int pgpGrab(const rpmuint8_t * s, size_t nbytes)
/*@*/
{
unsigned int i = 0;
size_t nb = (nbytes <= sizeof(i) ? nbytes : sizeof(i));
while (nb--)
i = (i << 8) | *s++;
return i;
}
/*@unused@*/ static inline
unsigned int pgpLen(const rpmuint8_t * s, /*@out@*/ unsigned int * lenp)
/*@modifies *lenp @*/
{
if (*s < (rpmuint8_t)192) {
*lenp = (unsigned int) *s++;
return 1;
} else if (*s < (rpmuint8_t)255) {
*lenp = (unsigned int) ((((unsigned)s[0]) - 192) << 8) + (unsigned)s[1] + 192;
return 2;
} else {
*lenp = pgpGrab(s+1, 4);
return 5;
}
}
/*@unused@*/ static inline
unsigned int pgpMpiBits(const rpmuint8_t * p)
/*@requires maxRead(p) >= 1 @*/
/*@*/
{
return (unsigned int) ((p[0] << 8) | p[1]);
}
/*@unused@*/ static inline
unsigned int pgpMpiLen(const rpmuint8_t * p)
/*@requires maxRead(p) >= 1 @*/
/*@*/
{
return (2 + ((pgpMpiBits(p)+7)>>3));
}
/*@unused@*/ static inline
char * pgpHexCvt(/*@returned@*/ char * t, const rpmuint8_t * s, size_t nbytes)
/*@modifies *t @*/
{
static char hex[] = "0123456789abcdef";
while (nbytes-- > 0) {
unsigned int i;
i = (unsigned int) *s++;
*t++ = hex[ (i >> 4) & 0xf ];
*t++ = hex[ (i ) & 0xf ];
}
*t = '\0';
return t;
}
/*@unused@*/ static inline /*@observer@*/
char * pgpHexStr(const rpmuint8_t * p, size_t plen)
/*@*/
{
static char prbuf[8*BUFSIZ]; /* XXX ick */
char *t = prbuf;
t = pgpHexCvt(t, p, plen);
return prbuf;
}
/*@unused@*/ static inline /*@observer@*/
const char * pgpMpiStr(const rpmuint8_t * p)
/*@requires maxRead(p) >= 3 @*/
/*@*/
{
static char prbuf[8*BUFSIZ]; /* XXX ick */
char *t = prbuf;
sprintf(t, "[%4u]: ", pgpGrab(p, 2));
t += strlen(t);
t = pgpHexCvt(t, p+2, pgpMpiLen(p)-2);
return prbuf;
}
/*@unused@*/ static inline /*@observer@*/
const char * pgpValStr(pgpValTbl vs, rpmuint8_t val)
/*@*/
{
do {
if (vs->val == (int)val)
break;
} while ((++vs)->val != -1);
return vs->str;
}
/*@unused@*/ static inline
int pgpValTok(pgpValTbl vs, const char * s, const char * se)
/*@*/
{
do {
size_t vlen = strlen(vs->str);
if (vlen <= (size_t)(se-s) && !strncmp(s, vs->str, vlen))
break;
} while ((++vs)->val != -1);
return vs->val;
}
/*@-exportlocal@*/
void pgpPrtVal(const char * pre, pgpValTbl vs, rpmuint8_t val)
/*@globals fileSystem @*/
/*@modifies fileSystem @*/;
/*@=exportlocal@*/
/*@-exportlocal@*/
int pgpPrtSubType(const rpmuint8_t * h, size_t hlen, pgpSigType sigtype)
/*@globals fileSystem @*/
/*@modifies fileSystem @*/;
/*@=exportlocal@*/
/*@-exportlocal@*/
int pgpPrtSig(const pgpPkt pp)
/*@globals fileSystem, internalState @*/
/*@modifies fileSystem, internalState @*/;
/*@=exportlocal@*/
int pgpPrtKey(const pgpPkt pp)
/*@globals fileSystem, internalState @*/
/*@modifies fileSystem, internalState @*/;
/*@-exportlocal@*/
int pgpPrtUserID(const pgpPkt pp)
/*@globals fileSystem, internalState @*/
/*@modifies fileSystem, internalState @*/;
/*@=exportlocal@*/
/*@-exportlocal@*/
int pgpPrtComment(const pgpPkt pp)
/*@globals fileSystem @*/
/*@modifies fileSystem @*/;
/*@=exportlocal@*/
/*@-exportlocal@*/
int pgpPubkeyFingerprint(const rpmuint8_t * pkt, size_t pktlen,
/*@out@*/ rpmuint8_t * keyid)
/*@modifies *keyid @*/;
/*@=exportlocal@*/
int pgpExtractPubkeyFingerprint(const char * b64pkt,
/*@out@*/ rpmuint8_t * keyid)
/*@modifies *keyid @*/;
int pgpPktLen(const rpmuint8_t * pkt, size_t pleft, /*@out@*/ pgpPkt pp)
/*@modifies pp @*/;
/*@-exportlocal@*/
int pgpPrtPkt(const rpmuint8_t * pkt, size_t pleft)
/*@globals fileSystem, internalState @*/
/*@modifies fileSystem, internalState @*/;
/*@=exportlocal@*/
int pgpPrtPkts(const rpmuint8_t * pkts, size_t pktlen, pgpDig dig, int printing)
/*@globals fileSystem, internalState @*/
/*@modifies dig, fileSystem, internalState @*/;
pgpArmor pgpReadPkts(const char * fn,
/*@out@*/ rpmuint8_t ** pkt, /*@out@*/ size_t * pktlen)
/*@globals h_errno, fileSystem, internalState @*/
/*@modifies *pkt, *pktlen, fileSystem, internalState @*/;
char * pgpArmorWrap(rpmuint8_t atype, const unsigned char * s, size_t ns)
/*@*/;
pgpHashAlgo pgpHashAlgoStringToNumber(const char *name, size_t name_len)
/*@*/;
/*@unchecked@*/
extern pgpVSFlags pgpDigVSFlags;
/*@unused@*/ /*@null@*/
pgpDig pgpDigUnlink (/*@killref@*/ /*@only@*/ /*@null@*/ pgpDig dig,
/*@null@*/ const char * msg)
/*@modifies dig @*/;
#define pgpDigUnlink(_dig, _msg) \
((pgpDig)rpmioUnlinkPoolItem((rpmioItem)(_dig), _msg, __FILE__, __LINE__))
/*@unused@*/ /*@newref@*/ /*@null@*/
pgpDig pgpDigLink (/*@null@*/ pgpDig dig, /*@null@*/ const char * msg)
/*@modifies dig @*/;
#define pgpDigLink(_dig, _msg) \
((pgpDig)rpmioLinkPoolItem((rpmioItem)(_dig), _msg, __FILE__, __LINE__))
/*@unused@*/ /*@null@*/
pgpDig pgpDigFree(/*@killref@*/ /*@only@*/ /*@null@*/ pgpDig dig)
/*@modifies dig @*/;
#define pgpDigFree(_dig, _msg) \
((pgpDig)rpmioFreePoolItem((rpmioItem)(_dig), _msg, __FILE__, __LINE__))
/*@relnull@*/
pgpDig pgpDigNew(/*@unused@*/ pgpVSFlags vsflags)
/*@globals fileSystem @*/
/*@modifies fileSystem @*/;
void pgpDigClean(/*@null@*/ pgpDig dig)
/*@modifies dig @*/;
/*@exposed@*/
pgpDigParams pgpGetPubkey(const pgpDig dig)
/*@*/;
/*@exposed@*/
pgpDigParams pgpGetSignature(const pgpDig dig)
/*@*/;
rpmuint32_t pgpGetSigtag(const pgpDig dig)
/*@*/;
rpmuint32_t pgpGetSigtype(const pgpDig dig)
/*@*/;
/*@observer@*/ /*@null@*/
extern const void * pgpGetSig(const pgpDig dig)
/*@*/;
rpmuint32_t pgpGetSiglen(const pgpDig dig)
/*@*/;
int pgpSetSig(pgpDig dig,
rpmuint32_t sigtag, rpmuint32_t sigtype,
/*@kept@*/ /*@null@*/ const void * sig, rpmuint32_t siglen)
/*@modifies dig @*/;
/*@null@*/
void * pgpStatsAccumulator(pgpDig dig, int opx)
/*@*/;
int pgpSetFindPubkey(pgpDig dig,
/*@null@*/ int (*findPubkey) (void *ts, /*@null@*/ void *dig),
/*@exposed@*/ /*@null@*/ void * _ts)
/*@modifies dig @*/;
int pgpFindPubkey(pgpDig dig)
/*@modifies dig @*/;
/*@unused@*/ static inline
int pgpIsPkt(const rpmuint8_t * p, /*@null@*/ pgpTag * tagp)
/*@modifies *tagp @*/
{
unsigned int val = (unsigned int) *p++;
pgpTag tag;
int rc;
/* XXX can't deal with these. */
if (!(val & 0x80))
return 0;
if (val & 0x40)
tag = (pgpTag)(val & 0x3f);
else
tag = (pgpTag)((val >> 2) & 0xf);
switch (tag) {
case PGPTAG_MARKER:
case PGPTAG_SYMMETRIC_SESSION_KEY:
case PGPTAG_ONEPASS_SIGNATURE:
case PGPTAG_PUBLIC_KEY:
case PGPTAG_SECRET_KEY:
case PGPTAG_PUBLIC_SESSION_KEY:
case PGPTAG_SIGNATURE:
case PGPTAG_COMMENT:
case PGPTAG_COMMENT_OLD:
case PGPTAG_LITERAL_DATA:
case PGPTAG_COMPRESSED_DATA:
case PGPTAG_SYMMETRIC_DATA:
rc = 1;
break;
case PGPTAG_PUBLIC_SUBKEY:
case PGPTAG_SECRET_SUBKEY:
case PGPTAG_USER_ID:
case PGPTAG_RESERVED:
case PGPTAG_TRUST:
case PGPTAG_PHOTOID:
case PGPTAG_ENCRYPTED_MDC:
case PGPTAG_MDC:
case PGPTAG_PRIVATE_60:
case PGPTAG_PRIVATE_62:
case PGPTAG_CONTROL:
default:
rc = 0;
break;
}
if (tagp != NULL)
*tagp = tag;
return rc;
}
#define CRC24_INIT 0xb704ce
#define CRC24_POLY 0x1864cfb
/*@unused@*/ static inline
unsigned int pgpCRC(const rpmuint8_t * octets, size_t len)
/*@*/
{
unsigned int crc = CRC24_INIT;
int i;
while (len--) {
crc ^= (*octets++) << 16;
for (i = 0; i < 8; i++) {
crc <<= 1;
if (crc & 0x1000000)
crc ^= CRC24_POLY;
}
}
return crc & 0xffffff;
}
typedef int (*pgpImplSet_t) (/*@only@*/ DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
/*@modifies ctx, dig @*/;
typedef int (*pgpImplVerify_t) (pgpDig dig)
/*@*/;
typedef int (*pgpImplMpiItem_t) (const char * pre, pgpDig dig, int itemno,
const rpmuint8_t * p, /*@null@*/ const rpmuint8_t * pend)
/*@globals fileSystem @*/
/*@modifies dig, fileSystem @*/;
typedef void (*pgpImplClean_t) (void * impl)
/*@modifies impl @*/;
typedef void * (*pgpImplFree_t) (/*@only@*/ void * impl)
/*@modifies impl @*/;
typedef void * (*pgpImplInit_t) (void)
/*@*/;
typedef struct pgpImplVecs_s {
pgpImplSet_t _pgpSetRSA;
pgpImplVerify_t _pgpVerifyRSA;
pgpImplSet_t _pgpSetDSA;
pgpImplVerify_t _pgpVerifyDSA;
pgpImplSet_t _pgpSetECDSA;
pgpImplVerify_t _pgpVerifyECDSA;
pgpImplMpiItem_t _pgpMpiItem;
pgpImplClean_t _pgpClean;
pgpImplFree_t _pgpFree;
pgpImplInit_t _pgpInit;
} pgpImplVecs_t;
/*@unchecked@*/
extern pgpImplVecs_t * pgpImplVecs;
/*@-mustmod@*/
/*@unused@*/ static inline
int pgpImplSetRSA(/*@only@*/ DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
/*@modifies ctx, dig @*/
{
return (*pgpImplVecs->_pgpSetRSA) (ctx, dig, sigp);
}
/*@unused@*/ static inline
int pgpImplVerifyRSA(pgpDig dig)
/*@*/
{
return (*pgpImplVecs->_pgpVerifyRSA) (dig);
}
/*@unused@*/ static inline
int pgpImplSetDSA(/*@only@*/ DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
/*@modifies ctx, dig @*/
{
return (*pgpImplVecs->_pgpSetDSA) (ctx, dig, sigp);
}
/*@unused@*/ static inline
int pgpImplVerifyDSA(pgpDig dig)
/*@*/
{
return (*pgpImplVecs->_pgpVerifyDSA) (dig);
}
/*@unused@*/ static inline
int pgpImplSetECDSA(/*@only@*/ DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
/*@modifies ctx, dig @*/
{
return (*pgpImplVecs->_pgpSetECDSA) (ctx, dig, sigp);
}
/*@unused@*/ static inline
int pgpImplVerifyECDSA(pgpDig dig)
/*@*/
{
return (*pgpImplVecs->_pgpVerifyECDSA) (dig);
}
/*@unused@*/ static inline
int pgpImplMpiItem(const char * pre, pgpDig dig, int itemno,
const rpmuint8_t * p, /*@null@*/ const rpmuint8_t * pend)
/*@modifies dig @*/
{
return (*pgpImplVecs->_pgpMpiItem) (pre, dig, itemno, p, pend);
}
/*@unused@*/ static inline
void pgpImplClean(void * impl)
/*@modifies impl @*/
{
/*@-noeffectuncon@*/
(*pgpImplVecs->_pgpClean) (impl);
/*@=noeffectuncon@*/
}
/*@unused@*/ static inline
/*@null@*/
void * pgpImplFree(/*@only@*/ void * impl)
/*@modifies impl @*/
{
return (*pgpImplVecs->_pgpFree) (impl);
}
/*@unused@*/ static inline
void * pgpImplInit(void)
/*@*/
{
return (*pgpImplVecs->_pgpInit) ();
}
/*@=mustmod@*/
#ifdef __cplusplus
}
#endif
/*@=fcnuse@*/
#endif /* H_RPMPGP */