メインページ | アルファベット順一覧 | 構成 | ファイル一覧 | 構成メンバ | ファイルメンバ | 関連ページ

# dkcRijndael.c

説明を見る。

    00001
    00047
    00048 #define GETBYTE(x, y) (unsigned int)byte((x)>>(8*(y)))
    00049
    00050
    00051
    00052
    00053 #include "dkcRijndael.h"
    00054 #include "dkcOSIndependent.h"
    00055
    00056 //#include "rijndael-alg-fst.h"
    00057 #include "rijndael-api-fst.h"
    00058
    00059 DKC_RIJNDAEL *WINAPI dkcAllocRijndael(){
    00060     DKC_RIJNDAEL *p = dkcAllocate(sizeof(DKC_RIJNDAEL));
    00061     if(NULL==p){
    00062         return NULL;
    00063     }
    00064
    00065     p->mKey = dkcAllocate(sizeof(keyInstance));
    00066     if(NULL==p->mKey){
    00067         goto Error;
    00068     }
    00069
    00070     p->mRijndael = dkcAllocate(sizeof(cipherInstance));
    00071     if(NULL==p->mRijndael){
    00072         goto Error;
    00073     }
    00074     return p;
    00075 Error:
    00076     dkcFree(&p->mRijndael);
    00077     dkcFree(&p->mKey);
    00078     dkcFree(&p);
    00079     return NULL;
    00080 }
    00081
    00082 DKC_RIJNDAEL *WINAPI dkcAllocRijndaelEncrypt(const BYTE *key,size_t keysize)
    00083 {
    00084     DKC_RIJNDAEL *p = dkcAllocate(sizeof(DKC_RIJNDAEL));
    00085     if(NULL==p){
    00086         return NULL;
    00087     }
    00088
    00089     return p;
    00090 }
    00091
    00092
    00093 DKC_RIJNDAEL *WINAPI dkcAllocRijndaelDecrypt(const BYTE *key,size_t keysize){
    00094     DKC_RIJNDAEL *p = dkcAllocate(sizeof(DKC_RIJNDAEL));
    00095     if(NULL==p){
    00096         return NULL;
    00097     }
    00098
    00099     return p;
    00100
    00101 }
    00102 typedef int (*RIJNDAEL_CALLBACK_PROCESS)(cipherInstance *, keyInstance *,
    00103         BYTE *, int , BYTE *);
    00104
    00105 static ProcessCall(RIJNDAEL_CALLBACK_PROCESS proc,DKC_RIJNDAEL *p,
    00106                                         BYTE *dest,int dsize,const BYTE *src,int ssize)
    00107 {
    00108
    00109     int r;
    00110     BYTE *tsrc = (BYTE *)src;
    00111
    00112     if(dsize < ssize){
    00113         return edk_BufferOverFlow;
    00114     }
    00115
    00116     r = proc((cipherInstance *)p->mRijndael,(keyInstance *)p->mKey,tsrc,ssize,dest);
    00117
    00118     if(r > edkcBAD_KEY_DIR){
    00119         return edk_SUCCEEDED;
    00120     }
    00121         //error
    00122     return r;
    00123 }
    00124
    00125 int WINAPI dkcRijndaelBlockEncrypt(DKC_RIJNDAEL *p,
    00126                                                             BYTE *dest,int dsize,const BYTE *src,int ssize){
    00127     return ProcessCall(blockEncrypt,p,dest,dsize,src,ssize);
    00128 }
    00129
    00130 int WINAPI dkcRijndaelBlockDecrypt(DKC_RIJNDAEL *p,
    00131                                                                      BYTE *dest,int dsize,const BYTE *src,int ssize){
    00132     return ProcessCall(blockDecrypt,p,dest,dsize,src,ssize);
    00133 }
    00134
    00135 int WINAPI dkcRijndaelPadEncrypt(DKC_RIJNDAEL *p,
    00136                                                                  BYTE *dest,int dsize,const BYTE *src,int ssize)
    00137 {
    00138     return ProcessCall(padEncrypt,p,dest,dsize,src,ssize);
    00139 }
    00140
    00141
    00142 int WINAPI dkcRijndaelPadDecrypt(DKC_RIJNDAEL *p,
    00143                                                                  BYTE *dest,int dsize,const BYTE *src,int ssize)
    00144 {
    00145     return ProcessCall(padDecrypt,p,dest,dsize,src,ssize);
    00146 }
    00147
    00148 BOOL WINAPI dkcRijndaelErrorMessage(int result,char *buff,size_t size)
    00149 {
    00150 #define RDEM_SC(a) dkc_strcpy(buff,size,a,strlen(b))
    00151 #if 0
    00152     switch(result){
    00153     case    edkcBAD_KEY_DIR://  Key direction is invalid, e.g., unknown value
    00154     RDEM_SC("キーのdirectoinが不正");break;
    00155     case edkcBAD_KEY_MAT://  Key material not of correct length
    00156         RDEM_SC("キーの元データの長さが足りないかも");break;
    00157     case edkcBAD_KEY_MAT://  Key passed is not valid
    00158         RDEM_SC("キーのpassedが無効かも");break;
    00159     case edkcBAD_KEY_INSTANCE://  Params struct passed to cipherInit invalid
    00160
    00161     edkcBAD_CIPHER_MODE =     -4 ,
    00163     edkcBAD_CIPHER_STATE =    -5 ,
    00164     edkcBAD_BLOCK_LENGTH  =   -6,
    00165     edkcBAD_CIPHER_INSTANCE = -7,
    00167     edkcBAD_DATA        =     -8 ,
    00169     edkcBAD_OTHER       =     -9,
    00170 #endif
    00171     return TRUE;
    00172 }
    00173
    00174 int WINAPI dkcFreeRijndael(DKC_RIJNDAEL **p){
    00175     if(NULL==p){
    00176         return edk_FAILED;
    00177     }
    00178     return dkcFree((void **)p);
    00179 }
    00180
    00181 int WINAPI dkcRijndaelStringKey(DKC_RIJNDAEL *p,
    00182                                                                 char *dest_and_material,int size,BYTE option)
    00183
    00184 {
    00185     keyInstance *pk;
    00186     if(NULL==p){
    00187         return edkcBAD_OTHER;
    00188     }
    00189     pk   = (keyInstance *)p->mKey;
    00190     return makeKey(pk,option,size,dest_and_material);
    00191 }
    00192
    00193
    00194
    00195
    00196
    00197 #ifdef dkcdBRIAN_GLADMAN_RIJNDAEL
    00198 //http://fp.gladman.plus.com/cryptography_technology/index.htmでダウンできる奴
    00199 #include "rijndael/aes.h"
    00200
    00201
    00202
    00203 DKC_RIJNDAEL *WINAPI dkcAllocRijndaelEncrypt(const BYTE *key,size_t keysize){
    00204     DKC_RIJNDAEL *p = dkcAllocate(sizeof(DKC_RIJNDAEL));
    00205     if(NULL==p){
    00206         return NULL;
    00207     }
    00208     //p->mKey = dkcAllocMemoryStream(keysize);
    00209
    00210     if(aes_good != aes_enc_key(key,keysize,&(p->mCtx))){
    00211         dkcFreeRijndael(&p);
    00212         return NULL;
    00213     }
    00214     return p;
    00215 }
    00216
    00217
    00218 DKC_RIJNDAEL *WINAPI dkcAllocRijndaelDecrypt(const BYTE *key,size_t keysize){
    00219     DKC_RIJNDAEL *p = dkcAllocate(sizeof(DKC_RIJNDAEL));
    00220     if(NULL==p){
    00221         return NULL;
    00222     }
    00223
    00224     if(aes_good != aes_dec_key(key,keysize,&(p->mCtx))){
    00225         dkcFreeRijndael(&p);
    00226         return NULL;
    00227     }
    00228     return p;
    00229
    00230 }
    00231
    00232 int WINAPI dkcRijndaelEncrypt(DKC_RIJNDAEL *p,BYTE *dest,size_t dsize,const BYTE *src,size_t ssize){
    00233     size_t i;
    00234     if(ssize % BLOCK_SIZE != 0){
    00235         //ちょっとBLOCK_SIZEで割れる数でないとねぇ。
    00236         return edk_LogicError;
    00237     }
    00238     for( i=0;i<ssize;i += BLOCK_SIZE)
    00239     {
    00240 #   ifdef NDEBUG
    00241         if(aes_bad==aes_enc_blk(&src[i],&dest[i],&(p->mCtx))){
    00242             return edk_FAILED;
    00243         }
    00244 #   else
    00245         dkcmNOT_ASSERT(aes_bad==aes_enc_blk(&src[i],&dest[i],&(p->mCtx)));
    00246 #   endif
    00247     }
    00248     return edk_SUCCEEDED;
    00249 }
    00250
    00251 int WINAPI dkcRijndaelDecrypt(DKC_RIJNDAEL *p,BYTE *dest,size_t dsize,const BYTE *src,size_t ssize){
    00252     size_t i;
    00253
    00254     if(ssize % BLOCK_SIZE != 0){
    00255         //ちょっとBLOCK_SIZEで割れる数でないとねぇ。
    00256         return edk_LogicError;
    00257     }
    00258
    00259     for( i=0;i<ssize;i += BLOCK_SIZE)
    00260     {
    00261 #   ifdef NDEBUG
    00262         if(aes_bad==aes_dec_blk(&src[i],&dest[i],&(p->mCtx))){
    00263             return edk_FAILED;
    00264         }
    00265 #   else
    00266         dkcmNOT_ASSERT(aes_bad==aes_dec_blk(&src[i],&dest[i],&(p->mCtx)));
    00267 #   endif
    00268     }
    00269     return edk_SUCCEEDED;
    00270 }
    00271
    00272 int WINAPI dkcFreeRijndael(DKC_RIJNDAEL **p){
    00273     if(NULL==p){
    00274         return edk_FAILED;
    00275     }
    00276     return dkcFree((void **)p);
    00277 }
    00278
    00279 #endif
    00280
    00281 #if 0
    00282
    00283 static void UncheckedSetKey(CipherDir dir, const byte *userKey, unsigned int keylen)
    00284 {
    00285     AssertValidKeyLength(keylen);
    00286
    00287     m_rounds = keylen/4 + 6;
    00288     m_key.New(4*(m_rounds+1));
    00289
    00290     word32 temp, *rk = m_key;
    00291     unsigned int i=0;
    00292
    00293     GetUserKey(BIG_ENDIAN_ORDER, rk, keylen/4, userKey, keylen);
    00294
    00295     switch(keylen)
    00296     {
    00297     case 16:
    00298         while (true)
    00299         {
    00300             temp  = rk[3];
    00301             rk[4] = rk[0] ^
    00302                 (Te4[GETBYTE(temp, 2)] & 0xff000000) ^
    00303                 (Te4[GETBYTE(temp, 1)] & 0x00ff0000) ^
    00304                 (Te4[GETBYTE(temp, 0)] & 0x0000ff00) ^
    00305                 (Te4[GETBYTE(temp, 3)] & 0x000000ff) ^
    00306                 rcon[i];
    00307             rk[5] = rk[1] ^ rk[4];
    00308             rk[6] = rk[2] ^ rk[5];
    00309             rk[7] = rk[3] ^ rk[6];
    00310             if (++i == 10)
    00311                 break;
    00312             rk += 4;
    00313         }
    00314         break;
    00315
    00316     case 24:
    00317         while (true)    // for (;;) here triggers a bug in VC60 SP4 w/ Processor Pack
    00318         {
    00319             temp = rk[ 5];
    00320             rk[ 6] = rk[ 0] ^
    00321                 (Te4[GETBYTE(temp, 2)] & 0xff000000) ^
    00322                 (Te4[GETBYTE(temp, 1)] & 0x00ff0000) ^
    00323                 (Te4[GETBYTE(temp, 0)] & 0x0000ff00) ^
    00324                 (Te4[GETBYTE(temp, 3)] & 0x000000ff) ^
    00325                 rcon[i];
    00326             rk[ 7] = rk[ 1] ^ rk[ 6];
    00327             rk[ 8] = rk[ 2] ^ rk[ 7];
    00328             rk[ 9] = rk[ 3] ^ rk[ 8];
    00329             if (++i == 8)
    00330                 break;
    00331             rk[10] = rk[ 4] ^ rk[ 9];
    00332             rk[11] = rk[ 5] ^ rk[10];
    00333             rk += 6;
    00334         }
    00335         break;
    00336
    00337     case 32:
    00338         while (true)
    00339         {
    00340             temp = rk[ 7];
    00341             rk[ 8] = rk[ 0] ^
    00342                 (Te4[GETBYTE(temp, 2)] & 0xff000000) ^
    00343                 (Te4[GETBYTE(temp, 1)] & 0x00ff0000) ^
    00344                 (Te4[GETBYTE(temp, 0)] & 0x0000ff00) ^
    00345                 (Te4[GETBYTE(temp, 3)] & 0x000000ff) ^
    00346                 rcon[i];
    00347             rk[ 9] = rk[ 1] ^ rk[ 8];
    00348             rk[10] = rk[ 2] ^ rk[ 9];
    00349             rk[11] = rk[ 3] ^ rk[10];
    00350             if (++i == 7)
    00351                 break;
    00352             temp = rk[11];
    00353             rk[12] = rk[ 4] ^
    00354                 (Te4[GETBYTE(temp, 3)] & 0xff000000) ^
    00355                 (Te4[GETBYTE(temp, 2)] & 0x00ff0000) ^
    00356                 (Te4[GETBYTE(temp, 1)] & 0x0000ff00) ^
    00357                 (Te4[GETBYTE(temp, 0)] & 0x000000ff);
    00358             rk[13] = rk[ 5] ^ rk[12];
    00359             rk[14] = rk[ 6] ^ rk[13];
    00360             rk[15] = rk[ 7] ^ rk[14];
    00361
    00362             rk += 8;
    00363         }
    00364         break;
    00365     }
    00366
    00367     if (dir == DECRYPTION)
    00368     {
    00369         unsigned int i, j;
    00370         rk = m_key;
    00371
    00372         /* invert the order of the round keys: */
    00373         for (i = 0, j = 4*m_rounds; i < j; i += 4, j -= 4) {
    00374             temp = rk[i    ]; rk[i    ] = rk[j    ]; rk[j    ] = temp;
    00375             temp = rk[i + 1]; rk[i + 1] = rk[j + 1]; rk[j + 1] = temp;
    00376             temp = rk[i + 2]; rk[i + 2] = rk[j + 2]; rk[j + 2] = temp;
    00377             temp = rk[i + 3]; rk[i + 3] = rk[j + 3]; rk[j + 3] = temp;
    00378         }
    00379         /* apply the inverse MixColumn transform to all round keys but the first and the last: */
    00380         for (i = 1; i < m_rounds; i++) {
    00381             rk += 4;
    00382             rk[0] =
    00383                 Td0[Te4[GETBYTE(rk[0], 3)] & 0xff] ^
    00384                 Td1[Te4[GETBYTE(rk[0], 2)] & 0xff] ^
    00385                 Td2[Te4[GETBYTE(rk[0], 1)] & 0xff] ^
    00386                 Td3[Te4[GETBYTE(rk[0], 0)] & 0xff];
    00387             rk[1] =
    00388                 Td0[Te4[GETBYTE(rk[1], 3)] & 0xff] ^
    00389                 Td1[Te4[GETBYTE(rk[1], 2)] & 0xff] ^
    00390                 Td2[Te4[GETBYTE(rk[1], 1)] & 0xff] ^
    00391                 Td3[Te4[GETBYTE(rk[1], 0)] & 0xff];
    00392             rk[2] =
    00393                 Td0[Te4[GETBYTE(rk[2], 3)] & 0xff] ^
    00394                 Td1[Te4[GETBYTE(rk[2], 2)] & 0xff] ^
    00395                 Td2[Te4[GETBYTE(rk[2], 1)] & 0xff] ^
    00396                 Td3[Te4[GETBYTE(rk[2], 0)] & 0xff];
    00397             rk[3] =
    00398                 Td0[Te4[GETBYTE(rk[3], 3)] & 0xff] ^
    00399                 Td1[Te4[GETBYTE(rk[3], 2)] & 0xff] ^
    00400                 Td2[Te4[GETBYTE(rk[3], 1)] & 0xff] ^
    00401                 Td3[Te4[GETBYTE(rk[3], 0)] & 0xff];
    00402         }
    00403     }
    00404 }
    00405
    00406 typedef BlockGetAndPut<word32, BigEndian> Block;
    00407
    00408 void EncProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
    00409 {
    00410     word32 s0, s1, s2, s3, t0, t1, t2, t3;
    00411     const word32 *rk = m_key;
    00412
    00413     /*
    00414      * map byte array block to cipher state
    00415      * and add initial round key:
    00416      */
    00417     Block::Get(inBlock)(s0)(s1)(s2)(s3);
    00418     s0 ^= rk[0];
    00419     s1 ^= rk[1];
    00420     s2 ^= rk[2];
    00421     s3 ^= rk[3];
    00422     /*
    00423      * Nr - 1 full rounds:
    00424      */
    00425     unsigned int r = m_rounds >> 1;
    00426     for (;;) {
    00427         t0 =
    00428             Te0[GETBYTE(s0, 3)] ^
    00429             Te1[GETBYTE(s1, 2)] ^
    00430             Te2[GETBYTE(s2, 1)] ^
    00431             Te3[GETBYTE(s3, 0)] ^
    00432             rk[4];
    00433         t1 =
    00434             Te0[GETBYTE(s1, 3)] ^
    00435             Te1[GETBYTE(s2, 2)] ^
    00436             Te2[GETBYTE(s3, 1)] ^
    00437             Te3[GETBYTE(s0, 0)] ^
    00438             rk[5];
    00439         t2 =
    00440             Te0[GETBYTE(s2, 3)] ^
    00441             Te1[GETBYTE(s3, 2)] ^
    00442             Te2[GETBYTE(s0, 1)] ^
    00443             Te3[GETBYTE(s1, 0)] ^
    00444             rk[6];
    00445         t3 =
    00446             Te0[GETBYTE(s3, 3)] ^
    00447             Te1[GETBYTE(s0, 2)] ^
    00448             Te2[GETBYTE(s1, 1)] ^
    00449             Te3[GETBYTE(s2, 0)] ^
    00450             rk[7];
    00451
    00452         rk += 8;
    00453         if (--r == 0) {
    00454             break;
    00455         }
    00456
    00457         s0 =
    00458             Te0[GETBYTE(t0, 3)] ^
    00459             Te1[GETBYTE(t1, 2)] ^
    00460             Te2[GETBYTE(t2, 1)] ^
    00461             Te3[GETBYTE(t3, 0)] ^
    00462             rk[0];
    00463         s1 =
    00464             Te0[GETBYTE(t1, 3)] ^
    00465             Te1[GETBYTE(t2, 2)] ^
    00466             Te2[GETBYTE(t3, 1)] ^
    00467             Te3[GETBYTE(t0, 0)] ^
    00468             rk[1];
    00469         s2 =
    00470             Te0[GETBYTE(t2, 3)] ^
    00471             Te1[GETBYTE(t3, 2)] ^
    00472             Te2[GETBYTE(t0, 1)] ^
    00473             Te3[GETBYTE(t1, 0)] ^
    00474             rk[2];
    00475         s3 =
    00476             Te0[GETBYTE(t3, 3)] ^
    00477             Te1[GETBYTE(t0, 2)] ^
    00478             Te2[GETBYTE(t1, 1)] ^
    00479             Te3[GETBYTE(t2, 0)] ^
    00480             rk[3];
    00481     }
    00482     /*
    00483      * apply last round and
    00484      * map cipher state to byte array block:
    00485      */
    00486
    00487     s0 =
    00488         (Te4[GETBYTE(t0, 3)] & 0xff000000) ^
    00489         (Te4[GETBYTE(t1, 2)] & 0x00ff0000) ^
    00490         (Te4[GETBYTE(t2, 1)] & 0x0000ff00) ^
    00491         (Te4[GETBYTE(t3, 0)] & 0x000000ff) ^
    00492         rk[0];
    00493     s1 =
    00494         (Te4[GETBYTE(t1, 3)] & 0xff000000) ^
    00495         (Te4[GETBYTE(t2, 2)] & 0x00ff0000) ^
    00496         (Te4[GETBYTE(t3, 1)] & 0x0000ff00) ^
    00497         (Te4[GETBYTE(t0, 0)] & 0x000000ff) ^
    00498         rk[1];
    00499     s2 =
    00500         (Te4[GETBYTE(t2, 3)] & 0xff000000) ^
    00501         (Te4[GETBYTE(t3, 2)] & 0x00ff0000) ^
    00502         (Te4[GETBYTE(t0, 1)] & 0x0000ff00) ^
    00503         (Te4[GETBYTE(t1, 0)] & 0x000000ff) ^
    00504         rk[2];
    00505     s3 =
    00506         (Te4[GETBYTE(t3, 3)] & 0xff000000) ^
    00507         (Te4[GETBYTE(t0, 2)] & 0x00ff0000) ^
    00508         (Te4[GETBYTE(t1, 1)] & 0x0000ff00) ^
    00509         (Te4[GETBYTE(t2, 0)] & 0x000000ff) ^
    00510         rk[3];
    00511
    00512     Block::Put(xorBlock, outBlock)(s0)(s1)(s2)(s3);
    00513 }
    00514
    00515 void DecProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
    00516 {
    00517     word32 s0, s1, s2, s3, t0, t1, t2, t3;
    00518     const word32 *rk = m_key;
    00519
    00520     /*
    00521      * map byte array block to cipher state
    00522      * and add initial round key:
    00523      */
    00524     Block::Get(inBlock)(s0)(s1)(s2)(s3);
    00525     s0 ^= rk[0];
    00526     s1 ^= rk[1];
    00527     s2 ^= rk[2];
    00528     s3 ^= rk[3];
    00529     /*
    00530      * Nr - 1 full rounds:
    00531      */
    00532     unsigned int r = m_rounds >> 1;
    00533     for (;;) {
    00534         t0 =
    00535             Td0[GETBYTE(s0, 3)] ^
    00536             Td1[GETBYTE(s3, 2)] ^
    00537             Td2[GETBYTE(s2, 1)] ^
    00538             Td3[GETBYTE(s1, 0)] ^
    00539             rk[4];
    00540         t1 =
    00541             Td0[GETBYTE(s1, 3)] ^
    00542             Td1[GETBYTE(s0, 2)] ^
    00543             Td2[GETBYTE(s3, 1)] ^
    00544             Td3[GETBYTE(s2, 0)] ^
    00545             rk[5];
    00546         t2 =
    00547             Td0[GETBYTE(s2, 3)] ^
    00548             Td1[GETBYTE(s1, 2)] ^
    00549             Td2[GETBYTE(s0, 1)] ^
    00550             Td3[GETBYTE(s3, 0)] ^
    00551             rk[6];
    00552         t3 =
    00553             Td0[GETBYTE(s3, 3)] ^
    00554             Td1[GETBYTE(s2, 2)] ^
    00555             Td2[GETBYTE(s1, 1)] ^
    00556             Td3[GETBYTE(s0, 0)] ^
    00557             rk[7];
    00558
    00559         rk += 8;
    00560         if (--r == 0) {
    00561             break;
    00562         }
    00563
    00564         s0 =
    00565             Td0[GETBYTE(t0, 3)] ^
    00566             Td1[GETBYTE(t3, 2)] ^
    00567             Td2[GETBYTE(t2, 1)] ^
    00568             Td3[GETBYTE(t1, 0)] ^
    00569             rk[0];
    00570         s1 =
    00571             Td0[GETBYTE(t1, 3)] ^
    00572             Td1[GETBYTE(t0, 2)] ^
    00573             Td2[GETBYTE(t3, 1)] ^
    00574             Td3[GETBYTE(t2, 0)] ^
    00575             rk[1];
    00576         s2 =
    00577             Td0[GETBYTE(t2, 3)] ^
    00578             Td1[GETBYTE(t1, 2)] ^
    00579             Td2[GETBYTE(t0, 1)] ^
    00580             Td3[GETBYTE(t3, 0)] ^
    00581             rk[2];
    00582         s3 =
    00583             Td0[GETBYTE(t3, 3)] ^
    00584             Td1[GETBYTE(t2, 2)] ^
    00585             Td2[GETBYTE(t1, 1)] ^
    00586             Td3[GETBYTE(t0, 0)] ^
    00587             rk[3];
    00588     }
    00589     /*
    00590      * apply last round and
    00591      * map cipher state to byte array block:
    00592      */
    00593     s0 =
    00594         (Td4[GETBYTE(t0, 3)] & 0xff000000) ^
    00595         (Td4[GETBYTE(t3, 2)] & 0x00ff0000) ^
    00596         (Td4[GETBYTE(t2, 1)] & 0x0000ff00) ^
    00597         (Td4[GETBYTE(t1, 0)] & 0x000000ff) ^
    00598         rk[0];
    00599     s1 =
    00600         (Td4[GETBYTE(t1, 3)] & 0xff000000) ^
    00601         (Td4[GETBYTE(t0, 2)] & 0x00ff0000) ^
    00602         (Td4[GETBYTE(t3, 1)] & 0x0000ff00) ^
    00603         (Td4[GETBYTE(t2, 0)] & 0x000000ff) ^
    00604         rk[1];
    00605     s2 =
    00606         (Td4[GETBYTE(t2, 3)] & 0xff000000) ^
    00607         (Td4[GETBYTE(t1, 2)] & 0x00ff0000) ^
    00608         (Td4[GETBYTE(t0, 1)] & 0x0000ff00) ^
    00609         (Td4[GETBYTE(t3, 0)] & 0x000000ff) ^
    00610         rk[2];
    00611     s3 =
    00612         (Td4[GETBYTE(t3, 3)] & 0xff000000) ^
    00613         (Td4[GETBYTE(t2, 2)] & 0x00ff0000) ^
    00614         (Td4[GETBYTE(t1, 1)] & 0x0000ff00) ^
    00615         (Td4[GETBYTE(t0, 0)] & 0x000000ff) ^
    00616         rk[3];
    00617
    00618     Block::Put(xorBlock, outBlock)(s0)(s1)(s2)(s3);
    00619 }
    00620
    00621
    00622 #endif