os/security/crypto/weakcrypto/inc/rijndael.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
* ** IMPORTANT ** PublishedPartner API's in this file are published to 3rd party developers via the 
sl@0
    16
* Symbian website. Changes to these API's should be treated as PublishedAll API changes and the Security TA should be consulted.
sl@0
    17
* Rijndael implementation
sl@0
    18
*
sl@0
    19
*/
sl@0
    20
sl@0
    21
sl@0
    22
/**
sl@0
    23
 @file 
sl@0
    24
 @publishedPartner
sl@0
    25
 @released 
sl@0
    26
*/
sl@0
    27
 
sl@0
    28
#ifndef __RIJNDAEL_H__
sl@0
    29
#define __RIJNDAEL_H__
sl@0
    30
sl@0
    31
#include "blocktransformation.h"
sl@0
    32
sl@0
    33
/**
sl@0
    34
* Abstract base class for Rijndael, implementing the parts of Rijndael common to both
sl@0
    35
* Rijndael encryption and decryption.
sl@0
    36
*
sl@0
    37
*/
sl@0
    38
class CRijndael : public CBlockTransformation
sl@0
    39
{
sl@0
    40
public:	//	From CBlockTransformation
sl@0
    41
	virtual void Reset(void);
sl@0
    42
	virtual TInt KeySize(void) const;
sl@0
    43
	/** The destructor frees all resources owned by the object, prior to its destruction. */
sl@0
    44
	IMPORT_C virtual ~CRijndael(void);
sl@0
    45
protected:
sl@0
    46
	/** Default constructor */
sl@0
    47
	IMPORT_C CRijndael(void);
sl@0
    48
	virtual void SetKey(const TDesC8& aKey);
sl@0
    49
	virtual void ConstructL(const TDesC8& aKey);
sl@0
    50
protected:
sl@0
    51
	/** 
sl@0
    52
	 * The key schedule 
sl@0
    53
	 *
sl@0
    54
	 * The maximum size is (((KAESMaxBlockSize/4)+6)+1)*4
sl@0
    55
	 */
sl@0
    56
	TUint32 iK[60];
sl@0
    57
	/** The number of rounds */
sl@0
    58
	TUint iRounds;
sl@0
    59
	/** 
sl@0
    60
	 * The input key 
sl@0
    61
	 *
sl@0
    62
	 * The key length (in bytes) must be one of the following:
sl@0
    63
	 * - KAESKeySize128 (=16)
sl@0
    64
	 * - KAESKeySize192 (=24)
sl@0
    65
	 * - KAESKeySize256 (=32).
sl@0
    66
	 */
sl@0
    67
	HBufC8* iKey;
sl@0
    68
private:
sl@0
    69
	CRijndael(const CRijndael&);
sl@0
    70
	const CRijndael& operator= (const CRijndael&);
sl@0
    71
};
sl@0
    72
sl@0
    73
/**
sl@0
    74
* Concrete class for AES encryption.
sl@0
    75
*
sl@0
    76
*/
sl@0
    77
