michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * crypto.c michael@0: * michael@0: * This file implements the NSSCKFWCryptoOperation type and methods. michael@0: */ michael@0: michael@0: #ifndef CK_T michael@0: #include "ck.h" michael@0: #endif /* CK_T */ michael@0: michael@0: /* michael@0: * NSSCKFWCryptoOperation michael@0: * michael@0: * -- create/destroy -- michael@0: * nssCKFWCrytoOperation_Create michael@0: * nssCKFWCryptoOperation_Destroy michael@0: * michael@0: * -- implement public accessors -- michael@0: * nssCKFWCryptoOperation_GetMDCryptoOperation michael@0: * nssCKFWCryptoOperation_GetType michael@0: * michael@0: * -- private accessors -- michael@0: * michael@0: * -- module fronts -- michael@0: * nssCKFWCryptoOperation_GetFinalLength michael@0: * nssCKFWCryptoOperation_GetOperationLength michael@0: * nssCKFWCryptoOperation_Final michael@0: * nssCKFWCryptoOperation_Update michael@0: * nssCKFWCryptoOperation_DigestUpdate michael@0: * nssCKFWCryptoOperation_UpdateFinal michael@0: */ michael@0: michael@0: struct NSSCKFWCryptoOperationStr { michael@0: /* NSSArena *arena; */ michael@0: NSSCKMDCryptoOperation *mdOperation; michael@0: NSSCKMDSession *mdSession; michael@0: NSSCKFWSession *fwSession; michael@0: NSSCKMDToken *mdToken; michael@0: NSSCKFWToken *fwToken; michael@0: NSSCKMDInstance *mdInstance; michael@0: NSSCKFWInstance *fwInstance; michael@0: NSSCKFWCryptoOperationType type; michael@0: }; michael@0: michael@0: /* michael@0: * nssCKFWCrytoOperation_Create michael@0: */ michael@0: NSS_EXTERN NSSCKFWCryptoOperation * michael@0: nssCKFWCryptoOperation_Create( michael@0: NSSCKMDCryptoOperation *mdOperation, michael@0: NSSCKMDSession *mdSession, michael@0: NSSCKFWSession *fwSession, michael@0: NSSCKMDToken *mdToken, michael@0: NSSCKFWToken *fwToken, michael@0: NSSCKMDInstance *mdInstance, michael@0: NSSCKFWInstance *fwInstance, michael@0: NSSCKFWCryptoOperationType type, michael@0: CK_RV *pError michael@0: ) michael@0: { michael@0: NSSCKFWCryptoOperation *fwOperation; michael@0: fwOperation = nss_ZNEW(NULL, NSSCKFWCryptoOperation); michael@0: if (!fwOperation) { michael@0: *pError = CKR_HOST_MEMORY; michael@0: return (NSSCKFWCryptoOperation *)NULL; michael@0: } michael@0: fwOperation->mdOperation = mdOperation; michael@0: fwOperation->mdSession = mdSession; michael@0: fwOperation->fwSession = fwSession; michael@0: fwOperation->mdToken = mdToken; michael@0: fwOperation->fwToken = fwToken; michael@0: fwOperation->mdInstance = mdInstance; michael@0: fwOperation->fwInstance = fwInstance; michael@0: fwOperation->type = type; michael@0: return fwOperation; michael@0: } michael@0: michael@0: /* michael@0: * nssCKFWCryptoOperation_Destroy michael@0: */ michael@0: NSS_EXTERN void michael@0: nssCKFWCryptoOperation_Destroy michael@0: ( michael@0: NSSCKFWCryptoOperation *fwOperation michael@0: ) michael@0: { michael@0: if ((NSSCKMDCryptoOperation *) NULL != fwOperation->mdOperation) { michael@0: if (fwOperation->mdOperation->Destroy) { michael@0: fwOperation->mdOperation->Destroy( michael@0: fwOperation->mdOperation, michael@0: fwOperation, michael@0: fwOperation->mdInstance, michael@0: fwOperation->fwInstance); michael@0: } michael@0: } michael@0: nss_ZFreeIf(fwOperation); michael@0: } michael@0: michael@0: /* michael@0: * nssCKFWCryptoOperation_GetMDCryptoOperation michael@0: */ michael@0: NSS_EXTERN NSSCKMDCryptoOperation * michael@0: nssCKFWCryptoOperation_GetMDCryptoOperation michael@0: ( michael@0: NSSCKFWCryptoOperation *fwOperation michael@0: ) michael@0: { michael@0: return fwOperation->mdOperation; michael@0: } michael@0: michael@0: /* michael@0: * nssCKFWCryptoOperation_GetType michael@0: */ michael@0: NSS_EXTERN NSSCKFWCryptoOperationType michael@0: nssCKFWCryptoOperation_GetType michael@0: ( michael@0: NSSCKFWCryptoOperation *fwOperation michael@0: ) michael@0: { michael@0: return fwOperation->type; michael@0: } michael@0: michael@0: /* michael@0: * nssCKFWCryptoOperation_GetFinalLength michael@0: */ michael@0: NSS_EXTERN CK_ULONG michael@0: nssCKFWCryptoOperation_GetFinalLength michael@0: ( michael@0: NSSCKFWCryptoOperation *fwOperation, michael@0: CK_RV *pError michael@0: ) michael@0: { michael@0: if (!fwOperation->mdOperation->GetFinalLength) { michael@0: *pError = CKR_FUNCTION_FAILED; michael@0: return 0; michael@0: } michael@0: return fwOperation->mdOperation->GetFinalLength( michael@0: fwOperation->mdOperation, michael@0: fwOperation, michael@0: fwOperation->mdSession, michael@0: fwOperation->fwSession, michael@0: fwOperation->mdToken, michael@0: fwOperation->fwToken, michael@0: fwOperation->mdInstance, michael@0: fwOperation->fwInstance, michael@0: pError); michael@0: } michael@0: michael@0: /* michael@0: * nssCKFWCryptoOperation_GetOperationLength michael@0: */ michael@0: NSS_EXTERN CK_ULONG michael@0: nssCKFWCryptoOperation_GetOperationLength michael@0: ( michael@0: NSSCKFWCryptoOperation *fwOperation, michael@0: NSSItem *inputBuffer, michael@0: CK_RV *pError michael@0: ) michael@0: { michael@0: if (!fwOperation->mdOperation->GetOperationLength) { michael@0: *pError = CKR_FUNCTION_FAILED; michael@0: return 0; michael@0: } michael@0: return fwOperation->mdOperation->GetOperationLength( michael@0: fwOperation->mdOperation, michael@0: fwOperation, michael@0: fwOperation->mdSession, michael@0: fwOperation->fwSession, michael@0: fwOperation->mdToken, michael@0: fwOperation->fwToken, michael@0: fwOperation->mdInstance, michael@0: fwOperation->fwInstance, michael@0: inputBuffer, michael@0: pError); michael@0: } michael@0: michael@0: /* michael@0: * nssCKFWCryptoOperation_Final michael@0: */ michael@0: NSS_EXTERN CK_RV michael@0: nssCKFWCryptoOperation_Final michael@0: ( michael@0: NSSCKFWCryptoOperation *fwOperation, michael@0: NSSItem *outputBuffer michael@0: ) michael@0: { michael@0: if (!fwOperation->mdOperation->Final) { michael@0: return CKR_FUNCTION_FAILED; michael@0: } michael@0: return fwOperation->mdOperation->Final( michael@0: fwOperation->mdOperation, michael@0: fwOperation, michael@0: fwOperation->mdSession, michael@0: fwOperation->fwSession, michael@0: fwOperation->mdToken, michael@0: fwOperation->fwToken, michael@0: fwOperation->mdInstance, michael@0: fwOperation->fwInstance, michael@0: outputBuffer); michael@0: } michael@0: michael@0: /* michael@0: * nssCKFWCryptoOperation_Update michael@0: */ michael@0: NSS_EXTERN CK_RV michael@0: nssCKFWCryptoOperation_Update michael@0: ( michael@0: NSSCKFWCryptoOperation *fwOperation, michael@0: NSSItem *inputBuffer, michael@0: NSSItem *outputBuffer michael@0: ) michael@0: { michael@0: if (!fwOperation->mdOperation->Update) { michael@0: return CKR_FUNCTION_FAILED; michael@0: } michael@0: return fwOperation->mdOperation->Update( michael@0: fwOperation->mdOperation, michael@0: fwOperation, michael@0: fwOperation->mdSession, michael@0: fwOperation->fwSession, michael@0: fwOperation->mdToken, michael@0: fwOperation->fwToken, michael@0: fwOperation->mdInstance, michael@0: fwOperation->fwInstance, michael@0: inputBuffer, michael@0: outputBuffer); michael@0: } michael@0: michael@0: /* michael@0: * nssCKFWCryptoOperation_DigestUpdate michael@0: */ michael@0: NSS_EXTERN CK_RV michael@0: nssCKFWCryptoOperation_DigestUpdate michael@0: ( michael@0: NSSCKFWCryptoOperation *fwOperation, michael@0: NSSItem *inputBuffer michael@0: ) michael@0: { michael@0: if (!fwOperation->mdOperation->DigestUpdate) { michael@0: return CKR_FUNCTION_FAILED; michael@0: } michael@0: return fwOperation->mdOperation->DigestUpdate( michael@0: fwOperation->mdOperation, michael@0: fwOperation, michael@0: fwOperation->mdSession, michael@0: fwOperation->fwSession, michael@0: fwOperation->mdToken, michael@0: fwOperation->fwToken, michael@0: fwOperation->mdInstance, michael@0: fwOperation->fwInstance, michael@0: inputBuffer); michael@0: } michael@0: michael@0: /* michael@0: * nssCKFWCryptoOperation_DigestKey michael@0: */ michael@0: NSS_EXTERN CK_RV michael@0: nssCKFWCryptoOperation_DigestKey michael@0: ( michael@0: NSSCKFWCryptoOperation *fwOperation, michael@0: NSSCKFWObject *fwObject /* Key */ michael@0: ) michael@0: { michael@0: NSSCKMDObject *mdObject; michael@0: michael@0: if (!fwOperation->mdOperation->DigestKey) { michael@0: return CKR_FUNCTION_FAILED; michael@0: } michael@0: mdObject = nssCKFWObject_GetMDObject(fwObject); michael@0: return fwOperation->mdOperation->DigestKey( michael@0: fwOperation->mdOperation, michael@0: fwOperation, michael@0: fwOperation->mdToken, michael@0: fwOperation->fwToken, michael@0: fwOperation->mdInstance, michael@0: fwOperation->fwInstance, michael@0: mdObject, michael@0: fwObject); michael@0: } michael@0: michael@0: /* michael@0: * nssCKFWCryptoOperation_UpdateFinal michael@0: */ michael@0: NSS_EXTERN CK_RV michael@0: nssCKFWCryptoOperation_UpdateFinal michael@0: ( michael@0: NSSCKFWCryptoOperation *fwOperation, michael@0: NSSItem *inputBuffer, michael@0: NSSItem *outputBuffer michael@0: ) michael@0: { michael@0: if (!fwOperation->mdOperation->UpdateFinal) { michael@0: return CKR_FUNCTION_FAILED; michael@0: } michael@0: return fwOperation->mdOperation->UpdateFinal( michael@0: fwOperation->mdOperation, michael@0: fwOperation, michael@0: fwOperation->mdSession, michael@0: fwOperation->fwSession, michael@0: fwOperation->mdToken, michael@0: fwOperation->fwToken, michael@0: fwOperation->mdInstance, michael@0: fwOperation->fwInstance, michael@0: inputBuffer, michael@0: outputBuffer); michael@0: } michael@0: michael@0: /* michael@0: * nssCKFWCryptoOperation_UpdateCombo michael@0: */ michael@0: NSS_EXTERN CK_RV michael@0: nssCKFWCryptoOperation_UpdateCombo michael@0: ( michael@0: NSSCKFWCryptoOperation *fwOperation, michael@0: NSSCKFWCryptoOperation *fwPeerOperation, michael@0: NSSItem *inputBuffer, michael@0: NSSItem *outputBuffer michael@0: ) michael@0: { michael@0: if (!fwOperation->mdOperation->UpdateCombo) { michael@0: return CKR_FUNCTION_FAILED; michael@0: } michael@0: return fwOperation->mdOperation->UpdateCombo( michael@0: fwOperation->mdOperation, michael@0: fwOperation, michael@0: fwPeerOperation->mdOperation, michael@0: fwPeerOperation, michael@0: fwOperation->mdSession, michael@0: fwOperation->fwSession, michael@0: fwOperation->mdToken, michael@0: fwOperation->fwToken, michael@0: fwOperation->mdInstance, michael@0: fwOperation->fwInstance, michael@0: inputBuffer, michael@0: outputBuffer); michael@0: }