crypto/weakcryptospi/inc/rijndael.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 * Rijndael implementation
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 /**
       
    23  @file 
       
    24  @publishedPartner
       
    25  @released 
       
    26 */
       
    27  
       
    28 #ifndef __RIJNDAEL_H__
       
    29 #define __RIJNDAEL_H__
       
    30 
       
    31 #include <blocktransformation.h>
       
    32 
       
    33 /**
       
    34 * Abstract base class for Rijndael, implementing the parts of Rijndael common to both
       
    35 * Rijndael encryption and decryption.
       
    36 *
       
    37 */
       
    38 class CRijndael : public CBlockTransformation
       
    39 {
       
    40 public:	//	From CBlockTransformation
       
    41 	virtual void Reset(void);
       
    42 	virtual TInt KeySize(void) const;
       
    43 	/** The destructor frees all resources owned by the object, prior to its destruction. */
       
    44 	IMPORT_C virtual ~CRijndael(void);
       
    45 protected:
       
    46 	/** Default constructor */
       
    47 	IMPORT_C CRijndael(void);
       
    48 	virtual void SetKey(const TDesC8& aKey);
       
    49 	virtual void ConstructL(const TDesC8& aKey);
       
    50 protected:
       
    51 	/** 
       
    52 	 * The key schedule 
       
    53 	 *
       
    54 	 * The maximum size is (((KAESMaxBlockSize/4)+6)+1)*4
       
    55 	 */
       
    56 	TUint32 iK[60];
       
    57 	/** The number of rounds */
       
    58 	TUint iRounds;
       
    59 	/** 
       
    60 	 * The input key 
       
    61 	 *
       
    62 	 * The key length (in bytes) must be one of the following:
       
    63 	 * - KAESKeySize128 (=16)
       
    64 	 * - KAESKeySize192 (=24)
       
    65 	 * - KAESKeySize256 (=32).
       
    66 	 */
       
    67 	HBufC8* iKey;
       
    68 private:
       
    69 	CRijndael(const CRijndael&);
       
    70 	const CRijndael& operator= (const CRijndael&);
       
    71 };
       
    72 
       
    73 /**
       
    74 * Concrete class for AES encryption.
       
    75 *
       
    76 */
       
    77 class CAESEncryptor : public CRijndael
       
    78 {
       
    79 public:	//	From CBlockTransformation
       
    80 	/**
       
    81 	* Creates an instance of this class.
       
    82 	*
       
    83 	* @param aKey	The key to be used for encryption. The key length must be either
       
    84 	*				KAESKeySize128 (=16), KAESKeySize192 (=24) or KAESKeySize256 (=32) bytes.
       
    85 	*
       
    86 	* @leave KErrKeyNotWeakEnough	If the key size is larger than that allowed by the
       
    87 	*								cipher strength restrictions of the crypto library.
       
    88 	*								See TCrypto::IsSymmetricWeakEnoughL()
       
    89 	*/
       
    90 	IMPORT_C static CAESEncryptor* NewL(const TDesC8& aKey);
       
    91 	
       
    92 	/**
       
    93 	* Creates an instance of this class and leaves it on the cleanup stack.
       
    94 	*
       
    95 	* @param aKey	The key to be used for encryption. The key length must be either
       
    96 	*				KAESKeySize128 (=16), KAESKeySize192 (=24) or KAESKeySize256 (=32) bytes.
       
    97 	*
       
    98 	* @leave KErrKeyNotWeakEnough	If the key size is larger than that allowed by the
       
    99 	*								cipher strength restrictions of the crypto library.
       
   100 	*								See TCrypto::IsSymmetricWeakEnoughL()
       
   101 	*/
       
   102 	IMPORT_C static CAESEncryptor* NewLC(const TDesC8& aKey);
       
   103 	virtual TInt BlockSize() const;
       
   104 	virtual void Transform(TDes8& aBlock);
       
   105 protected:
       
   106 	/** @internalAll */
       
   107 	CAESEncryptor(void);
       
   108 private:
       
   109 	CAESEncryptor(const CAESEncryptor&);
       
   110 	const CAESEncryptor& operator= (const CAESEncryptor&);
       
   111 };
       
   112 
       
   113 /**
       
   114 * Concrete class for AES decryption.
       
   115 *
       
   116 */
       
   117 class CAESDecryptor : public CRijndael
       
   118 {
       
   119 public:	//	From CBlockTransformation
       
   120 	/**
       
   121 	* Creates an instance of this class.
       
   122 	*
       
   123 	* @param aKey	The key to be used for decryption. The key length must be either
       
   124 	*				KAESKeySize128 (=16), KAESKeySize192 (=24) or KAESKeySize256 (=32) bytes.
       
   125 	*
       
   126 	* @leave KErrKeyNotWeakEnough	If the key size is larger than that allowed by the
       
   127 	*								cipher strength restrictions of the crypto library. 
       
   128 	*								See TCrypto::IsSymmetricWeakEnoughL()
       
   129 	*/
       
   130 	IMPORT_C static CAESDecryptor* NewL(const TDesC8& aKey);
       
   131 
       
   132 	/**
       
   133 	* Creates an instance of this class and leaves it on the cleanup stack.
       
   134 	*
       
   135 	* @param aKey	The key to be used for decryption. The key length must be either
       
   136 	*				KAESKeySize128 (=16), KAESKeySize192 (=24) or KAESKeySize256 (=32) bytes.
       
   137 	*
       
   138 	* @leave KErrKeyNotWeakEnough	If the key size is larger than that allowed by the
       
   139 	*								cipher strength restrictions of the crypto library.
       
   140 	*								See TCrypto::IsSymmetricWeakEnoughL()
       
   141 	*/
       
   142 	IMPORT_C static CAESDecryptor* NewLC(const TDesC8& aKey);
       
   143 	virtual TInt BlockSize() const;
       
   144 	virtual void Transform(TDes8& aBlock);
       
   145 protected:
       
   146 	virtual void SetKey(const TDesC8& aKey);
       
   147 	/** @internalAll */
       
   148 	CAESDecryptor(void);
       
   149 private:
       
   150 	CAESDecryptor(const CAESDecryptor&);
       
   151 	const CAESDecryptor& operator= (const CAESDecryptor&);
       
   152 };
       
   153 
       
   154 
       
   155 #endif	//	__RIJNDAEL_H__