|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "cryptospihai.h" |
|
20 #include "keys.h" |
|
21 #include <e32def.h> |
|
22 #include <cryptospi/cryptohashapi.h> |
|
23 #include <pbedata.h> |
|
24 #include "tcryptotokenhai.h" |
|
25 |
|
26 using namespace CryptoSpiHai; |
|
27 |
|
28 /** |
|
29 * Performs the signing operation. |
|
30 * |
|
31 * A cryptoSPI plugin uses this, when it does not have access to the |
|
32 * actual key. |
|
33 * |
|
34 * @param aKeyHandle The key handle retrieved from hw crypto |
|
35 * token |
|
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. |
|
39 * |
|
40 * @leave Can leave with all the leave codes present in HAI of |
|
41 * reference crypto token implementation. |
|
42 * |
|
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. |
|
49 */ |
|
50 EXPORT_C void CCryptoSpiHai::SignL(TInt aKeyHandle, |
|
51 const TDesC8& /*aInput*/, CryptoSpi::CCryptoParams& aSignature) |
|
52 { |
|
53 MCTToken* token = NULL; |
|
54 /** |
|
55 * We are dereferencing a NULL pointer below. We need to pass |
|
56 * MCTToken here. It is not used currently. |
|
57 */ |
|
58 CCryptoTokenHai *cryptoTokenHai = CCryptoTokenHai::NewLC(token); |
|
59 |
|
60 //Call Crypto Token HAI to get the actual key |
|
61 HBufC8* actualKey = NULL; |
|
62 cryptoTokenHai->ExportPrivateKeyL(aKeyHandle, actualKey); |
|
63 CleanupStack::PushL(actualKey); |
|
64 |
|
65 aSignature.AddL(*actualKey, CryptoSpi::KEccKeyTypeUid); |
|
66 CleanupStack::PopAndDestroy(actualKey); |
|
67 CleanupStack::PopAndDestroy(cryptoTokenHai); |
|
68 } |
|
69 |
|
70 /** |
|
71 * Performs the decryption operation. |
|
72 * |
|
73 * A cryptoSPI plugin uses this, when it does not have access to the |
|
74 * actual key. |
|
75 * |
|
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 |
|
80 * |
|
81 * @leave Can leave with all the leave codes present in HAI of |
|
82 * reference crypto token implementation. |
|
83 * |
|
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. |
|
90 */ |
|
91 EXPORT_C void CCryptoSpiHai::DecryptL(TInt aKeyHandle, |
|
92 const TDesC8& /*aInput*/, TDes8& aOutput) |
|
93 { |
|
94 MCTToken* token = NULL; |
|
95 CCryptoTokenHai *cryptoTokenHai = CCryptoTokenHai::NewLC(token); |
|
96 |
|
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); |
|
102 |
|
103 CleanupStack::PopAndDestroy(actualKey); |
|
104 CleanupStack::PopAndDestroy(cryptoTokenHai); |
|
105 } |
|
106 |
|
107 // End of file |
|
108 |
|
109 |