⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pgprngpriv.h

📁 vc环境下的pgp源码
💻 H
📖 第 1 页 / 共 2 页
字号:
#define NAMESETFILEMASK(name,val) ((name)->filemaskindex = \
	((name)->filemaskindex &~NAMEF_FILEMASK) | ((val)&NAMEF_FILEMASK))

struct RingSig
{
	union RingObject *next, *by, *up;
	FilePos pos;
	PGPVirtMask mask;
	PGPByte flags;
	PGPByte flags2;
	/* Prefix */
/*26*/	PGPByte trust;
/*27*/	PGPByte type;
/*28*/	PGPByte hashalg;
/*29*/	PGPByte version;
/*30*/	PGPUInt32 sigvalidity;
/*34*/	PGPUInt32 tstamp;
/*38*/	struct RingSig *nextby;
/*42*/	void *regexp;
/*43*/	PGPByte trustLevel;	/* 0 for regular sig, 1 for trust, 2 for meta */
/*44*/	PGPByte	trustValue;	/* new "extern" format, valid if trustLevel>0 */
/*45*/
};
typedef struct RingSig	RingSig;

#define NULLRINGSIG { (union RingObject *)0, (union RingObject *)0,		\
	(union RingObject *)0, NULLFILEPOS, VIRTMASKZERO, OBJFLAGS_SIG, 0,	\
	0, 0, 0, 0, (PGPUInt16)0, (PGPUInt32)0, (RingSig *)0, 0, 0, 0 }

/* Signature has some sort of parsing error */
#define SIGF_ERROR 1
/* Extra bytes are non-obvious */
#define SIGF_NONFIVE	2

/* Access the flags2 field */
#define SIGF2_EXPORTABLE	128		/* Sig can be exported to others */
#define SIGF2_USESREGEXP	 64		/* (Trust) sig qualified with regexp */
#define SIGF2_REVOCABLE		 32		/* Sig can be revoked */
#define SIGF2_X509			 16		/* Sig is an imported X.509 cert */
#define SIGF2_PRIMARYUID	  8		/* Sig says it's on primary userid */
#define SIGF2_DISTPOINT		  4		/* Sig has a distribution point */

#define SIGSETEXPORTABLE(sig)		(sig)->flags2 |= SIGF2_EXPORTABLE
#define SIGSETNONEXPORTABLE(sig)	(sig)->flags2 &= ~SIGF2_EXPORTABLE
#define SIGISEXPORTABLE(sig)		(((sig)->flags2 & SIGF2_EXPORTABLE)!=0)
#define SIGSETUSESREGEXP(sig)		(sig)->flags2 |= SIGF2_USESREGEXP
#define SIGCLEARUSESREGEXP(sig)		(sig)->flags2 &= ~SIGF2_USESREGEXP
#define SIGUSESREGEXP(sig)			(((sig)->flags2 & SIGF2_USESREGEXP)!=0)
#define SIGSETREVOCABLE(sig)		(sig)->flags2 |= SIGF2_REVOCABLE
#define SIGSETNONREVOCABLE(sig)		(sig)->flags2 &= ~SIGF2_REVOCABLE
#define SIGISREVOCABLE(sig)			(((sig)->flags2 & SIGF2_REVOCABLE)!=0)
#define SIGSETX509(sig)				(sig)->flags2 |= SIGF2_X509
#define SIGCLEARX509(sig)			(sig)->flags2 &= ~SIGF2_X509
#define SIGISX509(sig)				(((sig)->flags2 & SIGF2_X509)!=0)
#define SIGSETPRIMARYUID(sig)		(sig)->flags2 |= SIGF2_PRIMARYUID
#define SIGCLEARPRIMARYUID(sig)		(sig)->flags2 &= ~SIGF2_PRIMARYUID
#define SIGISPRIMARYUID(sig)		(((sig)->flags2 & SIGF2_PRIMARYUID)!=0)
#define SIGSETDISTPOINT(sig)		(sig)->flags2 |= SIGF2_DISTPOINT
#define SIGCLEARDISTPOINT(sig)		(sig)->flags2 &= ~SIGF2_DISTPOINT
#define SIGHASDISTPOINT(sig)		(((sig)->flags2 & SIGF2_DISTPOINT)!=0)


