First public contribution.
2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
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
28 #ifndef __RIJNDAEL_H__
29 #define __RIJNDAEL_H__
31 #include <blocktransformation.h>
34 * Abstract base class for Rijndael, implementing the parts of Rijndael common to both
35 * Rijndael encryption and decryption.
38 class CRijndael : public CBlockTransformation
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);
46 /** Default constructor */
47 IMPORT_C CRijndael(void);
48 virtual void SetKey(const TDesC8& aKey);
49 virtual void ConstructL(const TDesC8& aKey);
54 * The maximum size is (((KAESMaxBlockSize/4)+6)+1)*4
57 /** The number of rounds */
62 * The key length (in bytes) must be one of the following:
63 * - KAESKeySize128 (=16)
64 * - KAESKeySize192 (=24)
65 * - KAESKeySize256 (=32).
69 CRijndael(const CRijndael&);
70 const CRijndael& operator= (const CRijndael&);
74 * Concrete class for AES encryption.
77 class CAESEncryptor : public CRijndael
79 public: // From CBlockTransformation
81 * Creates an instance of this class.
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.
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()
90 IMPORT_C static CAESEncryptor* NewL(const TDesC8& aKey);
93 * Creates an instance of this class and leaves it on the cleanup stack.
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.
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()
102 IMPORT_C static CAESEncryptor* NewLC(const TDesC8& aKey);
103 virtual TInt BlockSize() const;
104 virtual void Transform(TDes8& aBlock);
109 CAESEncryptor(const CAESEncryptor&);
110 const CAESEncryptor& operator= (const CAESEncryptor&);
114 * Concrete class for AES decryption.
117 class CAESDecryptor : public CRijndael
119 public: // From CBlockTransformation
121 * Creates an instance of this class.
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.
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()
130 IMPORT_C static CAESDecryptor* NewL(const TDesC8& aKey);
133 * Creates an instance of this class and leaves it on the cleanup stack.
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.
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()
142 IMPORT_C static CAESDecryptor* NewLC(const TDesC8& aKey);
143 virtual TInt BlockSize() const;
144 virtual void Transform(TDes8& aBlock);
146 virtual void SetKey(const TDesC8& aKey);
150 CAESDecryptor(const CAESDecryptor&);
151 const CAESDecryptor& operator= (const CAESDecryptor&);
155 #endif // __RIJNDAEL_H__