williamr@4: /* williamr@4: * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@4: * All rights reserved. williamr@4: * This component and the accompanying materials are made available williamr@4: * under the terms of the License "Eclipse Public License v1.0" williamr@4: * which accompanies this distribution, and is available williamr@4: * at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@4: * williamr@4: * Initial Contributors: williamr@4: * Nokia Corporation - initial contribution. williamr@4: * williamr@4: * Contributors: williamr@4: * williamr@4: * Description: williamr@4: * crypto hash application interface williamr@4: * williamr@4: */ williamr@4: williamr@4: williamr@4: /** williamr@4: @file williamr@4: @publishedAll williamr@4: @released williamr@4: */ williamr@4: williamr@4: #ifndef __CRYPTOAPI_HASHAPI_H__ williamr@4: #define __CRYPTOAPI_HASHAPI_H__ williamr@4: williamr@4: #include williamr@4: #include williamr@4: williamr@4: williamr@4: namespace CryptoSpi williamr@4: { williamr@4: class MPlugin; williamr@4: class MHash; williamr@4: class MAsyncHash; williamr@4: class CCryptoParams; williamr@4: class CKey; williamr@4: williamr@4: /** williamr@4: Hash API, which wraps a synchronous Hash plugin implementation williamr@4: */ williamr@4: NONSHARABLE_CLASS(CHash) : public CCryptoBase williamr@4: { williamr@4: public: williamr@4: /** williamr@4: * @internalComponent williamr@4: * williamr@4: * Create a CHash instance from the given MHash instance williamr@4: * @param aHash The hash plugin instance williamr@4: * @return A pointer to a CHash instance williamr@4: **/ williamr@4: static CHash* NewL(MHash* aHash, TInt aHandle); williamr@4: williamr@4: /** williamr@4: Destructor williamr@4: */ williamr@4: IMPORT_C ~CHash(); williamr@4: williamr@4: /** williamr@4: Adds aMessage to the internal representation of data to be hashed, williamr@4: then returns a TPtrC8 of the finalised hash of all the previously williamr@4: appended messages. williamr@4: @param aMessage The data to be included in the hash. williamr@4: @return A descriptor pointer to the buffer containing the resulting hash. williamr@4: */ williamr@4: IMPORT_C TPtrC8 Hash(const TDesC8& aMessage); // Combination of Update and Final williamr@4: williamr@4: /** williamr@4: Adds data to the internal representation of messages to be hashed. williamr@4: @param aMessage The data to be included in the hash. williamr@4: */ williamr@4: IMPORT_C void Update(const TDesC8& aMessage); williamr@4: williamr@4: /** williamr@4: Produces a final hash value from all the previous updates of data williamr@4: to be hashed. williamr@4: @param aMessage The data to be included in the hash. williamr@4: */ williamr@4: IMPORT_C TPtrC8 Final(const TDesC8& aMessage); williamr@4: williamr@4: /** williamr@4: Creates a brand new reset CHash object containing no state williamr@4: information from the current object. This API is only to support williamr@4: the old crypto API for BC reason. It is strongly recommended not to use this API. williamr@4: williamr@4: To make a copy of a message digest with its internal state intact, williamr@4: see CopyL(). williamr@4: williamr@4: @return A pointer to the new reset CHash object. williamr@4: @leave ... Any of the crypto error codes defined in williamr@4: cryptospi_errs.h or any of the system-wide error codes. williamr@4: */ williamr@4: IMPORT_C CHash* ReplicateL(); williamr@4: williamr@4: /** williamr@4: Creates a new CHash object with the exact same state as williamr@4: the current object.This API is only to support williamr@4: the old crypto API for BC reason. It is strongly recommended not to use this API. williamr@4: williamr@4: This function copies all internal state of the message digest. williamr@4: To create a new CHash object without the state of williamr@4: the current object, see ReplicateL(). williamr@4: williamr@4: @return A pointer to the new CHash object. williamr@4: @leave ... Any of the crypto error codes defined in williamr@4: cryptospi_errs.h or any of the system-wide error codes. williamr@4: */ williamr@4: IMPORT_C CHash* CopyL(); williamr@4: williamr@4: /** williamr@4: * @deprecated williamr@4: * williamr@4: * Set the key used for HMAC mode operation. williamr@4: * @param aKey The key for HMAC williamr@4: * @leave KErrArgument if aKey is not of the expected type. williamr@4: * @leave ... Any of the crypto error codes defined in williamr@4: cryptospi_errs.h or any of the system-wide error codes. williamr@4: */ williamr@4: IMPORT_C void SetKeyL(const CKey& aKey); williamr@4: williamr@4: /** williamr@4: * @deprecated williamr@4: * williamr@4: * Set the operation mode, ie hash or hmac williamr@4: * @param aOperationMode The UID to identifiy the operation mode williamr@4: * @leave KErrNotSupported if the specified operation mode is not supported. williamr@4: * @leave ... Any of the crypto error codes defined in williamr@4: cryptospi_errs.h or any of the system-wide error codes. williamr@4: */ williamr@4: IMPORT_C void SetOperationModeL(TUid aOperationMode); williamr@4: williamr@4: private: williamr@4: /** williamr@4: Constructor williamr@4: */ williamr@4: CHash(MHash* aHash, TInt aHandle); williamr@4: }; williamr@4: williamr@4: williamr@4: /** williamr@4: Asynchronous Hash API, which wraps an asynchronous Hash plugin implementation williamr@4: */ williamr@4: NONSHARABLE_CLASS(CAsyncHash) : public CCryptoBase williamr@4: { williamr@4: public: williamr@4: /** williamr@4: * @internalComponent williamr@4: * williamr@4: * Create a CAsyncHash instance from the given MAsyncHash instance williamr@4: * @param aAsyncHash The async hash plugin instance williamr@4: * @return A pointer to a CAsyncHash instance williamr@4: **/ williamr@4: static CAsyncHash* NewL(MAsyncHash* aAsyncHash, TInt aHandle); williamr@4: williamr@4: /** williamr@4: Destructor williamr@4: */ williamr@4: IMPORT_C ~CAsyncHash(); williamr@4: williamr@4: /** williamr@4: Adds aMessage to the internal representation of data to be hashed, williamr@4: then returns a TPtrC8 of the finalised hash of all the previously williamr@4: appended messages. williamr@4: @param aMessage The data to be included in the hash. williamr@4: @param aHash A descriptor pointer to the buffer containing the hash result. williamr@4: @param aStatus williamr@4: */ williamr@4: IMPORT_C void Hash(const TDesC8& aMessage, TPtrC8& aHash, TRequestStatus& aStatus); williamr@4: williamr@4: /** williamr@4: Adds data to the internal representation of messages to be hashed. williamr@4: @param aMessage The data to be included in the hash. williamr@4: @param aStatus williamr@4: */ williamr@4: IMPORT_C void Update(const TDesC8& aMessage, TRequestStatus& aStatus); williamr@4: williamr@4: /** williamr@4: Produces a final hash value from all the previous updates of data williamr@4: to be hashed. williamr@4: @param aMessage The data to be included in the hash. williamr@4: @param aFinal A descriptor pointer to the buffer containing the hash result. williamr@4: @param aStatus williamr@4: @return A descriptor pointer to the buffer containing the resulting hash. williamr@4: */ williamr@4: IMPORT_C void Final(const TDesC8& aMessage, TPtrC8& aFinal, TRequestStatus& aStatus); williamr@4: williamr@4: /** williamr@4: Cancel the outstanding request williamr@4: */ williamr@4: IMPORT_C void Cancel(); williamr@4: williamr@4: /** williamr@4: Creates a brand new reset CAsyncHash object containing no state williamr@4: information from the current object. This API is only to support williamr@4: the old crypto API for BC reason. It is strongly recommended not to use this API. williamr@4: williamr@4: To make a copy of a message digest with its internal state intact, williamr@4: see CopyL(). williamr@4: williamr@4: @return A pointer to the new reset CAsyncHash object. williamr@4: @leave ... Any of the crypto error codes defined in williamr@4: cryptospi_errs.h or any of the system-wide error codes. williamr@4: */ williamr@4: IMPORT_C CAsyncHash* ReplicateL(); williamr@4: williamr@4: /** williamr@4: Creates a new CAsyncHash object with the exact same state as williamr@4: the current object. This API is only to support williamr@4: the old crypto API for BC reason. It is strongly recommended not to use this API. williamr@4: williamr@4: This function copies all internal state of the message digest. williamr@4: To create a new CAsyncHash object without the state of williamr@4: the current object, see ReplicateL(). williamr@4: williamr@4: @return A pointer to the new CAsyncHash object. williamr@4: @leave ... Any of the crypto error codes defined in williamr@4: cryptospi_errs.h or any of the system-wide error codes. williamr@4: */ williamr@4: IMPORT_C CAsyncHash* CopyL(); williamr@4: williamr@4: /** williamr@4: * @deprecated williamr@4: * williamr@4: * Set the key used for HMAC mode operation. williamr@4: * @param aKey the key for HMAC williamr@4: * @leave KErrArgument if aKey is not of the expected type. williamr@4: * @leave ... Any of the crypto error codes defined in williamr@4: cryptospi_errs.h or any of the system-wide error codes. williamr@4: */ williamr@4: IMPORT_C void SetKeyL(const CKey& aKey); williamr@4: williamr@4: /** williamr@4: * @deprecated williamr@4: * williamr@4: * Set the operation mode, ie hash or hmac williamr@4: * @param aOperationMode The UID to identifiy the operation mode williamr@4: * @leave KErrNotSupported if the specified mode is not supported. williamr@4: * @leave ... Any of the crypto error codes defined in williamr@4: cryptospi_errs.h or any of the system-wide error codes. williamr@4: */ williamr@4: IMPORT_C void SetOperationModeL(TUid aOperationMode); williamr@4: williamr@4: private: williamr@4: williamr@4: /** williamr@4: Constructor williamr@4: */ williamr@4: CAsyncHash(MAsyncHash* aAsyncHash, TInt aHandle); williamr@4: }; williamr@4: williamr@4: /** williamr@4: the Factory to create synchronous and asynchronous hash instances williamr@4: */ williamr@4: class CHashFactory williamr@4: { williamr@4: public: williamr@4: williamr@4: /** williamr@4: * @deprecated williamr@4: * williamr@4: * Create a CHash instance williamr@4: * williamr@4: * @param aHash The pointer to CHash williamr@4: * @param aAlgorithmUid The specific hash algorithm e.g. MD2, SHA1, MD4 williamr@4: * @param aOperationMode The operation mode of the hash e.g. Hash mode, Hmac mode williamr@4: * @param aKey The key for Hmac mode, which should be NULL in Hash mode williamr@4: * @param aAlgorithmParams The parameters that are specific to a particular williamr@4: * algorithm. This is for extendibility and will normally be null. williamr@4: * @return KErrNone if successful; otherwise, a system wide error code. williamr@4: */ williamr@4: IMPORT_C static void CreateHashL(CHash*& aHash, williamr@4: TUid aAlgorithmUid, williamr@4: TUid aOperationMode, williamr@4: const CKey* aKey, williamr@4: const CCryptoParams* aAlgorithmParams); williamr@4: williamr@4: /** williamr@4: * @deprecated williamr@4: * williamr@4: * Create a CAsyncHash instance williamr@4: * williamr@4: * @param aAsyncHash The pointer to CAsyncHash williamr@4: * @param aAlgorithmUid The specific hash algorithm e.g. MD2, SHA1, MD4 williamr@4: * @param aOperationMode The operation mode of the hash e.g. Hash mode, Hmac mode williamr@4: * @param aKey The key for Hmac mode, which should be NULL in Hash mode williamr@4: * @param aAlgorithmParams The parameters that are specific to a particular williamr@4: * algorithm. This is for extendibility and will normally be null. williamr@4: * @return KErrNone if successful; otherwise, a system wide error code. williamr@4: */ williamr@4: IMPORT_C static void CreateAsyncHashL(CAsyncHash*& aAsyncHash, williamr@4: TUid aAlgorithmUid, williamr@4: TUid aOperationMode, williamr@4: const CKey* aKey, williamr@4: const CCryptoParams* aAlgorithmParams); williamr@4: williamr@4: #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT williamr@4: /** williamr@4: * Create a CHash instance williamr@4: * williamr@4: * @param aHash The pointer to CHash williamr@4: * @param aAlgorithmUid The specific hash algorithm e.g. MD2, SHA1, MD4 williamr@4: * @param aAlgorithmParams The parameters that are specific to a particular williamr@4: * algorithm. This is for extendibility and will normally be null. williamr@4: * @return KErrNone if successful; otherwise, a system wide error code. williamr@4: */ williamr@4: IMPORT_C static void CreateHashL(CHash*& aHash, williamr@4: TUid aAlgorithmUid, williamr@4: const CCryptoParams* aAlgorithmParams); williamr@4: williamr@4: /** williamr@4: * Create a CAsyncHash instance williamr@4: * williamr@4: * @param aAsyncHash The pointer to CAsyncHash williamr@4: * @param aAlgorithmUid The specific hash algorithm e.g. MD2, SHA1, MD4 williamr@4: * @param aAlgorithmParams The parameters that are specific to a particular williamr@4: * algorithm. This is for extendibility and will normally be null. williamr@4: * @return KErrNone if successful; otherwise, a system wide error code. williamr@4: */ williamr@4: IMPORT_C static void CreateAsyncHashL(CAsyncHash*& aAsyncHash, williamr@4: TUid aAlgorithmUid, williamr@4: const CCryptoParams* aAlgorithmParams); williamr@4: #endif williamr@4: williamr@4: }; williamr@4: } williamr@4: williamr@4: #endif //__CRYPTOAPI_HASHAPI_H__