struct RingCRL
{
	union RingObject *next, *down, *up;
	FilePos pos;
	PGPVirtMask mask;
	PGPByte flags;
	PGPByte flags2;
	/* Prefix */
/*26*/	PGPByte version;
/*27*/	PGPByte trust;
/*28*/	PGPUInt32 hash;
/*32*/	PGPUInt32 dpointhash;
/*36*/	PGPUInt32 tstamp;
/*40*/	PGPUInt32 tstampnext;
/*44*/
};
typedef struct RingCRL	RingCRL;

#define NULLRINGCRL { (union RingObject *)0, (union RingObject *)0,		\
	(union RingObject *)0, NULLFILEPOS, VIRTMASKZERO, OBJFLAGS_CRL, 0,	\
	0, 0, 0, 0, 0, 0 }

/* CRL type values */
#define PGPCRLTYPE_X509			1
#define PGPCRLTYPE_X509DPOINT	2

/* CRL has some sort of parsing error */
#define CRL_F_ERROR 1

/* Access the flags2 field */
#define CRL_F2_X509			 16		/* Crl is an X509 CRL */
#define CRL_F2_DPOINT		  8		/* Crl has a distribution point */

#define CRLSETX509(crl)				(crl)->flags2 |= CRL_F2_X509
#define CRLCLEARX509(crl)			(crl)->flags2 &= ~CRL_F2_X509
#define CRLISX509(crl)				(((crl)->flags2 & CRL_F2_X509)!=0)
#define CRLSETDPOINT(crl)			(crl)->flags2 |= CRL_F2_DPOINT
#define CRLCLEARDPOINT(crl)			(crl)->flags2 &= ~CRL_F2_DPOINT
#define CRLHASDPOINT(crl)			(((crl)->flags2 & CRL_F2_DPOINT)!=0)


/*
 * An unknown packet in a keyring.  "pktbyte" is the type.
 * This is so we can at least propagate the thing, even if it's
 * incomprehensible.
 */
struct RingUnk
{
	union RingObject *next, *down, *up;
	FilePos pos;
	PGPVirtMask mask;
	PGPByte flags;
	PGPByte flags2;
	/* Prefix */
/*26*/	PGPByte trust;
/*27*/	PGPByte pktbyte;
/*28*/	PGPUInt32 hash;
/*32*/
};
typedef struct RingUnk RingUnk;

#define NULLRINGUNK { (union RingObject *)0, (union RingObject *)0,		\
	(union RingObject *)0, NULLFILEPOS, VIRTMASKZERO, OBJFLAGS_UNK, 0,	\
	0, 0, (PGPUInt32)0 }

/*
 * A generic RingObject.  "obj->x.foo" occurs so often that the brevity
 * of the one-letter tags has advantages in clarity that override any
 * documentation gains from greater verbosity.
 */
union RingObject {
	struct RingGeneric g;
	RingKey k;
	RingSec c;	/* Note this odd choice of letter */
	RingName n;
	RingSig s;
	RingCRL r;
	RingUnk u;
};

/*
 * The basic collection-of-keys type.
 * This comes in two flavours: mutable and immutable.
 * A mutable set can have members added and removed,
 * while an immutable one cannot.
 */

struct RingPool;
struct RingSet {
	RingSet *next;
	RingPool *pool;
	RingError err;
	PGPVirtMask mask;
	char type;
};

#define RINGSET_MUTABLE 0
#define RINGSET_IMMUTABLE 1
#define RINGSET_ITERATOR 2	/* Also immutable */
#define RINGSET_FILE 3	/* Also immutable */
#define RINGSET_FREE 4	/* Free flag */

#define RINGSETISMUTABLE(set) (!(set)->type)

struct RingTrouble;

/* A file that holds information about a file */
struct RingFile {
	RingSet set;
	PGPFile *f;	/* File handle */
	void (*destructor)(RingFile *, PGPFile *, void *);
	void *arg;
	MemPool strings;	/* Cache of name strings */
	MemPool troublepool;
	struct RingTrouble const *trouble, **troubletail;
	MemPool fpos;
	FilePos *freepos;
	PGPVirtMask higherpri;	/* see ringFetchPacket in pgpRngRead.c */
	PGPByte flags;
        PgpVersion version;     
};

#if PGPTRUSTMODEL>1

/* This is a path or a path segment.  next->src may be unequal to dest. */
typedef struct Path {
	struct Path         *next;
	RingObject          *src,
	                    *dest;
	double               confidence;
	DEBUG_STRUCT_CONSTRUCTOR( Path )
} Path;

