os/security/cryptoplugins/cryptospiplugins/source/softwarecrypto/asymmetriccipherimpl.h
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoplugins/cryptospiplugins/source/softwarecrypto/asymmetriccipherimpl.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,137 @@
1.4 +/*
1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#ifndef __ASYMMETRICCIPHERIMPL_H__
1.23 +#define __ASYMMETRICCIPHERIMPL_H__
1.24 +
1.25 +/**
1.26 +@file
1.27 +@internalComponent
1.28 +@released
1.29 +*/
1.30 +
1.31 +#include <e32base.h>
1.32 +#include <cryptospi/cryptospidef.h>
1.33 +#include <padding.h>
1.34 +#include "asymmetriccipherplugin.h"
1.35 +#include "keys.h"
1.36 +#include "common/inlines.h"
1.37 +
1.38 +/**
1.39 + * Abstract base class for symmetric cipher plug-ins.
1.40 + */
1.41 +namespace SoftwareCrypto
1.42 + {
1.43 + using namespace CryptoSpi;
1.44 +
1.45 + NONSHARABLE_CLASS(CAsymmetricCipherImpl) : public CBase, public MAsymmetricCipher
1.46 + {
1.47 + public:
1.48 +
1.49 + // Override MPlugin virtual functions
1.50 + void Close();
1.51 + void Reset(); // Always call reset in super-class if you override this
1.52 + TAny* GetExtension(TUid aExtensionId);
1.53 + void GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics);
1.54 + // End of MPlugin
1.55 +
1.56 + // Override MAsymmetricCipherBase virtual functions
1.57 + void SetKeyL(const CKey& aKey); // override DoSetKeyL instead
1.58 + void SetCryptoModeL(TUid aCryptoMode); // override DoSetCryptoModeL instead
1.59 + void SetPaddingModeL(TUid aPaddingMode); // override DoSetPaddingModeL instead
1.60 + virtual TInt GetMaximumInputLengthL() const;
1.61 + virtual TInt GetMaximumOutputLengthL() const;
1.62 + // End of MAsymmetricCipherBase
1.63 +
1.64 + // Override MAsymmetricCipher virtual functions
1.65 + virtual void ProcessL(const TDesC8& aInput, TDes8& aOutput) = 0;
1.66 + // End of MAsymmetricCipher
1.67 +
1.68 + /// Destructor
1.69 + ~CAsymmetricCipherImpl();
1.70 +
1.71 + protected:
1.72 + /**
1.73 + Constructor
1.74 + @param aCryptoMode Whether to encrypt or decrypt
1.75 + @param aPaddingMode The padding mode
1.76 + */
1.77 + CAsymmetricCipherImpl(TUid aCryptoMode, TUid aPaddingMode);
1.78 +
1.79 + /**
1.80 + Second phase of construction. Always call ConstructL in the super-class
1.81 + if you override this method.
1.82 +
1.83 + @param aKey The key to initialise the cipher with.
1.84 + */
1.85 + virtual void ConstructL(const CKey& aKey);
1.86 +
1.87 + /**
1.88 + Implemented by each cipher subclass to determine whether the
1.89 + specified key length is valid for that cipher.
1.90 + This is called by ConstructL and SetKeyL
1.91 + @param aKeyBytes The key length in bytes to verify.
1.92 + @return ETrue if key length is acceptable
1.93 + */
1.94 + virtual TBool IsValidKeyLengthL(TInt aKeyBytes) const = 0;
1.95 +
1.96 + /**
1.97 + Helper function implemented by concrete cipher sub-class that allows
1.98 + GetCharacteristicsL to return the correct characteristics object.
1.99 + @return The implemention uid
1.100 + */
1.101 + virtual TUid ImplementationUid() const = 0;
1.102 +
1.103 + /**
1.104 + Validates and sets the crypto mode (iCryptoMode)
1.105 + @param aCryptoMode The crypto mode
1.106 + */
1.107 + virtual void DoSetCryptoModeL(TUid aCryptoMode);
1.108 +
1.109 + /**
1.110 + Extracts the raw key from aKey and sets iKey and iKeyBytes
1.111 + The key length is also checked to meet export restrictions and
1.112 + to ensure that it is appropriate for the cipher.
1.113 + @param aKey The key
1.114 + */
1.115 + virtual void DoSetKeyL(const CKey& aKey);
1.116 +
1.117 + /**
1.118 + Validates and sets the padding mode (iPaddingMode & iPadding)
1.119 + @param aPadding The desired padding mode
1.120 + */
1.121 + virtual void DoSetPaddingModeL(TUid aPadding);
1.122 +
1.123 + private:
1.124 +
1.125 + protected:
1.126 + /// encryption or decryption
1.127 + TUid iCryptoMode;
1.128 +
1.129 + /// the current padding scheme
1.130 + TUid iPaddingMode;
1.131 +
1.132 + /// the key
1.133 + CKey* iKey;
1.134 +
1.135 + /// current padding scheme implementation
1.136 + CPadding* iPadding;
1.137 + };
1.138 + }
1.139 +
1.140 +#endif // __ASYMMETRICCIPHERIMPL_H__