Changeset a7282fb for tools/traceanon/rijndael.c
- Timestamp:
- 11/14/06 13:56:01 (14 years ago)
- Branches:
- 4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
- Children:
- 2595c4d
- Parents:
- 35e0869
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/traceanon/rijndael.c
rc631f0f ra7282fb 1 / / $Id$2 3 / /1 /* $Id$ */ 2 3 /* 4 4 // File : rijndael.cpp 5 5 // Creation date : Sun Nov 5 2000 03:22:10 CEST … … 10 10 // This code is public domain. 11 11 // Based on the Vincent Rijmen and K.U.Leuven implementation 2.4. 12 //13 14 / /12 */ 13 14 /* 15 15 // Original Copyright notice: 16 16 // … … 28 28 // 29 29 // This code is placed in the public domain. 30 //31 32 / /30 */ 31 32 /* 33 33 // This implementation works on 128 , 192 , 256 bit keys 34 34 // and on 128 bit blocks 35 //35 */ 36 36 37 37 #define _RIJNDAEL_CPP_ … … 971 971 972 972 973 / /////////////////////////////////////////////////////////////////////////////////////////////////////////////////973 /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////// 974 974 // API 975 //////////////////////////////////////////////////////////////////////////////////////////////////////////////// //975 //////////////////////////////////////////////////////////////////////////////////////////////////////////////// */ 976 976 977 977 int rijndael_init(Mode mode,Direction dir,const UINT8 * key,KeyLength keyLen,UINT8 * initVector) … … 982 982 UINT32 j; 983 983 984 / / Not initialized yet984 /* Not initialized yet */ 985 985 m_state = Invalid; 986 986 987 / / Check the mode987 /* Check the mode */ 988 988 if((mode != CBC) && (mode != ECB) && (mode != CFB1))return RIJNDAEL_UNSUPPORTED_MODE; 989 989 m_mode = mode; 990 990 991 / / And the direction991 /* And the direction */ 992 992 if((dir != Encrypt) && (dir != Decrypt))return RIJNDAEL_UNSUPPORTED_DIRECTION; 993 993 m_direction = dir; 994 994 995 / / Allow to set an init vector995 /* Allow to set an init vector */ 996 996 if(initVector) 997 997 { 998 / / specified init vector998 /* specified init vector */ 999 999 for(i = 0;i < MAX_IV_SIZE;i++) 1000 1000 { … … 1002 1002 } 1003 1003 } else { 1004 / / zero init vector1004 /* zero init vector */ 1005 1005 for(i = 0;i < MAX_IV_SIZE;i++) 1006 1006 { … … 1010 1010 1011 1011 1012 / / And check the key length1012 /* And check the key length */ 1013 1013 switch(keyLen) 1014 1014 { … … 1029 1029 break; 1030 1030 } 1031 / /The number of rounds is calculated as1031 /* The number of rounds is calculated as 1032 1032 // m_uRounds = (m_uKeyLenInBits / 32) + 6; 1033 */ 1033 1034 1034 1035 if(!key)return RIJNDAEL_BAD_KEY; … … 1154 1155 } 1155 1156 padLen = 16 - (inputOctets - 16*numBlocks); 1156 // assert(padLen > 0 && padLen <= 16);1157 1157 memcpy(block, input, 16 - padLen); 1158 1158 memset(block + 16 - padLen, padLen, padLen); … … 1173 1173 } 1174 1174 padLen = 16 - (inputOctets - 16*numBlocks); 1175 // assert(padLen > 0 && padLen <= 16); // DO SOMETHING HERE ?1176 1175 for (i = 0; i < 16 - padLen; i++) { 1177 1176 block[i] = input[i] ^ iv[i]; … … 1358 1357 } 1359 1358 1360 / /////////////////////////////////////////////////////////////////////////////////////////////////////////////////1359 /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1361 1360 // ALGORITHM 1362 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1361 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */ 1363 1362 1364 1363 … … 1369 1368 int t = 0; 1370 1369 1371 / / Calculate the necessary round keys1372 / / The number of calculations depends on keyBits and blockBits1370 /* Calculate the necessary round keys */ 1371 /* The number of calculations depends on keyBits and blockBits */ 1373 1372 int uKeyColumns = m_uRounds - 6; 1374 1373 1375 1374 UINT8 tempKey[_MAX_KEY_COLUMNS][4]; 1376 1375 1377 / / Copy the input key to the temporary key matrix1376 /* Copy the input key to the temporary key matrix */ 1378 1377 1379 1378 for(j = 0;j < uKeyColumns;j++) … … 1383 1382 1384 1383 1385 / / copy values into round key array1384 /* copy values into round key array */ 1386 1385 for(j = 0;(j < uKeyColumns) && (r <= m_uRounds); ) 1387 1386 { … … 1540 1539 UINT8 temp[4][4]; 1541 1540 1542 *((UINT32*)temp[0]) = *(( UINT32*)(a )) ^ *((UINT32*)m_expandedKey[m_uRounds][0]);1543 *((UINT32*)temp[1]) = *(( UINT32*)(a+ 4)) ^ *((UINT32*)m_expandedKey[m_uRounds][1]);1544 *((UINT32*)temp[2]) = *(( UINT32*)(a+ 8)) ^ *((UINT32*)m_expandedKey[m_uRounds][2]);1545 *((UINT32*)temp[3]) = *(( UINT32*)(a+12)) ^ *((UINT32*)m_expandedKey[m_uRounds][3]);1546 1547 *((UINT32*)(b )) = *(( UINT32*)T5[temp[0][0]])1548 ^ *(( UINT32*)T6[temp[3][1]])1549 ^ *(( UINT32*)T7[temp[2][2]])1550 ^ *(( UINT32*)T8[temp[1][3]]);1551 *((UINT32*)(b+ 4)) = *(( UINT32*)T5[temp[1][0]])1552 ^ *(( UINT32*)T6[temp[0][1]])1553 ^ *(( UINT32*)T7[temp[3][2]])1554 ^ *(( UINT32*)T8[temp[2][3]]);1541 *((UINT32*)temp[0]) = *((const UINT32*)(a )) ^ *((const UINT32*)m_expandedKey[m_uRounds][0]); 1542 *((UINT32*)temp[1]) = *((const UINT32*)(a+ 4)) ^ *((const UINT32*)m_expandedKey[m_uRounds][1]); 1543 *((UINT32*)temp[2]) = *((const UINT32*)(a+ 8)) ^ *((const UINT32*)m_expandedKey[m_uRounds][2]); 1544 *((UINT32*)temp[3]) = *((const UINT32*)(a+12)) ^ *((const UINT32*)m_expandedKey[m_uRounds][3]); 1545 1546 *((UINT32*)(b )) = *((const UINT32*)T5[temp[0][0]]) 1547 ^ *((const UINT32*)T6[temp[3][1]]) 1548 ^ *((const UINT32*)T7[temp[2][2]]) 1549 ^ *((const UINT32*)T8[temp[1][3]]); 1550 *((UINT32*)(b+ 4)) = *((const UINT32*)T5[temp[1][0]]) 1551 ^ *((const UINT32*)T6[temp[0][1]]) 1552 ^ *((const UINT32*)T7[temp[3][2]]) 1553 ^ *((const UINT32*)T8[temp[2][3]]); 1555 1554 *((UINT32*)(b+ 8)) = *((UINT32*)T5[temp[2][0]]) 1556 ^ *(( UINT32*)T6[temp[1][1]])1557 ^ *(( UINT32*)T7[temp[0][2]])1558 ^ *(( UINT32*)T8[temp[3][3]]);1555 ^ *((const UINT32*)T6[temp[1][1]]) 1556 ^ *((const UINT32*)T7[temp[0][2]]) 1557 ^ *((const UINT32*)T8[temp[3][3]]); 1559 1558 *((UINT32*)(b+12)) = *((UINT32*)T5[temp[3][0]]) 1560 ^ *(( UINT32*)T6[temp[2][1]])1561 ^ *(( UINT32*)T7[temp[1][2]])1562 ^ *(( UINT32*)T8[temp[0][3]]);1559 ^ *((const UINT32*)T6[temp[2][1]]) 1560 ^ *((const UINT32*)T7[temp[1][2]]) 1561 ^ *((const UINT32*)T8[temp[0][3]]); 1563 1562 for(r = m_uRounds-1; r > 1; r--) 1564 1563 {
Note: See TracChangeset
for help on using the changeset viewer.