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: andre@0: /* andre@0: * crypto.c andre@0: * andre@0: * This file implements the NSSCKFWCryptoOperation type and methods. andre@0: */ andre@0: andre@0: #ifndef CK_T andre@0: #include "ck.h" andre@0: #endif /* CK_T */ andre@0: andre@0: /* andre@0: * NSSCKFWCryptoOperation andre@0: * andre@0: * -- create/destroy -- andre@0: * nssCKFWCrytoOperation_Create andre@0: * nssCKFWCryptoOperation_Destroy andre@0: * andre@0: * -- implement public accessors -- andre@0: * nssCKFWCryptoOperation_GetMDCryptoOperation andre@0: * nssCKFWCryptoOperation_GetType andre@0: * andre@0: * -- private accessors -- andre@0: * andre@0: * -- module fronts -- andre@0: * nssCKFWCryptoOperation_GetFinalLength andre@0: * nssCKFWCryptoOperation_GetOperationLength andre@0: * nssCKFWCryptoOperation_Final andre@0: * nssCKFWCryptoOperation_Update andre@0: * nssCKFWCryptoOperation_DigestUpdate andre@0: * nssCKFWCryptoOperation_UpdateFinal andre@0: */ andre@0: andre@0: struct NSSCKFWCryptoOperationStr { andre@0: /* NSSArena *arena; */ andre@0: NSSCKMDCryptoOperation *mdOperation; andre@0: NSSCKMDSession *mdSession; andre@0: NSSCKFWSession *fwSession; andre@0: NSSCKMDToken *mdToken; andre@0: NSSCKFWToken *fwToken; andre@0: NSSCKMDInstance *mdInstance; andre@0: NSSCKFWInstance *fwInstance; andre@0: NSSCKFWCryptoOperationType type; andre@0: }; andre@0: andre@0: /* andre@0: * nssCKFWCrytoOperation_Create andre@0: */ andre@0: NSS_EXTERN NSSCKFWCryptoOperation * andre@0: nssCKFWCryptoOperation_Create( andre@0: NSSCKMDCryptoOperation *mdOperation, andre@0: NSSCKMDSession *mdSession, andre@0: NSSCKFWSession *fwSession, andre@0: NSSCKMDToken *mdToken, andre@0: NSSCKFWToken *fwToken, andre@0: NSSCKMDInstance *mdInstance, andre@0: NSSCKFWInstance *fwInstance, andre@0: NSSCKFWCryptoOperationType type, andre@0: CK_RV *pError andre@0: ) andre@0: { andre@0: NSSCKFWCryptoOperation *fwOperation; andre@0: fwOperation = nss_ZNEW(NULL, NSSCKFWCryptoOperation); andre@0: if (!fwOperation) { andre@0: *pError = CKR_HOST_MEMORY; andre@0: return (NSSCKFWCryptoOperation *)NULL; andre@0: } andre@0: fwOperation->mdOperation = mdOperation; andre@0: fwOperation->mdSession = mdSession; andre@0: fwOperation->fwSession = fwSession; andre@0: fwOperation->mdToken = mdToken; andre@0: fwOperation->fwToken = fwToken; andre@0: fwOperation->mdInstance = mdInstance; andre@0: fwOperation->fwInstance = fwInstance; andre@0: fwOperation->type = type; andre@0: return fwOperation; andre@0: } andre@0: andre@0: /* andre@0: * nssCKFWCryptoOperation_Destroy andre@0: */ andre@0: NSS_EXTERN void andre@0: nssCKFWCryptoOperation_Destroy andre@0: ( andre@0: NSSCKFWCryptoOperation *fwOperation andre@0: ) andre@0: { andre@0: if ((NSSCKMDCryptoOperation *) NULL != fwOperation->mdOperation) { andre@0: if (fwOperation->mdOperation->Destroy) { andre@0: fwOperation->mdOperation->Destroy( andre@0: fwOperation->mdOperation, andre@0: fwOperation, andre@0: fwOperation->mdInstance, andre@0: fwOperation->fwInstance); andre@0: } andre@0: } andre@0: nss_ZFreeIf(fwOperation); andre@0: } andre@0: andre@0: /* andre@0: * nssCKFWCryptoOperation_GetMDCryptoOperation andre@0: */ andre@0: NSS_EXTERN NSSCKMDCryptoOperation * andre@0: nssCKFWCryptoOperation_GetMDCryptoOperation andre@0: ( andre@0: NSSCKFWCryptoOperation *fwOperation andre@0: ) andre@0: { andre@0: return fwOperation->mdOperation; andre@0: } andre@0: andre@0: /* andre@0: * nssCKFWCryptoOperation_GetType andre@0: */ andre@0: NSS_EXTERN NSSCKFWCryptoOperationType andre@0: nssCKFWCryptoOperation_GetType andre@0: ( andre@0: NSSCKFWCryptoOperation *fwOperation andre@0: ) andre@0: { andre@0: return fwOperation->type; andre@0: } andre@0: andre@0: /* andre@0: * nssCKFWCryptoOperation_GetFinalLength andre@0: */ andre@0: NSS_EXTERN CK_ULONG andre@0: nssCKFWCryptoOperation_GetFinalLength andre@0: ( andre@0: NSSCKFWCryptoOperation *fwOperation, andre@0: CK_RV *pError andre@0: ) andre@0: { andre@0: if (!fwOperation->mdOperation->GetFinalLength) { andre@0: *pError = CKR_FUNCTION_FAILED; andre@0: return 0; andre@0: } andre@0: return fwOperation->mdOperation->GetFinalLength( andre@0: fwOperation->mdOperation, andre@0: fwOperation, andre@0: fwOperation->mdSession, andre@0: fwOperation->fwSession, andre@0: fwOperation->mdToken, andre@0: fwOperation->fwToken, andre@0: fwOperation->mdInstance, andre@0: fwOperation->fwInstance, andre@0: pError); andre@0: } andre@0: andre@0: /* andre@0: * nssCKFWCryptoOperation_GetOperationLength andre@0: */ andre@0: NSS_EXTERN CK_ULONG andre@0: nssCKFWCryptoOperation_GetOperationLength andre@0: ( andre@0: NSSCKFWCryptoOperation *fwOperation, andre@0: NSSItem *inputBuffer, andre@0: CK_RV *pError andre@0: ) andre@0: { andre@0: if (!fwOperation->mdOperation->GetOperationLength) { andre@0: *pError = CKR_FUNCTION_FAILED; andre@0: return 0; andre@0: } andre@0: return fwOperation->mdOperation->GetOperationLength( andre@0: fwOperation->mdOperation, andre@0: fwOperation, andre@0: fwOperation->mdSession, andre@0: fwOperation->fwSession, andre@0: fwOperation->mdToken, andre@0: fwOperation->fwToken, andre@0: fwOperation->mdInstance, andre@0: fwOperation->fwInstance, andre@0: inputBuffer, andre@0: pError); andre@0: } andre@0: andre@0: /* andre@0: * nssCKFWCryptoOperation_Final andre@0: */ andre@0: NSS_EXTERN CK_RV andre@0: nssCKFWCryptoOperation_Final andre@0: ( andre@0: NSSCKFWCryptoOperation *fwOperation, andre@0: NSSItem *outputBuffer andre@0: ) andre@0: { andre@0: if (!fwOperation->mdOperation->Final) { andre@0: return CKR_FUNCTION_FAILED; andre@0: } andre@0: return fwOperation->mdOperation->Final( andre@0: fwOperation->mdOperation, andre@0: fwOperation, andre@0: fwOperation->mdSession, andre@0: fwOperation->fwSession, andre@0: fwOperation->mdToken, andre@0: fwOperation->fwToken, andre@0: fwOperation->mdInstance, andre@0: fwOperation->fwInstance, andre@0: outputBuffer); andre@0: } andre@0: andre@0: /* andre@0: * nssCKFWCryptoOperation_Update andre@0: */ andre@0: NSS_EXTERN CK_RV andre@0: nssCKFWCryptoOperation_Update andre@0: ( andre@0: NSSCKFWCryptoOperation *fwOperation, andre@0: NSSItem *inputBuffer, andre@0: NSSItem *outputBuffer andre@0: ) andre@0: { andre@0: if (!fwOperation->mdOperation->Update) { andre@0: return CKR_FUNCTION_FAILED; andre@0: } andre@0: return fwOperation->mdOperation->Update( andre@0: fwOperation->mdOperation, andre@0: fwOperation, andre@0: fwOperation->mdSession, andre@0: fwOperation->fwSession, andre@0: fwOperation->mdToken, andre@0: fwOperation->fwToken, andre@0: fwOperation->mdInstance, andre@0: fwOperation->fwInstance, andre@0: inputBuffer, andre@0: outputBuffer); andre@0: } andre@0: andre@0: /* andre@0: * nssCKFWCryptoOperation_DigestUpdate andre@0: */ andre@0: NSS_EXTERN CK_RV andre@0: nssCKFWCryptoOperation_DigestUpdate andre@0: ( andre@0: NSSCKFWCryptoOperation *fwOperation, andre@0: NSSItem *inputBuffer andre@0: ) andre@0: { andre@0: if (!fwOperation->mdOperation->DigestUpdate) { andre@0: return CKR_FUNCTION_FAILED; andre@0: } andre@0: return fwOperation->mdOperation->DigestUpdate( andre@0: fwOperation->mdOperation, andre@0: fwOperation, andre@0: fwOperation->mdSession, andre@0: fwOperation->fwSession, andre@0: fwOperation->mdToken, andre@0: fwOperation->fwToken, andre@0: fwOperation->mdInstance, andre@0: fwOperation->fwInstance, andre@0: inputBuffer); andre@0: } andre@0: andre@0: /* andre@0: * nssCKFWCryptoOperation_DigestKey andre@0: */ andre@0: NSS_EXTERN CK_RV andre@0: nssCKFWCryptoOperation_DigestKey andre@0: ( andre@0: NSSCKFWCryptoOperation *fwOperation, andre@0: NSSCKFWObject *fwObject /* Key */ andre@0: ) andre@0: { andre@0: NSSCKMDObject *mdObject; andre@0: andre@0: if (!fwOperation->mdOperation->DigestKey) { andre@0: return CKR_FUNCTION_FAILED; andre@0: } andre@0: mdObject = nssCKFWObject_GetMDObject(fwObject); andre@0: return fwOperation->mdOperation->DigestKey( andre@0: fwOperation->mdOperation, andre@0: fwOperation, andre@0: fwOperation->mdToken, andre@0: fwOperation->fwToken, andre@0: fwOperation->mdInstance, andre@0: fwOperation->fwInstance, andre@0: mdObject, andre@0: fwObject); andre@0: } andre@0: andre@0: /* andre@0: * nssCKFWCryptoOperation_UpdateFinal andre@0: */ andre@0: NSS_EXTERN CK_RV andre@0: nssCKFWCryptoOperation_UpdateFinal andre@0: ( andre@0: NSSCKFWCryptoOperation *fwOperation, andre@0: NSSItem *inputBuffer, andre@0: NSSItem *outputBuffer andre@0: ) andre@0: { andre@0: if (!fwOperation->mdOperation->UpdateFinal) { andre@0: return CKR_FUNCTION_FAILED; andre@0: } andre@0: return fwOperation->mdOperation->UpdateFinal( andre@0: fwOperation->mdOperation, andre@0: fwOperation, andre@0: fwOperation->mdSession, andre@0: fwOperation->fwSession, andre@0: fwOperation->mdToken, andre@0: fwOperation->fwToken, andre@0: fwOperation->mdInstance, andre@0: fwOperation->fwInstance, andre@0: inputBuffer, andre@0: outputBuffer); andre@0: } andre@0: andre@0: /* andre@0: * nssCKFWCryptoOperation_UpdateCombo andre@0: */ andre@0: NSS_EXTERN CK_RV andre@0: nssCKFWCryptoOperation_UpdateCombo andre@0: ( andre@0: NSSCKFWCryptoOperation *fwOperation, andre@0: NSSCKFWCryptoOperation *fwPeerOperation, andre@0: NSSItem *inputBuffer, andre@0: NSSItem *outputBuffer andre@0: ) andre@0: { andre@0: if (!fwOperation->mdOperation->UpdateCombo) { andre@0: return CKR_FUNCTION_FAILED; andre@0: } andre@0: return fwOperation->mdOperation->UpdateCombo( andre@0: fwOperation->mdOperation, andre@0: fwOperation, andre@0: fwPeerOperation->mdOperation, andre@0: fwPeerOperation, andre@0: fwOperation->mdSession, andre@0: fwOperation->fwSession, andre@0: fwOperation->mdToken, andre@0: fwOperation->fwToken, andre@0: fwOperation->mdInstance, andre@0: fwOperation->fwInstance, andre@0: inputBuffer, andre@0: outputBuffer); andre@0: }