📄 pgprngpriv.h
字号:
/*
* $Id: pgpRngPriv.h,v 1.38.8.2 1999/06/13 21:12:13 heller Exp $
*/
#ifndef Included_pgpRngPriv_h
#define Included_pgpRngPriv_h
#include <stdio.h> /* For size_t */
#include "pgpDebug.h"
#include "pgpRngPub.h"
/* Private */
#include "pgpMemPool.h"
PGP_BEGIN_C_DECLARATIONS
/* See pgpRngMnt.c for a definition of the various trust models */
#ifndef PGPTRUSTMODEL
#define PGPTRUSTMODEL 2
#endif
/* VIRTMASK enables virtual bitmask for unlimited number of sets */
#ifndef VIRTMASK
#define VIRTMASK 0
#endif
/* Alternatively, MULTIMASK, if nonzero n, allows for n-word bitmask */
#if !VIRTMASK
/* Default to 5 words of 32 bits each for 160 bits */
#ifndef MULTIMASK
#define MULTIMASK 5
#endif
#endif /* !VIRTMASK */
#define MEMRINGBIT 0
#if VIRTMASK
typedef struct virtmask
{
PGPUInt32 nwords;
PGPUInt32 *words;
} PGPVirtMask;
#define VIRTMASKZERO {0,NULL}
#else /* VIRTMASK */
#if MULTIMASK
typedef struct virtmask
{
PGPUInt32 words[MULTIMASK];
} PGPVirtMask;
#define VIRTMASKZERO {{0}}
#else /* MULTIMASK */
/*
* This number should probably be increased for multiple keyrings and GUIs.
* At the moment, it is low to help memory consumption.
*/
#ifndef RINGMASKBITS
#define RINGMASKBITS 32
#endif
#if RINGMASKBITS <= 8
typedef PGPByte ringmask;
#elif RINGMASKBITS <= 16
typedef PGPUInt16 ringmask;
#elif RINGMASKBITS <= 32
typedef PGPUInt32 ringmask;
#else
#error Invalid RINGMASKBITS value
#endif
#define MEMRINGMASK ((ringmask)1<<MEMRINGBIT)
typedef ringmask PGPVirtMask;
#define VIRTMASKZERO (PGPVirtMask)0
#endif /* MULTIMASK */
#endif /* VIRTMASK */
/* PGP version information */
#define PGPVERSION_2 2
#define KNOWN_PGP_VERSION(x) ((x)==PGPVERSION_2 || (x) == PGPVERSION_3 || \
(x)==PGPVERSION_4)
/* Position in a file */
typedef struct FilePos {
union {
struct FilePos *next;
void *buf;
} ptr;
PGPUInt32 fpos;
} FilePos;
#define NULLFILEPOS { { (FilePos *)0 }, (PGPUInt32)0 }
/*
* Since C requires in-order allocation of structure fields, a poor choice of
* field order can cause lots of holes in a structure for alignment reasons.
* E.g. long/char/long/char/long/char/long/char assuming the usual 4-byte
* longs aligned on 4-byte boundaries requires 32 bytes of storage, while
* long/long/long/long/char/char/char/char requires only 20.
* Storage required can be minimized by allocating the largest fields in
* the structure at the ends, against the aligned edges of the structure,
* and filling the hole in the middle with progressively less aligned
* fields. We use this by declaring the common (generic) fields in
* largest-to-smallest order, then the type-specific extensions in
* smallest-to-largest.
*
* The sizes listed are for the platform where memory consumption is the
* greatest concern - the IBM PC. Other platforms aren't quite as tight.
*/
/* (Note that PGPVirtMask may be bigger than shown below) */
struct RingGeneric
{
/* 0*/ union RingObject *next, *down, *up;
/*12*/ FilePos pos;
/*20*/ PGPVirtMask mask;
/*24*/ PGPByte flags;
/*25*/ PGPByte flags2;
/*26*/
};
/* Generic flags (apply to more than one type) */
#define RINGOBJF_TRUST 128
#define RINGOBJF_TRUSTCHANGED 64
/*
* The type bits are encoded as follows:
* 76543210
* 0000 - Unknown keyring object
* 0001 - Secret (We use the letter "c" for this)
* 0010 - Topkey
* 0011 - Subkey (letter "B")
* 0100 - Signature (s)
* 0101 - Name (n)
* 0110 - CRL (r)
* Changes here need to be propagated to ringObjectType().
*/
#define RINGOBJF_TYPE 0x3c /* Mask for object type */
#define RINGOBJF_KEYTYPE 0x38 /* Mask ignoring diff among keys */
#define RINGOBJ_SHIFT 2 /* Shift down for type */
#define RINGOBJF_UNK 0x00 /* Unknown object type */
#define RINGOBJF_SEC 0x04 /* Secret component object */
#define RINGOBJF_KEY 0x08 /* Key (top) object */
#define RINGOBJF_SUBKEY 0x0c /* Subkey object */
#define RINGOBJF_SIG 0x10 /* Signature object */
#define RINGOBJF_NAME 0x14 /* Name object */
#define RINGOBJF_CRL 0x18 /* CRL object */
#define OBJISNAME(obj) (((obj)->g.flags & RINGOBJF_TYPE) == RINGOBJF_NAME)
#define OBJISSIG(obj) (((obj)->g.flags & RINGOBJF_TYPE) == RINGOBJF_SIG)
/* Note that this includes top-level keys *and* subkeys */
#define OBJISKEY(obj) (((obj)->g.flags & RINGOBJF_KEYTYPE) == RINGOBJF_KEY)
#define OBJISTOPKEY(obj) (((obj)->g.flags & RINGOBJF_TYPE) == RINGOBJF_KEY)
#define OBJISSUBKEY(obj) (((obj)->g.flags & RINGOBJF_TYPE) == RINGOBJF_SUBKEY)
#define OBJISSEC(obj) (((obj)->g.flags & RINGOBJF_TYPE) == RINGOBJF_SEC)
#define OBJISCRL(obj) (((obj)->g.flags & RINGOBJF_TYPE) == RINGOBJF_CRL)
#define OBJISUNK(obj) (((obj)->g.flags & RINGOBJF_TYPE) == RINGOBJF_UNK)
/* These versions are for pgpAssert() macro use */
#define NAMEISNAME(name) (((name)->flags & RINGOBJF_TYPE) == RINGOBJF_NAME)
#define SIGISSIG(sig) (((sig)->flags & RINGOBJF_TYPE) == RINGOBJF_SIG)
#define KEYISKEY(key) (((key)->flags & RINGOBJF_KEYTYPE) == RINGOBJF_KEY)
#define KEYISTOPKEY(key) (((key)->flags & RINGOBJF_TYPE) == RINGOBJF_KEY)
#define KEYISSUBKEY(key) (((key)->flags & RINGOBJF_TYE) == RINGOBJF_SUBKEY)
#define CRLISCRL(crl) (((crl)->flags & RINGOBJF_TYPE) == RINGOBJF_CRL)
#define OBJFLAGS_NAME RINGOBJF_NAME
#define OBJFLAGS_SIG RINGOBJF_SIG
#define OBJFLAGS_KEY RINGOBJF_KEY
#define OBJFLAGS_SUBKEY RINGOBJF_SUBKEY
#define OBJFLAGS_SEC RINGOBJF_SEC
#define OBJFLAGS_CRL RINGOBJF_CRL
#define OBJFLAGS_UNK RINGOBJF_UNK
/* Does this object's up pointer point to a meaningful parent? */
#define OBJISTOP OBJISTOPKEY
/* Does this object's down pointer point to a meaningful child? */
#define OBJISBOT(obj) (OBJISSIG(obj)||OBJISSEC(obj))
/* Maximum depth of nesting in a keyring */
#define RINGMAXDEPTH 3
/* A subkey is the same, but the "sigsby" pointer is "up" */
struct RingKey
{
union RingObject *next, *down, *sigsby;
FilePos pos;
PGPVirtMask mask;
PGPByte flags;
PGPByte flags2;
/*26*/ PGPByte trust;
/*27*/ PGPByte pkalg;
/*28*/ PGPUInt16 validity; /* Validity period, in days */
#if PGPTRUSTMODEL>0
/*30*/ PGPUInt16 confidence; /* A trust value temporary */
#endif
/*32*/ PGPUInt16 keybits;
/*34*/ PGPByte signedTrust; /* Trust from sigs on key */
/*35*/ PGPByte fp20n; /* First byte from fp20n fingerprint */
/*36*/ PGPUInt32 tstamp;
/*40*/ PGPByte keyID[8];
/*48*/ struct RingKey *util;
/*52*/ void *regexp;
/*56*/
};
typedef struct RingKey RingKey;
#if PGPTRUSTMODEL>0
#define NULLRINGKEY { (union RingObject *)0, (union RingObject *)0, \
(union RingObject *)0, NULLFILEPOS, VIRTMASKZERO, OBJFLAGS_KEY, 0, \
0, 0, (PGPUInt16)0, (PGPUInt16)0, (PGPUInt16)0, 0, 0, (PGPUInt32)0, \
{ 0, 0, 0, 0, 0, 0, 0, 0 }, (RingKey *)0, 0 }
#define NULLRINGSUBKEY { (union RingObject *)0, (union RingObject *)0, \
(union RingObject *)0, NULLFILEPOS, VIRTMASKZERO, OBJFLAGS_SUBKEY, 0, \
0, 0, (PGPUInt16)0, (PGPUInt16)0, (PGPUInt16)0, 0, 0, (PGPUInt32)0, \
{ 0, 0, 0, 0, 0, 0, 0, 0 }, (RingKey *)0, 0 }
#else
#define NULLRINGKEY { (union RingObject *)0, (union RingObject *)0, \
(union RingObject *)0, NULLFILEPOS, VIRTMASKZERO, OBJFLAGS_KEY, 0, \
0, 0, (PGPUInt16)0, (PGPUInt16)0, 0, 0, (PGPUInt32)0, \
{ 0, 0, 0, 0, 0, 0, 0, 0 }, (RingKey *)0, 0 }
#define NULLRINGSUBKEY { (union RingObject *)0, (union RingObject *)0, \
(union RingObject *)0, NULLFILEPOS, VIRTMASKZERO, OBJFLAGS_SUBKEY, 0, \
0, 0, (PGPUInt16)0, (PGPUInt16)0, 0, 0, (PGPUInt32)0, \
{ 0, 0, 0, 0, 0, 0, 0, 0 }, (RingKey *)0, 0 }
#endif
/* The key has some sort of error */
#define KEYF_ERROR 1
/* The key is a trusted introducer, used in the maintenance pass. */
#define KEYF_TRUSTED 2
/* Access the flags2 field */
/* V2 or V3 key, something earlier than V4 */
#define KEYF2_V3 128
#define KEYISV3(key) ((key)->flags2 & KEYF2_V3)
#define KEYSETV3(key) ((key)->flags2 |= KEYF2_V3)
#define KEYCLEARV3(key) ((key)->flags2 &= ~KEYF2_V3)
/*
* This is used to record information about the locations for a key's
* secret components. If present, it is always the FIRST child of a
* key. This is a very boring structure, as there's nothing we can
* read in about the encrypted secret componenets without the passphrase.
* (Option: have multiples of these for different encrypted forms of the
* secret components?)
*
* The FilePos entries on this are a subset of the entries in the
* parent RingKey's.
*/
struct RingSec
{
union RingObject *next, *down, *up;
FilePos pos;
PGPVirtMask mask;
PGPByte flags;
PGPByte flags2;
/*26*/
/*28*/ PGPUInt32 hash; /* Hash of secret fr matching purposes */
/*32*/
};
typedef struct RingSec RingSec;
#define NULLRINGSEC { (union RingObject *)0, (union RingObject *)0, \
(union RingObject *)0, NULLFILEPOS, VIRTMASKZERO, OBJFLAGS_SEC, 0, 0 }
/*
* If SECF_VERSION_BUG is set, then patch the version byte from 3 to 2
* when using the secret key. This is to fix a bug in 2.6 through early 2.9
* that, when editing a secret key, would write out the edited secret key
* with a version byte of 3 even if it originally had a version byte
* of 2. This has been fixed in 2.9, but it is common enough (due to 2.6)
* that we need to kludge around it.
*/
#define SECF_VERSION_BUG 1
#if PGPTRUSTMODEL==0
struct RingName
{
union RingObject *next, *down, *up;
FilePos pos;
PGPVirtMask mask;
PGPByte flags;
PGPByte flags2;
/*26*/ PGPByte trust;
/*27*/
/*28*/ int trustval;
/*30*/ size_t len;
/*32*/ union {
char const *ptr; /* If cached, pointer to string */
PGPUInt32 hash; /* If not cached, hash code */
} name;
/*36*/ PGPUInt32 filemaskindex; /* PGPFile for cached name */
/*40*/
};
typedef struct RingName RingName;
#define NULLRINGNAME { (union RingObject *)0, (union RingObject *)0, \
(union RingObject *)0, NULLFILEPOS, VIRTMASKZERO, OBJFLAGS_NAME, 0, \
0, 0, (size_t)0, { (char const *)0 }}
#else /* New trust */
struct RingName
{
union RingObject *next, *down, *up;
FilePos pos;
PGPVirtMask mask;
PGPByte flags;
PGPByte flags2;
/*26*/ PGPByte trust;
/*27*/ PGPByte validity; /* Stored validity */
/*28*/ PGPByte confidence; /* Stored confidence */
/*29*/
/*30*/ PGPUInt16 valid; /* Computed validity */
/*32*/ size_t len;
/*36*/ union {
char const *ptr; /* If cached, pointer to string */
PGPUInt32 hash; /* If not cached, hash code */
} name;
/*40*/ PGPUInt32 filemaskindex; /* PGPFile for cached name */
/*44*/
};
typedef struct RingName RingName;
/*
* The intermediate validity results are 16 bits wide instead of 8.
* This is used for extra precision (fraction bits) and extra range.
* This is the number of extra precision bits. (4 more range bits
* increases the upper bound to 10^-25.)
*/
#define TRUST_CERTSHIFT 6
#define NULLRINGNAME { (union RingObject *)0, (union RingObject *)0, \
(union RingObject *)0, NULLFILEPOS, VIRTMASKZERO, OBJFLAGS_NAME, 0, \
0, 0, 0, 0, (size_t)0, { (char const *)0 }, 0}
#endif
/* Access the flags2 field */
#define NAMEF2_ISCACHED 128
#define NAMEF2_NEWTRUST 64
#define NAMEF2_ATTR 32
#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)
/* Is general attribute */
#define NAMEISATTR(name) ((name)->flags2 & NAMEF2_ATTR)
#define NAMESETATTR(name) ((name)->flags2 |= NAMEF2_ATTR)
#define NAMECLEARATTR(name) ((name)->flags2 &= ~NAMEF2_ATTR)
/* Certification depth */
#define NAMELEVEL(name) ((name)->flags2 & NAMEF2_LEVELMASK)
#define NAMESETLEVEL(name,lv) \
((name)->flags2 = ((name)->flags2 & ~NAMEF2_LEVELMASK) + lv)
#define NAMEF_FILEMASK 0xffffffff
/* File mask value tells where name is cached from */
#define NAMEFILEMASK(name) ((name)->filemaskindex & NAMEF_FILEMASK)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -