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.
20 #include "rijndaelshim.h"
21 #include "rijndaeltables.h"
22 #include "../common/inlines.h"
23 #include <cryptostrength.h>
25 const TUint KAESKeyBytes128 = 16;
26 const TUint KAESKeyBytes192 = 24;
27 const TUint KAESKeyBytes256 = 32;
28 const TUint KAESBlockBytes = 16;
31 EXPORT_C CRijndael::CRijndael(void)
35 void CRijndael::Reset()
37 // CRijndael is externally derivable. Don't delete this code
41 TInt CRijndael::KeySize() const
43 // CRijndael is externally derivable. Don't delete this code
44 return (4*(iRounds+1));
47 EXPORT_C CRijndael::~CRijndael()
49 // CRijndael is externally derivable. Don't delete this code
53 void CRijndael::ConstructL(const TDesC8& aKey)
55 // CRijndael is externally derivable. Don't delete this code
56 TUint keySize = aKey.Size();
57 assert((keySize==KAESKeyBytes128)||(keySize==KAESKeyBytes192)||(keySize==KAESKeyBytes256));
59 iRounds = keySize/4 + 6;
63 void CRijndael::SetKey(const TDesC8& aKey)
65 // CRijndael is externally derivable. Don't delete this code
66 TUint keySize = aKey.Size();
72 GetUserKeyBigEndian(rk, keySize/4, &aKey[0], keySize);
76 case (KAESKeyBytes128):
82 (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 2)] & 0xff000000) ^
83 (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 1)] & 0x00ff0000) ^
84 (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 0)] & 0x0000ff00) ^
85 (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 3)] & 0x000000ff) ^
86 RIJNDAEL_TABLE::rcon[i];
87 rk[5] = rk[1] ^ rk[4];
88 rk[6] = rk[2] ^ rk[5];
89 rk[7] = rk[3] ^ rk[6];
97 case (KAESKeyBytes192):
103 (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 2)] & 0xff000000) ^
104 (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 1)] & 0x00ff0000) ^
105 (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 0)] & 0x0000ff00) ^
106 (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 3)] & 0x000000ff) ^
107 RIJNDAEL_TABLE::rcon[i];
108 rk[ 7] = rk[ 1] ^ rk[ 6];
109 rk[ 8] = rk[ 2] ^ rk[ 7];
110 rk[ 9] = rk[ 3] ^ rk[ 8];
113 rk[10] = rk[ 4] ^ rk[ 9];
114 rk[11] = rk[ 5] ^ rk[10];
120 case (KAESKeyBytes256):
126 (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 2)] & 0xff000000) ^
127 (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 1)] & 0x00ff0000) ^
128 (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 0)] & 0x0000ff00) ^
129 (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 3)] & 0x000000ff) ^
130 RIJNDAEL_TABLE::rcon[i];
131 rk[ 9] = rk[ 1] ^ rk[ 8];
132 rk[10] = rk[ 2] ^ rk[ 9];
133 rk[11] = rk[ 3] ^ rk[10];
138 (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 3)] & 0xff000000) ^
139 (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 2)] & 0x00ff0000) ^
140 (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 1)] & 0x0000ff00) ^
141 (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 0)] & 0x000000ff);
142 rk[13] = rk[ 5] ^ rk[12];
143 rk[14] = rk[ 6] ^ rk[13];
144 rk[15] = rk[ 7] ^ rk[14];
152 assert(0); // Shouldn't get here, keeps compiler happy
158 EXPORT_C CAESEncryptor* CAESEncryptor::NewL(const TDesC8& aKey)
160 return CAESEncryptorShim::NewL(aKey);
163 EXPORT_C CAESEncryptor* CAESEncryptor::NewLC(const TDesC8& aKey)
165 return CAESEncryptorShim::NewLC(aKey);
168 CAESEncryptor::CAESEncryptor()
173 EXPORT_C CAESDecryptor* CAESDecryptor::NewL(const TDesC8& aKey)
175 return CAESDecryptorShim::NewL(aKey);
178 EXPORT_C CAESDecryptor* CAESDecryptor::NewLC(const TDesC8& aKey)
180 return CAESDecryptorShim::NewLC(aKey);
183 CAESDecryptor::CAESDecryptor()
187 // All these methods have been replaced by the shim
188 #ifdef _BullseyeCoverage
189 #pragma suppress_warnings on
190 #pragma BullseyeCoverage off
191 #pragma suppress_warnings off
194 TInt CAESDecryptor::BlockSize() const
196 // Method replaced by shim
201 void CAESDecryptor::Transform(TDes8& /*aBlock*/)
203 // Method replaced by shim
207 void CAESDecryptor::SetKey(const TDesC8& /*aKey*/)
209 // Method replaced by shim
213 TInt CAESEncryptor::BlockSize() const
215 // Method replaced by shim
217 return KAESBlockBytes;
220 void CAESEncryptor::Transform(TDes8& /*aBlock*/)
222 // Method replaced by shim