/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* * Internal data structures and functions used by pkcs11.c
*/ #ifndef _PKCS11I_H_ #define _PKCS11I_H_ 1
/* * Configuration Defines * * The following defines affect the space verse speed trade offs of * the PKCS #11 module. For the most part the current settings are optimized * for web servers, where we want faster speed and lower lock contention at * the expense of space.
*/
/* * The attribute allocation strategy is static allocation: * Attributes are pre-allocated as part of the session object and used from * the object array.
*/ #define MAX_OBJS_ATTRS 45 /* number of attributes to preallocate in \
* the object (must me the absolute max) */ #define ATTR_SPACE 50 /* Maximum size of attribute data before extra \ * data needs to be allocated. This is set to \
* enough space to hold an SSL MASTER secret */
#define NSC_STRICT PR_FALSE /* forces the code to do strict template \ * matching when doing C_FindObject on token \ * objects. This will slow down search in \
* NSS. */ /* default search block allocations and increments */ #define NSC_CERT_BLOCK_SIZE 50 #define NSC_SEARCH_BLOCK_SIZE 5 #define NSC_SLOT_LIST_BLOCK_SIZE 10
/* these are data base storage hashes, not cryptographic hashes.. The define
* the effective size of the various object hash tables */ /* clients care more about memory usage than lookup performance on * cyrptographic objects. Clients also have less objects around to play with * * we eventually should make this configurable at runtime! Especially now that * NSS is a shared library.
*/ #define SPACE_ATTRIBUTE_HASH_SIZE 32 #define SPACE_SESSION_OBJECT_HASH_SIZE 32 #define SPACE_SESSION_HASH_SIZE 32 #define TIME_ATTRIBUTE_HASH_SIZE 32 #define TIME_SESSION_OBJECT_HASH_SIZE 1024 #define TIME_SESSION_HASH_SIZE 1024 #define MAX_OBJECT_LIST_SIZE 800 /* how many objects to keep on the free list
* before we start freeing them */ #define MAX_KEY_LEN 256 /* maximum symmetric key length in bytes */
/* * LOG2_BUCKETS_PER_SESSION_LOCK must be a prime number. * With SESSION_HASH_SIZE=1024, LOG2 can be 9, 5, 1, or 0. * With SESSION_HASH_SIZE=4096, LOG2 can be 11, 9, 5, 1, or 0. * * HASH_SIZE LOG2_BUCKETS_PER BUCKETS_PER_LOCK NUMBER_OF_BUCKETS * 1024 9 512 2 * 1024 5 32 32 * 1024 1 2 512 * 1024 0 1 1024 * 4096 11 2048 2 * 4096 9 512 8 * 4096 5 32 128 * 4096 1 2 2048 * 4096 0 1 4096
*/ #define LOG2_BUCKETS_PER_SESSION_LOCK 1 #define BUCKETS_PER_SESSION_LOCK (1 << (LOG2_BUCKETS_PER_SESSION_LOCK)) /* NOSPREAD sessionID to hash table index macro has been slower. */
/* Value to tell if an attribute is modifiable or not. * NEVER: attribute is only set on creation. * ONCOPY: attribute is set on creation and can only be changed on copy. * SENSITIVE: attribute can only be changed to TRUE. * ALWAYS: attribute can always be changed.
*/ typedefenum {
SFTK_NEVER = 0,
SFTK_ONCOPY = 1,
SFTK_SENSITIVE = 2,
SFTK_ALWAYS = 3
} SFTKModifyType;
/* * Free Status Enum... tell us more information when we think we're * deleting an object.
*/ typedefenum {
SFTK_DestroyFailure,
SFTK_Destroyed,
SFTK_Busy
} SFTKFreeStatus;
/* * attribute values of an object.
*/ struct SFTKAttributeStr {
SFTKAttribute *next;
SFTKAttribute *prev;
PRBool freeAttr;
PRBool freeData; /*must be called handle to make sftkqueue_find work */
CK_ATTRIBUTE_TYPE handle;
CK_ATTRIBUTE attrib; unsignedchar space[ATTR_SPACE];
};
/* * doubly link list of objects
*/ struct SFTKObjectListStr {
SFTKObjectList *next;
SFTKObjectList *prev;
SFTKObject *parent;
};
struct SFTKObjectFreeListStr {
SFTKObject *head;
PZLock *lock; int count;
};
/* * slots (have sessions and objects) * * The array of sessionLock's protect the session hash table (head[]) * as well as the reference count of session objects in that bucket * (head[]->refCount), objectLock protects all elements of the slot's * object hash tables (sessObjHashTable[] and tokObjHashTable), and * sessionObjectHandleCount. * slotLock protects the remaining protected elements: * password, needLogin, isLoggedIn, ssoLoggedIn, and sessionCount, * and pwCheckLock serializes the key database password checks in * NSC_SetPIN and NSC_Login. * * Each of the fields below has the following lifetime as commented * next to the fields: * invariant - This value is set when the slot is first created and * never changed until it is destroyed. * per load - This value is set when the slot is first created, or * when the slot is used to open another directory. Between open and close * this field does not change. * variable - This value changes through the normal process of slot operation. * - reset. The value of this variable is cleared during an open/close * cycles. * - preserved. The value of this variable is preserved over open/close * cycles.
*/ struct SFTKSlotStr {
CK_SLOT_ID slotID; /* invariant */
PZLock *slotLock; /* invariant */
PZLock **sessionLock; /* invariant */ unsignedint numSessionLocks; /* invariant */ unsignedlong sessionLockMask; /* invariant */
PZLock *objectLock; /* invariant */
PRLock *pwCheckLock; /* invariant */
PRBool present; /* variable -set */
PRBool hasTokens; /* per load */
PRBool isLoggedIn; /* variable - reset */
PRBool ssoLoggedIn; /* variable - reset */
PRBool needLogin; /* per load */
PRBool DB_loaded; /* per load */
PRBool readOnly; /* per load */
PRBool optimizeSpace; /* invariant */
SFTKDBHandle *certDB; /* per load */
SFTKDBHandle *keyDB; /* per load */ int minimumPinLen; /* per load */
PRInt32 sessionIDCount; /* atomically incremented */ /* (preserved) */ int sessionIDConflict; /* not protected by a lock */ /* (preserved) */ int sessionCount; /* variable - reset */
PRInt32 rwSessionCount; /* set by atomic operations */ /* (reset) */ int sessionObjectHandleCount; /* variable - perserved */
CK_ULONG index; /* invariant */
PLHashTable *tokObjHashTable; /* invariant */
SFTKObject **sessObjHashTable; /* variable - reset */ unsignedint sessObjHashSize; /* invariant */
SFTKSession **head; /* variable -reset */ unsignedint sessHashSize; /* invariant */ char tokDescription[33]; /* per load */ char updateTokDescription[33]; /* per load */ char slotDescription[65]; /* invariant */
SFTKSession moduleObjects; /* global session to hang module specific * objects like profile objects or
* validation objects */
};
/* context for the Final SSLMAC message */ struct SFTKSSLMACInfoStr {
size_t size; /* must be first */ void *hashContext;
SFTKBegin begin;
SFTKHash update;
SFTKEnd end;
CK_ULONG macSize; int padSize; unsignedchar key[MAX_KEY_LEN]; unsignedint keySize;
};
/* SFTKChaCha20Poly1305Info saves the key, tag length, nonce,
* and additional data for a ChaCha20+Poly1305 AEAD operation. */ struct SFTKChaCha20Poly1305InfoStr {
ChaCha20Poly1305Context freeblCtx; unsignedchar nonce[12]; unsignedchar ad[16]; unsignedchar *adOverflow; unsignedint adLen;
};
/* SFTKChaCha20BlockInfoStr the key, nonce and counter for a
* ChaCha20 block operation. */ struct SFTKChaCha20CtrInfoStr {
PRUint8 key[32];
PRUint8 nonce[12];
PRUint32 counter;
};
/* * Template based on SECItems, suitable for passing as arrays
*/ struct SFTKItemTemplateStr {
CK_ATTRIBUTE_TYPE type;
SECItem *item;
};
#define SFTK_TOKEN_KRL_HANDLE (SFTK_TOKEN_MAGIC | SFTK_TOKEN_TYPE_CRL | 1) /* how big (in bytes) a password/pin we can deal with */ #define SFTK_MAX_PIN 500 /* minimum password/pin length (in Unicode characters) in FIPS mode */ #define FIPS_MIN_PIN 7
struct sftk_MACCtxStr { /* This is a common MAC context that supports both HMAC and CMAC * operations. This also presents a unified set of semantics: * * - Everything except Destroy returns a CK_RV, indicating success * or failure. (This handles the difference between HMAC's and CMAC's * interfaces, since the underlying AES _might_ fail with CMAC). * * - The underlying MAC is started on Init(...), so Update(...) can * called right away. (This handles the difference between HMAC and * CMAC in their *_Init(...) functions). * * - Calling semantics: * * - One of sftk_MAC_{Create,Init,InitRaw}(...) to set up the MAC * context, checking the return code. * - sftk_MAC_Update(...) as many times as necessary to process * input data, checking the return code. * - sftk_MAC_End(...) to get the output of the MAC; result_len * may be NULL if the caller knows the expected output length, * checking the return code. If result_len is NULL, this will * PR_ASSERT(...) that the actual returned length was equal to * max_result_len. * * Note: unlike HMAC_Finish(...), this allows the caller to specify * a return value less than return length, to align with * CMAC_Finish(...)'s semantics. This will force an additional * stack allocation of size SFTK_MAX_MAC_LENGTH. * - sftk_MAC_Reset(...) if the caller wishes to compute a new MAC * with the same key, checking the return code. * - sftk_MAC_DestroyContext(...) when the caller frees its associated * memory, passing PR_TRUE if sftk_MAC_Create(...) was called, * and PR_FALSE otherwise.
*/
CK_MECHANISM_TYPE mech; unsignedint mac_size;
union {
HMACContext *hmac;
CMACContext *cmac;
/* Functions to update when adding a new MAC or a new hash: * * - sftk_MAC_Init * - sftk_MAC_Update * - sftk_MAC_End * - sftk_MAC_Reset
*/ void *raw;
} mac;
/* helper function which calls nsslowkey_FindKeyByPublicKey after safely
* acquiring a reference to the keydb from the slot */
NSSLOWKEYPrivateKey *sftk_FindKeyByPublicKey(SFTKSlot *slot, SECItem *dbKey);
/* export the HKDF function for use in PowerupSelfTests */
CK_RV sftk_HKDF(CK_HKDF_PARAMS_PTR params, CK_SESSION_HANDLE hSession,
SFTKObject *sourceKey, constunsignedchar *sourceKeyBytes, int sourceKeyLen, SFTKObject *key, unsignedchar *outKeyBytes, int keySize,
PRBool canBeData, PRBool isFIPS);
/* dh verify functions */ /* verify that dhPrime matches one of our known primes, and if so return
* it's subprime value */ const SECItem *sftk_VerifyDH_Prime(SECItem *dhPrime, PRBool isFIPS); /* check if dhSubPrime claims dhPrime is a safe prime. */
SECStatus sftk_IsSafePrime(SECItem *dhPrime, SECItem *dhSubPrime, PRBool *isSafe); /* map an operation Attribute to a Mechanism flag */
CK_FLAGS sftk_AttributeToFlags(CK_ATTRIBUTE_TYPE op); /* check the FIPS table to determine if this current operation is allowed by
* FIPS security policy */
PRBool sftk_operationIsFIPS(SFTKSlot *slot, CK_MECHANISM *mech,
CK_ATTRIBUTE_TYPE op, SFTKObject *source); /* add validation objects to the slot */
CK_RV sftk_CreateValidationObjects(SFTKSlot *slot);
SEC_END_PROTOS
#endif/* _PKCS11I_H_ */
Messung V0.5
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.