crypto/weakcryptospi/source/symmetric/rc2shim.h
changeset 19 cd501b96611d
equal deleted inserted replaced
15:da2ae96f639b 19:cd501b96611d
       
     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 * RC2 shim classes definition
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file
       
    22  @internalComponent
       
    23  @released
       
    24 */
       
    25 
       
    26 #ifndef __RC2SHIM_H__
       
    27 #define __RC2SHIM_H__
       
    28 
       
    29 #include <rc2.h>
       
    30 
       
    31 namespace CryptoSpi
       
    32 	{
       
    33 	class CCryptoParams;
       
    34 	class CSymmetricCipher;
       
    35 	class CKey;
       
    36 	}
       
    37 	
       
    38 NONSHARABLE_CLASS(CRC2EncryptorShim) : public CRC2Encryptor
       
    39 {
       
    40 public:
       
    41 	/**
       
    42 	Creates an CRC2EncryptorShim object which has the same interface
       
    43 	as RC2 Encryptor but delegates all work to a Crypto SPI plug-in.
       
    44 	
       
    45 	@param aKey The encryption key
       
    46 	@return A pointer to a CRC2EncryptorShim instance
       
    47 	*/
       
    48 	static CRC2EncryptorShim* NewL(const TDesC8& aKey, TInt aEffectiveKeyLenBits);
       
    49 	
       
    50 	/**
       
    51 	Creates an CRC2EncryptorShim object which has the same interface
       
    52 	as RC2 Encryptor but delegates all work to a Crypto SPI plug-in.
       
    53 	
       
    54 	A pointer to the new object is placed on the cleanup stack
       
    55 	
       
    56 	@param aKey The encryption key
       
    57 	@return A pointer to a CRC2EncryptorShim instance
       
    58 	*/
       
    59 	static CRC2EncryptorShim* NewLC(const TDesC8& aKey, TInt aEffectiveKeyLenBits);
       
    60 	
       
    61 	// From CBlockTransform
       
    62 	TInt BlockSize() const;
       
    63 	void Transform(TDes8& aBlock);
       
    64 	void Reset(void);
       
    65 	TInt KeySize(void) const;
       
    66 	
       
    67 	/// Destructor
       
    68 	~CRC2EncryptorShim();
       
    69 		
       
    70 private:
       
    71 	/// Constructor
       
    72 	CRC2EncryptorShim();
       
    73 	void ConstructL(const TDesC8& aKey, TInt aEffectiveKeyLenBits);	
       
    74 	
       
    75 	// From CBase
       
    76 	TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
       
    77 	
       
    78 private:
       
    79 	/// SPI delegate
       
    80 	CryptoSpi::CSymmetricCipher* iSymmetricCipherImpl;
       
    81 		
       
    82 	/// SPI requires all key to passed as key-objects
       
    83 	CryptoSpi::CKey* iKey;		
       
    84 	
       
    85 	/// Temporary output block, SPI does not overwrite input
       
    86 	/// RC2 uses 64bit blocks
       
    87 	TBuf8<16> iOutputBlock;
       
    88 	
       
    89 	/// The effective key length is passed as an algorithm
       
    90 	/// parameter. This allows it to be externalised.
       
    91 	CryptoSpi::CCryptoParams* iAlgorithmParams;	
       
    92 };
       
    93 
       
    94 NONSHARABLE_CLASS(CRC2DecryptorShim) : public CRC2Decryptor
       
    95 {
       
    96 public:
       
    97 	/**
       
    98 	Creates an CRC2DecryptorShim object which has the same interface
       
    99 	as RC2 Decryptor but delegates all work to a Crypto SPI plug-in.
       
   100 	
       
   101 	@param aKey The decryption key
       
   102 	@return A pointer to a CRC2DecryptorShim instance
       
   103 	*/
       
   104 	static CRC2DecryptorShim* NewL(const TDesC8& aKey, TInt aEffectiveKeyLenBits);
       
   105 	
       
   106 	/**
       
   107 	Creates an CRC2DecryptorShim object which has the same interface
       
   108 	as RC2 Decryptor but delegates all work to a Crypto SPI plug-in.
       
   109 	
       
   110 	A pointer to the new object is placed on the cleanup stack
       
   111 	
       
   112 	@param aKey The decryption key
       
   113 	@return A pointer to a CRC2DecryptorShim instance
       
   114 	*/
       
   115 	static CRC2DecryptorShim* NewLC(const TDesC8& aKey, TInt aEffectiveKeyLenBits);
       
   116 	
       
   117 	// From CBlockTransform
       
   118 	TInt BlockSize() const;
       
   119 	void Transform(TDes8& aBlock);
       
   120 	void Reset(void);
       
   121 	TInt KeySize(void) const;
       
   122 	
       
   123 	/// Destructor
       
   124 	~CRC2DecryptorShim();
       
   125 	
       
   126 private:
       
   127 	/// Constructor	
       
   128 	CRC2DecryptorShim();	
       
   129 	void ConstructL(const TDesC8& aKey, TInt aEffectiveKeyLenBits);	
       
   130 	
       
   131 	/**
       
   132 	From CBase, to allow CBufferedTransform & CBlockChainingMode
       
   133 	to determine whether the functionality may be delegated to
       
   134 	the SPI object.
       
   135 	*/ 
       
   136 	TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
       
   137 	
       
   138 private:	
       
   139 	/// SPI delegate
       
   140 	CryptoSpi::CSymmetricCipher* iSymmetricCipherImpl;
       
   141 		
       
   142 	/// SPI requires all key to passed as key-objects
       
   143 	CryptoSpi::CKey* iKey;		
       
   144 	
       
   145 	/// Temporary output block, SPI does not overwrite input
       
   146 	/// RC2 uses 64bit blocks
       
   147 	TBuf8<16> iOutputBlock;
       
   148 	
       
   149 	/// The effective key length is passed as an algorithm
       
   150 	/// parameter. This allows it to be externalised.
       
   151 	CryptoSpi::CCryptoParams* iAlgorithmParams;
       
   152 };
       
   153 
       
   154 #endif // __RC2SHIM_H__