sl@0: /* sl@0: * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @internalComponent sl@0: @released sl@0: */ sl@0: #ifndef CRYPTODRIVER_H sl@0: #define CRYPTODRIVER_H sl@0: sl@0: #include sl@0: #include sl@0: #ifndef __KERNEL_MODE__ sl@0: #include sl@0: #endif sl@0: sl@0: /** sl@0: User interface for crypto hw sl@0: */ sl@0: class RCryptoDriver : public RBusLogicalChannel sl@0: { sl@0: public: sl@0: /** sl@0: Structure for holding driver capabilities information sl@0: */ sl@0: class TCaps sl@0: { sl@0: public: sl@0: TVersion iVersion; sl@0: }; sl@0: sl@0: /** sl@0: Structure for holding driver configuration data sl@0: */ sl@0: class TConfig sl@0: { sl@0: public: sl@0: TInt iFakeDriverSetting; sl@0: }; sl@0: /** sl@0: Typedef used for passing TConfig structure to GetConfig and SetConfig APIs sl@0: */ sl@0: typedef TPckgBuf TConfigBuf; sl@0: sl@0: /** sl@0: Structure for holding h/w version information sl@0: */ sl@0: class THwVersions sl@0: { sl@0: public: sl@0: TUint32 iRngHwVersion; ///< RNG h/w version number sl@0: TUint32 iDes3DesHwVersion; ///< 3DES h/w version number sl@0: TUint32 iSha1Md5HwVersion; ///< SHA1 h/w version number sl@0: TUint32 iAesHwVersion; ///< AES h/w version number sl@0: TUint32 iPkaHwVersion; ///< PKA h/w version number sl@0: }; sl@0: typedef TPckgBuf THwVersionsBuf; sl@0: sl@0: public: sl@0: IMPORT_C TInt Open(); sl@0: IMPORT_C TInt GetHwVersions(THwVersionsBuf& aHwVersionsBuf); sl@0: sl@0: IMPORT_C TInt GetConfig(TConfigBuf& aConfig); sl@0: IMPORT_C TInt SetConfig(const TConfigBuf& aConfig); sl@0: sl@0: inline static const TDesC& Name(); sl@0: inline static TVersion VersionRequired(); sl@0: sl@0: /** sl@0: Fill buffer with random data sl@0: Only one "random" request may be pending at any time. sl@0: sl@0: @param aStatus The request to be signalled when the data has been received. sl@0: The result value will be set to KErrNone on success; sl@0: or set to one of the system wide error codes when an error occurs. sl@0: sl@0: @param aData Fills the descriptor up to its current length with sl@0: random data. Any existing contents are lost. sl@0: */ sl@0: IMPORT_C void Random(TRequestStatus& aStatus, TDes8& aDestination); sl@0: /** sl@0: Causes the current Random request to cancel synchronously. sl@0: */ sl@0: IMPORT_C void RandomCancel(); sl@0: sl@0: enum TChainingMode {EEcbMode, ECbcMode, ECntrMode}; sl@0: /** sl@0: @param aEncrypt ETrue for encryption sl@0: @param aMode See TChainingMode sl@0: @param aKey Must be one of the following lengths - 128, 192 or 256 bits (16, 24 or 32 bytes). sl@0: @param aIV Initialisation Vector, Length must be, 0 for ECB mode, or 16 bytes (all other mdoes) sl@0: */ sl@0: IMPORT_C TInt SetAesConfig(TBool aEncrypt, TChainingMode aMode, const TDesC8& aKey, const TDesC8& aIV); sl@0: sl@0: /** sl@0: Any length of data may be written, but the h/w will only sl@0: process the data in multiples of 16 bytes. Any remainder will sl@0: be buffered pending future writes. sl@0: sl@0: Padding is NOT done by this function. sl@0: sl@0: Output sl@0: sl@0: @param aStatus sl@0: @param aBuffer sl@0: */ sl@0: IMPORT_C void AesWrite(TRequestStatus& aStatus, TDesC8& aBuffer); sl@0: sl@0: /** sl@0: Causes the current "to hw" requests to cancel synchronously. sl@0: */ sl@0: IMPORT_C void AesCancelWrite(); sl@0: sl@0: /** sl@0: The destination buffer is overwritten. This call will block sl@0: until the specified number of bytes have been read (the max sl@0: length of aBuffer). sl@0: sl@0: The length is not required to be a multiple of the block size sl@0: (16 bytes), but note that written data is only processed in sl@0: multiples of the block size. sl@0: sl@0: Data is appended to the supplied buffer. sl@0: sl@0: @param aStatus sl@0: @param aBuffer sl@0: @param aLength sl@0: */ sl@0: IMPORT_C void AesRead(TRequestStatus& aStatus, TDes8& aBuffer, TUint32 aLenth); sl@0: sl@0: /** sl@0: Causes the current "from hw" requests to cancel synchronously. sl@0: */ sl@0: IMPORT_C void AesCancelRead(); sl@0: sl@0: sl@0: private: sl@0: /** sl@0: Enumeration of Control messages. sl@0: */ sl@0: enum TControl sl@0: { sl@0: EGetHwVersions, sl@0: EAesSetConfig, sl@0: EGetConfig, sl@0: ESetConfig sl@0: }; sl@0: sl@0: /** sl@0: Enumeration of Request messages. sl@0: */ sl@0: enum TRequest sl@0: { sl@0: ERandom, sl@0: EAesWrite, sl@0: EAesRead, sl@0: ENumRequests, sl@0: EAllRequests = (1< TAesConfigBuf; sl@0: sl@0: // Kernel side LDD channel is a friend sl@0: friend class DCryptoLddChannel; sl@0: friend class DLddChanAes; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: Returns the driver's name sl@0: */ sl@0: inline const TDesC& RCryptoDriver::Name() sl@0: { sl@0: _LIT(KDriver1Name,"crypto"); sl@0: return KDriver1Name; sl@0: } sl@0: sl@0: /** sl@0: Returns the version number of the driver sl@0: */ sl@0: inline TVersion RCryptoDriver::VersionRequired() sl@0: { sl@0: const TInt KMajorVersionNumber=1; sl@0: const TInt KMinorVersionNumber=0; sl@0: const TInt KBuildVersionNumber=KE32BuildVersionNumber; sl@0: return TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber); sl@0: } sl@0: sl@0: sl@0: #endif