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