#include <aes.hpp>
Inheritance diagram for TaoCrypt::AES:


Public Types | |
| BLOCK_SIZE = AES_BLOCK_SIZE | |
| enum | { BLOCK_SIZE = AES_BLOCK_SIZE } |
Public Member Functions | |
| AES (CipherDir DIR, Mode MODE) | |
| void | Process (byte *, const byte *, word32) |
| void | SetKey (const byte *key, word32 sz, CipherDir fake=ENCRYPTION) |
| void | SetIV (const byte *iv) |
Private Member Functions | |
| void | encrypt (const byte *, const byte *, byte *) const |
| void | AsmEncrypt (const byte *, byte *, void *) const |
| void | decrypt (const byte *, const byte *, byte *) const |
| void | AsmDecrypt (const byte *, byte *, void *) const |
| void | ProcessAndXorBlock (const byte *, const byte *, byte *) const |
| AES (const AES &) | |
| AES & | operator= (const AES &) |
Private Attributes | |
| CipherDir | dir_ |
| Mode | mode_ |
| word32 | rounds_ |
| word32 | key_ [60] |
Static Private Attributes | |
| static const word32 | rcon_ [] |
| static const word32 | Te [5][256] |
| static const word32 | Td [5][256] |
| static const word32 * | Te0 = AES::Te[0] |
| static const word32 * | Te1 = AES::Te[1] |
| static const word32 * | Te2 = AES::Te[2] |
| static const word32 * | Te3 = AES::Te[3] |
| static const word32 * | Te4 = AES::Te[4] |
| static const word32 * | Td0 = AES::Td[0] |
| static const word32 * | Td1 = AES::Td[1] |
| static const word32 * | Td2 = AES::Td[2] |
| static const word32 * | Td3 = AES::Td[3] |
| static const word32 * | Td4 = AES::Td[4] |
Definition at line 44 of file aes.hpp.
| anonymous enum |
| TaoCrypt::AES::AES | ( | const AES & | ) | [private] |
Definition at line 357 of file aes.cpp.
References TaoCrypt::BlockGetAndPut< T, B, A >::Get(), GETBYTE, key_, rounds_, Td0, Td1, Td2, Td3, and Td4.
Referenced by ProcessAndXorBlock().
00359 { 00360 word32 s0, s1, s2, s3; 00361 word32 t0, t1, t2, t3; 00362 const word32* rk = key_; 00363 00364 /* 00365 * map byte array block to cipher state 00366 * and add initial round key: 00367 */ 00368 gpBlock::Get(inBlock)(s0)(s1)(s2)(s3); 00369 s0 ^= rk[0]; 00370 s1 ^= rk[1]; 00371 s2 ^= rk[2]; 00372 s3 ^= rk[3]; 00373 00374 /* 00375 * Nr - 1 full rounds: 00376 */ 00377 00378 unsigned int r = rounds_ >> 1; 00379 for (;;) { 00380 t0 = 00381 Td0[GETBYTE(s0, 3)] ^ 00382 Td1[GETBYTE(s3, 2)] ^ 00383 Td2[GETBYTE(s2, 1)] ^ 00384 Td3[GETBYTE(s1, 0)] ^ 00385 rk[4]; 00386 t1 = 00387 Td0[GETBYTE(s1, 3)] ^ 00388 Td1[GETBYTE(s0, 2)] ^ 00389 Td2[GETBYTE(s3, 1)] ^ 00390 Td3[GETBYTE(s2, 0)] ^ 00391 rk[5]; 00392 t2 = 00393 Td0[GETBYTE(s2, 3)] ^ 00394 Td1[GETBYTE(s1, 2)] ^ 00395 Td2[GETBYTE(s0, 1)] ^ 00396 Td3[GETBYTE(s3, 0)] ^ 00397 rk[6]; 00398 t3 = 00399 Td0[GETBYTE(s3, 3)] ^ 00400 Td1[GETBYTE(s2, 2)] ^ 00401 Td2[GETBYTE(s1, 1)] ^ 00402 Td3[GETBYTE(s0, 0)] ^ 00403 rk[7]; 00404 00405 rk += 8; 00406 if (--r == 0) { 00407 break; 00408 } 00409 00410 s0 = 00411 Td0[GETBYTE(t0, 3)] ^ 00412 Td1[GETBYTE(t3, 2)] ^ 00413 Td2[GETBYTE(t2, 1)] ^ 00414 Td3[GETBYTE(t1, 0)] ^ 00415 rk[0]; 00416 s1 = 00417 Td0[GETBYTE(t1, 3)] ^ 00418 Td1[GETBYTE(t0, 2)] ^ 00419 Td2[GETBYTE(t3, 1)] ^ 00420 Td3[GETBYTE(t2, 0)] ^ 00421 rk[1]; 00422 s2 = 00423 Td0[GETBYTE(t2, 3)] ^ 00424 Td1[GETBYTE(t1, 2)] ^ 00425 Td2[GETBYTE(t0, 1)] ^ 00426 Td3[GETBYTE(t3, 0)] ^ 00427 rk[2]; 00428 s3 = 00429 Td0[GETBYTE(t3, 3)] ^ 00430 Td1[GETBYTE(t2, 2)] ^ 00431 Td2[GETBYTE(t1, 1)] ^ 00432 Td3[GETBYTE(t0, 0)] ^ 00433 rk[3]; 00434 } 00435 /* 00436 * apply last round and 00437 * map cipher state to byte array block: 00438 */ 00439 s0 = 00440 (Td4[GETBYTE(t0, 3)] & 0xff000000) ^ 00441 (Td4[GETBYTE(t3, 2)] & 0x00ff0000) ^ 00442 (Td4[GETBYTE(t2, 1)] & 0x0000ff00) ^ 00443 (Td4[GETBYTE(t1, 0)] & 0x000000ff) ^ 00444 rk[0]; 00445 s1 = 00446 (Td4[GETBYTE(t1, 3)] & 0xff000000) ^ 00447 (Td4[GETBYTE(t0, 2)] & 0x00ff0000) ^ 00448 (Td4[GETBYTE(t3, 1)] & 0x0000ff00) ^ 00449 (Td4[GETBYTE(t2, 0)] & 0x000000ff) ^ 00450 rk[1]; 00451 s2 = 00452 (Td4[GETBYTE(t2, 3)] & 0xff000000) ^ 00453 (Td4[GETBYTE(t1, 2)] & 0x00ff0000) ^ 00454 (Td4[GETBYTE(t0, 1)] & 0x0000ff00) ^ 00455 (Td4[GETBYTE(t3, 0)] & 0x000000ff) ^ 00456 rk[2]; 00457 s3 = 00458 (Td4[GETBYTE(t3, 3)] & 0xff000000) ^ 00459 (Td4[GETBYTE(t2, 2)] & 0x00ff0000) ^ 00460 (Td4[GETBYTE(t1, 1)] & 0x0000ff00) ^ 00461 (Td4[GETBYTE(t0, 0)] & 0x000000ff) ^ 00462 rk[3]; 00463 00464 gpBlock::Put(xorBlock, outBlock)(s0)(s1)(s2)(s3); 00465 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 243 of file aes.cpp.
References TaoCrypt::BlockGetAndPut< T, B, A >::Get(), GETBYTE, key_, rounds_, Te0, Te1, Te2, Te3, and Te4.
Referenced by ProcessAndXorBlock().
00245 { 00246 word32 s0, s1, s2, s3; 00247 word32 t0, t1, t2, t3; 00248 00249 const word32 *rk = key_; 00250 /* 00251 * map byte array block to cipher state 00252 * and add initial round key: 00253 */ 00254 gpBlock::Get(inBlock)(s0)(s1)(s2)(s3); 00255 s0 ^= rk[0]; 00256 s1 ^= rk[1]; 00257 s2 ^= rk[2]; 00258 s3 ^= rk[3]; 00259 00260 /* 00261 * Nr - 1 full rounds: 00262 */ 00263 00264 unsigned int r = rounds_ >> 1; 00265 for (;;) { 00266 t0 = 00267 Te0[GETBYTE(s0, 3)] ^ 00268 Te1[GETBYTE(s1, 2)] ^ 00269 Te2[GETBYTE(s2, 1)] ^ 00270 Te3[GETBYTE(s3, 0)] ^ 00271 rk[4]; 00272 t1 = 00273 Te0[GETBYTE(s1, 3)] ^ 00274 Te1[GETBYTE(s2, 2)] ^ 00275 Te2[GETBYTE(s3, 1)] ^ 00276 Te3[GETBYTE(s0, 0)] ^ 00277 rk[5]; 00278 t2 = 00279 Te0[GETBYTE(s2, 3)] ^ 00280 Te1[GETBYTE(s3, 2)] ^ 00281 Te2[GETBYTE(s0, 1)] ^ 00282 Te3[GETBYTE(s1, 0)] ^ 00283 rk[6]; 00284 t3 = 00285 Te0[GETBYTE(s3, 3)] ^ 00286 Te1[GETBYTE(s0, 2)] ^ 00287 Te2[GETBYTE(s1, 1)] ^ 00288 Te3[GETBYTE(s2, 0)] ^ 00289 rk[7]; 00290 00291 rk += 8; 00292 if (--r == 0) { 00293 break; 00294 } 00295 00296 s0 = 00297 Te0[GETBYTE(t0, 3)] ^ 00298 Te1[GETBYTE(t1, 2)] ^ 00299 Te2[GETBYTE(t2, 1)] ^ 00300 Te3[GETBYTE(t3, 0)] ^ 00301 rk[0]; 00302 s1 = 00303 Te0[GETBYTE(t1, 3)] ^ 00304 Te1[GETBYTE(t2, 2)] ^ 00305 Te2[GETBYTE(t3, 1)] ^ 00306 Te3[GETBYTE(t0, 0)] ^ 00307 rk[1]; 00308 s2 = 00309 Te0[GETBYTE(t2, 3)] ^ 00310 Te1[GETBYTE(t3, 2)] ^ 00311 Te2[GETBYTE(t0, 1)] ^ 00312 Te3[GETBYTE(t1, 0)] ^ 00313 rk[2]; 00314 s3 = 00315 Te0[GETBYTE(t3, 3)] ^ 00316 Te1[GETBYTE(t0, 2)] ^ 00317 Te2[GETBYTE(t1, 1)] ^ 00318 Te3[GETBYTE(t2, 0)] ^ 00319 rk[3]; 00320 } 00321 00322 /* 00323 * apply last round and 00324 * map cipher state to byte array block: 00325 */ 00326 00327 s0 = 00328 (Te4[GETBYTE(t0, 3)] & 0xff000000) ^ 00329 (Te4[GETBYTE(t1, 2)] & 0x00ff0000) ^ 00330 (Te4[GETBYTE(t2, 1)] & 0x0000ff00) ^ 00331 (Te4[GETBYTE(t3, 0)] & 0x000000ff) ^ 00332 rk[0]; 00333 s1 = 00334 (Te4[GETBYTE(t1, 3)] & 0xff000000) ^ 00335 (Te4[GETBYTE(t2, 2)] & 0x00ff0000) ^ 00336 (Te4[GETBYTE(t3, 1)] & 0x0000ff00) ^ 00337 (Te4[GETBYTE(t0, 0)] & 0x000000ff) ^ 00338 rk[1]; 00339 s2 = 00340 (Te4[GETBYTE(t2, 3)] & 0xff000000) ^ 00341 (Te4[GETBYTE(t3, 2)] & 0x00ff0000) ^ 00342 (Te4[GETBYTE(t0, 1)] & 0x0000ff00) ^ 00343 (Te4[GETBYTE(t1, 0)] & 0x000000ff) ^ 00344 rk[2]; 00345 s3 = 00346 (Te4[GETBYTE(t3, 3)] & 0xff000000) ^ 00347 (Te4[GETBYTE(t0, 2)] & 0x00ff0000) ^ 00348 (Te4[GETBYTE(t1, 1)] & 0x0000ff00) ^ 00349 (Te4[GETBYTE(t2, 0)] & 0x000000ff) ^ 00350 rk[3]; 00351 00352 00353 gpBlock::Put(xorBlock, outBlock)(s0)(s1)(s2)(s3); 00354 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 48 of file aes.cpp.
References TaoCrypt::CBC, TaoCrypt::Mode_BASE::CBC_Decrypt(), TaoCrypt::Mode_BASE::CBC_Encrypt(), dir_, TaoCrypt::ECB, TaoCrypt::Mode_BASE::ECB_Process(), TaoCrypt::ENCRYPTION, and mode_.
00049 { 00050 if (mode_ == ECB) 00051 ECB_Process(out, in, sz); 00052 else if (mode_ == CBC) 00053 if (dir_ == ENCRYPTION) 00054 CBC_Encrypt(out, in, sz); 00055 else 00056 CBC_Decrypt(out, in, sz); 00057 }
Here is the call graph for this function:

| void TaoCrypt::AES::ProcessAndXorBlock | ( | const byte * | , | |
| const byte * | , | |||
| byte * | ||||
| ) | const [private, virtual] |
Implements TaoCrypt::Mode_BASE.
Definition at line 231 of file aes.cpp.
References decrypt(), dir_, encrypt(), and TaoCrypt::ENCRYPTION.
00232 { 00233 if (dir_ == ENCRYPTION) 00234 encrypt(in, xOr, out); 00235 else 00236 decrypt(in, xOr, out); 00237 }
Here is the call graph for this function:

| void TaoCrypt::AES::SetIV | ( | const byte * | iv | ) | [inline] |
Reimplemented from TaoCrypt::Mode_BASE.
Definition at line 53 of file aes.hpp.
References BLOCK_SIZE, memcpy, and TaoCrypt::Mode_BASE::r_.
00053 { memcpy(r_, iv, BLOCK_SIZE); }
Definition at line 107 of file aes.cpp.
References assert, TaoCrypt::BigEndianOrder, TaoCrypt::DECRYPTION, dir_, GETBYTE, TaoCrypt::GetUserKey(), key_, rcon_, rounds_, Td0, Td1, Td2, Td3, and Te4.
00108 { 00109 assert( (keylen == 16) || (keylen == 24) || (keylen == 32) ); 00110 00111 rounds_ = keylen/4 + 6; 00112 00113 word32 temp, *rk = key_; 00114 unsigned int i=0; 00115 00116 GetUserKey(BigEndianOrder, rk, keylen/4, userKey, keylen); 00117 00118 switch(keylen) 00119 { 00120 case 16: 00121 while (true) 00122 { 00123 temp = rk[3]; 00124 rk[4] = rk[0] ^ 00125 (Te4[GETBYTE(temp, 2)] & 0xff000000) ^ 00126 (Te4[GETBYTE(temp, 1)] & 0x00ff0000) ^ 00127 (Te4[GETBYTE(temp, 0)] & 0x0000ff00) ^ 00128 (Te4[GETBYTE(temp, 3)] & 0x000000ff) ^ 00129 rcon_[i]; 00130 rk[5] = rk[1] ^ rk[4]; 00131 rk[6] = rk[2] ^ rk[5]; 00132 rk[7] = rk[3] ^ rk[6]; 00133 if (++i == 10) 00134 break; 00135 rk += 4; 00136 } 00137 break; 00138 00139 case 24: 00140 while (true) // for (;;) here triggers a bug in VC60 SP4 w/ Pro Pack 00141 { 00142 temp = rk[ 5]; 00143 rk[ 6] = rk[ 0] ^ 00144 (Te4[GETBYTE(temp, 2)] & 0xff000000) ^ 00145 (Te4[GETBYTE(temp, 1)] & 0x00ff0000) ^ 00146 (Te4[GETBYTE(temp, 0)] & 0x0000ff00) ^ 00147 (Te4[GETBYTE(temp, 3)] & 0x000000ff) ^ 00148 rcon_[i]; 00149 rk[ 7] = rk[ 1] ^ rk[ 6]; 00150 rk[ 8] = rk[ 2] ^ rk[ 7]; 00151 rk[ 9] = rk[ 3] ^ rk[ 8]; 00152 if (++i == 8) 00153 break; 00154 rk[10] = rk[ 4] ^ rk[ 9]; 00155 rk[11] = rk[ 5] ^ rk[10]; 00156 rk += 6; 00157 } 00158 break; 00159 00160 case 32: 00161 while (true) 00162 { 00163 temp = rk[ 7]; 00164 rk[ 8] = rk[ 0] ^ 00165 (Te4[GETBYTE(temp, 2)] & 0xff000000) ^ 00166 (Te4[GETBYTE(temp, 1)] & 0x00ff0000) ^ 00167 (Te4[GETBYTE(temp, 0)] & 0x0000ff00) ^ 00168 (Te4[GETBYTE(temp, 3)] & 0x000000ff) ^ 00169 rcon_[i]; 00170 rk[ 9] = rk[ 1] ^ rk[ 8]; 00171 rk[10] = rk[ 2] ^ rk[ 9]; 00172 rk[11] = rk[ 3] ^ rk[10]; 00173 if (++i == 7) 00174 break; 00175 temp = rk[11]; 00176 rk[12] = rk[ 4] ^ 00177 (Te4[GETBYTE(temp, 3)] & 0xff000000) ^ 00178 (Te4[GETBYTE(temp, 2)] & 0x00ff0000) ^ 00179 (Te4[GETBYTE(temp, 1)] & 0x0000ff00) ^ 00180 (Te4[GETBYTE(temp, 0)] & 0x000000ff); 00181 rk[13] = rk[ 5] ^ rk[12]; 00182 rk[14] = rk[ 6] ^ rk[13]; 00183 rk[15] = rk[ 7] ^ rk[14]; 00184 00185 rk += 8; 00186 } 00187 break; 00188 } 00189 00190 if (dir_ == DECRYPTION) 00191 { 00192 unsigned int i, j; 00193 rk = key_; 00194 00195 /* invert the order of the round keys: */ 00196 for (i = 0, j = 4*rounds_; i < j; i += 4, j -= 4) { 00197 temp = rk[i ]; rk[i ] = rk[j ]; rk[j ] = temp; 00198 temp = rk[i + 1]; rk[i + 1] = rk[j + 1]; rk[j + 1] = temp; 00199 temp = rk[i + 2]; rk[i + 2] = rk[j + 2]; rk[j + 2] = temp; 00200 temp = rk[i + 3]; rk[i + 3] = rk[j + 3]; rk[j + 3] = temp; 00201 } 00202 // apply the inverse MixColumn transform to all round keys but the 00203 // first and the last: 00204 for (i = 1; i < rounds_; i++) { 00205 rk += 4; 00206 rk[0] = 00207 Td0[Te4[GETBYTE(rk[0], 3)] & 0xff] ^ 00208 Td1[Te4[GETBYTE(rk[0], 2)] & 0xff] ^ 00209 Td2[Te4[GETBYTE(rk[0], 1)] & 0xff] ^ 00210 Td3[Te4[GETBYTE(rk[0], 0)] & 0xff]; 00211 rk[1] = 00212 Td0[Te4[GETBYTE(rk[1], 3)] & 0xff] ^ 00213 Td1[Te4[GETBYTE(rk[1], 2)] & 0xff] ^ 00214 Td2[Te4[GETBYTE(rk[1], 1)] & 0xff] ^ 00215 Td3[Te4[GETBYTE(rk[1], 0)] & 0xff]; 00216 rk[2] = 00217 Td0[Te4[GETBYTE(rk[2], 3)] & 0xff] ^ 00218 Td1[Te4[GETBYTE(rk[2], 2)] & 0xff] ^ 00219 Td2[Te4[GETBYTE(rk[2], 1)] & 0xff] ^ 00220 Td3[Te4[GETBYTE(rk[2], 0)] & 0xff]; 00221 rk[3] = 00222 Td0[Te4[GETBYTE(rk[3], 3)] & 0xff] ^ 00223 Td1[Te4[GETBYTE(rk[3], 2)] & 0xff] ^ 00224 Td2[Te4[GETBYTE(rk[3], 1)] & 0xff] ^ 00225 Td3[Te4[GETBYTE(rk[3], 0)] & 0xff]; 00226 } 00227 } 00228 }
Here is the call graph for this function:

CipherDir TaoCrypt::AES::dir_ [private] |
word32 TaoCrypt::AES::key_[60] [private] |
Mode TaoCrypt::AES::mode_ [private] |
const word32 TaoCrypt::AES::rcon_ [static, private] |
word32 TaoCrypt::AES::rounds_ [private] |
const word32 TaoCrypt::AES::Td [static, private] |
const word32 * TaoCrypt::AES::Td0 = AES::Td[0] [static, private] |
const word32 * TaoCrypt::AES::Td1 = AES::Td[1] [static, private] |
const word32 * TaoCrypt::AES::Td2 = AES::Td[2] [static, private] |
const word32 * TaoCrypt::AES::Td3 = AES::Td[3] [static, private] |
const word32 * TaoCrypt::AES::Td4 = AES::Td[4] [static, private] |
const word32 TaoCrypt::AES::Te [static, private] |
const word32 * TaoCrypt::AES::Te0 = AES::Te[0] [static, private] |
const word32 * TaoCrypt::AES::Te1 = AES::Te[1] [static, private] |
const word32 * TaoCrypt::AES::Te2 = AES::Te[2] [static, private] |
const word32 * TaoCrypt::AES::Te3 = AES::Te[3] [static, private] |
const word32 * TaoCrypt::AES::Te4 = AES::Te[4] [static, private] |
1.4.7