/* This is a list of paths.  Some segments may be on multiple paths. */
typedef struct PathList {
	struct PathList     *next;
	Path                *path;
	Path               **ptail;
	double               confidence;
	DEBUG_STRUCT_CONSTRUCTOR( PathList )
} PathList, *pPathList;
#endif

/* Flags kept updated about a file */
#define RINGFILEF_DIRTY	1
#define RINGFILEF_TRUSTCHANGED	2

/* The home of a lot of keys */
struct RingPool {
	PGPContextRef	context;
	
	MemPool structs;
	union RingObject *keys;
	union RingObject *freeobjs[RINGTYPE_MAX];
	RingSet *sets;	/* Dynamically allocated sets (not files!) */
	RingSet *freesets;
	RingIterator *freeiter;
	char *pktbuf;
	size_t pktbuflen;
	size_t pktbufalloc;
	PGPVirtMask allocmask;	/* Bits in use (cache) */
	PGPVirtMask filemask;	/* Bits in use for files */
	PGPVirtMask memringmask;	/* Const, has MEMRING bit set */
	PGPUInt32 flags;

	PGPEnv const *env;
	int certdepth;
	/* TRUSTMODEL 0 values */
	int num_marginals;
	int num_completes;
	/* TRUSTMODEL 1 values */
	/* Translations from old to new trust models */
	PGPByte marginalconfidence;
	PGPByte completeconfidence;
	int threshold;
#if PGPTRUSTMODEL==2
    MemPool pathpool;
    Path *paths;
	PathList *pathlists;
#endif
	MemPool regexps;

	/* In case of error, the following is set */
	RingError e;

	/* Some large items go at the end... */
	RingKey *hashtable[256];
	PGPUInt32 nfiles;
	RingFile **files;
};

/* Values for erraction */
#define ACTERR_NONE	0
#define ACTERR_READ	1
#define ACTERR_WRITE	2
#define ACTERR_SEEK	3
#define ACTERR_OPEN     4
#define ACTERR_CLOSE    5
#define ACTERR_FLUSH    6
#define ACTERR_HUGE	7

#define ACTERR_EOF		101
#define ACTERR_BADPKTBYTE	102
#define ACTERR_WRONGPKTBYTE	103
#define ACTERR_WRONGLEN		104

#define ACTERR_ALLOC	201

/* Test for membership of a RingObj in a RingSet */
#define pgpIsRingSetMember(s,o)	\
	pgpVirtMaskIsOverlapping(&(s)->mask, &(o)->g.mask)

/*
 * How to distinguish starting from stopping?
 * It's NULL pointers either way.
 * Ah, wait!  "level" is the most recent level.
 * If it's 0, start the ring.  If it's 1, and the stack is NULL,
 * we're at the end.  Yes, that works!
 *
 * Okay, so it works like this:
 * The stack[i] array holds the object which is the head of the
 * current list, the last object returned at level i+1.
 * The last object returned, which defines the maximum depth to
 * which the stack is valid, is at "level".  Stack entries
 * up to level-1 are valid.
 * If a stack entry is NULL, is is the last entry at level-1,
 * and indicates that the list at this level is finished.
 * Repeated calls will keep returning NULL.
 *
 * If asked for a level one greater than the stored level, that's
 * a clue to start at the beginning of the list.
 * 
 * stack[-1], corresponding to a level of 0, is implicitly the
 * RingPool.
 */
struct RingIterator {
	RingSet set;
	unsigned level;	/* 1-based */
	union RingObject *stack[RINGMAXDEPTH];
};


PGPError pgpVirtMaskInit (RingPool const *pool, PGPVirtMask *mask);
PGPError pgpVirtMaskCleanup (RingPool const *pool, PGPVirtMask *mask);
PGPError pgpVirtMaskOR (RingPool const *pool, PGPVirtMask const *imask,
	PGPVirtMask *omask);
PGPError pgpVirtMaskAND (RingPool const *pool, PGPVirtMask const *imask,
	PGPVirtMask *omask);
PGPError pgpVirtMaskANDNOT (RingPool const *pool, PGPVirtMask const *imask,
	PGPVirtMask *omask);
PGPError pgpVirtMaskSetBit (RingPool const *pool, PGPVirtMask *mask,
	PGPUInt32 bitnumber);
