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