pgprngpriv.h
来自「著名的加密软件的应用于电子邮件中」· C头文件 代码 · 共 570 行 · 第 1/2 页
H
570 行
(union RingObject *)0, NULLFILEPOS, (ringmask)0, OBJFLAGS_NAME, \
0, 0, 0, 0, 0, (size_t)0, { (char const *)0 }}
#endif
/* Access the flags2 field */
#define NAMEF2_ISCACHED 128
#define NAMEF2_NEWTRUST 64
#define NAMEF2_LEVELMASK 31
#define NAMEISCACHED(name) ((name)->flags2 & NAMEF2_ISCACHED)
#define NAMESETCACHED(name) ((name)->flags2 |= NAMEF2_ISCACHED)
#define NAMECLEARCACHED(name) ((name)->flags2 &= ~NAMEF2_ISCACHED)
/* Has new-style trust info */
#define NAMEHASNEWTRUST(name) ((name)->flags2 & NAMEF2_NEWTRUST)
#define NAMESETNEWTRUST(name) ((name)->flags2 |= NAMEF2_NEWTRUST)
#define NAMECLEARNEWTRUST(name) ((name)->flags2 &= ~NAMEF2_NEWTRUST)
/* Certification depth */
#define NAMELEVEL(name) ((name)->flags2 & NAMEF2_LEVELMASK)
#define NAMESETLEVEL(name,lv) \
((name)->flags2 = ((name)->flags2 & ~NAMEF2_LEVELMASK) + lv)
#define NAMEF_FILEMASK 31
#if NAMEF_FILEMASK+1 < RINGMASKBITS
#error NAMEF_FILEMASK is too small...
#endif
struct RingSig
{
union RingObject *next, *by, *up;
struct FilePos pos;
ringmask mask;
byte flags;
/* Prefix */
/*22*/ byte trust;
/*23*/ byte type;
/*24*/ byte hashalg;
/*25*/ byte version;
/*26*/ word16 validity; /* Delete? */
/*28*/ word32 tstamp;
/*32*/ struct RingSig *nextby;
/*36*/
};
#define NULLRINGSIG { (union RingObject *)0, (union RingObject *)0, \
(union RingObject *)0, NULLFILEPOS, (ringmask)0, OBJFLAGS_SIG, \
0, 0, 0, 0, (word16)0, (word32)0, (struct RingSig *)0 }
/* Signature has some sort of parsing error */
#define SIGF_ERROR 1
/* Extra bytes are non-obvious */
#define SIGF_NONFIVE 2
/* This can be derived in other ways, but is kept around for convenience */
#define SIGF_KEY 4
/*
* 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;
struct FilePos pos;
ringmask mask;
byte flags;
/* Prefix */
/*22*/ byte trust;
/*23*/ byte pktbyte;
/*24*/ word32 hash;
/*28*/
};
#define NULLRINGUNK { (union RingObject *)0, (union RingObject *)0, \
(union RingObject *)0, NULLFILEPOS, (ringmask)0, OBJFLAGS_UNK, \
0, 0, (word32)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;
struct RingKey k;
struct RingSec c; /* Note this odd choice of letter */
struct RingName n;
struct RingSig s;
struct 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 {
struct RingSet *next;
struct RingPool *pool;
struct RingError err;
ringmask 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 {
struct RingSet set;
struct PgpFile *f; /* File handle */
void (*destructor)(struct RingFile *, struct PgpFile *, void *);
void *arg;
struct MemPool strings; /* Cache of name strings */
struct MemPool troublepool;
struct RingTrouble const *trouble, **troubletail;
struct MemPool fpos;
struct FilePos *freepos;
ringmask higherpri; /* see ringFetchPacket in pgpRngRead.c */
byte flags;
PgpVersion version;
};
#if PGPTRUSTMODEL>1
struct Path;
struct PathList;
#endif
/* Flags kept updated about a file */
#define RINGFILEF_DIRTY 1
#define RINGFILEF_TRUSTCHANGED 2
/* The home of a lot of keys */
struct RingPool {
struct MemPool structs;
union RingObject *keys;
union RingObject *freeobjs[RINGTYPE_MAX];
struct RingSet *sets; /* Dynamically allocated sets (not files!) */
struct RingSet *freesets;
struct RingIterator *freeiter;
char *pktbuf;
size_t pktbuflen;
size_t pktbufalloc;
ringmask allocmask; /* Bits in use (cache) */
ringmask filemask; /* Bits in use for files */
word32 flags;
struct PgpEnv const *env;
int certdepth;
#if PGPTRUSTMODEL==0
int num_marginals;
int num_completes;
#else
/* Translations from old to new trust models */
byte marginalconfidence;
byte completeconfidence;
int threshold;
#if PGPTRUSTMODEL==2
struct MemPool pathpool;
struct Path *paths;
struct PathList *pathlists;
#endif
#endif
/* In case of error, the following is set */
struct RingError e;
/* Some large items go at the end... */
struct RingKey *hashtable[256];
struct RingFile files[RINGMASKBITS];
};
/* 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
/*
* 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 {
struct RingSet set;
unsigned level; /* 1-based */
union RingObject *stack[RINGMAXDEPTH];
};
void ringErr(struct RingFile *file, word32 fpos, int code);
void ringSimpleErr(struct RingPool *pool, int code);
void ringAllocErr(struct RingPool *pool);
word32 ringHashBuf(byte const *buf, size_t len);
int ringLsBitFind(ringmask mask);
ringmask ringAllocMask(struct RingPool const *pool, struct RingSet const *);
ringmask
ringClearMask(struct RingPool *pool, union RingObject **objp, ringmask mask);
int ringGarbageCollect(struct RingPool *pool);
void ringGarbageCollectObject(struct RingPool *pool, union RingObject *obj);
int ringBitAlloc(struct RingPool *pool);
/* Misc utility functions */
union RingObject *ringNewObject(struct 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 ringNewUnk(pool) ringNewObject(pool, RINGTYPE_UNK)
void ringFreeObject(struct RingPool *pool, union RingObject *obj);
void ringRemObject(struct 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(struct RingPool *pool);
union RingObject *
ringPoolFindKey(struct RingPool const *pool, byte pkalg, byte const keyID[8]);
void ringPoolListSigsBy(struct RingPool *pool);
#define ringFileMarkDirty(file) ((file)->flags |= RINGFILEF_DIRTY)
void ringPoolMarkDirty(struct RingPool *pool, ringmask mask);
void ringPoolMarkTrustChanged(struct RingPool *pool, ringmask mask);
union RingObject *ringBestSec(struct RingSet const *set,
union RingObject const *key);
int ringSubkeyValid(struct RingSet const *set, union RingObject *subkey);
void ringPurgeCachedName(struct RingName *name, ringmask mask);
/* To be added: a function to allocate one of these first! */
void ringPoolInit(struct RingPool *pool, struct PgpEnv const *env);
void ringPoolFini(struct RingPool *pool);
int pgpFingerprint20HashBuf(byte const *buf, size_t len, byte *hash);
void ringObjCheck (union RingObject *obj, ringmask validmask,
ringmask parentmask);
#ifdef __cplusplus
}
#endif
#endif /* PGPRNGPRIV_H */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?