|
1 /* |
|
2 * Copyright (c) 2003-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 * ** IMPORTANT ** PublishedPartner API's in this file are published to 3rd party developers via the |
|
16 * Symbian website. Changes to these API's should be treated as PublishedAll API changes and the Security TA should be consulted. |
|
17 * Asymmetric crypto implementation |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 /** |
|
25 @file |
|
26 @internalAll |
|
27 */ |
|
28 |
|
29 #ifndef __ASYMMETRIC_H__ |
|
30 #define __ASYMMETRIC_H__ |
|
31 |
|
32 #include <padding.h> |
|
33 #include <asymmetrickeys.h> |
|
34 #include <random.h> |
|
35 #include <hash.h> |
|
36 |
|
37 // All the classes in this file have their default constructors and |
|
38 // assignment operators defined private, but not implemented, in order to |
|
39 // prevent their use. |
|
40 |
|
41 /** |
|
42 * Mixin class defining common operations for public key encryption and |
|
43 * decryption classes. |
|
44 * |
|
45 * @publishedPartner |
|
46 * @released |
|
47 */ |
|
48 class MCryptoSystem |
|
49 { |
|
50 public: |
|
51 /** |
|
52 * Gets the maximum size of input accepted by this object. |
|
53 * |
|
54 * @return The maximum input length allowed in bytes. |
|
55 */ |
|
56 virtual TInt MaxInputLength(void) const = 0; |
|
57 |
|
58 /** |
|
59 * Gets the maximum size of output that can be generated by this object. |
|
60 * |
|
61 * @return The maximum output length in bytes. |
|
62 */ |
|
63 virtual TInt MaxOutputLength(void) const = 0; |
|
64 protected: |
|
65 /** |
|
66 * Constructor |
|
67 */ |
|
68 IMPORT_C MCryptoSystem(void); |
|
69 private: |
|
70 MCryptoSystem(const MCryptoSystem&); |
|
71 MCryptoSystem& operator=(const MCryptoSystem&); |
|
72 }; |
|
73 |
|
74 /** |
|
75 * Abstract base class for all public key encryptors. |
|
76 * |
|
77 * @publishedPartner |
|
78 * @released |
|
79 */ |
|
80 class CEncryptor : public CBase, public MCryptoSystem |
|
81 { |
|
82 public: |
|
83 /** |
|
84 * Encrypts the specified plaintext into ciphertext. |
|
85 * |
|
86 * @param aInput The plaintext |
|
87 * @param aOutput On return, the ciphertext |
|
88 * |
|
89 * @panic KCryptoPanic If the input data is too long. |
|
90 * See ECryptoPanicInputTooLarge |
|
91 * @panic KCryptoPanic If the supplied output descriptor is not large enough to store the result. |
|
92 * See ECryptoPanicOutputDescriptorOverflow |
|
93 */ |
|
94 virtual void EncryptL(const TDesC8& aInput, TDes8& aOutput) const = 0; |
|
95 protected: |
|
96 /** Default constructor */ |
|
97 IMPORT_C CEncryptor(void); |
|
98 private: |
|
99 CEncryptor(const CEncryptor&); |
|
100 CEncryptor& operator=(const CEncryptor&); |
|
101 }; |
|
102 |
|
103 /** |
|
104 * Abstract base class for all public key decryptors. |
|
105 * |
|
106 * @publishedPartner |
|
107 * @released |
|
108 */ |
|
109 class CDecryptor : public CBase, public MCryptoSystem |
|
110 { |
|
111 public: |
|
112 /** |
|
113 * Decrypts the specified ciphertext into plaintext |
|
114 * |
|
115 * @param aInput The ciphertext to be decrypted |
|
116 * @param aOutput On return, the plaintext |
|
117 * |
|
118 * @panic KCryptoPanic If the input data is too long. |
|
119 * See ECryptoPanicInputTooLarge |
|
120 * @panic KCryptoPanic If the supplied output descriptor is not large enough to store the result. |
|
121 * See ECryptoPanicOutputDescriptorOverflow |
|
122 */ |
|
123 virtual void DecryptL(const TDesC8& aInput, TDes8& aOutput) const = 0; |
|
124 protected: |
|
125 /** Default constructor */ |
|
126 IMPORT_C CDecryptor(void); |
|
127 private: |
|
128 CDecryptor(const CDecryptor&); |
|
129 CDecryptor& operator=(const CDecryptor&); |
|
130 }; |
|
131 |
|
132 /** |
|
133 * Implementation of RSA encryption as described in PKCS#1 v1.5. |
|
134 * |
|
135 * @publishedPartner |
|
136 * @released |
|
137 */ |
|
138 class CRSAPKCS1v15Encryptor : public CEncryptor |
|
139 { |
|
140 public: |
|
141 /** |
|
142 * Creates a new RSA encryptor object using PKCS#1 v1.5 padding. |
|
143 * |
|
144 * @param aKey The RSA encryption key |
|
145 * @return A pointer to a new CRSAPKCS1v15Encryptor object |
|
146 * |
|
147 * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the |
|
148 * cipher strength restrictions of the crypto library. |
|
149 * See TCrypto::IsAsymmetricWeakEnoughL() |
|
150 * @leave KErrKeySize If the key length is too small |
|
151 */ |
|
152 IMPORT_C static CRSAPKCS1v15Encryptor* NewL(const CRSAPublicKey& aKey); |
|
153 |
|
154 /** |
|
155 * Creates a new RSA encryptor object using PKCS#1 v1.5 padding. |
|
156 * |
|
157 * The returned pointer is put onto the cleanup stack. |
|
158 * |
|
159 * @param aKey The RSA encryption key |
|
160 * @return A pointer to a new CRSAPKCS1v15Encryptor object |
|
161 * |
|
162 * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the |
|
163 * cipher strength restrictions of the crypto library. |
|
164 * See TCrypto::IsAsymmetricWeakEnoughL() |
|
165 * @leave KErrKeySize If the key length is too small |
|
166 */ |
|
167 IMPORT_C static CRSAPKCS1v15Encryptor* NewLC(const CRSAPublicKey& aKey); |
|
168 void EncryptL(const TDesC8& aInput, TDes8& aOutput) const; |
|
169 TInt MaxInputLength(void) const; |
|
170 TInt MaxOutputLength(void) const; |
|
171 /** The destructor frees all resources owned by the object, prior to its destruction. */ |
|
172 virtual ~CRSAPKCS1v15Encryptor(void); |
|
173 protected: |
|
174 /** @internalAll */ |
|
175 CRSAPKCS1v15Encryptor(const CRSAPublicKey& aKey); |
|
176 /** @internalAll */ |
|
177 void ConstructL(void); |
|
178 protected: |
|
179 /** The RSA public key */ |
|
180 const CRSAPublicKey& iPublicKey; |
|
181 /** The PKCS#1 v1.5 encryption padding */ |
|
182 CPaddingPKCS1Encryption* iPadding; |
|
183 private: |
|
184 CRSAPKCS1v15Encryptor(const CRSAPKCS1v15Encryptor&); |
|
185 CRSAPKCS1v15Encryptor& operator=(const CRSAPKCS1v15Encryptor&); |
|
186 }; |
|
187 |
|
188 /** |
|
189 * Implementation of RSA decryption as described in PKCS#1 v1.5. |
|
190 * |
|
191 * @publishedPartner |
|
192 * @released |
|
193 */ |
|
194 class CRSAPKCS1v15Decryptor : public CDecryptor |
|
195 { |
|
196 public: |
|
197 /** |
|
198 * Creates a new RSA decryptor object using PKCS#1 v1.5 padding. |
|
199 * |
|
200 * @param aKey The RSA private key for decryption |
|
201 * |
|
202 * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the |
|
203 * cipher strength restrictions of the crypto library. |
|
204 * See TCrypto::IsAsymmetricWeakEnoughL() |
|
205 * @leave KErrKeySize If the key length is too small |
|
206 */ |
|
207 IMPORT_C static CRSAPKCS1v15Decryptor* NewL(const CRSAPrivateKey& aKey); |
|
208 |
|
209 /** |
|
210 * Creates a new RSA decryptor object using PKCS#1 v1.5 padding |
|
211 * |
|
212 * The returned pointer is put onto the cleanup stack. |
|
213 * |
|
214 * @param aKey The RSA private key for decryption |
|
215 * |
|
216 * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the |
|
217 * cipher strength restrictions of the crypto library. |
|
218 * See TCrypto::IsAsymmetricWeakEnoughL() |
|
219 * @leave KErrKeySize If the key length is too small |
|
220 * @leave KErrNotSupported If the RSA private key is not a supported TRSAPrivateKeyType |
|
221 */ |
|
222 IMPORT_C static CRSAPKCS1v15Decryptor* NewLC(const CRSAPrivateKey& aKey); |
|
223 void DecryptL(const TDesC8& aInput, TDes8& aOutput) const; |
|
224 TInt MaxInputLength(void) const; |
|
225 TInt MaxOutputLength(void) const; |
|
226 /** The destructor frees all resources owned by the object, prior to its destruction. */ |
|
227 virtual ~CRSAPKCS1v15Decryptor(void); |
|
228 protected: |
|
229 /** @internalAll */ |
|
230 CRSAPKCS1v15Decryptor(const CRSAPrivateKey& aKey); |
|
231 /** @internalAll */ |
|
232 void ConstructL(void); |
|
233 protected: |
|
234 /** The RSA private key */ |
|
235 const CRSAPrivateKey& iPrivateKey; |
|
236 /** The PKCS#1 v1.5 encryption padding */ |
|
237 CPaddingPKCS1Encryption* iPadding; |
|
238 private: |
|
239 CRSAPKCS1v15Decryptor(const CRSAPKCS1v15Decryptor&); |
|
240 CRSAPKCS1v15Decryptor& operator=(const CRSAPKCS1v15Decryptor&); |
|
241 }; |
|
242 |
|
243 /** |
|
244 * Mixin class defining operations common to all public key signature systems. |
|
245 * |
|
246 * @publishedPartner |
|
247 * @released |
|
248 */ |
|
249 class MSignatureSystem |
|
250 { |
|
251 public: |
|
252 /** |
|
253 * Gets the maximum size of input accepted by this object. |
|
254 * |
|
255 * @return The maximum length allowed in bytes |
|
256 */ |
|
257 virtual TInt MaxInputLength(void) const = 0; |
|
258 protected: |
|
259 /** Constructor */ |
|
260 IMPORT_C MSignatureSystem(void); |
|
261 private: |
|
262 MSignatureSystem(const MSignatureSystem&); |
|
263 MSignatureSystem& operator=(const MSignatureSystem&); |
|
264 }; |
|
265 |
|
266 /** |
|
267 * Abstract base class for all public key signers. |
|
268 * |
|
269 * The template parameter, CSignature, should be a class that encapsulates the |
|
270 * concept of a digital signature. Derived signature classes must own their |
|
271 * respective signatures (and hence be CBase derived). There are no other |
|
272 * restrictions on the formation of the signature classes. |
|
273 * |
|
274 * @publishedPartner |
|
275 * @released |
|
276 */ |
|
277 template <class CSignature> class CSigner : public CBase, public MSignatureSystem |
|
278 { |
|
279 public: |
|
280 /** |
|
281 * Digitally signs the specified input message |
|
282 * |
|
283 * @param aInput The raw data to sign, typically a hash of the actual message |
|
284 * @return A pointer to a new CSignature object |
|
285 * |
|
286 * @panic ECryptoPanicInputTooLarge If aInput is larger than MaxInputLength(), |
|
287 * which is likely to happen if the caller |
|
288 * has passed in something that has not been |
|
289 * hashed. |
|
290 */ |
|
291 virtual CSignature* SignL(const TDesC8& aInput) const = 0; |
|
292 protected: |
|
293 /** @internalAll */ |
|
294 CSigner(void); |
|
295 private: |
|
296 CSigner(const CSigner&); |
|
297 CSigner& operator=(const CSigner&); |
|
298 }; |
|
299 |
|
300 /** |
|
301 * Abstract class for all public key verifiers. |
|
302 * |
|
303 * The template parameter, CSignature, should be a class that encapsulates the |
|
304 * concept of a digital signature. Derived signature classes must own their |
|
305 * respective signatures (and hence be CBase derived). There are no other |
|
306 * restrictions on the formation of the signature classes. |
|
307 * |
|
308 * @publishedPartner |
|
309 * @released |
|
310 */ |
|
311 template <class CSignature> class CVerifier : public CBase, public MSignatureSystem |
|
312 { |
|
313 public: |
|
314 /** |
|
315 * Verifies the specified digital signature |
|
316 * |
|
317 * @param aInput The message digest that was originally signed |
|
318 * @param aSignature The signature to be verified |
|
319 * |
|
320 * @return Whether the signature is the result of signing |
|
321 * aInput with the supplied key |
|
322 */ |
|
323 virtual TBool VerifyL(const TDesC8& aInput, |
|
324 const CSignature& aSignature) const = 0; |
|
325 protected: |
|
326 /** @internalAll */ |
|
327 CVerifier(void); |
|
328 private: |
|
329 CVerifier(const CVerifier&); |
|
330 CVerifier& operator=(const CVerifier&); |
|
331 }; |
|
332 |
|
333 /* Template nastiness for CVerifier and CSigner in asymmetric.inl */ |
|
334 |
|
335 #include <asymmetric.inl> |
|
336 |
|
337 /** |
|
338 * An encapsulation of a RSA signature. |
|
339 * |
|
340 * @publishedPartner |
|
341 * @released |
|
342 */ |
|
343 class CRSASignature : public CBase |
|
344 { |
|
345 public: |
|
346 /** |
|
347 * Creates a new CRSASignature object from the integer value |
|
348 * output of a previous RSA signing operation. |
|
349 * |
|
350 * @param aS The integer value output from a previous RSA signing operation |
|
351 * @return A pointer to the new CRSASignature object. |
|
352 */ |
|
353 IMPORT_C static CRSASignature* NewL(RInteger& aS); |
|
354 |
|
355 /** |
|
356 * Creates a new CRSASignature object from the integer value |
|
357 * output of a previous RSA signing operation. |
|
358 * |
|
359 * The returned pointer is put onto the cleanup stack. |
|
360 * |
|
361 * @param aS The integer value output from a previous RSA signing operation |
|
362 * @return A pointer to the new CRSASignature object. |
|
363 */ |
|
364 IMPORT_C static CRSASignature* NewLC(RInteger& aS); |
|
365 |
|
366 /** |
|
367 * Gets the integer value of the RSA signature |
|
368 * |
|
369 * @return The integer value of the RSA signature |
|
370 */ |
|
371 IMPORT_C const TInteger& S(void) const; |
|
372 |
|
373 /** |
|
374 * Whether this RSASignature is identical to a specified RSASignature |
|
375 * |
|
376 * @param aSig The RSASignature for comparison |
|
377 * @return ETrue, if the two signatures are identical; EFalse, otherwise. |
|
378 */ |
|
379 IMPORT_C TBool operator== (const CRSASignature& aSig) const; |
|
380 |
|
381 /** Destructor */ |
|
382 /** The destructor frees all resources owned by the object, prior to its destruction. */ |
|
383 IMPORT_C virtual ~CRSASignature(void); |
|
384 protected: |
|
385 /** |
|
386 * Second phase constructor |
|
387 * |
|
388 * @see CRSASignature::NewL() |
|
389 * |
|
390 * @param aS The integer value output from a previous RSA signing operation |
|
391 */ |
|
392 IMPORT_C CRSASignature(RInteger& aS); |
|
393 |
|
394 /** Default constructor */ |
|
395 IMPORT_C CRSASignature(void); |
|
396 protected: |
|
397 /** An integer value; the output from a previous RSA signing operation. */ |
|
398 RInteger iS; |
|
399 private: |
|
400 CRSASignature(const CRSASignature&); |
|
401 CRSASignature& operator=(const CRSASignature); |
|
402 }; |
|
403 |
|
404 /** |
|
405 * Abstract base class for all RSA Signers. |
|
406 * |
|
407 * @publishedPartner |
|
408 * @released |
|
409 */ |
|
410 class CRSASigner : public CSigner<CRSASignature> |
|
411 { |
|
412 public: |
|
413 /** |
|
414 * Gets the maximum size of output that can be generated by this object. |
|
415 * |
|
416 * @return The maximum output length in bytes |
|
417 */ |
|
418 virtual TInt MaxOutputLength(void) const = 0; |
|
419 protected: |
|
420 /** Default constructor */ |
|
421 IMPORT_C CRSASigner(void); |
|
422 private: |
|
423 CRSASigner(const CRSASigner&); |
|
424 CRSASigner& operator=(const CRSASigner&); |
|
425 }; |
|
426 |
|
427 /** |
|
428 * Implementation of RSA signing as described in PKCS#1 v1.5. |
|
429 * |
|
430 * This class creates RSA signatures following the RSA PKCS#1 v1.5 standard (with |
|
431 * the one caveat noted below) and using PKCS#1 v1.5 signature padding. The only |
|
432 * exception is that the SignL() function simply performs a 'raw' PKCS#1 v1.5 sign |
|
433 * operation on whatever it is given. It does <b>not</b> hash or in any way |
|
434 * manipulate the input data before signing. |
|
435 * |
|
436 * @publishedPartner |
|
437 * @released |
|
438 */ |
|
439 class CRSAPKCS1v15Signer : public CRSASigner |
|
440 { |
|
441 public: |
|
442 /** |
|
443 * Creates a new CRSAPKCS1v15Signer object from a specified RSA private key. |
|
444 * |
|
445 * @param aKey The RSA private key to be used for signing |
|
446 * @return A pointer to the new CRSAPKCS1v15Signer object |
|
447 * |
|
448 * @leave KErrKeySize If the key length is too small |
|
449 */ |
|
450 IMPORT_C static CRSAPKCS1v15Signer* NewL(const CRSAPrivateKey& aKey); |
|
451 |
|
452 /** |
|
453 * Creates a new CRSAPKCS1v15Signer object from a specified RSA private key. |
|
454 * |
|
455 * The returned pointer is put onto the cleanup stack. |
|
456 * |
|
457 * @param aKey The RSA private key to be used for signing |
|
458 * @return A pointer to the new CRSAPKCS1v15Signer object |
|
459 * |
|
460 * @leave KErrKeySize If the key length is too small |
|
461 */ |
|
462 IMPORT_C static CRSAPKCS1v15Signer* NewLC(const CRSAPrivateKey& aKey); |
|
463 /** |
|
464 * Digitally signs the specified input message |
|
465 * |
|
466 * @param aInput The raw data to sign, typically a hash of the actual message |
|
467 * @return A pointer to a new CSignature object |
|
468 * |
|
469 * @leave KErrNotSupported If the private key is not a supported TRSAPrivateKeyType |
|
470 * @panic ECryptoPanicInputTooLarge If aInput is larger than MaxInputLength(), |
|
471 * which is likely to happen if the caller |
|
472 * has passed in something that has not been hashed. |
|
473 */ |
|
474 virtual CRSASignature* SignL(const TDesC8& aInput) const; |
|
475 virtual TInt MaxInputLength(void) const; |
|
476 virtual TInt MaxOutputLength(void) const; |
|
477 /** The destructor frees all resources owned by the object, prior to its destruction. |
|
478 * @internalAll */ |
|
479 ~CRSAPKCS1v15Signer(void); |
|
480 protected: |
|
481 /** @internalAll */ |
|
482 CRSAPKCS1v15Signer(const CRSAPrivateKey& aKey); |
|
483 /** @internalAll */ |
|
484 void ConstructL(void); |
|
485 protected: |
|
486 /** The RSA private key to be used for signing */ |
|
487 const CRSAPrivateKey& iPrivateKey; |
|
488 /** The PKCS#1 v1.5 signature padding */ |
|
489 CPaddingPKCS1Signature* iPadding; |
|
490 private: |
|
491 CRSAPKCS1v15Signer(const CRSAPKCS1v15Signer&); |
|
492 CRSAPKCS1v15Signer& operator=(const CRSAPKCS1v15Signer&); |
|
493 }; |
|
494 |
|
495 /** |
|
496 * Abstract base class for all RSA Verifiers. |
|
497 * |
|
498 * @publishedPartner |
|
499 * @released |
|
500 */ |
|
501 class CRSAVerifier : public CVerifier<CRSASignature> |
|
502 { |
|
503 public: |
|
504 /** |
|
505 * Gets the maximum size of output that can be generated by this object. |
|
506 * |
|
507 * @return The maximum output length in bytes |
|
508 */ |
|
509 virtual TInt MaxOutputLength(void) const = 0; |
|
510 |
|
511 /** |
|
512 * Performs a decryption operation on a signature using the public key. |
|
513 * |
|
514 * This is the inverse of the sign operation, which performs a encryption |
|
515 * operation on its input data using the private key. Although this can be |
|
516 * used to verify signatures, CRSAVerifier::VerifyL should be used in |
|
517 * preference. This method is however required by some security protocols. |
|
518 * |
|
519 * @param aSignature The signature to be verified |
|
520 * @return A pointer to a new buffer containing the result of the |
|
521 * operation. The pointer is left on the cleanup stack. |
|
522 */ |
|
523 virtual HBufC8* InverseSignLC(const CRSASignature& aSignature) const = 0; |
|
524 |
|
525 IMPORT_C virtual TBool VerifyL(const TDesC8& aInput, |
|
526 const CRSASignature& aSignature) const; |
|
527 protected: |
|
528 /** Default constructor */ |
|
529 IMPORT_C CRSAVerifier(void); |
|
530 private: |
|
531 CRSAVerifier(const CRSAVerifier&); |
|
532 CRSAVerifier& operator=(const CRSAVerifier&); |
|
533 }; |
|
534 |
|
535 /** |
|
536 * This class verifies RSA signatures given a message and its supposed |
|
537 * signature. It follows the RSA PKCS#1 v1.5 with PKCS#1 v1.5 padding specification |
|
538 * with the following exception: the VerifyL() function does <b>not</b> hash or |
|
539 * in any way manipulate the input data before checking. Thus in order to verify |
|
540 * RSA signatures in PKCS#1 v1.5 format, the input data needs to follow PKCS#1 v1.5 |
|
541 * specification, i.e. be ASN.1 encoded and prefixed by ASN.1 encoded digestId. |
|
542 * |
|
543 * @publishedPartner |
|
544 * @released |
|
545 */ |
|
546 class CRSAPKCS1v15Verifier : public CRSAVerifier |
|
547 { |
|
548 public: |
|
549 /** |
|
550 * Creates a new CRSAPKCS1v15Verifier object from a specified RSA public key. |
|
551 * |
|
552 * @param aKey The RSA public key to be used for verifying |
|
553 * @return A pointer to the new CRSAPKCS1v15Verifier object |
|
554 * |
|
555 * @leave KErrKeySize If the key length is too small |
|
556 */ |
|
557 IMPORT_C static CRSAPKCS1v15Verifier* NewL(const CRSAPublicKey& aKey); |
|
558 |
|
559 /** |
|
560 * Creates a new CRSAPKCS1v15Verifier object from a specified RSA public key. |
|
561 * |
|
562 * The returned pointer is put onto the cleanup stack. |
|
563 * |
|
564 * @param aKey The RSA public key to be used for verifying |
|
565 * @return A pointer to the new CRSAPKCS1v15Verifier object |
|
566 * |
|
567 * @leave KErrKeySize If the key length is too small |
|
568 */ |
|
569 IMPORT_C static CRSAPKCS1v15Verifier* NewLC(const CRSAPublicKey& aKey); |
|
570 virtual HBufC8* InverseSignLC(const CRSASignature& aSignature) const; |
|
571 virtual TInt MaxInputLength(void) const; |
|
572 virtual TInt MaxOutputLength(void) const; |
|
573 /** The destructor frees all resources owned by the object, prior to its destruction. */ |
|
574 virtual ~CRSAPKCS1v15Verifier(void); |
|
575 protected: |
|
576 /** @internalAll */ |
|
577 CRSAPKCS1v15Verifier(const CRSAPublicKey& aKey); |
|
578 /** @internalAll */ |
|
579 void ConstructL(void); |
|
580 protected: |
|
581 /** The RSA public key to be used for verification */ |
|
582 const CRSAPublicKey& iPublicKey; |
|
583 /** The PKCS#1 v1.5 signature padding */ |
|
584 CPaddingPKCS1Signature* iPadding; |
|
585 private: |
|
586 CRSAPKCS1v15Verifier(const CRSAPKCS1v15Verifier&); |
|
587 CRSAPKCS1v15Verifier& operator=(const CRSAPKCS1v15Verifier&); |
|
588 }; |
|
589 |
|
590 /** |
|
591 * An encapsulation of a DSA signature. |
|
592 * |
|
593 * @publishedPartner |
|
594 * @released |
|
595 */ |
|
596 class CDSASignature : public CBase |
|
597 { |
|
598 public: |
|
599 /** |
|
600 * Creates a new CDSASignature object from the specified R and S values. |
|
601 * |
|
602 * @param aR The DSA signature's R value |
|
603 * @param aS The DSA signature's S value |
|
604 * @return A pointer to the new CDSASignature object |
|
605 */ |
|
606 IMPORT_C static CDSASignature* NewL(RInteger& aR, RInteger& aS); |
|
607 |
|
608 /** |
|
609 * Creates a new CDSASignature object from the specified R and S values. |
|
610 * |
|
611 * The returned pointer is put onto the cleanup stack. |
|
612 * |
|
613 * @param aR The DSA signature's R value |
|
614 * @param aS The DSA signature's S value |
|
615 * @return A pointer to the new CDSASignature object |
|
616 */ |
|
617 IMPORT_C static CDSASignature* NewLC(RInteger& aR, RInteger& aS); |
|
618 |
|
619 /** |
|
620 * Gets the DSA signature's R value |
|
621 * |
|
622 * @return The R value |
|
623 */ |
|
624 IMPORT_C const TInteger& R(void) const; |
|
625 |
|
626 /** |
|
627 * Gets the DSA signature's S value |
|
628 * |
|
629 * @return The S value |
|
630 */ |
|
631 IMPORT_C const TInteger& S(void) const; |
|
632 |
|
633 /** |
|
634 * Whether this DSASignature is identical to a specified DSASignature |
|
635 * |
|
636 * @param aSig The DSASignature for comparison |
|
637 * @return ETrue, if the two signatures are identical; EFalse, otherwise. |
|
638 */ |
|
639 IMPORT_C TBool operator== (const CDSASignature& aSig) const; |
|
640 |
|
641 /** The destructor frees all resources owned by the object, prior to its destruction. */ |
|
642 IMPORT_C virtual ~CDSASignature(void); |
|
643 protected: |
|
644 /** |
|
645 * Protected constructor |
|
646 * |
|
647 * @param aR The DSA signature's R value |
|
648 * @param aS The DSA signature's S value |
|
649 */ |
|
650 IMPORT_C CDSASignature(RInteger& aR, RInteger& aS); |
|
651 |
|
652 /** Default constructor */ |
|
653 IMPORT_C CDSASignature(void); |
|
654 protected: |
|
655 /** The DSA signature's R value */ |
|
656 RInteger iR; |
|
657 /** The DSA signature's S value */ |
|
658 RInteger iS; |
|
659 private: |
|
660 CDSASignature(const CDSASignature&); |
|
661 CDSASignature& operator=(const CDSASignature&); |
|
662 }; |
|
663 |
|
664 /** |
|
665 * Implementation of DSA signing as specified in FIPS 186-2 change request 1. |
|
666 * |
|
667 * @publishedPartner |
|
668 * @released |
|
669 */ |
|
670 class CDSASigner : public CSigner<CDSASignature> |
|
671 { |
|
672 public: |
|
673 /** |
|
674 * Creates a new CDSASigner object from a specified DSA private key. |
|
675 * |
|
676 * @param aKey The DSA private key to be used for signing |
|
677 * @return A pointer to the new CDSASigner object |
|
678 */ |
|
679 IMPORT_C static CDSASigner* NewL(const CDSAPrivateKey& aKey); |
|
680 |
|
681 /** |
|
682 * Creates a new CDSASigner object from a specified DSA private key. |
|
683 * |
|
684 * The returned pointer is put onto the cleanup stack. |
|
685 * |
|
686 * @param aKey The DSA private key to be used for signing |
|
687 * @return A pointer to the new CDSASigner object |
|
688 */ |
|
689 IMPORT_C static CDSASigner* NewLC(const CDSAPrivateKey& aKey); |
|
690 /** |
|
691 * Digitally signs the specified input message |
|
692 * |
|
693 * Note that in order to be interoperable and compliant with the DSS, aInput |
|
694 * must be the result of a SHA-1 hash. |
|
695 * |
|
696 * @param aInput A SHA-1 hash of the message to sign |
|
697 * @return A pointer to a new CSignature object |
|
698 * |
|
699 * @panic ECryptoPanicInputTooLarge If aInput is larger than MaxInputLength(), |
|
700 * which is likely to happen if the caller |
|
701 * has passed in something that has not been hashed. |
|
702 */ |
|
703 virtual CDSASignature* SignL(const TDesC8& aInput) const; |
|
704 virtual TInt MaxInputLength(void) const; |
|
705 protected: |
|
706 /** @internalAll */ |
|
707 CDSASigner(const CDSAPrivateKey& aKey); |
|
708 protected: |
|
709 /** The DSA private key to be used for signing */ |
|
710 const CDSAPrivateKey& iPrivateKey; |
|
711 private: |
|
712 CDSASigner(const CDSASigner&); |
|
713 CDSASigner& operator=(const CDSASigner&); |
|
714 }; |
|
715 |
|
716 /** |
|
717 * Implementation of DSA signature verification as specified in FIPS 186-2 change |
|
718 * request 1. |
|
719 * |
|
720 * @publishedPartner |
|
721 * @released |
|
722 */ |
|
723 class CDSAVerifier : public CVerifier<CDSASignature> |
|
724 { |
|
725 public: |
|
726 /** |
|
727 * Creates a new CDSAVerifier object from a specified DSA public key. |
|
728 * |
|
729 * @param aKey The DSA public key to be used for verifying |
|
730 * @return A pointer to the new CDSAVerifier object |
|
731 */ |
|
732 IMPORT_C static CDSAVerifier* NewL(const CDSAPublicKey& aKey); |
|
733 |
|
734 /** |
|
735 * Creates a new CDSAVerifier object from a specified DSA public key. |
|
736 * |
|
737 * The returned pointer is put onto the cleanup stack. |
|
738 * |
|
739 * @param aKey The DSA public key to be used for verifying |
|
740 * @return A pointer to the new CDSAVerifier object |
|
741 */ |
|
742 IMPORT_C static CDSAVerifier* NewLC(const CDSAPublicKey& aKey); |
|
743 /** |
|
744 * Verifies the specified digital signature |
|
745 * |
|
746 * Note that in order to be interoperable and compliant with the DSS, aInput |
|
747 * must be the result of a SHA-1 hash. |
|
748 * |
|
749 * @param aInput A SHA-1 hash of the received message |
|
750 * @param aSignature The signature to be verified |
|
751 * |
|
752 * @return Whether the signature is the result of signing |
|
753 * aInput with the supplied key |
|
754 */ |
|
755 virtual TBool VerifyL(const TDesC8& aInput, const CDSASignature& aSignature) const; |
|
756 virtual TInt MaxInputLength(void) const; |
|
757 protected: |
|
758 /** @internalAll */ |
|
759 CDSAVerifier(const CDSAPublicKey& aKey); |
|
760 protected: |
|
761 /** The DSA public key to be used for verification */ |
|
762 const CDSAPublicKey& iPublicKey; |
|
763 private: |
|
764 CDSAVerifier(const CDSAVerifier&); |
|
765 CDSAVerifier& operator=(const CDSAVerifier&); |
|
766 }; |
|
767 |
|
768 /** |
|
769 * Implementation of Diffie-Hellman key agreement as specified in PKCS#3. |
|
770 * |
|
771 * @publishedPartner |
|
772 * @released |
|
773 */ |
|
774 class CDH : public CBase |
|
775 { |
|
776 public: |
|
777 /** |
|
778 * Creates a new CDH object from a specified DH private key. |
|
779 * |
|
780 * @param aPrivateKey The private key of this party |
|
781 * @return A pointer to the new CDH object |
|
782 */ |
|
783 IMPORT_C static CDH* NewL(const CDHPrivateKey& aPrivateKey); |
|
784 |
|
785 /** |
|
786 * Creates a new CDH object from a specified DH private key. |
|
787 * |
|
788 * The returned pointer is put onto the cleanup stack. |
|
789 * |
|
790 * @param aPrivateKey The private key of this party |
|
791 * @return A pointer to the new CDH object |
|
792 */ |
|
793 IMPORT_C static CDH* NewLC(const CDHPrivateKey& aPrivateKey); |
|
794 |
|
795 /** |
|
796 * Performs the key agreement operation. |
|
797 * |
|
798 * @param aPublicKey The public key of the other party |
|
799 * @return The agreed key |
|
800 */ |
|
801 IMPORT_C HBufC8* AgreeL(const CDHPublicKey& aPublicKey) const; |
|
802 protected: |
|
803 /** |
|
804 * Constructor |
|
805 * |
|
806 * @param aPrivateKey The DH private key |
|
807 */ |
|
808 IMPORT_C CDH(const CDHPrivateKey& aPrivateKey); |
|
809 protected: |
|
810 /** The DH private key */ |
|
811 const CDHPrivateKey& iPrivateKey; |
|
812 private: |
|
813 CDH(const CDH&); |
|
814 CDH& operator=(const CDH&); |
|
815 }; |
|
816 |
|
817 #endif // __ASYMMETRIC_H__ |