class CAESEncryptor : public CRijndael
sl@0
    78
{
sl@0
    79
public:	//	From CBlockTransformation
sl@0
    80
	/**
sl@0
    81
	* Creates an instance of this class.
sl@0
    82
	*
sl@0
    83
	* @param aKey	The key to be used for encryption. The key length must be either
sl@0
    84
	*				KAESKeySize128 (=16), KAESKeySize192 (=24) or KAESKeySize256 (=32) bytes.
sl@0
    85
	*
sl@0
    86
	* @leave KErrKeyNotWeakEnough	If the key size is larger than that allowed by the
sl@0
    87
	*								cipher strength restrictions of the crypto library.
sl@0
    88
	*								See TCrypto::IsSymmetricWeakEnoughL()
sl@0
    89
	*/
sl@0
    90
	IMPORT_C static CAESEncryptor* NewL(const TDesC8& aKey);
sl@0
    91
	
sl@0
    92
	/**
sl@0
    93
	* Creates an instance of this class and leaves it on the cleanup stack.
sl@0
    94
	*
sl@0
    95
	* @param aKey	The key to be used for encryption. The key length must be either
sl@0
    96
	*				KAESKeySize128 (=16), KAESKeySize192 (=24) or KAESKeySize256 (=32) bytes.
sl@0
    97
	*
sl@0
    98
	* @leave KErrKeyNotWeakEnough	If the key size is larger than that allowed by the
sl@0
    99
	*								cipher strength restrictions of the crypto library.
sl@0
   100
	*								See TCrypto::IsSymmetricWeakEnoughL()
sl@0
   101
	*/
sl@0
   102
	IMPORT_C static CAESEncryptor* NewLC(const TDesC8& aKey);
sl@0
   103
	virtual TInt BlockSize() const;
sl@0
   104
	virtual void Transform(TDes8& aBlock);
sl@0
   105
protected:
sl@0
   106
	/** @internalAll */
sl@0
   107
	CAESEncryptor(void);
sl@0
   108
private:
sl@0
   109
	CAESEncryptor(const CAESEncryptor&);
sl@0
   110
	const CAESEncryptor& operator= (const CAESEncryptor&);
sl@0
   111
};
sl@0
   112
sl@0
   113
/**
sl@0
   114
* Concrete class for AES decryption.
sl@0
   115
*
sl@0
   116
*/
sl@0
   117
class CAESDecryptor : public CRijndael
sl@0
   118
{
sl@0
   119
public:	//	From CBlockTransformation
sl@0
   120
	/**
sl@0
   121
	* Creates an instance of this class.
sl@0
   122
	*
sl@0
   123
	* @param aKey	The key to be used for decryption. The key length must be either
sl@0
   124
	*				KAESKeySize128 (=16), KAESKeySize192 (=24) or KAESKeySize256 (=32) bytes.
sl@0
   125
	*
sl@0
   126
	* @leave KErrKeyNotWeakEnough	If the key size is larger than that allowed by the
sl@0
   127
	*								cipher strength restrictions of the crypto library. 
sl@0
   128
	*								See TCrypto::IsSymmetricWeakEnoughL()
sl@0
   129
	*/
sl@0
   130
	IMPORT_C static CAESDecryptor* NewL(const TDesC8& aKey);
sl@0
   131
sl@0
   132
	/**
sl@0
   133
	* Creates an instance of this class and leaves it on the cleanup stack.
sl@0
   134
	*
sl@0
   135
	* @param aKey	The key to be used for decryption. The key length must be either
sl@0
   136
	*				KAESKeySize128 (=16), KAESKeySize192 (=24) or KAESKeySize256 (=32) bytes.
sl@0
   137
	*
sl@0
   138
	* @leave KErrKeyNotWeakEnough	If the key size is larger than that allowed by the
sl@0
   139
	*								cipher strength restrictions of the crypto library.
sl@0
   140
	*								See TCrypto::IsSymmetricWeakEnoughL()
sl@0
   141
	*/
sl@0
   142
	IMPORT_C static CAESDecryptor* NewLC(const TDesC8& aKey);
sl@0
   143
	virtual TInt BlockSize() const;
sl@0
   144
	virtual void Transform(TDes8& aBlock);
sl@0
   145
protected:
sl@0
   146
	virtual void SetKey(const TDesC8& aKey);
sl@0
   147
	/** @internalAll */
sl@0
   148
	CAESDecryptor(void);
sl@0
   149
private:
sl@0
   150
	CAESDecryptor(const CAESDecryptor&);
sl@0
   151
	const CAESDecryptor& operator= (const CAESDecryptor&);
sl@0
   152
};
sl@0
   153
sl@0
   154
sl@0
   155
#endif	//	__RIJNDAEL_H__