crypto/weakcryptospi/inc/3des.h
changeset 8 35751d3474b7
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
       
     1 /*
       
     2 * Copyright (c) 2002-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 * ** IMPORTANT ** PublishedPartner API's in this file are published to 3rd party developers via the 
       
    16 * Symbian website. Changes to these API's should be treated as PublishedAll API changes and the Security TA should be consulted.
       
    17 * 3DES implementation
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 /**
       
    23  @file 
       
    24  @publishedPartner
       
    25  @released 
       
    26 */
       
    27  
       
    28 #ifndef __3DES_H__
       
    29 #define __3DES_H__
       
    30 
       
    31 #include <des.h>
       
    32 
       
    33 /**
       
    34 * Abstract base class for triple-DES.
       
    35 *
       
    36 * Implements features common to triple-DES encryption and decryption.
       
    37 *
       
    38 */
       
    39 class C3DES : public CDES
       
    40 {
       
    41 public:
       
    42 	virtual void Transform(TDes8& aBlock);
       
    43 	virtual void Reset();
       
    44 	virtual TInt BlockSize() const;
       
    45 	virtual TInt KeySize() const;
       
    46 protected:
       
    47 	/** @internalAll */
       
    48 	C3DES();
       
    49 	virtual void ConstructL(const TDesC8& aKey);
       
    50 	/**
       
    51 	 * Initialises the three key schedule arrays from the specified key.
       
    52 	 * 
       
    53 	 * @param aKey	The key to be used for encryption. The key length
       
    54 	 *				must be K3DESKeySize = 24 bytes.
       
    55 	 */
       
    56 	virtual void DoSetKey(const TDesC8& aKey) = 0;
       
    57 	
       
    58 protected:
       
    59 	/** The second key schedule array */
       
    60 	TUint32 iK2[KDESScheduleSizeInWords];	//	= 32
       
    61 	/** The third key schedule array */
       
    62 	TUint32 iK3[KDESScheduleSizeInWords];
       
    63 };
       
    64 
       
    65 /**
       
    66 * Concrete class for triple-DES encryption.
       
    67 *
       
    68 */
       
    69 class C3DESEncryptor : public C3DES
       
    70 {
       
    71 public:
       
    72 	/**
       
    73 	* Creates an instance of this class.
       
    74 	*
       
    75 	* @param aKey	The key to be used for encryption. The key length
       
    76 	*				must be K3DESKeySize = 24 bytes.
       
    77 	* @return		A pointer to the new C3DESEncryptor object.
       
    78 	*
       
    79 	* @leave KErrKeyNotWeakEnough	If the key size is larger than that allowed by the
       
    80 	*								cipher strength restrictions of the crypto library.
       
    81 	*								See TCrypto::IsSymmetricWeakEnoughL()
       
    82 	*/
       
    83 	IMPORT_C static C3DESEncryptor* NewL(const TDesC8& aKey);
       
    84 
       
    85 	/**
       
    86 	* Creates an instance of this class and leaves it on the cleanup stack.
       
    87 	*
       
    88 	* @param aKey	The key to be used for encryption. The key length
       
    89 	*				must be K3DESKeySize = 24 bytes.
       
    90 	* @return		A pointer to the new C3DESEncryptor object.
       
    91 	*
       
    92 	* @leave KErrKeyNotWeakEnough 	If the key size is larger than that allowed by the
       
    93 	* 								cipher strength restrictions of the crypto library.
       
    94 	* 								See TCrypto::IsSymmetricWeakEnoughL()
       
    95 	*/
       
    96 	IMPORT_C static C3DESEncryptor* NewLC(const TDesC8& aKey);
       
    97 protected:
       
    98 	virtual void DoSetKey(const TDesC8& aKey);
       
    99 };
       
   100 
       
   101 /**
       
   102 * Concrete class for triple-DES decryption.
       
   103 *
       
   104 */
       
   105 class C3DESDecryptor : public C3DES
       
   106 {
       
   107 public:
       
   108 	/**
       
   109 	* Creates an instance of this class.
       
   110 	*
       
   111 	* @param aKey	The key to be used for decryption. The key length
       
   112 	*				must be K3DESKeySize = 24 bytes.
       
   113 	* @return		A pointer to the new C3DESDecryptor object.
       
   114 	*
       
   115 	* @leave KErrKeyNotWeakEnough	If the key size is larger than that allowed by the
       
   116 	*								cipher strength restrictions of the crypto library.
       
   117 	*								See TCrypto::IsSymmetricWeakEnoughL()
       
   118 	*/
       
   119 	IMPORT_C static C3DESDecryptor* NewL(const TDesC8& aKey);
       
   120 
       
   121 	/**
       
   122 	* Creates an instance of this class and leaves it on the cleanup stack.
       
   123 	*
       
   124 	* @param aKey	The key to be used for decryption. The key length
       
   125 	*				must be K3DESKeySize = 24 bytes.
       
   126 	* @return		A pointer to the new C3DESDecryptor object.
       
   127 	*
       
   128 	* @leave KErrKeyNotWeakEnough	If the key size is larger than that allowed by the
       
   129 	*								cipher strength restrictions of the crypto library.  
       
   130 	*								See TCrypto::IsSymmetricWeakEnoughL()
       
   131 	*/
       
   132 	IMPORT_C static C3DESDecryptor* NewLC(const TDesC8& aKey);
       
   133 protected:
       
   134 	virtual void DoSetKey(const TDesC8& aKey);
       
   135 };
       
   136 
       
   137 #endif	//	__3DES_H__