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