andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: #ifndef _PK11PUB_H_ andre@0: #define _PK11PUB_H_ andre@0: #include "plarena.h" andre@0: #include "seccomon.h" andre@0: #include "secoidt.h" andre@0: #include "secdert.h" andre@0: #include "keyt.h" andre@0: #include "certt.h" andre@0: #include "pkcs11t.h" andre@0: #include "secmodt.h" andre@0: #include "seccomon.h" andre@0: #include "pkcs7t.h" andre@0: #include "cmsreclist.h" andre@0: andre@0: /* andre@0: * Exported PK11 wrap functions. andre@0: */ andre@0: andre@0: SEC_BEGIN_PROTOS andre@0: andre@0: /************************************************************ andre@0: * Generic Slot Lists Management andre@0: ************************************************************/ andre@0: void PK11_FreeSlotList(PK11SlotList *list); andre@0: SECStatus PK11_FreeSlotListElement(PK11SlotList *list, PK11SlotListElement *le); andre@0: PK11SlotListElement * PK11_GetFirstSafe(PK11SlotList *list); andre@0: PK11SlotListElement *PK11_GetNextSafe(PK11SlotList *list, andre@0: PK11SlotListElement *le, PRBool restart); andre@0: andre@0: /************************************************************ andre@0: * Generic Slot Management andre@0: ************************************************************/ andre@0: PK11SlotInfo *PK11_ReferenceSlot(PK11SlotInfo *slot); andre@0: void PK11_FreeSlot(PK11SlotInfo *slot); andre@0: SECStatus PK11_DestroyObject(PK11SlotInfo *slot,CK_OBJECT_HANDLE object); andre@0: SECStatus PK11_DestroyTokenObject(PK11SlotInfo *slot,CK_OBJECT_HANDLE object); andre@0: PK11SlotInfo *PK11_GetInternalKeySlot(void); andre@0: PK11SlotInfo *PK11_GetInternalSlot(void); andre@0: SECStatus PK11_Logout(PK11SlotInfo *slot); andre@0: void PK11_LogoutAll(void); andre@0: andre@0: andre@0: /************************************************************ andre@0: * Slot Password Management andre@0: ************************************************************/ andre@0: void PK11_SetSlotPWValues(PK11SlotInfo *slot,int askpw, int timeout); andre@0: void PK11_GetSlotPWValues(PK11SlotInfo *slot,int *askpw, int *timeout); andre@0: SECStatus PK11_CheckSSOPassword(PK11SlotInfo *slot, char *ssopw); andre@0: SECStatus PK11_CheckUserPassword(PK11SlotInfo *slot, const char *pw); andre@0: PRBool PK11_IsLoggedIn(PK11SlotInfo *slot, void *wincx); andre@0: SECStatus PK11_InitPin(PK11SlotInfo *slot,const char *ssopw, andre@0: const char *pk11_userpwd); andre@0: SECStatus PK11_ChangePW(PK11SlotInfo *slot, const char *oldpw, andre@0: const char *newpw); andre@0: void PK11_SetPasswordFunc(PK11PasswordFunc func); andre@0: int PK11_GetMinimumPwdLength(PK11SlotInfo *slot); andre@0: SECStatus PK11_ResetToken(PK11SlotInfo *slot, char *sso_pwd); andre@0: SECStatus PK11_Authenticate(PK11SlotInfo *slot, PRBool loadCerts, void *wincx); andre@0: SECStatus PK11_TokenRefresh(PK11SlotInfo *slot); andre@0: andre@0: andre@0: /****************************************************************** andre@0: * Slot info functions andre@0: ******************************************************************/ andre@0: PK11SlotInfo *PK11_FindSlotByName(const char *name); andre@0: /****************************************************************** andre@0: * PK11_FindSlotsByNames searches for a PK11SlotInfo using one or andre@0: * more criteria : dllName, slotName and tokenName . In addition, if andre@0: * presentOnly is set , only slots with a token inserted will be andre@0: * returned. andre@0: ******************************************************************/ andre@0: PK11SlotList *PK11_FindSlotsByNames(const char *dllName, andre@0: const char* slotName, const char* tokenName, PRBool presentOnly); andre@0: PRBool PK11_IsReadOnly(PK11SlotInfo *slot); andre@0: PRBool PK11_IsInternal(PK11SlotInfo *slot); andre@0: PRBool PK11_IsInternalKeySlot(PK11SlotInfo *slot); andre@0: char * PK11_GetTokenName(PK11SlotInfo *slot); andre@0: char * PK11_GetSlotName(PK11SlotInfo *slot); andre@0: PRBool PK11_NeedLogin(PK11SlotInfo *slot); andre@0: PRBool PK11_IsFriendly(PK11SlotInfo *slot); andre@0: PRBool PK11_IsHW(PK11SlotInfo *slot); andre@0: PRBool PK11_IsRemovable(PK11SlotInfo *slot); andre@0: PRBool PK11_NeedUserInit(PK11SlotInfo *slot); andre@0: PRBool PK11_ProtectedAuthenticationPath(PK11SlotInfo *slot); andre@0: int PK11_GetSlotSeries(PK11SlotInfo *slot); andre@0: int PK11_GetCurrentWrapIndex(PK11SlotInfo *slot); andre@0: unsigned long PK11_GetDefaultFlags(PK11SlotInfo *slot); andre@0: CK_SLOT_ID PK11_GetSlotID(PK11SlotInfo *slot); andre@0: SECMODModuleID PK11_GetModuleID(PK11SlotInfo *slot); andre@0: SECStatus PK11_GetSlotInfo(PK11SlotInfo *slot, CK_SLOT_INFO *info); andre@0: SECStatus PK11_GetTokenInfo(PK11SlotInfo *slot, CK_TOKEN_INFO *info); andre@0: PRBool PK11_IsDisabled(PK11SlotInfo *slot); andre@0: PRBool PK11_HasRootCerts(PK11SlotInfo *slot); andre@0: PK11DisableReasons PK11_GetDisabledReason(PK11SlotInfo *slot); andre@0: /* Prevents the slot from being used, and set disable reason to user-disable */ andre@0: /* NOTE: Mechanisms that were ON continue to stay ON */ andre@0: /* Therefore, when the slot is enabled, it will remember */ andre@0: /* what mechanisms needs to be turned on */ andre@0: PRBool PK11_UserDisableSlot(PK11SlotInfo *slot); andre@0: /* Allow all mechanisms that are ON before UserDisableSlot() */ andre@0: /* was called to be available again */ andre@0: PRBool PK11_UserEnableSlot(PK11SlotInfo *slot); andre@0: /* andre@0: * wait for a specific slot event. andre@0: * event is a specific event to wait for. Currently only andre@0: * PK11TokenChangeOrRemovalEvent and PK11TokenPresentEvents are defined. andre@0: * timeout can be an interval time to wait, PR_INTERVAL_NO_WAIT (meaning only andre@0: * poll once), or PR_INTERVAL_NO_TIMEOUT (meaning block until a change). andre@0: * pollInterval is a suggested pulling interval value. '0' means use the andre@0: * default. Future implementations that don't poll may ignore this value. andre@0: * series is the current series for the last slot. This should be the series andre@0: * value for the slot the last time you read persistant information from the andre@0: * slot. For instance, if you publish a cert from the slot, you should obtain andre@0: * the slot series at that time. Then PK11_WaitForTokenEvent can detect a andre@0: * a change in the slot between the time you publish and the time andre@0: * PK11_WaitForTokenEvent is called, elliminating potential race conditions. andre@0: * andre@0: * The current status that is returned is: andre@0: * PK11TokenNotRemovable - always returned for any non-removable token. andre@0: * PK11TokenPresent - returned when the token is present and we are waiting andre@0: * on a PK11TokenPresentEvent. Then next event to look for is a andre@0: * PK11TokenChangeOrRemovalEvent. andre@0: * PK11TokenChanged - returned when the old token has been removed and a new andre@0: * token ad been inserted, and we are waiting for a andre@0: * PK11TokenChangeOrRemovalEvent. The next event to look for is another andre@0: * PK11TokenChangeOrRemovalEvent. andre@0: * PK11TokenRemoved - returned when the token is not present and we are andre@0: * waiting for a PK11TokenChangeOrRemovalEvent. The next event to look for andre@0: * is a PK11TokenPresentEvent. andre@0: */ andre@0: PK11TokenStatus PK11_WaitForTokenEvent(PK11SlotInfo *slot, PK11TokenEvent event, andre@0: PRIntervalTime timeout, PRIntervalTime pollInterval, int series); andre@0: andre@0: PRBool PK11_NeedPWInit(void); andre@0: PRBool PK11_TokenExists(CK_MECHANISM_TYPE); andre@0: SECStatus PK11_GetModInfo(SECMODModule *mod, CK_INFO *info); andre@0: PRBool PK11_IsFIPS(void); andre@0: SECMODModule *PK11_GetModule(PK11SlotInfo *slot); andre@0: andre@0: /********************************************************************* andre@0: * Slot mapping utility functions. andre@0: *********************************************************************/ andre@0: PRBool PK11_IsPresent(PK11SlotInfo *slot); andre@0: PRBool PK11_DoesMechanism(PK11SlotInfo *slot, CK_MECHANISM_TYPE type); andre@0: PK11SlotList * PK11_GetAllTokens(CK_MECHANISM_TYPE type,PRBool needRW, andre@0: PRBool loadCerts, void *wincx); andre@0: PK11SlotInfo *PK11_GetBestSlotMultipleWithAttributes(CK_MECHANISM_TYPE *type, andre@0: CK_FLAGS *mechFlag, unsigned int *keySize, andre@0: unsigned int count, void *wincx); andre@0: PK11SlotInfo *PK11_GetBestSlotMultiple(CK_MECHANISM_TYPE *type, andre@0: unsigned int count, void *wincx); andre@0: PK11SlotInfo *PK11_GetBestSlot(CK_MECHANISM_TYPE type, void *wincx); andre@0: PK11SlotInfo *PK11_GetBestSlotWithAttributes(CK_MECHANISM_TYPE type, andre@0: CK_FLAGS mechFlag, unsigned int keySize, void *wincx); andre@0: CK_MECHANISM_TYPE PK11_GetBestWrapMechanism(PK11SlotInfo *slot); andre@0: int PK11_GetBestKeyLength(PK11SlotInfo *slot, CK_MECHANISM_TYPE type); andre@0: andre@0: /* andre@0: * Open a new database using the softoken. The caller is responsible for making andre@0: * sure the module spec is correct and usable. The caller should ask for one andre@0: * new database per call if the caller wants to get meaningful information andre@0: * about the new database. andre@0: * andre@0: * moduleSpec is the same data that you would pass to softoken at andre@0: * initialization time under the 'tokens' options. For example, if you were andre@0: * to specify tokens=<0x4=[configdir='./mybackup' tokenDescription='Backup']> andre@0: * You would specify "configdir='./mybackup' tokenDescription='Backup'" as your andre@0: * module spec here. The slot ID will be calculated for you by andre@0: * SECMOD_OpenUserDB(). andre@0: * andre@0: * Typical parameters here are configdir, tokenDescription and flags. andre@0: * andre@0: * a Full list is below: andre@0: * andre@0: * andre@0: * configDir - The location of the databases for this token. If configDir is andre@0: * not specified, and noCertDB and noKeyDB is not specified, the load andre@0: * will fail. andre@0: * certPrefix - Cert prefix for this token. andre@0: * keyPrefix - Prefix for the key database for this token. (if not specified, andre@0: * certPrefix will be used). andre@0: * tokenDescription - The label value for this token returned in the andre@0: * CK_TOKEN_INFO structure with an internationalize string (UTF8). andre@0: * This value will be truncated at 32 bytes (no NULL, partial UTF8 andre@0: * characters dropped). You should specify a user friendly name here andre@0: * as this is the value the token will be referred to in most andre@0: * application UI's. You should make sure tokenDescription is unique. andre@0: * slotDescription - The slotDescription value for this token returned andre@0: * in the CK_SLOT_INFO structure with an internationalize string andre@0: * (UTF8). This value will be truncated at 64 bytes (no NULL, partial andre@0: * UTF8 characters dropped). This name will not change after the andre@0: * database is closed. It should have some number to make this unique. andre@0: * minPWLen - minimum password length for this token. andre@0: * flags - comma separated list of flag values, parsed case-insensitive. andre@0: * Valid flags are: andre@0: * readOnly - Databases should be opened read only. andre@0: * noCertDB - Don't try to open a certificate database. andre@0: * noKeyDB - Don't try to open a key database. andre@0: * forceOpen - Don't fail to initialize the token if the andre@0: * databases could not be opened. andre@0: * passwordRequired - zero length passwords are not acceptable andre@0: * (valid only if there is a keyDB). andre@0: * optimizeSpace - allocate smaller hash tables and lock tables. andre@0: * When this flag is not specified, Softoken will allocate andre@0: * large tables to prevent lock contention. andre@0: */ andre@0: PK11SlotInfo *SECMOD_OpenUserDB(const char *moduleSpec); andre@0: SECStatus SECMOD_CloseUserDB(PK11SlotInfo *slot); andre@0: andre@0: /* andre@0: * This is exactly the same as OpenUserDB except it can be called on any andre@0: * module that understands softoken style new slot entries. The resulting andre@0: * slot can be closed using SECMOD_CloseUserDB above. Value of moduleSpec andre@0: * is token specific. andre@0: */ andre@0: PK11SlotInfo *SECMOD_OpenNewSlot(SECMODModule *mod, const char *moduleSpec); andre@0: andre@0: andre@0: /* andre@0: * merge the permanent objects from on token to another andre@0: */ andre@0: SECStatus PK11_MergeTokens(PK11SlotInfo *targetSlot, PK11SlotInfo *sourceSlot, andre@0: PK11MergeLog *log, void *targetPwArg, void *sourcePwArg); andre@0: andre@0: /* andre@0: * create and destroy merge logs needed by PK11_MergeTokens andre@0: */ andre@0: PK11MergeLog * PK11_CreateMergeLog(void); andre@0: void PK11_DestroyMergeLog(PK11MergeLog *log); andre@0: andre@0: andre@0: andre@0: /********************************************************************* andre@0: * Mechanism Mapping functions andre@0: *********************************************************************/ andre@0: CK_KEY_TYPE PK11_GetKeyType(CK_MECHANISM_TYPE type,unsigned long len); andre@0: CK_MECHANISM_TYPE PK11_GetKeyGen(CK_MECHANISM_TYPE type); andre@0: int PK11_GetBlockSize(CK_MECHANISM_TYPE type,SECItem *params); andre@0: int PK11_GetIVLength(CK_MECHANISM_TYPE type); andre@0: SECItem *PK11_ParamFromIV(CK_MECHANISM_TYPE type,SECItem *iv); andre@0: unsigned char *PK11_IVFromParam(CK_MECHANISM_TYPE type,SECItem *param,int *len); andre@0: SECItem * PK11_BlockData(SECItem *data,unsigned long size); andre@0: andre@0: /* PKCS #11 to DER mapping functions */ andre@0: SECItem *PK11_ParamFromAlgid(SECAlgorithmID *algid); andre@0: SECItem *PK11_GenerateNewParam(CK_MECHANISM_TYPE, PK11SymKey *); andre@0: CK_MECHANISM_TYPE PK11_AlgtagToMechanism(SECOidTag algTag); andre@0: SECOidTag PK11_MechanismToAlgtag(CK_MECHANISM_TYPE type); andre@0: SECOidTag PK11_FortezzaMapSig(SECOidTag algTag); andre@0: SECStatus PK11_ParamToAlgid(SECOidTag algtag, SECItem *param, andre@0: PLArenaPool *arena, SECAlgorithmID *algid); andre@0: SECStatus PK11_SeedRandom(PK11SlotInfo *,unsigned char *data,int len); andre@0: SECStatus PK11_GenerateRandomOnSlot(PK11SlotInfo *,unsigned char *data,int len); andre@0: SECStatus PK11_RandomUpdate(void *data, size_t bytes); andre@0: SECStatus PK11_GenerateRandom(unsigned char *data,int len); andre@0: andre@0: /* warning: cannot work with pkcs 5 v2 andre@0: * use algorithm ID s instead of pkcs #11 mechanism pointers */ andre@0: CK_RV PK11_MapPBEMechanismToCryptoMechanism(CK_MECHANISM_PTR pPBEMechanism, andre@0: CK_MECHANISM_PTR pCryptoMechanism, andre@0: SECItem *pbe_pwd, PRBool bad3DES); andre@0: CK_MECHANISM_TYPE PK11_GetPadMechanism(CK_MECHANISM_TYPE); andre@0: CK_MECHANISM_TYPE PK11_MapSignKeyType(KeyType keyType); andre@0: andre@0: /********************************************************************** andre@0: * Symmetric, Public, and Private Keys andre@0: **********************************************************************/ andre@0: void PK11_FreeSymKey(PK11SymKey *key); andre@0: PK11SymKey *PK11_ReferenceSymKey(PK11SymKey *symKey); andre@0: PK11SymKey *PK11_ImportSymKey(PK11SlotInfo *slot, CK_MECHANISM_TYPE type, andre@0: PK11Origin origin, CK_ATTRIBUTE_TYPE operation, SECItem *key, void *wincx); andre@0: PK11SymKey *PK11_ImportSymKeyWithFlags(PK11SlotInfo *slot, andre@0: CK_MECHANISM_TYPE type, PK11Origin origin, CK_ATTRIBUTE_TYPE operation, andre@0: SECItem *key, CK_FLAGS flags, PRBool isPerm, void *wincx); andre@0: PK11SymKey *PK11_SymKeyFromHandle(PK11SlotInfo *slot, PK11SymKey *parent, andre@0: PK11Origin origin, CK_MECHANISM_TYPE type, CK_OBJECT_HANDLE keyID, andre@0: PRBool owner, void *wincx); andre@0: PK11SymKey *PK11_GetWrapKey(PK11SlotInfo *slot, int wrap, andre@0: CK_MECHANISM_TYPE type,int series, void *wincx); andre@0: /* andre@0: * This function is not thread-safe. It can only be called when only andre@0: * one thread has a reference to wrapKey. andre@0: */ andre@0: void PK11_SetWrapKey(PK11SlotInfo *slot, int wrap, PK11SymKey *wrapKey); andre@0: CK_MECHANISM_TYPE PK11_GetMechanism(PK11SymKey *symKey); andre@0: /* andre@0: * import a public key into the desired slot andre@0: * andre@0: * This function takes a public key structure and creates a public key in a andre@0: * given slot. If isToken is set, then a persistant public key is created. andre@0: * andre@0: * Note: it is possible for this function to return a handle for a key which andre@0: * is persistant, even if isToken is not set. andre@0: */ andre@0: CK_OBJECT_HANDLE PK11_ImportPublicKey(PK11SlotInfo *slot, andre@0: SECKEYPublicKey *pubKey, PRBool isToken); andre@0: PK11SymKey *PK11_KeyGen(PK11SlotInfo *slot,CK_MECHANISM_TYPE type, andre@0: SECItem *param, int keySize,void *wincx); andre@0: PK11SymKey *PK11_TokenKeyGen(PK11SlotInfo *slot, CK_MECHANISM_TYPE type, andre@0: SECItem *param, int keySize, SECItem *keyid, andre@0: PRBool isToken, void *wincx); andre@0: PK11SymKey *PK11_TokenKeyGenWithFlags(PK11SlotInfo *slot, andre@0: CK_MECHANISM_TYPE type, SECItem *param, andre@0: int keySize, SECItem *keyid, CK_FLAGS opFlags, andre@0: PK11AttrFlags attrFlags, void *wincx); andre@0: /* Generates a key using the exact template supplied by the caller. The other andre@0: * PK11_[Token]KeyGen mechanisms should be used instead of this one whenever andre@0: * they work because they include/exclude the CKA_VALUE_LEN template value andre@0: * based on the mechanism type as required by many tokens. andre@0: * andre@0: * keyGenType should be PK11_GetKeyGenWithSize(type, ) or it should andre@0: * be equal to type if PK11_GetKeyGenWithSize cannot be used (e.g. because andre@0: * pk11wrap does not know about the mechanisms). andre@0: */ andre@0: PK11SymKey *PK11_KeyGenWithTemplate(PK11SlotInfo *slot, CK_MECHANISM_TYPE type, andre@0: CK_MECHANISM_TYPE keyGenType, andre@0: SECItem *param, CK_ATTRIBUTE * attrs, andre@0: unsigned int attrsCount, void *wincx); andre@0: PK11SymKey * PK11_ListFixedKeysInSlot(PK11SlotInfo *slot, char *nickname, andre@0: void *wincx); andre@0: PK11SymKey *PK11_GetNextSymKey(PK11SymKey *symKey); andre@0: CK_KEY_TYPE PK11_GetSymKeyType(PK11SymKey *key); andre@0: CK_OBJECT_HANDLE PK11_GetSymKeyHandle(PK11SymKey *symKey); andre@0: andre@0: andre@0: /* andre@0: * PK11_SetSymKeyUserData andre@0: * sets generic user data on keys (usually a pointer to a data structure) andre@0: * that can later be retrieved by PK11_GetSymKeyUserData(). andre@0: * symKey - key where data will be set. andre@0: * data - data to be set. andre@0: * freefunc - function used to free the data. andre@0: * Setting user data on symKeys with existing user data already set will cause andre@0: * the existing user data to be freed before the new user data is set. andre@0: * Freeing user data is done by calling the user specified freefunc. andre@0: * If freefunc is NULL, the user data is assumed to be global or static an andre@0: * not freed. Passing NULL for user data to PK11_SetSymKeyUserData has the andre@0: * effect of freeing any existing user data, and clearing the user data andre@0: * pointer. If user data exists when the symKey is finally freed, that andre@0: * data will be freed with freefunc. andre@0: * andre@0: * Applications should only use this function on keys which the application andre@0: * has created directly, as there is only one user data value per key. andre@0: */ andre@0: void PK11_SetSymKeyUserData(PK11SymKey *symKey, void *data, andre@0: PK11FreeDataFunc freefunc); andre@0: /* PK11_GetSymKeyUserData andre@0: * retrieves generic user data which was set on a key by andre@0: * PK11_SetSymKeyUserData. andre@0: * symKey - key with data to be fetched andre@0: * andre@0: * If no data exists, or the data has been cleared, PK11_GetSymKeyUserData andre@0: * will return NULL. Returned data is still owned and managed by the SymKey, andre@0: * the caller should not free the data. andre@0: * andre@0: */ andre@0: void *PK11_GetSymKeyUserData(PK11SymKey *symKey); andre@0: andre@0: SECStatus PK11_PubWrapSymKey(CK_MECHANISM_TYPE type, SECKEYPublicKey *pubKey, andre@0: PK11SymKey *symKey, SECItem *wrappedKey); andre@0: SECStatus PK11_WrapSymKey(CK_MECHANISM_TYPE type, SECItem *params, andre@0: PK11SymKey *wrappingKey, PK11SymKey *symKey, SECItem *wrappedKey); andre@0: /* move a key to 'slot' optionally set the key attributes according to either andre@0: * operation or the flags and making the key permanent at the same time. andre@0: * If the key is moved to the same slot, operation and flags values are andre@0: * currently ignored */ andre@0: PK11SymKey *PK11_MoveSymKey(PK11SlotInfo *slot, CK_ATTRIBUTE_TYPE operation, andre@0: CK_FLAGS flags, PRBool perm, PK11SymKey *symKey); andre@0: /* andre@0: * derive a new key from the base key. andre@0: * PK11_Derive returns a key which can do exactly one operation, and is andre@0: * ephemeral (session key). andre@0: * PK11_DeriveWithFlags is the same as PK11_Derive, except you can use andre@0: * CKF_ flags to enable more than one operation. andre@0: * PK11_DeriveWithFlagsPerm is the same as PK11_DeriveWithFlags except you can andre@0: * (optionally) make the key permanent (token key). andre@0: */ andre@0: PK11SymKey *PK11_Derive(PK11SymKey *baseKey, CK_MECHANISM_TYPE mechanism, andre@0: SECItem *param, CK_MECHANISM_TYPE target, andre@0: CK_ATTRIBUTE_TYPE operation, int keySize); andre@0: PK11SymKey *PK11_DeriveWithFlags( PK11SymKey *baseKey, andre@0: CK_MECHANISM_TYPE derive, SECItem *param, CK_MECHANISM_TYPE target, andre@0: CK_ATTRIBUTE_TYPE operation, int keySize, CK_FLAGS flags); andre@0: PK11SymKey * PK11_DeriveWithFlagsPerm( PK11SymKey *baseKey, andre@0: CK_MECHANISM_TYPE derive, andre@0: SECItem *param, CK_MECHANISM_TYPE target, CK_ATTRIBUTE_TYPE operation, andre@0: int keySize, CK_FLAGS flags, PRBool isPerm); andre@0: PK11SymKey * andre@0: PK11_DeriveWithTemplate( PK11SymKey *baseKey, CK_MECHANISM_TYPE derive, andre@0: SECItem *param, CK_MECHANISM_TYPE target, CK_ATTRIBUTE_TYPE operation, andre@0: int keySize, CK_ATTRIBUTE *userAttr, unsigned int numAttrs, andre@0: PRBool isPerm); andre@0: andre@0: andre@0: PK11SymKey *PK11_PubDerive( SECKEYPrivateKey *privKey, andre@0: SECKEYPublicKey *pubKey, PRBool isSender, SECItem *randomA, SECItem *randomB, andre@0: CK_MECHANISM_TYPE derive, CK_MECHANISM_TYPE target, andre@0: CK_ATTRIBUTE_TYPE operation, int keySize,void *wincx) ; andre@0: PK11SymKey *PK11_PubDeriveWithKDF( SECKEYPrivateKey *privKey, andre@0: SECKEYPublicKey *pubKey, PRBool isSender, SECItem *randomA, SECItem *randomB, andre@0: CK_MECHANISM_TYPE derive, CK_MECHANISM_TYPE target, andre@0: CK_ATTRIBUTE_TYPE operation, int keySize, andre@0: CK_ULONG kdf, SECItem *sharedData, void *wincx); andre@0: andre@0: /* andre@0: * unwrap a new key with a symetric key. andre@0: * PK11_Unwrap returns a key which can do exactly one operation, and is andre@0: * ephemeral (session key). andre@0: * PK11_UnwrapWithFlags is the same as PK11_Unwrap, except you can use andre@0: * CKF_ flags to enable more than one operation. andre@0: * PK11_UnwrapWithFlagsPerm is the same as PK11_UnwrapWithFlags except you can andre@0: * (optionally) make the key permanent (token key). andre@0: */ andre@0: PK11SymKey *PK11_UnwrapSymKey(PK11SymKey *key, andre@0: CK_MECHANISM_TYPE wraptype, SECItem *param, SECItem *wrapppedKey, andre@0: CK_MECHANISM_TYPE target, CK_ATTRIBUTE_TYPE operation, int keySize); andre@0: PK11SymKey *PK11_UnwrapSymKeyWithFlags(PK11SymKey *wrappingKey, andre@0: CK_MECHANISM_TYPE wrapType, SECItem *param, SECItem *wrappedKey, andre@0: CK_MECHANISM_TYPE target, CK_ATTRIBUTE_TYPE operation, int keySize, andre@0: CK_FLAGS flags); andre@0: PK11SymKey * PK11_UnwrapSymKeyWithFlagsPerm(PK11SymKey *wrappingKey, andre@0: CK_MECHANISM_TYPE wrapType, andre@0: SECItem *param, SECItem *wrappedKey, andre@0: CK_MECHANISM_TYPE target, CK_ATTRIBUTE_TYPE operation, andre@0: int keySize, CK_FLAGS flags, PRBool isPerm); andre@0: andre@0: /* andre@0: * unwrap a new key with a private key. andre@0: * PK11_PubUnwrap returns a key which can do exactly one operation, and is andre@0: * ephemeral (session key). andre@0: * PK11_PubUnwrapWithFlagsPerm is the same as PK11_PubUnwrap except you can andre@0: * use * CKF_ flags to enable more than one operation, and optionally make andre@0: * the key permanent (token key). andre@0: */ andre@0: PK11SymKey *PK11_PubUnwrapSymKey(SECKEYPrivateKey *key, SECItem *wrapppedKey, andre@0: CK_MECHANISM_TYPE target, CK_ATTRIBUTE_TYPE operation, int keySize); andre@0: PK11SymKey * PK11_PubUnwrapSymKeyWithFlagsPerm(SECKEYPrivateKey *wrappingKey, andre@0: SECItem *wrappedKey, CK_MECHANISM_TYPE target, andre@0: CK_ATTRIBUTE_TYPE operation, int keySize, andre@0: CK_FLAGS flags, PRBool isPerm); andre@0: PK11SymKey *PK11_FindFixedKey(PK11SlotInfo *slot, CK_MECHANISM_TYPE type, andre@0: SECItem *keyID, void *wincx); andre@0: SECStatus PK11_DeleteTokenPrivateKey(SECKEYPrivateKey *privKey,PRBool force); andre@0: SECStatus PK11_DeleteTokenPublicKey(SECKEYPublicKey *pubKey); andre@0: SECStatus PK11_DeleteTokenSymKey(PK11SymKey *symKey); andre@0: SECStatus PK11_DeleteTokenCertAndKey(CERTCertificate *cert,void *wincx); andre@0: SECKEYPrivateKey * PK11_LoadPrivKey(PK11SlotInfo *slot, andre@0: SECKEYPrivateKey *privKey, SECKEYPublicKey *pubKey, andre@0: PRBool token, PRBool sensitive); andre@0: char * PK11_GetSymKeyNickname(PK11SymKey *symKey); andre@0: char * PK11_GetPrivateKeyNickname(SECKEYPrivateKey *privKey); andre@0: char * PK11_GetPublicKeyNickname(SECKEYPublicKey *pubKey); andre@0: SECStatus PK11_SetSymKeyNickname(PK11SymKey *symKey, const char *nickname); andre@0: SECStatus PK11_SetPrivateKeyNickname(SECKEYPrivateKey *privKey, andre@0: const char *nickname); andre@0: SECStatus PK11_SetPublicKeyNickname(SECKEYPublicKey *pubKey, andre@0: const char *nickname); andre@0: andre@0: /* size to hold key in bytes */ andre@0: unsigned int PK11_GetKeyLength(PK11SymKey *key); andre@0: /* size of actual secret parts of key in bits */ andre@0: /* algid is because RC4 strength is determined by the effective bits as well andre@0: * as the key bits */ andre@0: unsigned int PK11_GetKeyStrength(PK11SymKey *key,SECAlgorithmID *algid); andre@0: SECStatus PK11_ExtractKeyValue(PK11SymKey *symKey); andre@0: SECItem * PK11_GetKeyData(PK11SymKey *symKey); andre@0: PK11SlotInfo * PK11_GetSlotFromKey(PK11SymKey *symKey); andre@0: void *PK11_GetWindow(PK11SymKey *symKey); andre@0: andre@0: /* andre@0: * Explicitly set the key usage for the generated private key. andre@0: * andre@0: * This allows us to specify single use EC and RSA keys whose usage andre@0: * can be regulated by the underlying token. andre@0: * andre@0: * The underlying key usage is set using opFlags. opFlagsMask specifies andre@0: * which operations are specified by opFlags. For instance to turn encrypt andre@0: * on and signing off, opFlags would be CKF_ENCRYPT|CKF_DECRYPT and andre@0: * opFlagsMask would be CKF_ENCRYPT|CKF_DECRYPT|CKF_SIGN|CKF_VERIFY. You andre@0: * need to specify both the public and private key flags, andre@0: * PK11_GenerateKeyPairWithOpFlags will sort out the correct flag to the andre@0: * correct key type. Flags not specified in opFlagMask will be defaulted andre@0: * according to mechanism type and token capabilities. andre@0: */ andre@0: SECKEYPrivateKey *PK11_GenerateKeyPairWithOpFlags(PK11SlotInfo *slot, andre@0: CK_MECHANISM_TYPE type, void *param, SECKEYPublicKey **pubk, andre@0: PK11AttrFlags attrFlags, CK_FLAGS opFlags, CK_FLAGS opFlagsMask, andre@0: void *wincx); andre@0: /* andre@0: * The attrFlags is the logical OR of the PK11_ATTR_XXX bitflags. andre@0: * These flags apply to the private key. The PK11_ATTR_TOKEN, andre@0: * PK11_ATTR_SESSION, PK11_ATTR_MODIFIABLE, and PK11_ATTR_UNMODIFIABLE andre@0: * flags also apply to the public key. andre@0: */ andre@0: SECKEYPrivateKey *PK11_GenerateKeyPairWithFlags(PK11SlotInfo *slot, andre@0: CK_MECHANISM_TYPE type, void *param, SECKEYPublicKey **pubk, andre@0: PK11AttrFlags attrFlags, void *wincx); andre@0: SECKEYPrivateKey *PK11_GenerateKeyPair(PK11SlotInfo *slot, andre@0: CK_MECHANISM_TYPE type, void *param, SECKEYPublicKey **pubk, andre@0: PRBool isPerm, PRBool isSensitive, void *wincx); andre@0: SECKEYPrivateKey * PK11_FindPrivateKeyFromCert(PK11SlotInfo *slot, andre@0: CERTCertificate *cert, void *wincx); andre@0: SECKEYPrivateKey * PK11_FindKeyByAnyCert(CERTCertificate *cert, void *wincx); andre@0: SECKEYPrivateKey * PK11_FindKeyByKeyID(PK11SlotInfo *slot, SECItem *keyID, andre@0: void *wincx); andre@0: int PK11_GetPrivateModulusLen(SECKEYPrivateKey *key); andre@0: andre@0: SECStatus PK11_Decrypt(PK11SymKey *symkey, andre@0: CK_MECHANISM_TYPE mechanism, SECItem *param, andre@0: unsigned char *out, unsigned int *outLen, andre@0: unsigned int maxLen, andre@0: const unsigned char *enc, unsigned int encLen); andre@0: SECStatus PK11_Encrypt(PK11SymKey *symKey, andre@0: CK_MECHANISM_TYPE mechanism, SECItem *param, andre@0: unsigned char *out, unsigned int *outLen, andre@0: unsigned int maxLen, andre@0: const unsigned char *data, unsigned int dataLen); andre@0: andre@0: /* note: despite the name, this function takes a private key. */ andre@0: SECStatus PK11_PubDecryptRaw(SECKEYPrivateKey *key, andre@0: unsigned char *data, unsigned *outLen, andre@0: unsigned int maxLen, andre@0: const unsigned char *enc, unsigned encLen); andre@0: #define PK11_PrivDecryptRaw PK11_PubDecryptRaw andre@0: /* The encrypt function that complements the above decrypt function. */ andre@0: SECStatus PK11_PubEncryptRaw(SECKEYPublicKey *key, andre@0: unsigned char *enc, andre@0: const unsigned char *data, unsigned dataLen, andre@0: void *wincx); andre@0: andre@0: SECStatus PK11_PrivDecryptPKCS1(SECKEYPrivateKey *key, andre@0: unsigned char *data, unsigned *outLen, andre@0: unsigned int maxLen, andre@0: const unsigned char *enc, unsigned encLen); andre@0: /* The encrypt function that complements the above decrypt function. */ andre@0: SECStatus PK11_PubEncryptPKCS1(SECKEYPublicKey *key, andre@0: unsigned char *enc, andre@0: const unsigned char *data, unsigned dataLen, andre@0: void *wincx); andre@0: andre@0: SECStatus PK11_PrivDecrypt(SECKEYPrivateKey *key, andre@0: CK_MECHANISM_TYPE mechanism, SECItem *param, andre@0: unsigned char *out, unsigned int *outLen, andre@0: unsigned int maxLen, andre@0: const unsigned char *enc, unsigned int encLen); andre@0: SECStatus PK11_PubEncrypt(SECKEYPublicKey *key, andre@0: CK_MECHANISM_TYPE mechanism, SECItem *param, andre@0: unsigned char *out, unsigned int *outLen, andre@0: unsigned int maxLen, andre@0: const unsigned char *data, unsigned int dataLen, andre@0: void *wincx); andre@0: andre@0: SECStatus PK11_ImportPrivateKeyInfo(PK11SlotInfo *slot, andre@0: SECKEYPrivateKeyInfo *pki, SECItem *nickname, andre@0: SECItem *publicValue, PRBool isPerm, PRBool isPrivate, andre@0: unsigned int usage, void *wincx); andre@0: SECStatus PK11_ImportPrivateKeyInfoAndReturnKey(PK11SlotInfo *slot, andre@0: SECKEYPrivateKeyInfo *pki, SECItem *nickname, andre@0: SECItem *publicValue, PRBool isPerm, PRBool isPrivate, andre@0: unsigned int usage, SECKEYPrivateKey** privk, void *wincx); andre@0: SECStatus PK11_ImportDERPrivateKeyInfo(PK11SlotInfo *slot, andre@0: SECItem *derPKI, SECItem *nickname, andre@0: SECItem *publicValue, PRBool isPerm, PRBool isPrivate, andre@0: unsigned int usage, void *wincx); andre@0: SECStatus PK11_ImportDERPrivateKeyInfoAndReturnKey(PK11SlotInfo *slot, andre@0: SECItem *derPKI, SECItem *nickname, andre@0: SECItem *publicValue, PRBool isPerm, PRBool isPrivate, andre@0: unsigned int usage, SECKEYPrivateKey** privk, void *wincx); andre@0: SECStatus PK11_ImportEncryptedPrivateKeyInfo(PK11SlotInfo *slot, andre@0: SECKEYEncryptedPrivateKeyInfo *epki, SECItem *pwitem, andre@0: SECItem *nickname, SECItem *publicValue, PRBool isPerm, andre@0: PRBool isPrivate, KeyType type, andre@0: unsigned int usage, void *wincx); andre@0: SECStatus PK11_ImportEncryptedPrivateKeyInfoAndReturnKey(PK11SlotInfo *slot, andre@0: SECKEYEncryptedPrivateKeyInfo *epki, SECItem *pwitem, andre@0: SECItem *nickname, SECItem *publicValue, PRBool isPerm, andre@0: PRBool isPrivate, KeyType type, andre@0: unsigned int usage, SECKEYPrivateKey** privk, void *wincx); andre@0: SECItem *PK11_ExportDERPrivateKeyInfo(SECKEYPrivateKey *pk, void *wincx); andre@0: SECKEYPrivateKeyInfo *PK11_ExportPrivKeyInfo( andre@0: SECKEYPrivateKey *pk, void *wincx); andre@0: SECKEYPrivateKeyInfo *PK11_ExportPrivateKeyInfo( andre@0: CERTCertificate *cert, void *wincx); andre@0: SECKEYEncryptedPrivateKeyInfo *PK11_ExportEncryptedPrivKeyInfo( andre@0: PK11SlotInfo *slot, SECOidTag algTag, SECItem *pwitem, andre@0: SECKEYPrivateKey *pk, int iteration, void *wincx); andre@0: SECKEYEncryptedPrivateKeyInfo *PK11_ExportEncryptedPrivateKeyInfo( andre@0: PK11SlotInfo *slot, SECOidTag algTag, SECItem *pwitem, andre@0: CERTCertificate *cert, int iteration, void *wincx); andre@0: SECKEYPrivateKey *PK11_FindKeyByDERCert(PK11SlotInfo *slot, andre@0: CERTCertificate *cert, void *wincx); andre@0: SECKEYPublicKey *PK11_MakeKEAPubKey(unsigned char *data, int length); andre@0: SECStatus PK11_DigestKey(PK11Context *context, PK11SymKey *key); andre@0: PRBool PK11_VerifyKeyOK(PK11SymKey *key); andre@0: SECKEYPrivateKey *PK11_UnwrapPrivKey(PK11SlotInfo *slot, andre@0: PK11SymKey *wrappingKey, CK_MECHANISM_TYPE wrapType, andre@0: SECItem *param, SECItem *wrappedKey, SECItem *label, andre@0: SECItem *publicValue, PRBool token, PRBool sensitive, andre@0: CK_KEY_TYPE keyType, CK_ATTRIBUTE_TYPE *usage, int usageCount, andre@0: void *wincx); andre@0: SECStatus PK11_WrapPrivKey(PK11SlotInfo *slot, PK11SymKey *wrappingKey, andre@0: SECKEYPrivateKey *privKey, CK_MECHANISM_TYPE wrapType, andre@0: SECItem *param, SECItem *wrappedKey, void *wincx); andre@0: /* andre@0: * The caller of PK11_DEREncodePublicKey should free the returned SECItem with andre@0: * a SECITEM_FreeItem(..., PR_TRUE) call. andre@0: */ andre@0: SECItem* PK11_DEREncodePublicKey(const SECKEYPublicKey *pubk); andre@0: PK11SymKey* PK11_CopySymKeyForSigning(PK11SymKey *originalKey, andre@0: CK_MECHANISM_TYPE mech); andre@0: SECKEYPrivateKeyList* PK11_ListPrivKeysInSlot(PK11SlotInfo *slot, andre@0: char *nickname, void *wincx); andre@0: SECKEYPublicKeyList* PK11_ListPublicKeysInSlot(PK11SlotInfo *slot, andre@0: char *nickname); andre@0: SECKEYPQGParams *PK11_GetPQGParamsFromPrivateKey(SECKEYPrivateKey *privKey); andre@0: /* deprecated */ andre@0: SECKEYPrivateKeyList* PK11_ListPrivateKeysInSlot(PK11SlotInfo *slot); andre@0: andre@0: PK11SymKey *PK11_ConvertSessionSymKeyToTokenSymKey(PK11SymKey *symk, andre@0: void *wincx); andre@0: SECKEYPrivateKey *PK11_ConvertSessionPrivKeyToTokenPrivKey( andre@0: SECKEYPrivateKey *privk, void* wincx); andre@0: SECKEYPrivateKey * PK11_CopyTokenPrivKeyToSessionPrivKey(PK11SlotInfo *destSlot, andre@0: SECKEYPrivateKey *privKey); andre@0: andre@0: /********************************************************************** andre@0: * Certs andre@0: **********************************************************************/ andre@0: SECItem *PK11_MakeIDFromPubKey(SECItem *pubKeyData); andre@0: SECStatus PK11_TraverseSlotCerts( andre@0: SECStatus(* callback)(CERTCertificate*,SECItem *,void *), andre@0: void *arg, void *wincx); andre@0: CERTCertificate * PK11_FindCertFromNickname(const char *nickname, void *wincx); andre@0: CERTCertList * PK11_FindCertsFromEmailAddress(const char *email, void *wincx); andre@0: CERTCertList * PK11_FindCertsFromNickname(const char *nickname, void *wincx); andre@0: CERTCertificate *PK11_GetCertFromPrivateKey(SECKEYPrivateKey *privKey); andre@0: SECStatus PK11_ImportCert(PK11SlotInfo *slot, CERTCertificate *cert, andre@0: CK_OBJECT_HANDLE key, const char *nickname, andre@0: PRBool includeTrust); andre@0: SECStatus PK11_ImportDERCert(PK11SlotInfo *slot, SECItem *derCert, andre@0: CK_OBJECT_HANDLE key, char *nickname, PRBool includeTrust); andre@0: PK11SlotInfo *PK11_ImportCertForKey(CERTCertificate *cert, andre@0: const char *nickname, void *wincx); andre@0: PK11SlotInfo *PK11_ImportDERCertForKey(SECItem *derCert, char *nickname, andre@0: void *wincx); andre@0: PK11SlotInfo *PK11_KeyForCertExists(CERTCertificate *cert, andre@0: CK_OBJECT_HANDLE *keyPtr, void *wincx); andre@0: PK11SlotInfo *PK11_KeyForDERCertExists(SECItem *derCert, andre@0: CK_OBJECT_HANDLE *keyPtr, void *wincx); andre@0: CERTCertificate * PK11_FindCertByIssuerAndSN(PK11SlotInfo **slot, andre@0: CERTIssuerAndSN *sn, void *wincx); andre@0: CERTCertificate * PK11_FindCertAndKeyByRecipientList(PK11SlotInfo **slot, andre@0: SEC_PKCS7RecipientInfo **array, SEC_PKCS7RecipientInfo **rip, andre@0: SECKEYPrivateKey**privKey, void *wincx); andre@0: int PK11_FindCertAndKeyByRecipientListNew(NSSCMSRecipient **recipientlist, andre@0: void *wincx); andre@0: SECStatus PK11_TraverseCertsForSubjectInSlot(CERTCertificate *cert, andre@0: PK11SlotInfo *slot, SECStatus(*callback)(CERTCertificate *, void *), andre@0: void *arg); andre@0: CERTCertificate *PK11_FindCertFromDERCert(PK11SlotInfo *slot, andre@0: CERTCertificate *cert, void *wincx); andre@0: CERTCertificate *PK11_FindCertFromDERCertItem(PK11SlotInfo *slot, andre@0: const SECItem *derCert, void *wincx); andre@0: SECStatus PK11_ImportCertForKeyToSlot(PK11SlotInfo *slot, CERTCertificate *cert, andre@0: char *nickname, PRBool addUsage, andre@0: void *wincx); andre@0: CERTCertificate *PK11_FindBestKEAMatch(CERTCertificate *serverCert,void *wincx); andre@0: PRBool PK11_FortezzaHasKEA(CERTCertificate *cert); andre@0: CK_OBJECT_HANDLE PK11_FindCertInSlot(PK11SlotInfo *slot, CERTCertificate *cert, andre@0: void *wincx); andre@0: SECStatus PK11_TraverseCertsForNicknameInSlot(SECItem *nickname, andre@0: PK11SlotInfo *slot, SECStatus(*callback)(CERTCertificate *, void *), andre@0: void *arg); andre@0: CERTCertList * PK11_ListCerts(PK11CertListType type, void *pwarg); andre@0: CERTCertList * PK11_ListCertsInSlot(PK11SlotInfo *slot); andre@0: CERTSignedCrl* PK11_ImportCRL(PK11SlotInfo * slot, SECItem *derCRL, char *url, andre@0: int type, void *wincx, PRInt32 importOptions, PLArenaPool* arena, PRInt32 decodeOptions); andre@0: andre@0: /********************************************************************** andre@0: * Sign/Verify andre@0: **********************************************************************/ andre@0: andre@0: /* andre@0: * Return the length in bytes of a signature generated with the andre@0: * private key. andre@0: * andre@0: * Return 0 or -1 on failure. (XXX Should we fix it to always return andre@0: * -1 on failure?) andre@0: */ andre@0: int PK11_SignatureLen(SECKEYPrivateKey *key); andre@0: PK11SlotInfo * PK11_GetSlotFromPrivateKey(SECKEYPrivateKey *key); andre@0: SECStatus PK11_Sign(SECKEYPrivateKey *key, SECItem *sig, andre@0: const SECItem *hash); andre@0: SECStatus PK11_SignWithSymKey(PK11SymKey *symKey, CK_MECHANISM_TYPE mechanism, andre@0: SECItem *param, SECItem *sig, const SECItem *data); andre@0: SECStatus PK11_VerifyRecover(SECKEYPublicKey *key, const SECItem *sig, andre@0: SECItem *dsig, void * wincx); andre@0: SECStatus PK11_Verify(SECKEYPublicKey *key, const SECItem *sig, andre@0: const SECItem *hash, void *wincx); andre@0: andre@0: andre@0: andre@0: /********************************************************************** andre@0: * Crypto Contexts andre@0: **********************************************************************/ andre@0: void PK11_DestroyContext(PK11Context *context, PRBool freeit); andre@0: PK11Context *PK11_CreateContextBySymKey(CK_MECHANISM_TYPE type, andre@0: CK_ATTRIBUTE_TYPE operation, PK11SymKey *symKey, SECItem *param); andre@0: PK11Context *PK11_CreateDigestContext(SECOidTag hashAlg); andre@0: PK11Context *PK11_CloneContext(PK11Context *old); andre@0: SECStatus PK11_DigestBegin(PK11Context *cx); andre@0: /* andre@0: * The output buffer 'out' must be big enough to hold the output of andre@0: * the hash algorithm 'hashAlg'. andre@0: */ andre@0: SECStatus PK11_HashBuf(SECOidTag hashAlg, unsigned char *out, andre@0: const unsigned char *in, PRInt32 len); andre@0: SECStatus PK11_DigestOp(PK11Context *context, const unsigned char *in, andre@0: unsigned len); andre@0: SECStatus PK11_CipherOp(PK11Context *context, unsigned char * out, int *outlen, andre@0: int maxout, const unsigned char *in, int inlen); andre@0: SECStatus PK11_Finalize(PK11Context *context); andre@0: SECStatus PK11_DigestFinal(PK11Context *context, unsigned char *data, andre@0: unsigned int *outLen, unsigned int length); andre@0: #define PK11_CipherFinal PK11_DigestFinal andre@0: SECStatus PK11_SaveContext(PK11Context *cx,unsigned char *save, andre@0: int *len, int saveLength); andre@0: andre@0: /* Save the context's state, with possible allocation. andre@0: * The caller may supply an already allocated buffer in preAllocBuf, andre@0: * with length pabLen. If the buffer is large enough for the context's andre@0: * state, it will receive the state. andre@0: * If the buffer is not large enough (or NULL), then a new buffer will andre@0: * be allocated with PORT_Alloc. andre@0: * In either case, the state will be returned as a buffer, and the length andre@0: * of the state will be given in *stateLen. andre@0: */ andre@0: unsigned char * andre@0: PK11_SaveContextAlloc(PK11Context *cx, andre@0: unsigned char *preAllocBuf, unsigned int pabLen, andre@0: unsigned int *stateLen); andre@0: andre@0: SECStatus PK11_RestoreContext(PK11Context *cx,unsigned char *save,int len); andre@0: SECStatus PK11_GenerateFortezzaIV(PK11SymKey *symKey,unsigned char *iv,int len); andre@0: void PK11_SetFortezzaHack(PK11SymKey *symKey) ; andre@0: andre@0: andre@0: /********************************************************************** andre@0: * PBE functions andre@0: **********************************************************************/ andre@0: andre@0: /* This function creates PBE parameters from the given inputs. The result andre@0: * can be used to create a password integrity key for PKCS#12, by sending andre@0: * the return value to PK11_KeyGen along with the appropriate mechanism. andre@0: */ andre@0: SECItem * andre@0: PK11_CreatePBEParams(SECItem *salt, SECItem *pwd, unsigned int iterations); andre@0: andre@0: /* free params created above (can be called after keygen is done */ andre@0: void PK11_DestroyPBEParams(SECItem *params); andre@0: andre@0: SECAlgorithmID * andre@0: PK11_CreatePBEAlgorithmID(SECOidTag algorithm, int iteration, SECItem *salt); andre@0: andre@0: /* use to create PKCS5 V2 algorithms with finder control than that provided andre@0: * by PK11_CreatePBEAlgorithmID. */ andre@0: SECAlgorithmID * andre@0: PK11_CreatePBEV2AlgorithmID(SECOidTag pbeAlgTag, SECOidTag cipherAlgTag, andre@0: SECOidTag prfAlgTag, int keyLength, int iteration, andre@0: SECItem *salt); andre@0: PK11SymKey * andre@0: PK11_PBEKeyGen(PK11SlotInfo *slot, SECAlgorithmID *algid, SECItem *pwitem, andre@0: PRBool faulty3DES, void *wincx); andre@0: andre@0: /* warning: cannot work with PKCS 5 v2 use PK11_PBEKeyGen instead */ andre@0: PK11SymKey * andre@0: PK11_RawPBEKeyGen(PK11SlotInfo *slot, CK_MECHANISM_TYPE type, SECItem *params, andre@0: SECItem *pwitem, PRBool faulty3DES, void *wincx); andre@0: SECItem * andre@0: PK11_GetPBEIV(SECAlgorithmID *algid, SECItem *pwitem); andre@0: /* andre@0: * Get the Mechanism and parameter of the base encryption or mac scheme from andre@0: * a PBE algorithm ID. andre@0: * Caller is responsible for freeing the return parameter (param). andre@0: */ andre@0: CK_MECHANISM_TYPE andre@0: PK11_GetPBECryptoMechanism(SECAlgorithmID *algid, andre@0: SECItem **param, SECItem *pwd); andre@0: andre@0: /********************************************************************** andre@0: * Functions to manage secmod flags andre@0: **********************************************************************/ andre@0: const PK11DefaultArrayEntry *PK11_GetDefaultArray(int *size); andre@0: SECStatus PK11_UpdateSlotAttribute(PK11SlotInfo *slot, andre@0: const PK11DefaultArrayEntry *entry, andre@0: PRBool add); andre@0: andre@0: /********************************************************************** andre@0: * Functions to look at PKCS #11 dependent data andre@0: **********************************************************************/ andre@0: PK11GenericObject *PK11_FindGenericObjects(PK11SlotInfo *slot, andre@0: CK_OBJECT_CLASS objClass); andre@0: PK11GenericObject *PK11_GetNextGenericObject(PK11GenericObject *object); andre@0: PK11GenericObject *PK11_GetPrevGenericObject(PK11GenericObject *object); andre@0: SECStatus PK11_UnlinkGenericObject(PK11GenericObject *object); andre@0: SECStatus PK11_LinkGenericObject(PK11GenericObject *list, andre@0: PK11GenericObject *object); andre@0: SECStatus PK11_DestroyGenericObjects(PK11GenericObject *object); andre@0: SECStatus PK11_DestroyGenericObject(PK11GenericObject *object); andre@0: PK11GenericObject *PK11_CreateGenericObject(PK11SlotInfo *slot, andre@0: const CK_ATTRIBUTE *pTemplate, andre@0: int count, PRBool token); andre@0: andre@0: /* andre@0: * PK11_ReadRawAttribute and PK11_WriteRawAttribute are generic andre@0: * functions to read and modify the actual PKCS #11 attributes of andre@0: * the underlying pkcs #11 object. andre@0: * andre@0: * object is a pointer to an NSS object that represents the underlying andre@0: * PKCS #11 object. It's type must match the type of PK11ObjectType andre@0: * as follows: andre@0: * andre@0: * type object andre@0: * PK11_TypeGeneric PK11GenericObject * andre@0: * PK11_TypePrivKey SECKEYPrivateKey * andre@0: * PK11_TypePubKey SECKEYPublicKey * andre@0: * PK11_TypeSymKey PK11SymKey * andre@0: * andre@0: * All other types are considered invalid. If type does not match the object andre@0: * passed, unpredictable results will occur. andre@0: * andre@0: * PK11_ReadRawAttribute allocates the buffer for returning the attribute andre@0: * value. The caller of PK11_ReadRawAttribute should free the data buffer andre@0: * pointed to by item using a SECITEM_FreeItem(item, PR_FALSE) or andre@0: * PORT_Free(item->data) call. andre@0: */ andre@0: SECStatus PK11_ReadRawAttribute(PK11ObjectType type, void *object, andre@0: CK_ATTRIBUTE_TYPE attr, SECItem *item); andre@0: SECStatus PK11_WriteRawAttribute(PK11ObjectType type, void *object, andre@0: CK_ATTRIBUTE_TYPE attr, SECItem *item); andre@0: andre@0: /* andre@0: * PK11_GetAllSlotsForCert returns all the slots that a given certificate andre@0: * exists on, since it's possible for a cert to exist on more than one andre@0: * PKCS#11 token. andre@0: */ andre@0: PK11SlotList * andre@0: PK11_GetAllSlotsForCert(CERTCertificate *cert, void *arg); andre@0: andre@0: /********************************************************************** andre@0: * New functions which are already deprecated.... andre@0: **********************************************************************/ andre@0: SECItem * andre@0: PK11_GetLowLevelKeyIDForCert(PK11SlotInfo *slot, andre@0: CERTCertificate *cert, void *pwarg); andre@0: SECItem * andre@0: PK11_GetLowLevelKeyIDForPrivateKey(SECKEYPrivateKey *key); andre@0: andre@0: PRBool SECMOD_HasRootCerts(void); andre@0: andre@0: SEC_END_PROTOS andre@0: andre@0: #endif