Add support for the cryptoki crypto functions. This support is necessary for

capi and mackey. r=kaie
This commit is contained in:
rrelyea%redhat.com 2005-12-16 00:48:02 +00:00
parent a36360cfa0
commit ec7b991d91
14 changed files with 5307 additions and 467 deletions

View File

@ -34,7 +34,7 @@
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
MAKEFILE_CVS_ID = "@(#) $RCSfile: Makefile,v $ $Revision: 1.7 $ $Date: 2005/01/20 02:25:45 $"
MAKEFILE_CVS_ID = "@(#) $RCSfile: Makefile,v $ $Revision: 1.8 $ $Date: 2005/12/16 00:48:01 $"
include manifest.mn
include $(CORE_DEPTH)/coreconf/config.mk
@ -56,3 +56,7 @@ include $(CORE_DEPTH)/coreconf/rules.mk
export:: private_export
# can't do this in manifest.mn because OS_TARGET isn't defined there.
ifeq (,$(filter-out WIN%,$(OS_TARGET)))
DIRS += capi
endif

View File

@ -36,7 +36,7 @@
*
* ***** END LICENSE BLOCK ***** */
#ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: cfind.c,v $ $Revision: 1.2 $ $Date: 2005/11/15 00:13:58 $";
static const char CVS_ID[] = "@(#) $RCSfile: cfind.c,v $ $Revision: 1.3 $ $Date: 2005/12/16 00:48:02 $";
#endif /* DEBUG */
#ifndef CKCAPI_H
@ -358,11 +358,11 @@ collect_class(
/* first filter out non user certs if we are looking for keys */
if (isKey) {
/* make sure there is a Key Provider Info property */
CRYPT_KEY_PROV_INFO key_prov;
DWORD size = sizeof(CRYPT_KEY_PROV_INFO);
CRYPT_KEY_PROV_INFO *keyProvInfo;
DWORD size = 0;
BOOL rv;
rv =CertGetCertificateContextProperty(certContext,
CERT_KEY_PROV_INFO_PROP_ID, &key_prov, &size);
CERT_KEY_PROV_INFO_PROP_ID, NULL, &size);
if (!rv) {
int reason = GetLastError();
/* we only care if it exists, we don't really need to fetch it yet */
@ -370,6 +370,29 @@ collect_class(
continue;
}
}
/* filter out the non-microsoft providers */
keyProvInfo = (CRYPT_KEY_PROV_INFO *)nss_ZAlloc(NULL, size);
if (keyProvInfo) {
rv =CertGetCertificateContextProperty(certContext,
CERT_KEY_PROV_INFO_PROP_ID, keyProvInfo, &size);
if (rv) {
char *provName = nss_ckcapi_WideToUTF8(keyProvInfo->pwszProvName);
nss_ZFreeIf(keyProvInfo);
if (provName &&
(strncmp(provName, "Microsoft", sizeof("Microsoft")-1) != 0)) {
continue;
}
} else {
int reason = GetLastError();
/* we only care if it exists, we don't really need to fetch it yet */
nss_ZFreeIf(keyProvInfo);
if (reason == CRYPT_E_NOT_FOUND) {
continue;
}
}
}
}
if ((ckcapiInternalObject *)NULL == next) {
@ -419,8 +442,8 @@ nss_ckcapi_collect_all_certs(
{
count = collect_class(CKO_CERTIFICATE, "My", PR_TRUE, pTemplate,
ulAttributeCount, listp, sizep, count, pError);
count = collect_class(CKO_CERTIFICATE, "AddressBook", PR_FALSE, pTemplate,
ulAttributeCount, listp, sizep, count, pError);
/*count = collect_class(CKO_CERTIFICATE, "AddressBook", PR_FALSE, pTemplate,
ulAttributeCount, listp, sizep, count, pError); */
count = collect_class(CKO_CERTIFICATE, "CA", PR_FALSE, pTemplate,
ulAttributeCount, listp, sizep, count, pError);
count = collect_class(CKO_CERTIFICATE, "Root", PR_FALSE, pTemplate,

View File

@ -38,7 +38,7 @@
#define CKFW_H
#ifdef DEBUG
static const char CKFW_CVS_ID[] = "@(#) $RCSfile: ckfw.h,v $ $Revision: 1.7 $ $Date: 2005/01/20 02:25:45 $";
static const char CKFW_CVS_ID[] = "@(#) $RCSfile: ckfw.h,v $ $Revision: 1.8 $ $Date: 2005/12/16 00:48:01 $";
#endif /* DEBUG */
/*
@ -1105,7 +1105,6 @@ nssCKFWToken_GetObjectHandleHash
*
* -- implement public accessors --
* nssCKFWMechanism_GetMDMechanism
* nssCKFWMechanism_GetParameter
*
* -- private accessors --
*
@ -1113,6 +1112,30 @@ nssCKFWToken_GetObjectHandleHash
* nssCKFWMechanism_GetMinKeySize
* nssCKFWMechanism_GetMaxKeySize
* nssCKFWMechanism_GetInHardware
* nssCKFWMechanism_GetCanEncrypt
* nssCKFWMechanism_GetCanDecrypt
* nssCKFWMechanism_GetCanDigest
* nssCKFWMechanism_GetCanSignRecover
* nssCKFWMechanism_GetCanVerify
* nssCKFWMechanism_GetCanVerifyRecover
* nssCKFWMechanism_GetCanGenerate
* nssCKFWMechanism_GetCanGenerateKeyPair
* nssCKFWMechanism_GetCanWrap
* nssCKFWMechanism_GetCanUnwrap
* nssCKFWMechanism_GetCanDerive
* nssCKFWMechanism_EncryptInit
* nssCKFWMechanism_DecryptInit
* nssCKFWMechanism_DigestInit
* nssCKFWMechanism_SignInit
* nssCKFWMechanism_SignRecoverInit
* nssCKFWMechanism_VerifyInit
* nssCKFWMechanism_VerifyRecoverInit
* nssCKFWMechanism_GenerateKey
* nssCKFWMechanism_GenerateKeyPair
* nssCKFWMechanism_GetWrapKeyLength
* nssCKFWMechanism_WrapKey
* nssCKFWMechanism_UnwrapKey
* nssCKFWMechanism_DeriveKey
*/
/*
@ -1122,14 +1145,18 @@ nssCKFWToken_GetObjectHandleHash
NSS_EXTERN NSSCKFWMechanism *
nssCKFWMechanism_Create
(
void /* XXX fgmr */
NSSCKMDMechanism *mdMechanism,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance
);
/*
* nssCKFWMechanism_Destroy
*
*/
NSS_EXTERN CK_RV
NSS_EXTERN void
nssCKFWMechanism_Destroy
(
NSSCKFWMechanism *fwMechanism
@ -1146,17 +1173,6 @@ nssCKFWMechanism_GetMDMechanism
NSSCKFWMechanism *fwMechanism
);
/*
* nssCKFWMechanism_GetParameter
*
* XXX fgmr-- or as an additional parameter to the crypto ops?
*/
NSS_EXTERN NSSItem *
nssCKFWMechanism_GetParameter
(
NSSCKFWMechanism *fwMechanism
);
/*
* nssCKFWMechanism_GetMinKeySize
*
@ -1164,7 +1180,8 @@ nssCKFWMechanism_GetParameter
NSS_EXTERN CK_ULONG
nssCKFWMechanism_GetMinKeySize
(
NSSCKFWMechanism *fwMechanism
NSSCKFWMechanism *fwMechanism,
CK_RV *pError
);
/*
@ -1174,7 +1191,8 @@ nssCKFWMechanism_GetMinKeySize
NSS_EXTERN CK_ULONG
nssCKFWMechanism_GetMaxKeySize
(
NSSCKFWMechanism *fwMechanism
NSSCKFWMechanism *fwMechanism,
CK_RV *pError
);
/*
@ -1184,9 +1202,460 @@ nssCKFWMechanism_GetMaxKeySize
NSS_EXTERN CK_BBOOL
nssCKFWMechanism_GetInHardware
(
NSSCKFWMechanism *fwMechanism
NSSCKFWMechanism *fwMechanism,
CK_RV *pError
);
/*
* the following are determined automatically by which of the cryptographic
* functions are defined for this mechanism.
*/
/*
* nssCKFWMechanism_GetCanEncrypt
*
*/
NSS_EXTERN CK_BBOOL
nssCKFWMechanism_GetCanEncrypt
(
NSSCKFWMechanism *fwMechanism,
CK_RV *pError
);
/*
* nssCKFWMechanism_GetCanDecrypt
*
*/
NSS_EXTERN CK_BBOOL
nssCKFWMechanism_GetCanDecrypt
(
NSSCKFWMechanism *fwMechanism,
CK_RV *pError
);
/*
* nssCKFWMechanism_GetCanDigest
*
*/
NSS_EXTERN CK_BBOOL
nssCKFWMechanism_GetCanDigest
(
NSSCKFWMechanism *fwMechanism,
CK_RV *pError
);
/*
* nssCKFWMechanism_GetCanSign
*
*/
NSS_EXTERN CK_BBOOL
nssCKFWMechanism_GetCanSign
(
NSSCKFWMechanism *fwMechanism,
CK_RV *pError
);
/*
* nssCKFWMechanism_GetCanSignRecover
*
*/
NSS_EXTERN CK_BBOOL
nssCKFWMechanism_GetCanSignRecover
(
NSSCKFWMechanism *fwMechanism,
CK_RV *pError
);
/*
* nssCKFWMechanism_GetCanVerify
*
*/
NSS_EXTERN CK_BBOOL
nssCKFWMechanism_GetCanVerify
(
NSSCKFWMechanism *fwMechanism,
CK_RV *pError
);
/*
* nssCKFWMechanism_GetCanVerifyRecover
*
*/
NSS_EXTERN CK_BBOOL
nssCKFWMechanism_GetCanVerifyRecover
(
NSSCKFWMechanism *fwMechanism,
CK_RV *pError
);
/*
* nssCKFWMechanism_GetCanGenerate
*
*/
NSS_EXTERN CK_BBOOL
nssCKFWMechanism_GetCanGenerate
(
NSSCKFWMechanism *fwMechanism,
CK_RV *pError
);
/*
* nssCKFWMechanism_GetCanGenerateKeyPair
*
*/
NSS_EXTERN CK_BBOOL
nssCKFWMechanism_GetCanGenerateKeyPair
(
NSSCKFWMechanism *fwMechanism,
CK_RV *pError
);
/*
* nssCKFWMechanism_GetCanWrap
*
*/
NSS_EXTERN CK_BBOOL
nssCKFWMechanism_GetCanWrap
(
NSSCKFWMechanism *fwMechanism,
CK_RV *pError
);
/*
* nssCKFWMechanism_GetCanUnwrap
*
*/
NSS_EXTERN CK_BBOOL
nssCKFWMechanism_GetCanUnwrap
(
NSSCKFWMechanism *fwMechanism,
CK_RV *pError
);
/*
* nssCKFWMechanism_GetCanDerive
*
*/
NSS_EXTERN CK_BBOOL
nssCKFWMechanism_GetCanDerive
(
NSSCKFWMechanism *fwMechanism,
CK_RV *pError
);
/*
* nssCKFWMechanism_EncryptInit
*/
NSS_EXTERN CK_RV
nssCKFWMechanism_EncryptInit
(
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM *pMechanism,
NSSCKFWSession *fwSession,
NSSCKFWObject *fwObject
);
/*
* nssCKFWMechanism_DecryptInit
*/
NSS_EXTERN CK_RV
nssCKFWMechanism_DecryptInit
(
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM *pMechanism,
NSSCKFWSession *fwSession,
NSSCKFWObject *fwObject
);
/*
* nssCKFWMechanism_DigestInit
*/
NSS_EXTERN CK_RV
nssCKFWMechanism_DigestInit
(
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM *pMechanism,
NSSCKFWSession *fwSession
);
/*
* nssCKFWMechanism_SignInit
*/
NSS_EXTERN CK_RV
nssCKFWMechanism_SignInit
(
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM *pMechanism,
NSSCKFWSession *fwSession,
NSSCKFWObject *fwObject
);
/*
* nssCKFWMechanism_SignRecoverInit
*/
NSS_EXTERN CK_RV
nssCKFWMechanism_SignRecoverInit
(
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM *pMechanism,
NSSCKFWSession *fwSession,
NSSCKFWObject *fwObject
);
/*
* nssCKFWMechanism_VerifyInit
*/
NSS_EXTERN CK_RV
nssCKFWMechanism_VerifyInit
(
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM *pMechanism,
NSSCKFWSession *fwSession,
NSSCKFWObject *fwObject
);
/*
* nssCKFWMechanism_VerifyRecoverInit
*/
NSS_EXTERN CK_RV
nssCKFWMechanism_VerifyRecoverInit
(
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM *pMechanism,
NSSCKFWSession *fwSession,
NSSCKFWObject *fwObject
);
/*
* nssCKFWMechanism_GenerateKey
*/
NSS_EXTERN NSSCKFWObject *
nssCKFWMechanism_GenerateKey
(
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM_PTR pMechanism,
NSSCKFWSession *fwSession,
CK_ATTRIBUTE_PTR pTemplate,
CK_ULONG ulAttributeCount,
CK_RV *pError
);
/*
* nssCKFWMechanism_GenerateKeyPair
*/
NSS_EXTERN CK_RV
nssCKFWMechanism_GenerateKeyPair
(
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM_PTR pMechanism,
NSSCKFWSession *fwSession,
CK_ATTRIBUTE_PTR pPublicKeyTemplate,
CK_ULONG ulPublicKeyAttributeCount,
CK_ATTRIBUTE_PTR pPrivateKeyTemplate,
CK_ULONG ulPrivateKeyAttributeCount,
NSSCKFWObject **fwPublicKeyObject,
NSSCKFWObject **fwPrivateKeyObject
);
/*
* nssCKFWMechanism_GetWrapKeyLength
*/
NSS_EXTERN CK_ULONG
nssCKFWMechanism_GetWrapKeyLength
(
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM_PTR pMechanism,
NSSCKFWSession *fwSession,
NSSCKFWObject *fwWrappingKeyObject,
NSSCKFWObject *fwObject,
CK_RV *pError
);
/*
* nssCKFWMechanism_WrapKey
*/
NSS_EXTERN CK_RV
nssCKFWMechanism_WrapKey
(
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM_PTR pMechanism,
NSSCKFWSession *fwSession,
NSSCKFWObject *fwWrappingKeyObject,
NSSCKFWObject *fwObject,
NSSItem *wrappedKey
);
/*
* nssCKFWMechanism_UnwrapKey
*/
NSS_EXTERN NSSCKFWObject *
nssCKFWMechanism_UnwrapKey
(
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM_PTR pMechanism,
NSSCKFWSession *fwSession,
NSSCKFWObject *fwWrappingKeyObject,
NSSItem *wrappedKey,
CK_ATTRIBUTE_PTR pTemplate,
CK_ULONG ulAttributeCount,
CK_RV *pError
);
/*
* nssCKFWMechanism_DeriveKey
*/
NSS_EXTERN NSSCKFWObject *
nssCKFWMechanism_DeriveKey
(
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM_PTR pMechanism,
NSSCKFWSession *fwSession,
NSSCKFWObject *fwBaseKeyObject,
CK_ATTRIBUTE_PTR pTemplate,
CK_ULONG ulAttributeCount,
CK_RV *pError
);
/*
* NSSCKFWCryptoOperation
*
* -- create/destroy --
* nssCKFWCryptoOperation_Create
* nssCKFWCryptoOperation_Destroy
*
* -- implement public accessors --
* nssCKFWCryptoOperation_GetMDCryptoOperation
* nssCKFWCryptoOperation_GetType
*
* -- private accessors --
*
* -- module fronts --
* nssCKFWCryptoOperation_GetFinalLength
* nssCKFWCryptoOperation_GetOperationLength
* nssCKFWCryptoOperation_Final
* nssCKFWCryptoOperation_Update
* nssCKFWCryptoOperation_DigestUpdate
* nssCKFWCryptoOperation_DigestKey
* nssCKFWCryptoOperation_UpdateFinal
*/
/*
* nssCKFWCrytoOperation_Create
*/
NSS_EXTERN NSSCKFWCryptoOperation *
nssCKFWCryptoOperation_Create
(
NSSCKMDCryptoOperation *mdOperation,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSCKFWCryptoOperationType type,
CK_RV *pError
);
/*
* nssCKFWCryptoOperation_Destroy
*/
NSS_EXTERN void
nssCKFWCryptoOperation_Destroy
(
NSSCKFWCryptoOperation *fwOperation
);
/*
* nssCKFWCryptoOperation_GetMDCryptoOperation
*/
NSS_EXTERN NSSCKMDCryptoOperation *
nssCKFWCryptoOperation_GetMDCryptoOperation
(
NSSCKFWCryptoOperation *fwOperation
);
/*
* nssCKFWCryptoOperation_GetType
*/
NSS_EXTERN NSSCKFWCryptoOperationType
nssCKFWCryptoOperation_GetType
(
NSSCKFWCryptoOperation *fwOperation
);
/*
* nssCKFWCryptoOperation_GetFinalLength
*/
NSS_EXTERN CK_ULONG
nssCKFWCryptoOperation_GetFinalLength
(
NSSCKFWCryptoOperation *fwOperation,
CK_RV *pError
);
/*
* nssCKFWCryptoOperation_GetOperationLength
*/
NSS_EXTERN CK_ULONG
nssCKFWCryptoOperation_GetOperationLength
(
NSSCKFWCryptoOperation *fwOperation,
NSSItem *inputBuffer,
CK_RV *pError
);
/*
* nssCKFWCryptoOperation_Final
*/
NSS_EXTERN CK_RV
nssCKFWCryptoOperation_Final
(
NSSCKFWCryptoOperation *fwOperation,
NSSItem *outputBuffer
);
/*
* nssCKFWCryptoOperation_Update
*/
NSS_EXTERN CK_RV
nssCKFWCryptoOperation_Update
(
NSSCKFWCryptoOperation *fwOperation,
NSSItem *inputBuffer,
NSSItem *outputBuffer
);
/*
* nssCKFWCryptoOperation_DigestUpdate
*/
NSS_EXTERN CK_RV
nssCKFWCryptoOperation_DigestUpdate
(
NSSCKFWCryptoOperation *fwOperation,
NSSItem *inputBuffer
);
/*
* nssCKFWCryptoOperation_DigestKey
*/
NSS_EXTERN CK_RV
nssCKFWCryptoOperation_DigestKey
(
NSSCKFWCryptoOperation *fwOperation,
NSSCKFWObject *fwKey
);
/*
* nssCKFWCryptoOperation_UpdateFinal
*/
NSS_EXTERN CK_RV
nssCKFWCryptoOperation_UpdateFinal
(
NSSCKFWCryptoOperation *fwOperation,
NSSItem *inputBuffer,
NSSItem *outputBuffer
);
/*
* NSSCKFWSession
*
@ -1200,6 +1669,7 @@ nssCKFWMechanism_GetInHardware
* nssCKFWSession_CallNotification
* nssCKFWSession_IsRWSession
* nssCKFWSession_IsSO
* nssCKFWSession_GetCurrentCryptoOperation
*
* -- private accessors --
* nssCKFWSession_GetFWSlot
@ -1211,6 +1681,7 @@ nssCKFWMechanism_GetInHardware
* nssCKFWSession_GetHandle
* nssCKFWSession_RegisterSessionObject
* nssCKFWSession_DeregisterSessionObject
* nssCKFWSession_SetCurrentCryptoOperation
*
* -- module fronts --
* nssCKFWSession_GetDeviceError
@ -1226,6 +1697,12 @@ nssCKFWMechanism_GetInHardware
* nssCKFWSession_FindObjectsInit
* nssCKFWSession_SeedRandom
* nssCKFWSession_GetRandom
* nssCKFWSession_Final
* nssCKFWSession_Update
* nssCKFWSession_DigestUpdate
* nssCKFWSession_DigestKey
* nssCKFWSession_UpdateFinal
* nssCKFWSession_UpdateCombo
*/
/*
@ -1531,6 +2008,115 @@ nssCKFWSession_FindObjectsInit
CK_RV *pError
);
/*
* nssCKFWSession_SetCurrentCryptoOperation
*/
NSS_IMPLEMENT void
nssCKFWSession_SetCurrentCryptoOperation
(
NSSCKFWSession *fwSession,
NSSCKFWCryptoOperation * fwOperation,
NSSCKFWCryptoOperationState state
);
/*
* nssCKFWSession_GetCurrentCryptoOperation
*/
NSS_IMPLEMENT NSSCKFWCryptoOperation *
nssCKFWSession_GetCurrentCryptoOperation
(
NSSCKFWSession *fwSession,
NSSCKFWCryptoOperationState state
);
/*
* nssCKFWSession_Final
* (terminate a cryptographic operation and get the result)
*/
NSS_IMPLEMENT CK_RV
nssCKFWSession_Final
(
NSSCKFWSession *fwSession,
NSSCKFWCryptoOperationType type,
NSSCKFWCryptoOperationState state,
CK_BYTE_PTR outBuf,
CK_ULONG_PTR outBufLen
);
/*
* nssCKFWSession_Update
* (get the next step of an encrypt/decrypt operation)
*/
NSS_IMPLEMENT CK_RV
nssCKFWSession_Update
(
NSSCKFWSession *fwSession,
NSSCKFWCryptoOperationType type,
NSSCKFWCryptoOperationState state,
CK_BYTE_PTR inBuf,
CK_ULONG inBufLen,
CK_BYTE_PTR outBuf,
CK_ULONG_PTR outBufLen
);
/*
* nssCKFWSession_DigestUpdate
* (do the next step of an digest/sign/verify operation)
*/
NSS_IMPLEMENT CK_RV
nssCKFWSession_DigestUpdate
(
NSSCKFWSession *fwSession,
NSSCKFWCryptoOperationType type,
NSSCKFWCryptoOperationState state,
CK_BYTE_PTR inBuf,
CK_ULONG inBufLen
);
/*
* nssCKFWSession_DigestKey
* (do the next step of an digest/sign/verify operation)
*/
NSS_IMPLEMENT CK_RV
nssCKFWSession_DigestKey
(
NSSCKFWSession *fwSession,
NSSCKFWObject *fwKey
);
/*
* nssCKFWSession_UpdateFinal
* (do a single-step of a cryptographic operation and get the result)
*/
NSS_IMPLEMENT CK_RV
nssCKFWSession_UpdateFinal
(
NSSCKFWSession *fwSession,
NSSCKFWCryptoOperationType type,
NSSCKFWCryptoOperationState state,
CK_BYTE_PTR inBuf,
CK_ULONG inBufLen,
CK_BYTE_PTR outBuf,
CK_ULONG_PTR outBufLen
);
/*
* nssCKFWSession_UpdateCombo
* (do a combination encrypt/decrypt and sign/digest/verify operation)
*/
NSS_IMPLEMENT CK_RV
nssCKFWSession_UpdateCombo
(
NSSCKFWSession *fwSession,
NSSCKFWCryptoOperationType encryptType,
NSSCKFWCryptoOperationType digestType,
NSSCKFWCryptoOperationState digestState,
CK_BYTE_PTR inBuf,
CK_ULONG inBufLen,
CK_BYTE_PTR outBuf,
CK_ULONG_PTR outBufLen
);
/*
* nssCKFWSession_SeedRandom
*
@ -1729,6 +2315,7 @@ NSS_EXTERN CK_RV
nssCKFWObject_SetAttribute
(
NSSCKFWObject *fwObject,
NSSCKFWSession *fwSession,
CK_ATTRIBUTE_TYPE attribute,
NSSItem *value
);

View File

@ -0,0 +1,379 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Netscape security libraries.
*
* The Initial Developer of the Original Code is
* Red Hat, Inc.
* Portions created by the Initial Developer are Copyright (C) 2005
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Bob Relyea (rrelyea@redhat.com)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: crypto.c,v $ $Revision: 1.1 $ $Date: 2005/12/16 00:48:01 $";
#endif /* DEBUG */
/*
* crypto.c
*
* This file implements the NSSCKFWCryptoOperation type and methods.
*/
#ifndef CK_T
#include "ck.h"
#endif /* CK_T */
/*
* NSSCKFWCryptoOperation
*
* -- create/destroy --
* nssCKFWCrytoOperation_Create
* nssCKFWCryptoOperation_Destroy
*
* -- implement public accessors --
* nssCKFWCryptoOperation_GetMDCryptoOperation
* nssCKFWCryptoOperation_GetType
*
* -- private accessors --
*
* -- module fronts --
* nssCKFWCryptoOperation_GetFinalLength
* nssCKFWCryptoOperation_GetOperationLength
* nssCKFWCryptoOperation_Final
* nssCKFWCryptoOperation_Update
* nssCKFWCryptoOperation_DigestUpdate
* nssCKFWCryptoOperation_UpdateFinal
*/
struct NSSCKFWCryptoOperationStr {
/* NSSArena *arena; */
NSSCKMDCryptoOperation *mdOperation;
NSSCKMDSession *mdSession;
NSSCKFWSession *fwSession;
NSSCKMDToken *mdToken;
NSSCKFWToken *fwToken;
NSSCKMDInstance *mdInstance;
NSSCKFWInstance *fwInstance;
NSSCKFWCryptoOperationType type;
};
/*
* nssCKFWCrytoOperation_Create
*/
NSS_EXTERN NSSCKFWCryptoOperation *
nssCKFWCryptoOperation_Create(
NSSCKMDCryptoOperation *mdOperation,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSCKFWCryptoOperationType type,
CK_RV *pError
)
{
NSSCKFWCryptoOperation *fwOperation;
fwOperation = nss_ZNEW(NULL, NSSCKFWCryptoOperation);
if ((NSSCKFWCryptoOperation *)NULL == fwOperation) {
*pError = CKR_HOST_MEMORY;
return (NSSCKFWCryptoOperation *)NULL;
}
fwOperation->mdOperation = mdOperation;
fwOperation->mdSession = mdSession;
fwOperation->fwSession = fwSession;
fwOperation->mdToken = mdToken;
fwOperation->fwToken = fwToken;
fwOperation->mdInstance = mdInstance;
fwOperation->fwInstance = fwInstance;
fwOperation->type = type;
return fwOperation;
}
/*
* nssCKFWCryptoOperation_Destroy
*/
NSS_EXTERN void
nssCKFWCryptoOperation_Destroy
(
NSSCKFWCryptoOperation *fwOperation
)
{
if ((NSSCKMDCryptoOperation *) NULL != fwOperation->mdOperation) {
if ((void *) NULL != (void *)fwOperation->mdOperation->Destroy) {
fwOperation->mdOperation->Destroy(
fwOperation->mdOperation,
fwOperation,
fwOperation->mdInstance,
fwOperation->fwInstance);
}
}
nss_ZFreeIf(fwOperation);
}
/*
* nssCKFWCryptoOperation_GetMDCryptoOperation
*/
NSS_EXTERN NSSCKMDCryptoOperation *
nssCKFWCryptoOperation_GetMDCryptoOperation
(
NSSCKFWCryptoOperation *fwOperation
)
{
return fwOperation->mdOperation;
}
/*
* nssCKFWCryptoOperation_GetType
*/
NSS_EXTERN NSSCKFWCryptoOperationType
nssCKFWCryptoOperation_GetType
(
NSSCKFWCryptoOperation *fwOperation
)
{
return fwOperation->type;
}
/*
* nssCKFWCryptoOperation_GetFinalLength
*/
NSS_EXTERN CK_ULONG
nssCKFWCryptoOperation_GetFinalLength
(
NSSCKFWCryptoOperation *fwOperation,
CK_RV *pError
)
{
if ((void *) NULL == (void *)fwOperation->mdOperation->GetFinalLength) {
*pError = CKR_FUNCTION_FAILED;
return 0;
}
return fwOperation->mdOperation->GetFinalLength(
fwOperation->mdOperation,
fwOperation,
fwOperation->mdSession,
fwOperation->fwSession,
fwOperation->mdToken,
fwOperation->fwToken,
fwOperation->mdInstance,
fwOperation->fwInstance,
pError);
}
/*
* nssCKFWCryptoOperation_GetOperationLength
*/
NSS_EXTERN CK_ULONG
nssCKFWCryptoOperation_GetOperationLength
(
NSSCKFWCryptoOperation *fwOperation,
NSSItem *inputBuffer,
CK_RV *pError
)
{
if ((void *) NULL == (void *)fwOperation->mdOperation->GetOperationLength) {
*pError = CKR_FUNCTION_FAILED;
return 0;
}
return fwOperation->mdOperation->GetOperationLength(
fwOperation->mdOperation,
fwOperation,
fwOperation->mdSession,
fwOperation->fwSession,
fwOperation->mdToken,
fwOperation->fwToken,
fwOperation->mdInstance,
fwOperation->fwInstance,
inputBuffer,
pError);
}
/*
* nssCKFWCryptoOperation_Final
*/
NSS_EXTERN CK_RV
nssCKFWCryptoOperation_Final
(
NSSCKFWCryptoOperation *fwOperation,
NSSItem *outputBuffer
)
{
if ((void *) NULL == (void *)fwOperation->mdOperation->Final) {
return CKR_FUNCTION_FAILED;
}
return fwOperation->mdOperation->Final(
fwOperation->mdOperation,
fwOperation,
fwOperation->mdSession,
fwOperation->fwSession,
fwOperation->mdToken,
fwOperation->fwToken,
fwOperation->mdInstance,
fwOperation->fwInstance,
outputBuffer);
}
/*
* nssCKFWCryptoOperation_Update
*/
NSS_EXTERN CK_RV
nssCKFWCryptoOperation_Update
(
NSSCKFWCryptoOperation *fwOperation,
NSSItem *inputBuffer,
NSSItem *outputBuffer
)
{
if ((void *) NULL == (void *)fwOperation->mdOperation->Update) {
return CKR_FUNCTION_FAILED;
}
return fwOperation->mdOperation->Update(
fwOperation->mdOperation,
fwOperation,
fwOperation->mdSession,
fwOperation->fwSession,
fwOperation->mdToken,
fwOperation->fwToken,
fwOperation->mdInstance,
fwOperation->fwInstance,
inputBuffer,
outputBuffer);
}
/*
* nssCKFWCryptoOperation_DigestUpdate
*/
NSS_EXTERN CK_RV
nssCKFWCryptoOperation_DigestUpdate
(
NSSCKFWCryptoOperation *fwOperation,
NSSItem *inputBuffer
)
{
if ((void *) NULL == (void *)fwOperation->mdOperation->DigestUpdate) {
return CKR_FUNCTION_FAILED;
}
return fwOperation->mdOperation->DigestUpdate(
fwOperation->mdOperation,
fwOperation,
fwOperation->mdSession,
fwOperation->fwSession,
fwOperation->mdToken,
fwOperation->fwToken,
fwOperation->mdInstance,
fwOperation->fwInstance,
inputBuffer);
}
/*
* nssCKFWCryptoOperation_DigestKey
*/
NSS_EXTERN CK_RV
nssCKFWCryptoOperation_DigestKey
(
NSSCKFWCryptoOperation *fwOperation,
NSSCKFWObject *fwObject /* Key */
)
{
NSSCKMDObject *mdObject;
if ((void *) NULL == (void *)fwOperation->mdOperation->DigestKey) {
return CKR_FUNCTION_FAILED;
}
mdObject = nssCKFWObject_GetMDObject(fwObject);
return fwOperation->mdOperation->DigestUpdate(
fwOperation->mdOperation,
fwOperation,
fwOperation->mdSession,
fwOperation->fwSession,
fwOperation->mdToken,
fwOperation->fwToken,
fwOperation->mdInstance,
fwOperation->fwInstance,
mdObject,
fwObject);
}
/*
* nssCKFWCryptoOperation_UpdateFinal
*/
NSS_EXTERN CK_RV
nssCKFWCryptoOperation_UpdateFinal
(
NSSCKFWCryptoOperation *fwOperation,
NSSItem *inputBuffer,
NSSItem *outputBuffer
)
{
if ((void *) NULL == (void *)fwOperation->mdOperation->UpdateFinal) {
return CKR_FUNCTION_FAILED;
}
return fwOperation->mdOperation->UpdateFinal(
fwOperation->mdOperation,
fwOperation,
fwOperation->mdSession,
fwOperation->fwSession,
fwOperation->mdToken,
fwOperation->fwToken,
fwOperation->mdInstance,
fwOperation->fwInstance,
inputBuffer,
outputBuffer);
}
/*
* nssCKFWCryptoOperation_UpdateFinal
*/
NSS_EXTERN CK_RV
nssCKFWCryptoOperation_UpdateCombo
(
NSSCKFWCryptoOperation *fwOperation,
NSSCKFWCryptoOperation *fwPeerOperation,
NSSItem *inputBuffer,
NSSItem *outputBuffer
)
{
if ((void *) NULL == (void *)fwOperation->mdOperation->UpdateCombo) {
return CKR_FUNCTION_FAILED;
}
return fwOperation->mdOperation->UpdateCombo(
fwOperation->mdOperation,
fwOperation,
fwPeerOperation->mdOperation,
fwPeerOperation,
fwOperation->mdSession,
fwOperation->fwSession,
fwOperation->mdToken,
fwOperation->fwToken,
fwOperation->mdInstance,
fwOperation->fwInstance,
inputBuffer,
outputBuffer);
}

View File

@ -35,7 +35,7 @@
* ***** END LICENSE BLOCK ***** */
#ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: find.c,v $ $Revision: 1.6 $ $Date: 2005/01/20 02:25:45 $";
static const char CVS_ID[] = "@(#) $RCSfile: find.c,v $ $Revision: 1.7 $ $Date: 2005/12/16 00:48:01 $";
#endif /* DEBUG */
/*
@ -356,11 +356,19 @@ nssCKFWFindObjects_Next
wrap:
/*
* This is less than ideal-- we should determine if it's a token
* This seems is less than ideal-- we should determine if it's a token
* object or a session object, and use the appropriate arena.
* But that duplicates logic in nssCKFWObject_IsTokenObject.
* Worry about that later. For now, be conservative, and use
* the token arena.
* Also we should lookup the real session the object was created on
* if the object was a session object... however this code is actually
* correct because nssCKFWObject_Create will return a cached version of
* the object from it's hash. This is necessary because 1) we don't want
* to create an arena style leak (where our arena grows with every search),
* and 2) we want the same object to always have the same ID. This means
* the only case the nssCKFWObject_Create() will need the objArena and the
* Session is in the case of token objects (session objects should already
* exist in the cache from their initial creation). So this code is correct,
* but it depends on nssCKFWObject_Create caching all objects.
*/
objArena = nssCKFWToken_GetArena(fwFindObjects->fwToken, pError);
if( (NSSArena *)NULL == objArena ) {
@ -371,7 +379,7 @@ nssCKFWFindObjects_Next
}
fwObject = nssCKFWObject_Create(objArena, mdObject,
fwFindObjects->fwSession, fwFindObjects->fwToken,
NULL, fwFindObjects->fwToken,
fwFindObjects->fwInstance, pError);
if( (NSSCKFWObject *)NULL == fwObject ) {
if( CKR_OK == *pError ) {

View File

@ -34,11 +34,11 @@
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
MANIFEST_CVS_ID = "@(#) $RCSfile: manifest.mn,v $ $Revision: 1.8 $ $Date: 2005/08/25 20:08:26 $"
MANIFEST_CVS_ID = "@(#) $RCSfile: manifest.mn,v $ $Revision: 1.9 $ $Date: 2005/12/16 00:48:01 $"
CORE_DEPTH = ../../..
DIRS = builtins
DIRS = builtins
PRIVATE_EXPORTS = \
ck.h \
@ -64,6 +64,7 @@ EXPORTS = \
MODULE = nss
CSRCS = \
crypto.c \
find.c \
hash.c \
instance.c \

File diff suppressed because it is too large Load Diff

View File

@ -38,7 +38,7 @@
#define NSSCKFW_H
#ifdef DEBUG
static const char NSSCKFW_CVS_ID[] = "@(#) $RCSfile: nssckfw.h,v $ $Revision: 1.4 $ $Date: 2005/01/20 02:25:45 $";
static const char NSSCKFW_CVS_ID[] = "@(#) $RCSfile: nssckfw.h,v $ $Revision: 1.5 $ $Date: 2005/12/16 00:48:01 $";
#endif /* DEBUG */
/*
@ -242,7 +242,7 @@ NSSCKFWToken_GetMDSlot
*/
NSS_EXTERN CK_STATE
NSSCKFWSession_GetSessionState
NSSCKFWToken_GetSessionState
(
NSSCKFWToken *fwToken
);
@ -285,6 +285,7 @@ NSSCKFWMechanism_GetParameter
* NSSCKFWSession_CallNotification
* NSSCKFWSession_IsRWSession
* NSSCKFWSession_IsSO
* NSSCKFWSession_GetCurrentCryptoOperation
*
*/
@ -345,6 +346,18 @@ NSSCKFWSession_IsSO
NSSCKFWSession *fwSession
);
/*
* NSSCKFWSession_GetCurrentCryptoOperation
*
*/
NSS_EXTERN NSSCKFWCryptoOperation *
NSSCKFWSession_GetCurrentCryptoOperation
(
NSSCKFWSession *fwSession,
NSSCKFWCryptoOperationState state
);
/*
* NSSCKFWObject
*

View File

@ -38,7 +38,7 @@
#define NSSCKFWT_H
#ifdef DEBUG
static const char NSSCKFWT_CVS_ID[] = "@(#) $RCSfile: nssckfwt.h,v $ $Revision: 1.4 $ $Date: 2005/01/20 02:25:45 $";
static const char NSSCKFWT_CVS_ID[] = "@(#) $RCSfile: nssckfwt.h,v $ $Revision: 1.5 $ $Date: 2005/12/16 00:48:01 $";
#endif /* DEBUG */
/*
@ -79,6 +79,15 @@ typedef struct NSSCKFWTokenStr NSSCKFWToken;
struct NSSCKFWMechanismStr;
typedef struct NSSCKFWMechanismStr NSSCKFWMechanism;
/*
* NSSCKFWCryptoOperation
*
*/
struct NSSCKFWCryptoOperationStr;
typedef struct NSSCKFWCryptoOperationStr NSSCKFWCryptoOperation;
/*
* NSSCKFWSession
*
@ -116,4 +125,22 @@ typedef enum {
MultiThreaded
} CryptokiLockingState ;
/* used as an index into an array, make sure it starts at '0' */
typedef enum {
NSSCKFWCryptoOperationState_EncryptDecrypt = 0,
NSSCKFWCryptoOperationState_SignVerify,
NSSCKFWCryptoOperationState_Digest,
NSSCKFWCryptoOperationState_Max
} NSSCKFWCryptoOperationState;
typedef enum {
NSSCKFWCryptoOperationType_Encrypt,
NSSCKFWCryptoOperationType_Decrypt,
NSSCKFWCryptoOperationType_Digest,
NSSCKFWCryptoOperationType_Sign,
NSSCKFWCryptoOperationType_Verify,
NSSCKFWCryptoOperationType_SignRecover,
NSSCKFWCryptoOperationType_VerifyRecover
} NSSCKFWCryptoOperationType;
#endif /* NSSCKFWT_H */

View File

@ -38,7 +38,7 @@
#define NSSCKMDT_H
#ifdef DEBUG
static const char NSSCKMDT_CVS_ID[] = "@(#) $RCSfile: nssckmdt.h,v $ $Revision: 1.5 $ $Date: 2005/01/20 02:25:45 $";
static const char NSSCKMDT_CVS_ID[] = "@(#) $RCSfile: nssckmdt.h,v $ $Revision: 1.6 $ $Date: 2005/12/16 00:48:01 $";
#endif /* DEBUG */
/*
@ -64,6 +64,7 @@ typedef struct NSSCKMDInstanceStr NSSCKMDInstance;
typedef struct NSSCKMDSlotStr NSSCKMDSlot;
typedef struct NSSCKMDTokenStr NSSCKMDToken;
typedef struct NSSCKMDSessionStr NSSCKMDSession;
typedef struct NSSCKMDCryptoOperationStr NSSCKMDCryptoOperation;
typedef struct NSSCKMDFindObjectsStr NSSCKMDFindObjects;
typedef struct NSSCKMDMechanismStr NSSCKMDMechanism;
typedef struct NSSCKMDObjectStr NSSCKMDObject;
@ -856,8 +857,8 @@ struct NSSCKMDTokenStr {
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM_TYPE which
CK_MECHANISM_TYPE which,
CK_RV *pError
);
/*
@ -1220,6 +1221,198 @@ struct NSSCKMDFindObjectsStr {
void *null;
};
/*
* NSSCKMDCryptoOperaion
*
* This is the basic handle for an encryption, decryption,
* sign, verify, or hash opertion.
* created by NSSCKMDMechanism->XXXXInit, and may be
* obtained from the Framework's corresponding object.
* It contains a pointer for use by the Module, to store
* any intermediate data, and it contains the EPV for a
* set of routines which the Module may implement for use
* by the Framework. Some of these routines are optional.
*/
struct NSSCKMDCryptoOperationStr {
/*
* The Module may use this pointer for its own purposes.
*/
void *etc;
/*
* This routine is called by the Framework clean up the mdCryptoOperation
* structure.
* This routine is optional; if unimplemented, it will be ignored.
*/
void (PR_CALLBACK *Destroy)(
NSSCKMDCryptoOperation *mdCryptoOperation,
NSSCKFWCryptoOperation *fwCryptoOperation,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance
);
/*
* how many bytes do we need to finish this buffer?
* must be implemented if Final is implemented.
*/
CK_ULONG (PR_CALLBACK *GetFinalLength)(
NSSCKMDCryptoOperation *mdCryptoOperation,
NSSCKFWCryptoOperation *fwCryptoOperation,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
CK_RV *pError
);
/*
* how many bytes do we need to complete the next operation.
* used in both Update and UpdateFinal.
*/
CK_ULONG (PR_CALLBACK *GetOperationLength)(
NSSCKMDCryptoOperation *mdCryptoOperation,
NSSCKFWCryptoOperation *fwCryptoOperation,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
const NSSItem *inputBuffer,
CK_RV *pError
);
/*
* This routine is called by the Framework to finish a
* search operation. Note that the Framework may finish
* a search before it has completed. This routine is
* optional; if unimplemented, it merely won't be called.
* The respective final call with fail with CKR_FUNCTION_FAILED
* Final should not free the mdCryptoOperation.
*/
CK_RV(PR_CALLBACK *Final)(
NSSCKMDCryptoOperation *mdCryptoOperation,
NSSCKFWCryptoOperation *fwCryptoOperation,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSItem *outputBuffer
);
/*
* This routine is called by the Framework to complete the
* next step in an encryption/decryption operation.
* This routine is optional; if unimplemented, the respective
* update call with fail with CKR_FUNCTION_FAILED.
* Update should not be implemented for signing/verification/digest
* mechanisms.
*/
CK_RV(PR_CALLBACK *Update)(
NSSCKMDCryptoOperation *mdCryptoOperation,
NSSCKFWCryptoOperation *fwCryptoOperation,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
const NSSItem *inputBuffer,
NSSItem *outputBuffer
);
/*
* This routine is called by the Framework to complete the
* next step in a signing/verification/digest operation.
* This routine is optional; if unimplemented, the respective
* update call with fail with CKR_FUNCTION_FAILED
* Update should not be implemented for encryption/decryption
* mechanisms.
*/
CK_RV(PR_CALLBACK *DigestUpdate)(
NSSCKMDCryptoOperation *mdCryptoOperation,
NSSCKFWCryptoOperation *fwCryptoOperation,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
const NSSItem *inputBuffer
);
/*
* This routine is called by the Framework to complete a
* single step operation. This routine is optional; if unimplemented,
* the framework will use the Update and Final functions to complete
* the operation.
*/
CK_RV(PR_CALLBACK *UpdateFinal)(
NSSCKMDCryptoOperation *mdCryptoOperation,
NSSCKFWCryptoOperation *fwCryptoOperation,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
const NSSItem *inputBuffer,
NSSItem *outputBuffer
);
/*
* This routine is called by the Framework to complete next
* step in a combined operation. The Decrypt/Encrypt mechanism
* should define and drive the combo step.
* This routine is optional; if unimplemented,
* the framework will use the appropriate Update functions to complete
* the operation.
*/
CK_RV(PR_CALLBACK *UpdateCombo)(
NSSCKMDCryptoOperation *mdCryptoOperation,
NSSCKFWCryptoOperation *fwCryptoOperation,
NSSCKMDCryptoOperation *mdPeerCryptoOperation,
NSSCKFWCryptoOperation *fwPeerCryptoOperation,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
const NSSItem *inputBuffer,
NSSItem *outputBuffer
);
/*
* Hash a key directly into the digest
*/
CK_RV(PR_CALLBACK *DigestKey)(
NSSCKMDCryptoOperation *mdCryptoOperation,
NSSCKFWCryptoOperation *fwCryptoOperation,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSCKMDObject *mdKey,
NSSCKFWObject *fwKey
);
/*
* This object may be extended in future versions of the
* NSS Cryptoki Framework. To allow for some flexibility
* in the area of binary compatibility, this field should
* be NULL.
*/
void *null;
};
/*
* NSSCKMDMechanism
*
@ -1231,6 +1424,19 @@ struct NSSCKMDMechanismStr {
*/
void *etc;
/*
* This also frees the fwMechanism if appropriate.
* If it is not supplied, the Framework will assume that the Token
* Manages a static list of mechanisms and the function will not be called.
*/
void (PR_CALLBACK *Destroy)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance
);
/*
* This routine returns the minimum key size allowed for
* this mechanism. This routine is optional; if unimplemented,
@ -1288,26 +1494,25 @@ struct NSSCKMDMechanismStr {
* method to feed data to the operation, and a Final method to
* obtain the final result. Single-part operations involve
* one method, to perform the crypto operation all at once.
*
* The NSS Cryptoki Framework can implement the single-part
* operations in terms of the streaming operations on behalf
* of the Module. There are a few variances.
*
* Only the Init Functions are defined by the mechanism. Each
* init function will return a NSSCKFWCryptoOperation which
* can supply update, final, the single part updateFinal, and
* the combo updateCombo functions.
*
* For simplicity, the routines are listed in summary here:
*
* EncryptInit, EncryptUpdate, EncryptFinal; Encrypt
* DecryptInit, DecryptUpdate, DecryptFinal; Decrypt
* DigestInit, DigestUpdate, DigestKey, DigestFinal; Digest
* SignInit, SignUpdate, SignFinal; Sign
* SignRecoverInit; SignRecover
* VerifyInit, VerifyUpdate, VerifyFinal; Verify
* VerifyRecoverInit; VerifyRecover
*
* Also, there are some combined-operation calls:
*
* DigestEncryptUpdate
* DecryptDigestUpdate
* SignEncryptUpdate
* DecryptVerifyUpdate
* EncryptInit,
* DecryptInit,
* DigestInit,
* SignInit,
* SignRecoverInit;
* VerifyInit,
* VerifyRecoverInit;
*
* The key-management routines are
*
@ -1317,59 +1522,16 @@ struct NSSCKMDMechanismStr {
* UnwrapKey
* DeriveKey
*
* All of these routines based directly on the Cryptoki API;
* All of these routines based on the Cryptoki API;
* see PKCS#11 for further information.
*/
/*
*/
CK_RV (PR_CALLBACK *EncryptInit)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSCKMDObject *mdKey,
NSSCKFWObject *fwKey
);
/*
*/
CK_RV (PR_CALLBACK *EncryptUpdate)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSItem *data,
NSSItem *buffer
);
/*
*/
CK_RV (PR_CALLBACK *EncryptFinal)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSItem *buffer
);
/*
*/
CK_RV (PR_CALLBACK *Encrypt)(
NSSCKMDCryptoOperation * (PR_CALLBACK *EncryptInit)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM_PTR pMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
@ -1378,59 +1540,15 @@ struct NSSCKMDMechanismStr {
NSSCKFWInstance *fwInstance,
NSSCKMDObject *mdKey,
NSSCKFWObject *fwKey,
NSSItem *data,
NSSItem *buffer
CK_RV *pError
);
/*
*/
CK_RV (PR_CALLBACK *DecryptInit)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSCKMDObject *mdKey,
NSSCKFWObject *fwKey
);
/*
*/
CK_RV (PR_CALLBACK *DecryptUpdate)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSItem *data,
NSSItem *buffer
);
/*
*/
CK_RV (PR_CALLBACK *DecryptFinal)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSItem *buffer
);
/*
*/
CK_RV (PR_CALLBACK *Decrypt)(
NSSCKMDCryptoOperation * (PR_CALLBACK *DecryptInit)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM_PTR pMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
@ -1439,130 +1557,31 @@ struct NSSCKMDMechanismStr {
NSSCKFWInstance *fwInstance,
NSSCKMDObject *mdKey,
NSSCKFWObject *fwKey,
NSSItem *data,
NSSItem *buffer
CK_RV *pError
);
/*
*/
CK_RV (PR_CALLBACK *DigestInit)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance
);
/*
*/
CK_RV (PR_CALLBACK *DigestUpdate)(
NSSCKMDCryptoOperation * (PR_CALLBACK *DigestInit)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM_PTR pMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSItem *data
CK_RV *pError
);
/*
*/
CK_RV (PR_CALLBACK *DigestKey)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSCKMDObject *mdKey,
NSSCKFWObject *fwKey
);
/*
*/
CK_RV (PR_CALLBACK *DigestFinal)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSItem *buffer
);
/*
*/
CK_RV (PR_CALLBACK *Digest)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSItem *data,
NSSItem *buffer
);
/*
*/
CK_RV (PR_CALLBACK *SignInit)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSCKMDObject *mdKey,
NSSCKFWObject *fwKey
);
/*
*/
CK_RV (PR_CALLBACK *SignUpdate)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSItem *data,
NSSItem *buffer
);
/*
*/
CK_RV (PR_CALLBACK *SignFinal)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSItem *buffer
);
/*
*/
CK_RV (PR_CALLBACK *Sign)(
NSSCKMDCryptoOperation * (PR_CALLBACK *SignInit)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM_PTR pMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
@ -1571,73 +1590,15 @@ struct NSSCKMDMechanismStr {
NSSCKFWInstance *fwInstance,
NSSCKMDObject *mdKey,
NSSCKFWObject *fwKey,
NSSItem *data,
NSSItem *buffer
CK_RV *pError
);
/*
*/
CK_RV (PR_CALLBACK *VerifyInit)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSCKFWObject *key
);
/*
*/
CK_RV (PR_CALLBACK *VerifyUpdate)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSItem *data
);
/*
*/
CK_RV (PR_CALLBACK *VerifyFinish)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSItem *buffer
);
/*
*/
CK_RV (PR_CALLBACK *Verify)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSCKFWObject *key,
NSSItem *data,
NSSItem *buffer
);
/*
*/
CK_RV (PR_CALLBACK *SignRecover)(
NSSCKMDCryptoOperation * (PR_CALLBACK *VerifyInit)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM_PTR pMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
@ -1646,15 +1607,15 @@ struct NSSCKMDMechanismStr {
NSSCKFWInstance *fwInstance,
NSSCKMDObject *mdKey,
NSSCKFWObject *fwKey,
NSSItem *data,
NSSItem *buffer
CK_RV *pError
);
/*
*/
CK_RV (PR_CALLBACK *VerifyRecover)(
NSSCKMDCryptoOperation * (PR_CALLBACK *SignRecoverInit)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM_PTR pMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
@ -1663,68 +1624,24 @@ struct NSSCKMDMechanismStr {
NSSCKFWInstance *fwInstance,
NSSCKMDObject *mdKey,
NSSCKFWObject *fwKey,
NSSItem *data,
NSSItem *buffer
CK_RV *pError
);
/*
*/
CK_RV (PR_CALLBACK *DigestEncryptUpdate)(
NSSCKMDCryptoOperation * (PR_CALLBACK *VerifyRecoverInit)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM_PTR pMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSItem *data,
NSSItem *buffer
);
/*
*/
CK_RV (PR_CALLBACK *DecryptDigestUpdate)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSItem *data,
NSSItem *buffer
);
/*
*/
CK_RV (PR_CALLBACK *SignEncryptUpdate)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSItem *data,
NSSItem *buffer
);
/*
*/
CK_RV (PR_CALLBACK *DecryptVerifyUpdate)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSItem *data,
NSSItem *buffer
NSSCKMDObject *mdKey,
NSSCKFWObject *fwKey,
CK_RV *pError
);
/*
@ -1738,6 +1655,7 @@ struct NSSCKMDMechanismStr {
NSSCKMDObject *(PR_CALLBACK *GenerateKey)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM_PTR pMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
@ -1755,6 +1673,7 @@ struct NSSCKMDMechanismStr {
CK_RV (PR_CALLBACK *GenerateKeyPair)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM_PTR pMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
@ -1772,9 +1691,10 @@ struct NSSCKMDMechanismStr {
/*
* This routine wraps a key.
*/
CK_RV (PR_CALLBACK *WrapKey)(
CK_ULONG (PR_CALLBACK *GetWrapKeyLength)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM_PTR pMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
@ -1785,7 +1705,27 @@ struct NSSCKMDMechanismStr {
NSSCKFWObject *fwWrappingKey,
NSSCKMDObject *mdWrappedKey,
NSSCKFWObject *fwWrappedKey,
NSSItem *buffer
CK_RV *pError
);
/*
* This routine wraps a key.
*/
CK_RV (PR_CALLBACK *WrapKey)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM_PTR pMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
NSSCKFWToken *fwToken,
NSSCKMDInstance *mdInstance,
NSSCKFWInstance *fwInstance,
NSSCKMDObject *mdWrappingKey,
NSSCKFWObject *fwWrappingKey,
NSSCKMDObject *mdKeyObject,
NSSCKFWObject *fwKeyObject,
NSSItem *wrappedKey
);
/*
@ -1795,6 +1735,7 @@ struct NSSCKMDMechanismStr {
NSSCKMDObject *(PR_CALLBACK *UnwrapKey)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM_PTR pMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,
@ -1816,6 +1757,7 @@ struct NSSCKMDMechanismStr {
NSSCKMDObject *(PR_CALLBACK *DeriveKey)(
NSSCKMDMechanism *mdMechanism,
NSSCKFWMechanism *fwMechanism,
CK_MECHANISM_PTR pMechanism,
NSSCKMDSession *mdSession,
NSSCKFWSession *fwSession,
NSSCKMDToken *mdToken,

View File

@ -35,7 +35,7 @@
* ***** END LICENSE BLOCK ***** */
#ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: object.c,v $ $Revision: 1.11 $ $Date: 2005/01/20 02:25:45 $";
static const char CVS_ID[] = "@(#) $RCSfile: object.c,v $ $Revision: 1.12 $ $Date: 2005/12/16 00:48:01 $";
#endif /* DEBUG */
/*
@ -260,7 +260,9 @@ nssCKFWObject_Finalize
nssCKFWHash_Remove(mdObjectHash, fwObject->mdObject);
}
nssCKFWSession_DeregisterSessionObject(fwObject->fwSession, fwObject);
if (fwObject->fwSession) {
nssCKFWSession_DeregisterSessionObject(fwObject->fwSession, fwObject);
}
nss_ZFreeIf(fwObject);
#ifdef DEBUG
@ -301,7 +303,9 @@ nssCKFWObject_Destroy
nssCKFWHash_Remove(mdObjectHash, fwObject->mdObject);
}
nssCKFWSession_DeregisterSessionObject(fwObject->fwSession, fwObject);
if (fwObject->fwSession) {
nssCKFWSession_DeregisterSessionObject(fwObject->fwSession, fwObject);
}
nss_ZFreeIf(fwObject);
#ifdef DEBUG
@ -692,6 +696,7 @@ NSS_IMPLEMENT CK_RV
nssCKFWObject_SetAttribute
(
NSSCKFWObject *fwObject,
NSSCKFWSession *fwSession,
CK_ATTRIBUTE_TYPE attribute,
NSSItem *value
)
@ -719,7 +724,7 @@ nssCKFWObject_SetAttribute
a.pValue = value->data;
a.ulValueLen = value->size;
newFwObject = nssCKFWSession_CopyObject(fwObject->fwSession, fwObject,
newFwObject = nssCKFWSession_CopyObject(fwSession, fwObject,
&a, 1, &error);
if( (NSSCKFWObject *)NULL == newFwObject ) {
if( CKR_OK == error ) {
@ -770,13 +775,15 @@ nssCKFWObject_SetAttribute
* New one is a session object, except since we "stole" the fwObject, it's
* not in the list. Add it.
*/
nssCKFWSession_RegisterSessionObject(fwObject->fwSession, fwObject);
nssCKFWSession_RegisterSessionObject(fwSession, fwObject);
} else {
/*
* New one is a token object, except since we "stole" the fwObject, it's
* in the list. Remove it.
*/
nssCKFWSession_DeregisterSessionObject(fwObject->fwSession, fwObject);
if (fwObject->fwSession) {
nssCKFWSession_DeregisterSessionObject(fwObject->fwSession, fwObject);
}
}
/*

View File

@ -35,7 +35,7 @@
* ***** END LICENSE BLOCK ***** */
#ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: session.c,v $ $Revision: 1.8 $ $Date: 2005/01/20 02:25:45 $";
static const char CVS_ID[] = "@(#) $RCSfile: session.c,v $ $Revision: 1.9 $ $Date: 2005/12/16 00:48:01 $";
#endif /* DEBUG */
/*
@ -114,6 +114,7 @@ struct NSSCKFWSessionStr {
CK_BBOOL rw;
NSSCKFWFindObjects *fwFindObjects;
NSSCKFWCryptoOperation *fwOperationArray[NSSCKFWCryptoOperationState_Max];
nssCKFWHash *sessionObjectHash;
CK_SESSION_HANDLE hSession;
};
@ -268,6 +269,7 @@ nssCKFWSession_Destroy
{
CK_RV error = CKR_OK;
nssCKFWHash *sessionObjectHash;
NSSCKFWCryptoOperationState i;
#ifdef NSSDEBUG
error = nssCKFWSession_verifyPointer(fwSession);
@ -291,6 +293,12 @@ nssCKFWSession_Destroy
nss_ckfw_session_object_destroy_iterator,
(void *)NULL);
for (i=0; i < NSSCKFWCryptoOperationState_Max; i++) {
if ((NSSCKFWCryptoOperation *)NULL != fwSession->fwOperationArray[i]) {
nssCKFWCryptoOperation_Destroy(fwSession->fwOperationArray[i]);
}
}
#ifdef DEBUG
(void)session_remove_pointer(fwSession);
#endif /* DEBUG */
@ -949,7 +957,6 @@ nssCKFWSession_SetPIN
)
{
CK_RV error = CKR_OK;
CK_STATE state;
#ifdef NSSDEBUG
error = nssCKFWSession_verifyPointer(fwSession);
@ -962,12 +969,6 @@ nssCKFWSession_SetPIN
}
#endif /* NSSDEBUG */
state = nssCKFWToken_GetSessionState(fwSession->fwToken);
if( (CKS_RW_SO_FUNCTIONS != state) &&
(CKS_RW_USER_FUNCTIONS != state) ) {
return CKR_USER_NOT_LOGGED_IN;
}
if( (NSSItem *)NULL == newPin ) {
CK_BBOOL has = nssCKFWToken_GetHasProtectedAuthenticationPath(fwSession->fwToken);
if( CK_TRUE != has ) {
@ -1361,7 +1362,8 @@ nssCKFWSession_CreateObject
return (NSSCKFWObject *)NULL;
}
fwObject = nssCKFWObject_Create(arena, mdObject, fwSession,
fwObject = nssCKFWObject_Create(arena, mdObject,
isTokenObject ? NULL : fwSession,
fwSession->fwToken, fwSession->fwInstance, pError);
if( (NSSCKFWObject *)NULL == fwObject ) {
if( CKR_OK == *pError ) {
@ -1484,7 +1486,8 @@ nssCKFWSession_CopyObject
return (NSSCKFWObject *)NULL;
}
rv = nssCKFWObject_Create(arena, mdObject, fwSession,
rv = nssCKFWObject_Create(arena, mdObject,
newIsToken ? NULL : fwSession,
fwSession->fwToken, fwSession->fwInstance, pError);
if( (NSSCKFWObject *)NULL == fwObject ) {
if( CKR_OK == *pError ) {
@ -1854,6 +1857,520 @@ nssCKFWSession_GetRandom
return error;
}
/*
* nssCKFWSession_SetCurrentCryptoOperation
*/
NSS_IMPLEMENT void
nssCKFWSession_SetCurrentCryptoOperation
(
NSSCKFWSession *fwSession,
NSSCKFWCryptoOperation * fwOperation,
NSSCKFWCryptoOperationState state
)
{
#ifdef NSSDEBUG
CK_RV error = CKR_OK;
error = nssCKFWSession_verifyPointer(fwSession);
if( CKR_OK != error ) {
return;
}
if ( state >= NSSCKFWCryptoOperationState_Max) {
return;
}
if( (NSSCKMDSession *)NULL == fwSession->mdSession ) {
return;
}
#endif /* NSSDEBUG */
fwSession->fwOperationArray[state] = fwOperation;
return;
}
/*
* nssCKFWSession_GetCurrentCryptoOperation
*/
NSS_IMPLEMENT NSSCKFWCryptoOperation *
nssCKFWSession_GetCurrentCryptoOperation
(
NSSCKFWSession *fwSession,
NSSCKFWCryptoOperationState state
)
{
#ifdef NSSDEBUG
CK_RV error = CKR_OK;
error = nssCKFWSession_verifyPointer(fwSession);
if( CKR_OK != error ) {
return (NSSCKFWCryptoOperation *)NULL;
}
if ( state >= NSSCKFWCryptoOperationState_Max) {
return (NSSCKFWCryptoOperation *)NULL;
}
if( (NSSCKMDSession *)NULL == fwSession->mdSession ) {
return (NSSCKFWCryptoOperation *)NULL;
}
#endif /* NSSDEBUG */
return fwSession->fwOperationArray[state];
}
/*
* nssCKFWSession_Final
*/
NSS_IMPLEMENT CK_RV
nssCKFWSession_Final
(
NSSCKFWSession *fwSession,
NSSCKFWCryptoOperationType type,
NSSCKFWCryptoOperationState state,
CK_BYTE_PTR outBuf,
CK_ULONG_PTR outBufLen
)
{
NSSCKFWCryptoOperation *fwOperation;
NSSItem outputBuffer;
CK_RV error = CKR_OK;
#ifdef NSSDEBUG
error = nssCKFWSession_verifyPointer(fwSession);
if( CKR_OK != error ) {
return error;
}
if( (NSSCKMDSession *)NULL == fwSession->mdSession ) {
return CKR_GENERAL_ERROR;
}
#endif /* NSSDEBUG */
/* make sure we have a valid operation initialized */
fwOperation = nssCKFWSession_GetCurrentCryptoOperation(fwSession, state);
if ((NSSCKFWCryptoOperation *)NULL == fwOperation) {
return CKR_OPERATION_NOT_INITIALIZED;
}
/* make sure it's the correct type */
if (type != nssCKFWCryptoOperation_GetType(fwOperation)) {
return CKR_OPERATION_NOT_INITIALIZED;
}
/* handle buffer issues, note for Verify, the type is an input buffer. */
if (NSSCKFWCryptoOperationType_Verify == type) {
if ((CK_BYTE_PTR)NULL == outBuf) {
error = CKR_ARGUMENTS_BAD;
goto done;
}
} else {
CK_ULONG len = nssCKFWCryptoOperation_GetFinalLength(fwOperation, &error);
CK_ULONG maxBufLen = *outBufLen;
if (CKR_OK != error) {
goto done;
}
*outBufLen = len;
if ((CK_BYTE_PTR)NULL == outBuf) {
return CKR_OK;
}
if (len > maxBufLen) {
return CKR_BUFFER_TOO_SMALL;
}
}
outputBuffer.data = outBuf;
outputBuffer.size = *outBufLen;
error = nssCKFWCryptoOperation_Final(fwOperation, &outputBuffer);
done:
if (CKR_BUFFER_TOO_SMALL == error) {
return error;
}
/* clean up our state */
nssCKFWCryptoOperation_Destroy(fwOperation);
nssCKFWSession_SetCurrentCryptoOperation(fwSession, NULL, state);
return error;
}
/*
* nssCKFWSession_Update
*/
NSS_IMPLEMENT CK_RV
nssCKFWSession_Update
(
NSSCKFWSession *fwSession,
NSSCKFWCryptoOperationType type,
NSSCKFWCryptoOperationState state,
CK_BYTE_PTR inBuf,
CK_ULONG inBufLen,
CK_BYTE_PTR outBuf,
CK_ULONG_PTR outBufLen
)
{
NSSCKFWCryptoOperation *fwOperation;
NSSItem inputBuffer;
NSSItem outputBuffer;
CK_ULONG len;
CK_ULONG maxBufLen;
CK_RV error = CKR_OK;
#ifdef NSSDEBUG
error = nssCKFWSession_verifyPointer(fwSession);
if( CKR_OK != error ) {
return error;
}
if( (NSSCKMDSession *)NULL == fwSession->mdSession ) {
return CKR_GENERAL_ERROR;
}
#endif /* NSSDEBUG */
/* make sure we have a valid operation initialized */
fwOperation = nssCKFWSession_GetCurrentCryptoOperation(fwSession, state);
if ((NSSCKFWCryptoOperation *)NULL == fwOperation) {
return CKR_OPERATION_NOT_INITIALIZED;
}
/* make sure it's the correct type */
if (type != nssCKFWCryptoOperation_GetType(fwOperation)) {
return CKR_OPERATION_NOT_INITIALIZED;
}
inputBuffer.data = inBuf;
inputBuffer.size = inBufLen;
/* handle buffer issues, note for Verify, the type is an input buffer. */
len = nssCKFWCryptoOperation_GetOperationLength(fwOperation, &inputBuffer,
&error);
if (CKR_OK != error) {
return error;
}
maxBufLen = *outBufLen;
*outBufLen = len;
if ((CK_BYTE_PTR)NULL == outBuf) {
return CKR_OK;
}
if (len > maxBufLen) {
return CKR_BUFFER_TOO_SMALL;
}
outputBuffer.data = outBuf;
outputBuffer.size = *outBufLen;
return nssCKFWCryptoOperation_Update(fwOperation,
&inputBuffer, &outputBuffer);
}
/*
* nssCKFWSession_DigestUpdate
*/
NSS_IMPLEMENT CK_RV
nssCKFWSession_DigestUpdate
(
NSSCKFWSession *fwSession,
NSSCKFWCryptoOperationType type,
NSSCKFWCryptoOperationState state,
CK_BYTE_PTR inBuf,
CK_ULONG inBufLen
)
{
NSSCKFWCryptoOperation *fwOperation;
NSSItem inputBuffer;
CK_RV error = CKR_OK;
#ifdef NSSDEBUG
error = nssCKFWSession_verifyPointer(fwSession);
if( CKR_OK != error ) {
return error;
}
if( (NSSCKMDSession *)NULL == fwSession->mdSession ) {
return CKR_GENERAL_ERROR;
}
#endif /* NSSDEBUG */
/* make sure we have a valid operation initialized */
fwOperation = nssCKFWSession_GetCurrentCryptoOperation(fwSession, state);
if ((NSSCKFWCryptoOperation *)NULL == fwOperation) {
return CKR_OPERATION_NOT_INITIALIZED;
}
/* make sure it's the correct type */
if (type != nssCKFWCryptoOperation_GetType(fwOperation)) {
return CKR_OPERATION_NOT_INITIALIZED;
}
inputBuffer.data = inBuf;
inputBuffer.size = inBufLen;
error = nssCKFWCryptoOperation_DigestUpdate(fwOperation, &inputBuffer);
return error;
}
/*
* nssCKFWSession_DigestUpdate
*/
NSS_IMPLEMENT CK_RV
nssCKFWSession_DigestKey
(
NSSCKFWSession *fwSession,
NSSCKFWObject *fwKey
)
{
NSSCKFWCryptoOperation *fwOperation;
NSSItem *inputBuffer;
CK_RV error = CKR_OK;
#ifdef NSSDEBUG
error = nssCKFWSession_verifyPointer(fwSession);
if( CKR_OK != error ) {
return error;
}
if( (NSSCKMDSession *)NULL == fwSession->mdSession ) {
return CKR_GENERAL_ERROR;
}
#endif /* NSSDEBUG */
/* make sure we have a valid operation initialized */
fwOperation = nssCKFWSession_GetCurrentCryptoOperation(fwSession,
NSSCKFWCryptoOperationState_Digest);
if ((NSSCKFWCryptoOperation *)NULL == fwOperation) {
return CKR_OPERATION_NOT_INITIALIZED;
}
/* make sure it's the correct type */
if (NSSCKFWCryptoOperationType_Digest !=
nssCKFWCryptoOperation_GetType(fwOperation)) {
return CKR_OPERATION_NOT_INITIALIZED;
}
error = nssCKFWCryptoOperation_DigestKey(fwOperation, fwKey);
if (CKR_FUNCTION_FAILED != error) {
return error;
}
/* no machine depended way for this to happen, do it by hand */
inputBuffer=nssCKFWObject_GetAttribute(fwKey, CKA_VALUE, NULL, NULL, &error);
if ((NSSItem *)NULL == inputBuffer) {
/* couldn't get the value, just fail then */
return error;
}
error = nssCKFWCryptoOperation_DigestUpdate(fwOperation, inputBuffer);
nssItem_Destroy(inputBuffer);
return error;
}
/*
* nssCKFWSession_UpdateFinal
*/
NSS_IMPLEMENT CK_RV
nssCKFWSession_UpdateFinal
(
NSSCKFWSession *fwSession,
NSSCKFWCryptoOperationType type,
NSSCKFWCryptoOperationState state,
CK_BYTE_PTR inBuf,
CK_ULONG inBufLen,
CK_BYTE_PTR outBuf,
CK_ULONG_PTR outBufLen
)
{
NSSCKFWCryptoOperation *fwOperation;
NSSItem inputBuffer;
NSSItem outputBuffer;
PRBool isEncryptDecrypt;
CK_RV error = CKR_OK;
#ifdef NSSDEBUG
error = nssCKFWSession_verifyPointer(fwSession);
if( CKR_OK != error ) {
return error;
}
if( (NSSCKMDSession *)NULL == fwSession->mdSession ) {
return CKR_GENERAL_ERROR;
}
#endif /* NSSDEBUG */
/* make sure we have a valid operation initialized */
fwOperation = nssCKFWSession_GetCurrentCryptoOperation(fwSession, state);
if ((NSSCKFWCryptoOperation *)NULL == fwOperation) {
return CKR_OPERATION_NOT_INITIALIZED;
}
/* make sure it's the correct type */
if (type != nssCKFWCryptoOperation_GetType(fwOperation)) {
return CKR_OPERATION_NOT_INITIALIZED;
}
inputBuffer.data = inBuf;
inputBuffer.size = inBufLen;
isEncryptDecrypt = (PRBool) ((NSSCKFWCryptoOperationType_Encrypt == type) ||
(NSSCKFWCryptoOperationType_Decrypt == type)) ;
/* handle buffer issues, note for Verify, the type is an input buffer. */
if (NSSCKFWCryptoOperationType_Verify == type) {
if ((CK_BYTE_PTR)NULL == outBuf) {
error = CKR_ARGUMENTS_BAD;
goto done;
}
} else {
CK_ULONG maxBufLen = *outBufLen;
CK_ULONG len;
len = (isEncryptDecrypt) ?
nssCKFWCryptoOperation_GetOperationLength(fwOperation,
&inputBuffer, &error) :
nssCKFWCryptoOperation_GetFinalLength(fwOperation, &error);
if (CKR_OK != error) {
goto done;
}
*outBufLen = len;
if ((CK_BYTE_PTR)NULL == outBuf) {
return CKR_OK;
}
if (len > maxBufLen) {
return CKR_BUFFER_TOO_SMALL;
}
}
outputBuffer.data = outBuf;
outputBuffer.size = *outBufLen;
error = nssCKFWCryptoOperation_UpdateFinal(fwOperation,
&inputBuffer, &outputBuffer);
/* UpdateFinal isn't support, manually use Update and Final */
if (CKR_FUNCTION_FAILED == error) {
error = isEncryptDecrypt ?
nssCKFWCryptoOperation_Update(fwOperation, &inputBuffer, &outputBuffer) :
nssCKFWCryptoOperation_DigestUpdate(fwOperation, &inputBuffer);
if (CKR_OK == error) {
error = nssCKFWCryptoOperation_Final(fwOperation, &outputBuffer);
}
}
done:
if (CKR_BUFFER_TOO_SMALL == error) {
/* if we return CKR_BUFFER_TOO_SMALL, we the caller is not expecting.
* the crypto state to be freed */
return error;
}
/* clean up our state */
nssCKFWCryptoOperation_Destroy(fwOperation);
nssCKFWSession_SetCurrentCryptoOperation(fwSession, NULL, state);
return error;
}
NSS_IMPLEMENT CK_RV
nssCKFWSession_UpdateCombo
(
NSSCKFWSession *fwSession,
NSSCKFWCryptoOperationType encryptType,
NSSCKFWCryptoOperationType digestType,
NSSCKFWCryptoOperationState digestState,
CK_BYTE_PTR inBuf,
CK_ULONG inBufLen,
CK_BYTE_PTR outBuf,
CK_ULONG_PTR outBufLen
)
{
NSSCKFWCryptoOperation *fwOperation;
NSSCKFWCryptoOperation *fwPeerOperation;
NSSItem inputBuffer;
NSSItem outputBuffer;
CK_ULONG maxBufLen = *outBufLen;
CK_ULONG len;
CK_RV error = CKR_OK;
#ifdef NSSDEBUG
error = nssCKFWSession_verifyPointer(fwSession);
if( CKR_OK != error ) {
return error;
}
if( (NSSCKMDSession *)NULL == fwSession->mdSession ) {
return CKR_GENERAL_ERROR;
}
#endif /* NSSDEBUG */
/* make sure we have a valid operation initialized */
fwOperation = nssCKFWSession_GetCurrentCryptoOperation(fwSession,
NSSCKFWCryptoOperationState_EncryptDecrypt);
if ((NSSCKFWCryptoOperation *)NULL == fwOperation) {
return CKR_OPERATION_NOT_INITIALIZED;
}
/* make sure it's the correct type */
if (encryptType != nssCKFWCryptoOperation_GetType(fwOperation)) {
return CKR_OPERATION_NOT_INITIALIZED;
}
/* make sure we have a valid operation initialized */
fwPeerOperation = nssCKFWSession_GetCurrentCryptoOperation(fwSession,
digestState);
if ((NSSCKFWCryptoOperation *)NULL == fwPeerOperation) {
return CKR_OPERATION_NOT_INITIALIZED;
}
/* make sure it's the correct type */
if (digestType != nssCKFWCryptoOperation_GetType(fwOperation)) {
return CKR_OPERATION_NOT_INITIALIZED;
}
inputBuffer.data = inBuf;
inputBuffer.size = inBufLen;
len = nssCKFWCryptoOperation_GetOperationLength(fwOperation,
&inputBuffer, &error);
if (CKR_OK != error) {
return error;
}
*outBufLen = len;
if ((CK_BYTE_PTR)NULL == outBuf) {
return CKR_OK;
}
if (len > maxBufLen) {
return CKR_BUFFER_TOO_SMALL;
}
outputBuffer.data = outBuf;
outputBuffer.size = *outBufLen;
error = nssCKFWCryptoOperation_UpdateCombo(fwOperation, fwPeerOperation,
&inputBuffer, &outputBuffer);
if (CKR_FUNCTION_FAILED == error) {
PRBool isEncrypt =
(PRBool) (NSSCKFWCryptoOperationType_Encrypt == encryptType);
if (isEncrypt) {
error = nssCKFWCryptoOperation_DigestUpdate(fwPeerOperation,
&inputBuffer);
if (CKR_OK != error) {
return error;
}
}
error = nssCKFWCryptoOperation_Update(fwOperation,
&inputBuffer, &outputBuffer);
if (CKR_OK != error) {
return error;
}
if (!isEncrypt) {
error = nssCKFWCryptoOperation_DigestUpdate(fwPeerOperation,
&outputBuffer);
}
}
return error;
}
/*
* NSSCKFWSession_GetMDSession
*
@ -1963,3 +2480,24 @@ NSSCKFWSession_IsSO
return nssCKFWSession_IsSO(fwSession);
}
NSS_IMPLEMENT NSSCKFWCryptoOperation *
NSSCKFWSession_GetCurrentCryptoOperation
(
NSSCKFWSession *fwSession,
NSSCKFWCryptoOperationState state
)
{
#ifdef DEBUG
CK_RV error = CKR_OK;
error = nssCKFWSession_verifyPointer(fwSession);
if( CKR_OK != error ) {
return (NSSCKFWCryptoOperation *)NULL;
}
if ( state >= NSSCKFWCryptoOperationState_Max) {
return (NSSCKFWCryptoOperation *)NULL;
}
#endif /* DEBUG */
return nssCKFWSession_GetCurrentCryptoOperation(fwSession, state);
}

View File

@ -35,7 +35,7 @@
* ***** END LICENSE BLOCK ***** */
#ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: token.c,v $ $Revision: 1.10 $ $Date: 2005/01/20 02:25:45 $";
static const char CVS_ID[] = "@(#) $RCSfile: token.c,v $ $Revision: 1.11 $ $Date: 2005/12/16 00:48:01 $";
#endif /* DEBUG */
/*
@ -151,6 +151,7 @@ struct NSSCKFWTokenStr {
nssCKFWHash *sessions;
nssCKFWHash *sessionObjectHash;
nssCKFWHash *mdObjectHash;
nssCKFWHash *mdMechanismHash;
CK_STATE state;
};
@ -274,6 +275,15 @@ nssCKFWToken_Create
goto loser;
}
fwToken->mdMechanismHash = nssCKFWHash_Create(fwToken->fwInstance,
arena, pError);
if( (nssCKFWHash *)NULL == fwToken->mdMechanismHash ) {
if( CKR_OK == *pError ) {
*pError = CKR_GENERAL_ERROR;
}
goto loser;
}
/* More here */
if( (void *)NULL != (void *)mdToken->Setup ) {
@ -355,7 +365,7 @@ nssCKFWToken_Destroy
* referencing us (or _Destroy was invalidly called!)
*/
nssCKFWHash_Iterate(fwToken->sessions, nss_ckfwtoken_session_iterator,
(void *)NULL);
(void *)NULL);
nssCKFWHash_Destroy(fwToken->sessions);
if (fwToken->sessionObjectHash) {
@ -364,6 +374,9 @@ nssCKFWToken_Destroy
if (fwToken->mdObjectHash) {
nssCKFWHash_Destroy(fwToken->mdObjectHash);
}
if (fwToken->mdMechanismHash) {
nssCKFWHash_Destroy(fwToken->mdMechanismHash);
}
nssCKFWSlot_ClearToken(fwToken->fwSlot);
@ -1484,8 +1497,30 @@ nssCKFWToken_GetMechanism
CK_RV *pError
)
{
/* XXX fgmr */
return (NSSCKFWMechanism *)NULL;
NSSCKMDMechanism *mdMechanism;
if ((nssCKFWHash *)NULL == fwToken->mdMechanismHash) {
*pError = CKR_GENERAL_ERROR;
return (NSSCKFWMechanism *)NULL;
}
if( (void *)NULL == (void *)fwToken->mdToken->GetMechanism ) {
/*
* If we don't implement any GetMechanism function, then we must
* not support any.
*/
*pError = CKR_MECHANISM_INVALID;
return (NSSCKFWMechanism *)NULL;
}
/* lookup in hash table */
mdMechanism = fwToken->mdToken->GetMechanism(fwToken->mdToken, fwToken,
fwToken->mdInstance, fwToken->fwInstance, which, pError);
if ((NSSCKMDMechanism *)NULL == mdMechanism) {
return (NSSCKFWMechanism *) NULL;
}
/* store in hash table */
return nssCKFWMechanism_Create(mdMechanism, fwToken->mdToken, fwToken,
fwToken->mdInstance, fwToken->fwInstance);
}
NSS_IMPLEMENT CK_RV

File diff suppressed because it is too large Load Diff