crypto/weakcryptospi/inc/spi/cryptosignatureapi.h
changeset 8 35751d3474b7
child 33 cf642210ecb7
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
       
     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 * crypto signature application interface
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file
       
    22  @publishedPartner
       
    23  @released
       
    24 */
       
    25 
       
    26 #ifndef __CRYPTOAPI_SIGNATUREAPI_H__
       
    27 #define __CRYPTOAPI_SIGNATUREAPI_H__
       
    28 
       
    29 #include <cryptospi/cryptobaseapi.h>
       
    30 
       
    31 namespace CryptoSpi
       
    32 	{
       
    33 	class CKey;
       
    34 	class MSignatureBase;
       
    35 	class MSigner;
       
    36 	class CCryptoParams;
       
    37 	class MAsyncSigner;
       
    38 	class MVerifier;
       
    39 	class MAsyncVerifier;
       
    40 	
       
    41 	/**
       
    42 	Base class for signer and verifier
       
    43 	*/
       
    44 	NONSHARABLE_CLASS(CSignatureBase) : public CCryptoBase
       
    45 		{
       
    46 	public:
       
    47 
       
    48 		/**
       
    49 		Set the padding mode for the signer or verifier. Reset() is called to reinitialise the cipher.
       
    50 		@param aPaddingMode	The padding mode of the signer
       
    51 		*/
       
    52 		IMPORT_C void SetPaddingModeL(TUid aPaddingMode);
       
    53 
       
    54 		/**
       
    55 		Set the private key for the signer or verifier. Reset() is called to reinitialise the cipher.
       
    56 		@param aPrivateKey	The privatekey that used to sign
       
    57 		*/
       
    58 		IMPORT_C void SetKeyL(const CKey& aPrivateKey);
       
    59 
       
    60 		/**
       
    61 		Gets the maximum size of input accepted by this object.
       
    62 		@return The maximum length allowed in bytes
       
    63 		*/
       
    64 		IMPORT_C TInt GetMaximumInputLengthL() const;
       
    65 
       
    66 		/**
       
    67 		Gets the maximum size of output that can be generated by this object.
       
    68 		@return The maximum output length in bytes
       
    69 		*/	 
       
    70 		IMPORT_C TInt GetMaximumOutputLengthL() const;
       
    71 
       
    72 		/**
       
    73 		Destructor
       
    74 		*/
       
    75 		virtual ~CSignatureBase();
       
    76 	
       
    77 	protected:
       
    78 		/**
       
    79 		 * @internalComponent
       
    80 		 *
       
    81 		 * Constructor
       
    82 		 **/
       
    83 		CSignatureBase(MSignatureBase* aSignatureProcessor, TInt aHandle);
       
    84 		};
       
    85 
       
    86 
       
    87 	/**
       
    88 	Synchronous signer API, which wraps a synchronous signer plugin implementation
       
    89 	*/
       
    90 	NONSHARABLE_CLASS(CSigner) : public CSignatureBase
       
    91 		{
       
    92 	public:
       
    93 		/**
       
    94 		 * @internalComponent
       
    95 		 *
       
    96 		 * Create a CSigner instance from the given MSigner instance
       
    97 		 * @param aSigner	The signer plugin instance
       
    98 		 * @return A pointer to a CSigner instance
       
    99 		 **/
       
   100 		static CSigner* NewL(MSigner* aSigner, TInt aHandle);
       
   101 
       
   102 		/**
       
   103 		Destructor
       
   104 		*/
       
   105 		IMPORT_C ~CSigner();
       
   106 
       
   107 		/**
       
   108 		Signs the input hash
       
   109 		@param aInput	The hash of the message to sign
       
   110 		@param aSignature	The signature of the hash 
       
   111 		*/
       
   112 		IMPORT_C void SignL(const TDesC8& aInput, CCryptoParams& aSignature);
       
   113 
       
   114 	private:
       
   115 		CSigner(MSigner* aSigner, TInt aHandle);
       
   116 		};
       
   117 
       
   118 	/**
       
   119 	Asynchronous signer API, which wraps an asynchronous signer plugin implementation
       
   120 	*/
       
   121 	NONSHARABLE_CLASS(CAsyncSigner) : public CSignatureBase
       
   122 		{
       
   123 	public:
       
   124 
       
   125 		/**
       
   126 		 * @internalComponent
       
   127 		 *
       
   128 		 * Create a CAsyncSigner instance from the given MAsyncSigner instance
       
   129 		 * @param aAsyncSigner The async signer plugin instance
       
   130 		 * @return A pointer to a CAsyncSigner instance
       
   131 		 **/
       
   132 		static CAsyncSigner* NewL(MAsyncSigner* aAsyncSigner, TInt aHandle);
       
   133 
       
   134 		/**
       
   135 		Destructor
       
   136 		*/
       
   137 		IMPORT_C ~CAsyncSigner();
       
   138 
       
   139 		/**
       
   140 		Set the public key for the signer
       
   141 		@param aInput	The hash of the message to sign
       
   142 		@param aSignature	The signature of the hash 
       
   143 		@param aRequestStatus
       
   144 		*/
       
   145 		IMPORT_C void SignL(const TDesC8& aInput, CCryptoParams& aSignature, TRequestStatus& aRequestStatus);
       
   146 
       
   147 		/**
       
   148 		Cancel the outstanding request
       
   149 		*/
       
   150 		IMPORT_C void Cancel();
       
   151 
       
   152 	private:
       
   153 
       
   154 		CAsyncSigner(MAsyncSigner* aAsyncSigner, TInt aHandle);
       
   155 		};
       
   156 	
       
   157 	/**
       
   158 	Synchronous verifier API, which wraps a synchronous verifier plugin implementation
       
   159 	*/
       
   160 	NONSHARABLE_CLASS(CVerifier) : public CSignatureBase
       
   161 		{
       
   162 	public:
       
   163 
       
   164 		/**
       
   165 		 * @internalComponent
       
   166 		 *
       
   167 		 * Create a CVerifier instance from the given MVerifier instance
       
   168 		 * @param aVerifier	The verifier plugin instance
       
   169 		 * @return A pointer to a CVerifier instance
       
   170 		 **/
       
   171 		static CVerifier* NewL(MVerifier* aVerifier, TInt aHandle);
       
   172 
       
   173 		/**
       
   174 		Destructor
       
   175 		*/
       
   176 		IMPORT_C ~CVerifier();
       
   177 
       
   178 		/**
       
   179 		Verify the signature
       
   180 		@param aInput	The hash of the message to be verified
       
   181 		@param aSignature	The signature of the hash
       
   182 		@param aVerificationResult indicates the success or failure of the verification
       
   183 		*/
       
   184 		IMPORT_C void VerifyL(const TDesC8& aInput, const CCryptoParams& aSignature, TBool& aVerificationResult);
       
   185 
       
   186 		/**
       
   187 		Unsign the signature
       
   188 		@param aOutput	The unsigned hash
       
   189 		@param aSignature	The signature of the hash
       
   190 		*/
       
   191 		IMPORT_C void InverseSignL(HBufC8*& aOutput, const CCryptoParams& aSignature);
       
   192 
       
   193 	private:
       
   194 		/**
       
   195 		Constructor
       
   196 		*/
       
   197 		CVerifier(MVerifier* aVerifier, TInt aHandle);
       
   198 		};
       
   199 
       
   200 	/**
       
   201 	Asynchronous verfier API, which wraps a asynchronous verifier plugin implementation
       
   202 	*/
       
   203 	NONSHARABLE_CLASS(CAsyncVerifier) : public CSignatureBase
       
   204 		{
       
   205 	public:
       
   206 
       
   207 		/**
       
   208 		 * @internalComponent
       
   209 		 *
       
   210 		 * Create a CAsyncVerifier instance from the given MAsyncVerifier instance
       
   211 		 * @param aAsyncVerifier	The async verifier plugin instance
       
   212 		 * @return A pointer to a CAsyncVerifier instance
       
   213 		 */
       
   214 		static CAsyncVerifier* NewL(MAsyncVerifier* aAsyncVerifier, TInt aHandle);
       
   215 
       
   216 		/**
       
   217 		Destructor
       
   218 		*/
       
   219 		IMPORT_C ~CAsyncVerifier();
       
   220 
       
   221 		/**
       
   222 		Verify the signature
       
   223 		@param aInput	The hash of the message to be verified
       
   224 		@param aSignature	The signature of the hash.
       
   225 		@param aVerificationResult	Indicates the success or failure of the verification
       
   226 		@param aRequestStatus the request status.
       
   227 		*/
       
   228 		IMPORT_C void VerifyL(const TDesC8& aInput, const CCryptoParams& aSignature, TBool& aVerificationResult, TRequestStatus& aRequestStatus);
       
   229 
       
   230 		/**
       
   231 		Unsign the signature
       
   232 		@param aOutput	The unsigned hash
       
   233 		@param aSignature	The signature of the hash
       
   234 		@param aRequestStatus the request status.
       
   235 		*/
       
   236 		IMPORT_C void InverseSignL(HBufC8*& aOutput, const CCryptoParams& aSignature, TRequestStatus& aRequestStatus);
       
   237 
       
   238 		/**
       
   239 		Cancel the outstanding request
       
   240 		*/
       
   241 		IMPORT_C void Cancel();
       
   242 
       
   243 	private:
       
   244 		/**
       
   245 		Constructor
       
   246 		*/
       
   247 		CAsyncVerifier(MAsyncVerifier* aAsyncVerifier, TInt aHandle);
       
   248 		};
       
   249 
       
   250 
       
   251 	/**
       
   252 	the Factory to create synchronous and asynchronous signer and verifier instance 
       
   253 	*/
       
   254 	class CSignatureFactory
       
   255 		{
       
   256 	public:
       
   257 
       
   258 		/**
       
   259 		Creates a new instance of a synchronous signer.
       
   260 
       
   261 		@param aSigner A reference to a pointer that should be set to point to the new signer object.
       
   262 		@param aAlgorithmUid The algorithm to use.
       
   263 		@param aKey The signing key.
       
   264 		@param aPaddingMode The padding mode of the signer.
       
   265 		@param aAlgorithmParams Parameters that are specific to a particular algorithm. This is for extendibility and will normally be null.
       
   266 		@return KErrNone if successful; otherwise, a system wide error code.
       
   267 		*/
       
   268 		IMPORT_C static void CreateSignerL(CSigner*& aSigner,
       
   269 										TUid aAlgorithmUid,
       
   270 										const CKey& aKey,
       
   271 										TUid aPaddingMode,
       
   272 										const CCryptoParams* aAlgorithmParams);
       
   273 
       
   274 
       
   275 		/**
       
   276 		Creates a new instance of a asynchronous signer.
       
   277 
       
   278 		@param aAsyncSigner A reference to a pointer that should be set to point to the new signer object.
       
   279 		@param aAlgorithmUid The algorithm to use
       
   280 		@param aKey The signing key.
       
   281 		@param aPaddingMode The padding mode of the signer.
       
   282 		@param aAlgorithmParams Parameters that are specific to a particular algorithm. This is for extendibility and will normally be null.
       
   283 		@return KErrNone if successful; otherwise, a system wide error code.
       
   284 		*/
       
   285 		IMPORT_C static void CreateAsyncSignerL(CAsyncSigner*& aAsyncSigner,
       
   286 										TUid aAlgorithmUid,
       
   287 										const CKey& aKey,
       
   288 										TUid aPaddingMode,
       
   289 										const CCryptoParams* aAlgorithmParams);
       
   290 		
       
   291 		/**
       
   292 		Creates a new instance of a verifier.
       
   293 		
       
   294 		@param aVerifier A reference to a pointer that should be set to point to the new verifier object.
       
   295 		@param aAlgorithmUid The algorithm to use
       
   296 		@param aKey The key to verify the signature with.
       
   297 		@param aPaddingMode The padding mode of the signer.
       
   298 		@param aAlgorithmParams Parameters that are specific to a particular algorithm. This is for extendibility and will normally be null.
       
   299 		@return KErrNone if successful; otherwise, a system wide error code.
       
   300 		*/
       
   301 		IMPORT_C static void CreateVerifierL(CVerifier*& aVerifier,
       
   302 										TUid aAlgorithmUid,
       
   303 										const CKey& aKey,
       
   304 										TUid aPaddingMode,
       
   305 										const CCryptoParams* aAlgorithmParams);
       
   306 
       
   307 
       
   308 		/**
       
   309 		Creates a new instance of an asynchronous verifier.
       
   310 		
       
   311 		@param aAsyncVerifier A reference to a pointer that should be set to point to the new verifier object.
       
   312 		@param aAlgorithmUid The algorithm to use
       
   313 		@param aKey The key to verify the signature with.
       
   314 		@param aPaddingMode The padding mode of the signer.
       
   315 		@param aAlgorithmParams Parameters that are specific to a particular algorithm. This is for extendibility and will normally be null.
       
   316 		@return KErrNone if successful; otherwise, a system wide error code.
       
   317 		*/
       
   318 		IMPORT_C static void CreateAsyncVerifierL(CAsyncVerifier*& aAsyncVerifier,
       
   319 										TUid aAlgorithmUid,
       
   320 										const CKey& aKey,
       
   321 										TUid aPaddingMode,
       
   322 										const CCryptoParams* aAlgorithmParams);
       
   323 
       
   324 		};
       
   325 	}
       
   326 
       
   327 #endif //__CRYPTOAPI_SIGNATUREAPI_H__