sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#include "cryptospihai.h"
|
sl@0
|
20 |
#include "keys.h"
|
sl@0
|
21 |
#include <e32def.h>
|
sl@0
|
22 |
#include <cryptospi/cryptohashapi.h>
|
sl@0
|
23 |
#include <pbedata.h>
|
sl@0
|
24 |
#include "tcryptotokenhai.h"
|
sl@0
|
25 |
|
sl@0
|
26 |
using namespace CryptoSpiHai;
|
sl@0
|
27 |
|
sl@0
|
28 |
/**
|
sl@0
|
29 |
* Performs the signing operation.
|
sl@0
|
30 |
*
|
sl@0
|
31 |
* A cryptoSPI plugin uses this, when it does not have access to the
|
sl@0
|
32 |
* actual key.
|
sl@0
|
33 |
*
|
sl@0
|
34 |
* @param aKeyHandle The key handle retrieved from hw crypto
|
sl@0
|
35 |
* token
|
sl@0
|
36 |
* @param aInput The text which has to be signed. This is not being
|
sl@0
|
37 |
* used due to signing logic used in this function.
|
sl@0
|
38 |
* @param aSignature Output param. The cryptoSPI signature.
|
sl@0
|
39 |
*
|
sl@0
|
40 |
* @leave Can leave with all the leave codes present in HAI of
|
sl@0
|
41 |
* reference crypto token implementation.
|
sl@0
|
42 |
*
|
sl@0
|
43 |
* @note This function does not actually implement ECC signing. This
|
sl@0
|
44 |
* function just shows how the private key can be extracted from
|
sl@0
|
45 |
* crypto token hai. This function just returns the private key as
|
sl@0
|
46 |
* output signature. The caller can verify the signature by ensuring
|
sl@0
|
47 |
* that test case has same public and private keys and then comparing
|
sl@0
|
48 |
* the signature with public key.
|
sl@0
|
49 |
*/
|
sl@0
|
50 |
EXPORT_C void CCryptoSpiHai::SignL(TInt aKeyHandle,
|
sl@0
|
51 |
const TDesC8& /*aInput*/, CryptoSpi::CCryptoParams& aSignature)
|
sl@0
|
52 |
{
|
sl@0
|
53 |
MCTToken* token = NULL;
|
sl@0
|
54 |
/**
|
sl@0
|
55 |
* We are dereferencing a NULL pointer below. We need to pass
|
sl@0
|
56 |
* MCTToken here. It is not used currently.
|
sl@0
|
57 |
*/
|
sl@0
|
58 |
CCryptoTokenHai *cryptoTokenHai = CCryptoTokenHai::NewLC(token);
|
sl@0
|
59 |
|
sl@0
|
60 |
//Call Crypto Token HAI to get the actual key
|
sl@0
|
61 |
HBufC8* actualKey = NULL;
|
sl@0
|
62 |
cryptoTokenHai->ExportPrivateKeyL(aKeyHandle, actualKey);
|
sl@0
|
63 |
CleanupStack::PushL(actualKey);
|
sl@0
|
64 |
|
sl@0
|
65 |
aSignature.AddL(*actualKey, CryptoSpi::KEccKeyTypeUid);
|
sl@0
|
66 |
CleanupStack::PopAndDestroy(actualKey);
|
sl@0
|
67 |
CleanupStack::PopAndDestroy(cryptoTokenHai);
|
sl@0
|
68 |
}
|
sl@0
|
69 |
|
sl@0
|
70 |
/**
|
sl@0
|
71 |
* Performs the decryption operation.
|
sl@0
|
72 |
*
|
sl@0
|
73 |
* A cryptoSPI plugin uses this, when it does not have access to the
|
sl@0
|
74 |
* actual key.
|
sl@0
|
75 |
*
|
sl@0
|
76 |
* @param aKeyHandle The key handle retrieved from hw crypto token
|
sl@0
|
77 |
* @param aInput The cipher text. This is not being used due to signing
|
sl@0
|
78 |
* logic used in this function.
|
sl@0
|
79 |
* @param aOutput Output param. The decrypted plain text
|
sl@0
|
80 |
*
|
sl@0
|
81 |
* @leave Can leave with all the leave codes present in HAI of
|
sl@0
|
82 |
* reference crypto token implementation.
|
sl@0
|
83 |
*
|
sl@0
|
84 |
* @note This function does not actually implement ECC decryption. This
|
sl@0
|
85 |
* function just shows how the private key can be extracted from
|
sl@0
|
86 |
* crypto token hai. This function just returns the private key as
|
sl@0
|
87 |
* decrypted text. The caller can verify the decryption by ensuring
|
sl@0
|
88 |
* that test case has same public and private keys and then comparing
|
sl@0
|
89 |
* the decrypted text with public key.
|
sl@0
|
90 |
*/
|
sl@0
|
91 |
EXPORT_C void CCryptoSpiHai::DecryptL(TInt aKeyHandle,
|
sl@0
|
92 |
const TDesC8& /*aInput*/, TDes8& aOutput)
|
sl@0
|
93 |
{
|
sl@0
|
94 |
MCTToken* token = NULL;
|
sl@0
|
95 |
CCryptoTokenHai *cryptoTokenHai = CCryptoTokenHai::NewLC(token);
|
sl@0
|
96 |
|
sl@0
|
97 |
//Call Crypto Token HAI to get the actual key
|
sl@0
|
98 |
HBufC8* actualKey = NULL;
|
sl@0
|
99 |
cryptoTokenHai->ExportPrivateKeyL(aKeyHandle, actualKey);
|
sl@0
|
100 |
CleanupStack::PushL(actualKey);
|
sl@0
|
101 |
aOutput.Copy(*actualKey);
|
sl@0
|
102 |
|
sl@0
|
103 |
CleanupStack::PopAndDestroy(actualKey);
|
sl@0
|
104 |
CleanupStack::PopAndDestroy(cryptoTokenHai);
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
// End of file
|
sl@0
|
108 |
|
sl@0
|
109 |
|