sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2006-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 |
* RSA shim classes definition
|
sl@0
|
16 |
*
|
sl@0
|
17 |
*/
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
/**
|
sl@0
|
21 |
@file
|
sl@0
|
22 |
@internalComponent
|
sl@0
|
23 |
@released
|
sl@0
|
24 |
*/
|
sl@0
|
25 |
|
sl@0
|
26 |
#ifndef __RSASHIM_H__
|
sl@0
|
27 |
#define __RSASHIM_H__
|
sl@0
|
28 |
|
sl@0
|
29 |
#include <asymmetric.h>
|
sl@0
|
30 |
|
sl@0
|
31 |
namespace CryptoSpi
|
sl@0
|
32 |
{
|
sl@0
|
33 |
class CAsymmetricCipher;
|
sl@0
|
34 |
class CKey;
|
sl@0
|
35 |
class CSigner;
|
sl@0
|
36 |
class CVerifier;
|
sl@0
|
37 |
}
|
sl@0
|
38 |
|
sl@0
|
39 |
NONSHARABLE_CLASS(CRSAPKCS1v15EncryptorShim) : public CRSAPKCS1v15Encryptor
|
sl@0
|
40 |
{
|
sl@0
|
41 |
public:
|
sl@0
|
42 |
/**
|
sl@0
|
43 |
Creates an RSAPKCS1v15EncryptorShim object which has the same interface
|
sl@0
|
44 |
as CRSAPKCS1v15Encryptor but delegates all work to a Crypto SPI plug-in.
|
sl@0
|
45 |
|
sl@0
|
46 |
@param aKey The encryption key
|
sl@0
|
47 |
@return A pointer to a CRSAPKCS1v15EncryptorShim instance
|
sl@0
|
48 |
*/
|
sl@0
|
49 |
static CRSAPKCS1v15EncryptorShim* NewL(const CRSAPublicKey& aKey);
|
sl@0
|
50 |
|
sl@0
|
51 |
/**
|
sl@0
|
52 |
Creates an RSAPKCS1v15EncryptorShim object which has the same interface
|
sl@0
|
53 |
as CRSAPKCS1v15Encryptor but delegates all work to a Crypto SPI plug-in.
|
sl@0
|
54 |
|
sl@0
|
55 |
A pointer to the new object is placed on the cleanup stack
|
sl@0
|
56 |
|
sl@0
|
57 |
@param aKey The encryption key
|
sl@0
|
58 |
@return A pointer to a CRSAPKCS1v15EncryptorShim instance
|
sl@0
|
59 |
*/
|
sl@0
|
60 |
static CRSAPKCS1v15EncryptorShim* NewLC(const CRSAPublicKey& aKey);
|
sl@0
|
61 |
|
sl@0
|
62 |
// From CRSAPKCS1v15Encryptor
|
sl@0
|
63 |
void EncryptL(const TDesC8& aInput, TDes8& aOutput) const;
|
sl@0
|
64 |
TInt MaxInputLength(void) const;
|
sl@0
|
65 |
TInt MaxOutputLength(void) const;
|
sl@0
|
66 |
|
sl@0
|
67 |
/// Destructor
|
sl@0
|
68 |
~CRSAPKCS1v15EncryptorShim();
|
sl@0
|
69 |
|
sl@0
|
70 |
private:
|
sl@0
|
71 |
/// Constructor
|
sl@0
|
72 |
CRSAPKCS1v15EncryptorShim(const CRSAPublicKey& aKey);
|
sl@0
|
73 |
void ConstructL(const CRSAPublicKey& aKey);
|
sl@0
|
74 |
|
sl@0
|
75 |
private:
|
sl@0
|
76 |
/// SPI delegate
|
sl@0
|
77 |
CryptoSpi::CAsymmetricCipher* iAsymmetricCipherImpl;
|
sl@0
|
78 |
|
sl@0
|
79 |
/// SPI requires all key to passed as key-objects
|
sl@0
|
80 |
CryptoSpi::CKey* iKey;
|
sl@0
|
81 |
};
|
sl@0
|
82 |
|
sl@0
|
83 |
NONSHARABLE_CLASS(CRSAPKCS1v15DecryptorShim) : public CRSAPKCS1v15Decryptor
|
sl@0
|
84 |
{
|
sl@0
|
85 |
public:
|
sl@0
|
86 |
/**
|
sl@0
|
87 |
Creates an RSAPKCS1v15DecryptorShim object which has the same interface
|
sl@0
|
88 |
as CRSAPKCS1v15Decryptor but delegates all work to a Crypto SPI plug-in.
|
sl@0
|
89 |
|
sl@0
|
90 |
@param aKey The decryption key
|
sl@0
|
91 |
@return A pointer to a CRSAPKCS1v15DecryptorShim instance
|
sl@0
|
92 |
*/
|
sl@0
|
93 |
static CRSAPKCS1v15DecryptorShim* NewL(const CRSAPrivateKey& aKey);
|
sl@0
|
94 |
|
sl@0
|
95 |
/**
|
sl@0
|
96 |
Creates an RSAPKCS1v15EncryptorShim object which has the same interface
|
sl@0
|
97 |
as CRSAPKCS1v15Decryptor but delegates all work to a Crypto SPI plug-in.
|
sl@0
|
98 |
|
sl@0
|
99 |
A pointer to the new object is placed on the cleanup stack
|
sl@0
|
100 |
|
sl@0
|
101 |
@param aKey The decryption key
|
sl@0
|
102 |
@return A pointer to a CRSAPKCS1v15DecryptorShim instance
|
sl@0
|
103 |
*/
|
sl@0
|
104 |
static CRSAPKCS1v15DecryptorShim* NewLC(const CRSAPrivateKey& aKey);
|
sl@0
|
105 |
|
sl@0
|
106 |
// From CRSAPKCS1v15Decryptor
|
sl@0
|
107 |
void DecryptL(const TDesC8& aInput, TDes8& aOutput) const;
|
sl@0
|
108 |
TInt MaxInputLength(void) const;
|
sl@0
|
109 |
TInt MaxOutputLength(void) const;
|
sl@0
|
110 |
|
sl@0
|
111 |
/// Destructor
|
sl@0
|
112 |
~CRSAPKCS1v15DecryptorShim();
|
sl@0
|
113 |
|
sl@0
|
114 |
private:
|
sl@0
|
115 |
/// Constructor
|
sl@0
|
116 |
CRSAPKCS1v15DecryptorShim(const CRSAPrivateKey& aKey);
|
sl@0
|
117 |
void ConstructL(const CRSAPrivateKey& aKey);
|
sl@0
|
118 |
|
sl@0
|
119 |
private:
|
sl@0
|
120 |
/// SPI delegate
|
sl@0
|
121 |
CryptoSpi::CAsymmetricCipher* iAsymmetricCipherImpl;
|
sl@0
|
122 |
|
sl@0
|
123 |
/// SPI requires all key to passed as key-objects
|
sl@0
|
124 |
CryptoSpi::CKey* iKey;
|
sl@0
|
125 |
};
|
sl@0
|
126 |
|
sl@0
|
127 |
NONSHARABLE_CLASS(CRSAPKCS1v15SignerShim) : public CRSAPKCS1v15Signer
|
sl@0
|
128 |
{
|
sl@0
|
129 |
public:
|
sl@0
|
130 |
/**
|
sl@0
|
131 |
Creates a new CRSAPKCS1v15SignerShim object which has the same interface
|
sl@0
|
132 |
as CRSAPKCS1v15Signer but delegates all work to a Crypto SPI plug-in.
|
sl@0
|
133 |
|
sl@0
|
134 |
@param aKey The RSA private key to be used for signing
|
sl@0
|
135 |
@return A pointer to a CRSAPKCS1v15SignerShim instance
|
sl@0
|
136 |
@leave KErrKeySize If the key length is too small
|
sl@0
|
137 |
*/
|
sl@0
|
138 |
static CRSAPKCS1v15SignerShim* NewL(const CRSAPrivateKey& aKey);
|
sl@0
|
139 |
|
sl@0
|
140 |
/**
|
sl@0
|
141 |
Creates a new CRSAPKCS1v15SignerShim object which has the same interface
|
sl@0
|
142 |
as CRSAPKCS1v15Signer but delegates all work to a Crypto SPI plug-in.
|
sl@0
|
143 |
|
sl@0
|
144 |
@param aKey The RSA private key to be used for signing
|
sl@0
|
145 |
@return A pointer to a CRSAPKCS1v15SignerShim instance
|
sl@0
|
146 |
@leave KErrKeySize If the key length is too small
|
sl@0
|
147 |
*/
|
sl@0
|
148 |
static CRSAPKCS1v15SignerShim* NewLC(const CRSAPrivateKey& aKey);
|
sl@0
|
149 |
|
sl@0
|
150 |
// From CRSAPKCS1v15Signer
|
sl@0
|
151 |
virtual CRSASignature* SignL(const TDesC8& aInput) const;
|
sl@0
|
152 |
virtual TInt MaxInputLength(void) const;
|
sl@0
|
153 |
virtual TInt MaxOutputLength(void) const;
|
sl@0
|
154 |
/** The destructor frees all resources owned by the object, prior to its destruction.*/
|
sl@0
|
155 |
~CRSAPKCS1v15SignerShim(void);
|
sl@0
|
156 |
protected:
|
sl@0
|
157 |
|
sl@0
|
158 |
CRSAPKCS1v15SignerShim(const CRSAPrivateKey& aKey);
|
sl@0
|
159 |
void ConstructL(const CRSAPrivateKey& aKey);
|
sl@0
|
160 |
|
sl@0
|
161 |
protected:
|
sl@0
|
162 |
/// SPI delegate
|
sl@0
|
163 |
CryptoSpi::CSigner* iSignerImpl;
|
sl@0
|
164 |
|
sl@0
|
165 |
/// SPI requires all key to passed as key-objects
|
sl@0
|
166 |
CryptoSpi::CKey* iKey;
|
sl@0
|
167 |
private:
|
sl@0
|
168 |
CRSAPKCS1v15SignerShim(const CRSAPKCS1v15SignerShim&);
|
sl@0
|
169 |
CRSAPKCS1v15SignerShim& operator=(const CRSAPKCS1v15SignerShim&);
|
sl@0
|
170 |
};
|
sl@0
|
171 |
|
sl@0
|
172 |
/**
|
sl@0
|
173 |
* This class verifies RSA signatures given a message and its supposed
|
sl@0
|
174 |
* signature. It follows the RSA PKCS#1 v1.5 with PKCS#1 v1.5 padding specification
|
sl@0
|
175 |
* with the following exception: the VerifyL() function does <b>not</b> hash or
|
sl@0
|
176 |
* in any way manipulate the input data before checking. Thus in order to verify
|
sl@0
|
177 |
* RSA signatures in PKCS#1 v1.5 format, the input data needs to follow PKCS#1 v1.5
|
sl@0
|
178 |
* specification, i.e. be ASN.1 encoded and prefixed by ASN.1 encoded digestId.
|
sl@0
|
179 |
*
|
sl@0
|
180 |
* @internalComponent
|
sl@0
|
181 |
* @released
|
sl@0
|
182 |
*/
|
sl@0
|
183 |
NONSHARABLE_CLASS(CRSAPKCS1v15VerifierShim) : public CRSAPKCS1v15Verifier
|
sl@0
|
184 |
{
|
sl@0
|
185 |
public:
|
sl@0
|
186 |
/**
|
sl@0
|
187 |
@internalComponent
|
sl@0
|
188 |
|
sl@0
|
189 |
Creates a new CRSAPKCS1v15VerifierShim object which has the same interface
|
sl@0
|
190 |
as CRSAPKCS1v15Verifier but delegates all work to a Crypto SPI plug-in.
|
sl@0
|
191 |
|
sl@0
|
192 |
@param aKey The RSA public key to be used for verifying
|
sl@0
|
193 |
@return A pointer to a CRSAPKCS1v15VerifierShim instance
|
sl@0
|
194 |
@leave KErrKeySize If the key length is too small
|
sl@0
|
195 |
*/
|
sl@0
|
196 |
static CRSAPKCS1v15VerifierShim* NewL(const CRSAPublicKey& aKey);
|
sl@0
|
197 |
|
sl@0
|
198 |
/**
|
sl@0
|
199 |
@internalComponent
|
sl@0
|
200 |
|
sl@0
|
201 |
Creates a new CRSAPKCS1v15VerifierShim object which has the same interface
|
sl@0
|
202 |
as CRSAPKCS1v15Verifier but delegates all work to a Crypto SPI plug-in.
|
sl@0
|
203 |
|
sl@0
|
204 |
The returned pointer is put onto the cleanup stack.
|
sl@0
|
205 |
|
sl@0
|
206 |
@param aKey The RSA public key to be used for verifying
|
sl@0
|
207 |
@return A pointer to a CRSAPKCS1v15VerifierShim instance
|
sl@0
|
208 |
|
sl@0
|
209 |
@leave KErrKeySize If the key length is too small
|
sl@0
|
210 |
*/
|
sl@0
|
211 |
static CRSAPKCS1v15VerifierShim* NewLC(const CRSAPublicKey& aKey);
|
sl@0
|
212 |
|
sl@0
|
213 |
// CRSAPKCS1v15Verifier
|
sl@0
|
214 |
virtual TInt MaxInputLength(void) const;
|
sl@0
|
215 |
virtual TInt MaxOutputLength(void) const;
|
sl@0
|
216 |
|
sl@0
|
217 |
// RSAVerifier
|
sl@0
|
218 |
virtual TBool VerifyL(const TDesC8& aInput, const CRSASignature& aSignature) const;
|
sl@0
|
219 |
virtual HBufC8* InverseSignLC(const CRSASignature& aSignature) const;
|
sl@0
|
220 |
|
sl@0
|
221 |
/** The destructor frees all resources owned by the object, prior to its destruction. */
|
sl@0
|
222 |
virtual ~CRSAPKCS1v15VerifierShim(void);
|
sl@0
|
223 |
protected:
|
sl@0
|
224 |
CRSAPKCS1v15VerifierShim(const CRSAPublicKey& aKey);
|
sl@0
|
225 |
void ConstructL(const CRSAPublicKey& aKey);
|
sl@0
|
226 |
|
sl@0
|
227 |
protected:
|
sl@0
|
228 |
/// SPI delegate
|
sl@0
|
229 |
CryptoSpi::CVerifier* iVerifierImpl;
|
sl@0
|
230 |
|
sl@0
|
231 |
/// SPI requires all key to passed as key-objects
|
sl@0
|
232 |
CryptoSpi::CKey* iKey;
|
sl@0
|
233 |
private:
|
sl@0
|
234 |
CRSAPKCS1v15VerifierShim(const CRSAPKCS1v15VerifierShim&);
|
sl@0
|
235 |
CRSAPKCS1v15VerifierShim& operator=(const CRSAPKCS1v15VerifierShim&);
|
sl@0
|
236 |
};
|
sl@0
|
237 |
|
sl@0
|
238 |
#endif // __RSASHIM_H__
|