PGPError pgpVirtMaskClearBit (RingPool const *pool, PGPVirtMask *mask,
	PGPUInt32 bitnumber);
PGPError pgpVirtMaskClearGreaterBits (RingPool const *pool, PGPVirtMask *mask,
	PGPUInt32 firstbitnumber);
PGPError pgpVirtMaskNOT (RingPool const *pool, PGPVirtMask *mask,
	PGPUInt32 highbitnumber);
PGPError pgpVirtMaskCopy (RingPool const *pool, PGPVirtMask const *imask,
	PGPVirtMask *omask);
PGPInt32 pgpVirtMaskLSBit (PGPVirtMask const *mask);
PGPBoolean pgpVirtMaskIsEmpty (PGPVirtMask const *mask);
PGPBoolean pgpVirtMaskIsEqual (PGPVirtMask const *mask1,
	PGPVirtMask const *mask2);
PGPBoolean pgpVirtMaskIsOverlapping (PGPVirtMask const *mask1,
	PGPVirtMask const *mask2);

void ringErr(RingFile *file, PGPUInt32 fpos, PGPError code);
void ringSimpleErr(RingPool *pool, PGPError code);
void ringAllocErr(RingPool *pool);

PGPUInt32 ringHashBuf(PGPByte const *buf, size_t len);
int ringLsBitFind(PGPUInt32 mask);
PGPError ringAllocMask(RingPool const *pool, RingSet const *,
	PGPVirtMask *omask);
PGPError
ringClearMask(RingPool *pool, union RingObject **objp, PGPVirtMask *andmask,
	PGPVirtMask *andnotmask, PGPVirtMask *omask);
PGPBoolean ringGarbageCollect(RingPool *pool);
void ringGarbageCollectObject(RingPool *pool, union RingObject *obj);
PGPError ringBitAlloc(RingPool *pool, PGPUInt32 *newbit);

/* Misc utility functions */
union RingObject *ringNewObject(RingPool *pool, int objtype);
#define ringNewKey(pool) ringNewObject(pool, RINGTYPE_KEY)
#define ringNewSec(pool) ringNewObject(pool, RINGTYPE_SEC)
#define ringNewName(pool) ringNewObject(pool, RINGTYPE_NAME)
#define ringNewSig(pool) ringNewObject(pool, RINGTYPE_SIG)
#define ringNewCRL(pool) ringNewObject(pool, RINGTYPE_CRL)
#define ringNewUnk(pool) ringNewObject(pool, RINGTYPE_UNK)
void ringFreeObject(RingPool *pool, union RingObject *obj);
void ringRemObject(RingPool *pool, union RingObject *obj);

/* Insert a single key into the pool's hash table */
#define RINGPOOLHASHKEY(pool, key)  \
	((key)->k.util = (pool)->hashtable[(key)->k.keyID[0]], \
	 (pool)->hashtable[(key)->k.keyID[0]] = &(key)->k)
void ringPoolHash(RingPool *pool);
union RingObject *
ringPoolFindKey(RingPool const *pool, PGPByte pkalg, PGPByte const keyID[8]);
union RingObject *
ringPoolFindKey20n(RingPool *pool, PGPByte const *fp20n);
void ringPoolListSigsBy(RingPool *pool);
#define ringFileMarkDirty(file)	((file)->flags |= RINGFILEF_DIRTY)
void ringPoolMarkDirty(RingPool *pool, PGPVirtMask *mask);
void ringPoolMarkTrustChanged(RingPool *pool, PGPVirtMask *mask);

PGPError ringObjBetters(union RingObject const *obj, RingPool const *pool,
	PGPVirtMask *omask);
int ringSubkeyValid(RingSet const *set, union RingObject *subkey,
	PGPBoolean unExpired);
void ringPurgeCachedName(RingPool const *pool, RingName *name,
	PGPVirtMask *mask);

void ringFilesInit(RingPool *pool, PGPUInt32 nfiles);
void ringPoolInit( PGPContextRef context, RingPool *pool, PGPEnv const *env);
void ringPoolFini(RingPool *pool);

int pgpFingerprint20HashBuf(PGPContextRef context, PGPByte const *buf,
							size_t len, PGPByte *hash);

void * ringSigRegexp(RingSet const *set, RingObject *sig);

PGPBoolean sigRevokesKey(RingSet const *set, RingObject *sig);

PGP_END_C_DECLARATIONS

#endif /* Included_pgpRngPriv_h */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -