os/security/cryptoplugins/cryptospiplugins/test/dummyecchwplugin/src/cryptospihai.cpp
Update contrib.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include "cryptospihai.h"
22 #include <cryptospi/cryptohashapi.h>
24 #include "tcryptotokenhai.h"
26 using namespace CryptoSpiHai;
29 * Performs the signing operation.
31 * A cryptoSPI plugin uses this, when it does not have access to the
34 * @param aKeyHandle The key handle retrieved from hw crypto
36 * @param aInput The text which has to be signed. This is not being
37 * used due to signing logic used in this function.
38 * @param aSignature Output param. The cryptoSPI signature.
40 * @leave Can leave with all the leave codes present in HAI of
41 * reference crypto token implementation.
43 * @note This function does not actually implement ECC signing. This
44 * function just shows how the private key can be extracted from
45 * crypto token hai. This function just returns the private key as
46 * output signature. The caller can verify the signature by ensuring
47 * that test case has same public and private keys and then comparing
48 * the signature with public key.
50 EXPORT_C void CCryptoSpiHai::SignL(TInt aKeyHandle,
51 const TDesC8& /*aInput*/, CryptoSpi::CCryptoParams& aSignature)
53 MCTToken* token = NULL;
55 * We are dereferencing a NULL pointer below. We need to pass
56 * MCTToken here. It is not used currently.
58 CCryptoTokenHai *cryptoTokenHai = CCryptoTokenHai::NewLC(token);
60 //Call Crypto Token HAI to get the actual key
61 HBufC8* actualKey = NULL;
62 cryptoTokenHai->ExportPrivateKeyL(aKeyHandle, actualKey);
63 CleanupStack::PushL(actualKey);
65 aSignature.AddL(*actualKey, CryptoSpi::KEccKeyTypeUid);
66 CleanupStack::PopAndDestroy(actualKey);
67 CleanupStack::PopAndDestroy(cryptoTokenHai);
71 * Performs the decryption operation.
73 * A cryptoSPI plugin uses this, when it does not have access to the
76 * @param aKeyHandle The key handle retrieved from hw crypto token
77 * @param aInput The cipher text. This is not being used due to signing
78 * logic used in this function.
79 * @param aOutput Output param. The decrypted plain text
81 * @leave Can leave with all the leave codes present in HAI of
82 * reference crypto token implementation.
84 * @note This function does not actually implement ECC decryption. This
85 * function just shows how the private key can be extracted from
86 * crypto token hai. This function just returns the private key as
87 * decrypted text. The caller can verify the decryption by ensuring
88 * that test case has same public and private keys and then comparing
89 * the decrypted text with public key.
91 EXPORT_C void CCryptoSpiHai::DecryptL(TInt aKeyHandle,
92 const TDesC8& /*aInput*/, TDes8& aOutput)
94 MCTToken* token = NULL;
95 CCryptoTokenHai *cryptoTokenHai = CCryptoTokenHai::NewLC(token);
97 //Call Crypto Token HAI to get the actual key
98 HBufC8* actualKey = NULL;
99 cryptoTokenHai->ExportPrivateKeyL(aKeyHandle, actualKey);
100 CleanupStack::PushL(actualKey);
101 aOutput.Copy(*actualKey);
103 CleanupStack::PopAndDestroy(actualKey);
104 CleanupStack::PopAndDestroy(cryptoTokenHai);