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