sl@0: /* sl@0: * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "cryptospihai.h" sl@0: #include "keys.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include "tcryptotokenhai.h" sl@0: sl@0: using namespace CryptoSpiHai; sl@0: sl@0: /** sl@0: * Performs the signing operation. sl@0: * sl@0: * A cryptoSPI plugin uses this, when it does not have access to the sl@0: * actual key. sl@0: * sl@0: * @param aKeyHandle The key handle retrieved from hw crypto sl@0: * token sl@0: * @param aInput The text which has to be signed. This is not being sl@0: * used due to signing logic used in this function. sl@0: * @param aSignature Output param. The cryptoSPI signature. sl@0: * sl@0: * @leave Can leave with all the leave codes present in HAI of sl@0: * reference crypto token implementation. sl@0: * sl@0: * @note This function does not actually implement ECC signing. This sl@0: * function just shows how the private key can be extracted from sl@0: * crypto token hai. This function just returns the private key as sl@0: * output signature. The caller can verify the signature by ensuring sl@0: * that test case has same public and private keys and then comparing sl@0: * the signature with public key. sl@0: */ sl@0: EXPORT_C void CCryptoSpiHai::SignL(TInt aKeyHandle, sl@0: const TDesC8& /*aInput*/, CryptoSpi::CCryptoParams& aSignature) sl@0: { sl@0: MCTToken* token = NULL; sl@0: /** sl@0: * We are dereferencing a NULL pointer below. We need to pass sl@0: * MCTToken here. It is not used currently. sl@0: */ sl@0: CCryptoTokenHai *cryptoTokenHai = CCryptoTokenHai::NewLC(token); sl@0: sl@0: //Call Crypto Token HAI to get the actual key sl@0: HBufC8* actualKey = NULL; sl@0: cryptoTokenHai->ExportPrivateKeyL(aKeyHandle, actualKey); sl@0: CleanupStack::PushL(actualKey); sl@0: sl@0: aSignature.AddL(*actualKey, CryptoSpi::KEccKeyTypeUid); sl@0: CleanupStack::PopAndDestroy(actualKey); sl@0: CleanupStack::PopAndDestroy(cryptoTokenHai); sl@0: } sl@0: sl@0: /** sl@0: * Performs the decryption operation. sl@0: * sl@0: * A cryptoSPI plugin uses this, when it does not have access to the sl@0: * actual key. sl@0: * sl@0: * @param aKeyHandle The key handle retrieved from hw crypto token sl@0: * @param aInput The cipher text. This is not being used due to signing sl@0: * logic used in this function. sl@0: * @param aOutput Output param. The decrypted plain text sl@0: * sl@0: * @leave Can leave with all the leave codes present in HAI of sl@0: * reference crypto token implementation. sl@0: * sl@0: * @note This function does not actually implement ECC decryption. This sl@0: * function just shows how the private key can be extracted from sl@0: * crypto token hai. This function just returns the private key as sl@0: * decrypted text. The caller can verify the decryption by ensuring sl@0: * that test case has same public and private keys and then comparing sl@0: * the decrypted text with public key. sl@0: */ sl@0: EXPORT_C void CCryptoSpiHai::DecryptL(TInt aKeyHandle, sl@0: const TDesC8& /*aInput*/, TDes8& aOutput) sl@0: { sl@0: MCTToken* token = NULL; sl@0: CCryptoTokenHai *cryptoTokenHai = CCryptoTokenHai::NewLC(token); sl@0: sl@0: //Call Crypto Token HAI to get the actual key sl@0: HBufC8* actualKey = NULL; sl@0: cryptoTokenHai->ExportPrivateKeyL(aKeyHandle, actualKey); sl@0: CleanupStack::PushL(actualKey); sl@0: aOutput.Copy(*actualKey); sl@0: sl@0: CleanupStack::PopAndDestroy(actualKey); sl@0: CleanupStack::PopAndDestroy(cryptoTokenHai); sl@0: } sl@0: sl@0: // End of file sl@0: sl@0: