os/security/cryptoplugins/cryptospiplugins/test/h4drv/crypto_h4/cryptodriver.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2007-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 *
    16 */
    17 
    18 
    19 /**
    20  @file
    21  @internalComponent
    22  @released
    23 */
    24 #include "cryptodriver.h"
    25 
    26 /*
    27   NOTE: The following member functions would normally be exported from a separate client DLL
    28   but are included inline in this header file for convenience.
    29 */
    30 
    31 
    32 /**
    33   Opens a logical channel to the driver
    34 
    35   @return One of the system wide error codes.
    36 */
    37 EXPORT_C TInt RCryptoDriver::Open()
    38     {
    39     return DoCreate(Name(),VersionRequired(),KNullUnit,NULL,NULL,EOwnerThread);
    40     }
    41 
    42 
    43 /**
    44   Gets the HW versions
    45 
    46   @param aHwVersionsBuf A structure which will be filled with the versions
    47 
    48   @return KErrNone
    49 */
    50 EXPORT_C TInt RCryptoDriver::GetHwVersions(THwVersionsBuf& aHwVersionsBuf)
    51     {
    52     return DoControl(EGetHwVersions,(TAny*)&aHwVersionsBuf);
    53     }
    54 
    55 /**
    56   Gets the current configuration settings.
    57 
    58   @param aConfig A structure which will be filled with the configuration settings.
    59 
    60   @return KErrNone
    61 */
    62 EXPORT_C TInt RCryptoDriver::GetConfig(TConfigBuf& aConfig)
    63     {
    64     return DoControl(EGetConfig,(TAny*)&aConfig);
    65     }
    66 
    67 
    68 /**
    69   Sets the current configuration settings.
    70 
    71   @param aConfig The new configuration settings to be used.
    72 
    73   @return KErrInUse if there are outstanding data transfer requests.
    74           KErrArgument if any configuration values are invalid.
    75           KErrNone otherwise
    76 */
    77 EXPORT_C TInt RCryptoDriver::SetConfig(const TConfigBuf& aConfig)
    78     {
    79     return DoControl(ESetConfig,(TAny*)&aConfig);
    80     }
    81 
    82 EXPORT_C void RCryptoDriver::Random(TRequestStatus& aStatus,TDes8& aBuffer)
    83     {
    84     DoRequest(ERandom,aStatus,(TAny*)&aBuffer);
    85     }
    86 
    87 
    88 EXPORT_C void RCryptoDriver::RandomCancel()
    89     {
    90     DoCancel(1<<ERandom);
    91     }
    92 
    93 #include <e32debug.h>
    94 EXPORT_C TInt RCryptoDriver::SetAesConfig(TBool aEncrypt, TChainingMode aMode, 
    95 										  const TDesC8& aKey, const TDesC8& aIV)
    96     {
    97 	TAesConfigBuf configBuf;
    98 	TAesConfig &config = configBuf();
    99 	config.iEncrypt = aEncrypt;
   100 	config.iMode = aMode;
   101 	config.iKey = &aKey;
   102 	config.iIV = &aIV;
   103 
   104     return DoControl(EAesSetConfig, (TAny*)&configBuf);
   105     }
   106 
   107 EXPORT_C void RCryptoDriver::AesWrite(TRequestStatus& aStatus, TDesC8& aBuffer)
   108     {
   109     DoRequest(EAesWrite, aStatus,(TAny*)&aBuffer);
   110     }
   111 EXPORT_C void RCryptoDriver::AesCancelWrite()
   112     {
   113     DoCancel(1<<EAesWrite);
   114     }
   115 
   116 EXPORT_C void RCryptoDriver::AesRead(TRequestStatus& aStatus, TDes8& aBuffer, TUint32 aLength)
   117     {
   118     DoRequest(EAesRead, aStatus,(TAny*)&aBuffer, (TAny*)aLength);
   119     }
   120 
   121 EXPORT_C void RCryptoDriver::AesCancelRead()
   122     {
   123     DoCancel(1<<EAesRead);
   124     }
   125 
   126 // End of file