dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnet/support aes.c,1.1,1.2


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/support aes.c,1.1,1.2
Date: Wed, 14 May 2003 21:12:12 -0400

Update of /cvsroot/dotgnu-pnet/pnet/support
In directory subversions:/tmp/cvs-serv27739/support

Modified Files:
        aes.c 
Log Message:


Make the AES code 16-bit friendly.


Index: aes.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/support/aes.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** aes.c       12 Jul 2002 06:02:30 -0000      1.1
--- aes.c       15 May 2003 01:12:10 -0000      1.2
***************
*** 252,262 ****
                {
                        /* Perform "temp = SubWord(RotWord(temp))" in one step 
*/
!                       temp = (s[(temp >> 16) & 0xFF] << 24) |
!                                  (s[(temp >>  8) & 0xFF] << 16) |
!                                  (s[temp & 0xFF] << 8) |
!                                  (s[(temp >> 24) & 0xFF]);
  
                        /* Perform "temp = temp ^ Rcon[i / nk]" */
!                       temp ^= (bit << 24);
                        bit <<= 1;
                        if(bit >= 0x100)
--- 252,262 ----
                {
                        /* Perform "temp = SubWord(RotWord(temp))" in one step 
*/
!                       temp = (((ILInt32)(s[(temp >> 16) & 0xFF])) << 24) |
!                                  (((ILInt32)(s[(temp >>  8) & 0xFF])) << 16) |
!                                  (((ILInt32)(s[temp & 0xFF])) << 8) |
!                                  (((ILInt32)(s[(temp >> 24) & 0xFF])));
  
                        /* Perform "temp = temp ^ Rcon[i / nk]" */
!                       temp ^= (((ILInt32)bit) << 24);
                        bit <<= 1;
                        if(bit >= 0x100)
***************
*** 268,275 ****
                {
                        /* Special case for 256-bit keys: perform 
"SubWord(temp)" only */
!                       temp = (s[(temp >> 24) & 0xFF] << 24) |
!                                  (s[(temp >> 16) & 0xFF] << 16) |
!                                  (s[(temp >>  8) & 0xFF] << 8) |
!                                  (s[temp & 0xFF]);
                }
                aes->keySchedule[i] = aes->keySchedule[i - nk] ^ temp;
--- 268,275 ----
                {
                        /* Special case for 256-bit keys: perform 
"SubWord(temp)" only */
!                       temp = (((ILInt32)(s[(temp >> 24) & 0xFF])) << 24) |
!                                  (((ILInt32)(s[(temp >> 16) & 0xFF])) << 16) |
!                                  (((ILInt32)(s[(temp >>  8) & 0xFF])) << 8) |
!                                  (((ILInt32)(s[temp & 0xFF])));
                }
                aes->keySchedule[i] = aes->keySchedule[i - nk] ^ temp;
***************
*** 307,326 ****
        {
                /* Perform SubBytes() and ShiftRows() in one step */
!               ncol0 = (s[(col0 >> 24) & 0xFF] << 24) |
!                               (s[(col1 >> 16) & 0xFF] << 16) |
!                               (s[(col2 >>  8) & 0xFF] << 8) |
!                               (s[col3 & 0xFF]);
!               ncol1 = (s[(col1 >> 24) & 0xFF] << 24) |
!                               (s[(col2 >> 16) & 0xFF] << 16) |
!                               (s[(col3 >>  8) & 0xFF] << 8) |
!                               (s[col0 & 0xFF]);
!               ncol2 = (s[(col2 >> 24) & 0xFF] << 24) |
!                               (s[(col3 >> 16) & 0xFF] << 16) |
!                               (s[(col0 >>  8) & 0xFF] << 8) |
!                               (s[col1 & 0xFF]);
!               ncol3 = (s[(col3 >> 24) & 0xFF] << 24) |
!                               (s[(col0 >> 16) & 0xFF] << 16) |
!                               (s[(col1 >>  8) & 0xFF] << 8) |
!                               (s[col2 & 0xFF]);
  
                /* Perform MixColumns() */
--- 307,326 ----
        {
                /* Perform SubBytes() and ShiftRows() in one step */
!               ncol0 = (((ILInt32)(s[(col0 >> 24) & 0xFF])) << 24) |
!                               (((ILInt32)(s[(col1 >> 16) & 0xFF])) << 16) |
!                               (((ILInt32)(s[(col2 >>  8) & 0xFF])) << 8) |
!                               (((ILInt32)(s[col3 & 0xFF])));
!               ncol1 = (((ILInt32)(s[(col1 >> 24) & 0xFF])) << 24) |
!                               (((ILInt32)(s[(col2 >> 16) & 0xFF])) << 16) |
!                               (((ILInt32)(s[(col3 >>  8) & 0xFF])) << 8) |
!                               (((ILInt32)(s[col0 & 0xFF])));
!               ncol2 = (((ILInt32)(s[(col2 >> 24) & 0xFF])) << 24) |
!                               (((ILInt32)(s[(col3 >> 16) & 0xFF])) << 16) |
!                               (((ILInt32)(s[(col0 >>  8) & 0xFF])) << 8) |
!                               (((ILInt32)(s[col1 & 0xFF])));
!               ncol3 = (((ILInt32)(s[(col3 >> 24) & 0xFF])) << 24) |
!                               (((ILInt32)(s[(col0 >> 16) & 0xFF])) << 16) |
!                               (((ILInt32)(s[(col1 >>  8) & 0xFF])) << 8) |
!                               (((ILInt32)(s[col2 & 0xFF])));
  
                /* Perform MixColumns() */
***************
*** 338,357 ****
  
        /* Perform the last round, which omits MixColumns() */
!       ncol0 = (s[(col0 >> 24) & 0xFF] << 24) |
!                       (s[(col1 >> 16) & 0xFF] << 16) |
!                       (s[(col2 >>  8) & 0xFF] << 8) |
!                       (s[col3 & 0xFF]);
!       ncol1 = (s[(col1 >> 24) & 0xFF] << 24) |
!                       (s[(col2 >> 16) & 0xFF] << 16) |
!                       (s[(col3 >>  8) & 0xFF] << 8) |
!                       (s[col0 & 0xFF]);
!       ncol2 = (s[(col2 >> 24) & 0xFF] << 24) |
!                       (s[(col3 >> 16) & 0xFF] << 16) |
!                       (s[(col0 >>  8) & 0xFF] << 8) |
!                       (s[col1 & 0xFF]);
!       ncol3 = (s[(col3 >> 24) & 0xFF] << 24) |
!                       (s[(col0 >> 16) & 0xFF] << 16) |
!                       (s[(col1 >>  8) & 0xFF] << 8) |
!                       (s[col2 & 0xFF]);
        ncol0 ^= ks[keyIndex++];
        ncol1 ^= ks[keyIndex++];
--- 338,357 ----
  
        /* Perform the last round, which omits MixColumns() */
!       ncol0 = (((ILInt32)(s[(col0 >> 24) & 0xFF])) << 24) |
!                       (((ILInt32)(s[(col1 >> 16) & 0xFF])) << 16) |
!                       (((ILInt32)(s[(col2 >>  8) & 0xFF])) << 8) |
!                       (((ILInt32)(s[col3 & 0xFF])));
!       ncol1 = (((ILInt32)(s[(col1 >> 24) & 0xFF])) << 24) |
!                       (((ILInt32)(s[(col2 >> 16) & 0xFF])) << 16) |
!                       (((ILInt32)(s[(col3 >>  8) & 0xFF])) << 8) |
!                       (((ILInt32)(s[col0 & 0xFF])));
!       ncol2 = (((ILInt32)(s[(col2 >> 24) & 0xFF])) << 24) |
!                       (((ILInt32)(s[(col3 >> 16) & 0xFF])) << 16) |
!                       (((ILInt32)(s[(col0 >>  8) & 0xFF])) << 8) |
!                       (((ILInt32)(s[col1 & 0xFF])));
!       ncol3 = (((ILInt32)(s[(col3 >> 24) & 0xFF])) << 24) |
!                       (((ILInt32)(s[(col0 >> 16) & 0xFF])) << 16) |
!                       (((ILInt32)(s[(col1 >>  8) & 0xFF])) << 8) |
!                       (((ILInt32)(s[col2 & 0xFF])));
        ncol0 ^= ks[keyIndex++];
        ncol1 ^= ks[keyIndex++];
***************
*** 397,416 ****
        {
                /* Perform InvShiftRows() and InvSubBytes() in one step */
!               ncol0 = (s[(col0 >> 24) & 0xFF] << 24) |
!                               (s[(col3 >> 16) & 0xFF] << 16) |
!                               (s[(col2 >>  8) & 0xFF] << 8) |
!                               (s[col1 & 0xFF]);
!               ncol1 = (s[(col1 >> 24) & 0xFF] << 24) |
!                               (s[(col0 >> 16) & 0xFF] << 16) |
!                               (s[(col3 >>  8) & 0xFF] << 8) |
!                               (s[col2 & 0xFF]);
!               ncol2 = (s[(col2 >> 24) & 0xFF] << 24) |
!                               (s[(col1 >> 16) & 0xFF] << 16) |
!                               (s[(col0 >>  8) & 0xFF] << 8) |
!                               (s[col3 & 0xFF]);
!               ncol3 = (s[(col3 >> 24) & 0xFF] << 24) |
!                               (s[(col2 >> 16) & 0xFF] << 16) |
!                               (s[(col1 >>  8) & 0xFF] << 8) |
!                               (s[col0 & 0xFF]);
  
                /* Add the previous round key to the state */
--- 397,416 ----
        {
                /* Perform InvShiftRows() and InvSubBytes() in one step */
!               ncol0 = (((ILInt32)(s[(col0 >> 24) & 0xFF])) << 24) |
!                               (((ILInt32)(s[(col3 >> 16) & 0xFF])) << 16) |
!                               (((ILInt32)(s[(col2 >>  8) & 0xFF])) << 8) |
!                               (((ILInt32)(s[col1 & 0xFF])));
!               ncol1 = (((ILInt32)(s[(col1 >> 24) & 0xFF])) << 24) |
!                               (((ILInt32)(s[(col0 >> 16) & 0xFF])) << 16) |
!                               (((ILInt32)(s[(col3 >>  8) & 0xFF])) << 8) |
!                               (((ILInt32)(s[col2 & 0xFF])));
!               ncol2 = (((ILInt32)(s[(col2 >> 24) & 0xFF])) << 24) |
!                               (((ILInt32)(s[(col1 >> 16) & 0xFF])) << 16) |
!                               (((ILInt32)(s[(col0 >>  8) & 0xFF])) << 8) |
!                               (((ILInt32)(s[col3 & 0xFF])));
!               ncol3 = (((ILInt32)(s[(col3 >> 24) & 0xFF])) << 24) |
!                               (((ILInt32)(s[(col2 >> 16) & 0xFF])) << 16) |
!                               (((ILInt32)(s[(col1 >>  8) & 0xFF])) << 8) |
!                               (((ILInt32)(s[col0 & 0xFF])));
  
                /* Add the previous round key to the state */
***************
*** 428,447 ****
  
        /* Perform the last round, which omits InvMixColumns() */
!       ncol0 = (s[(col0 >> 24) & 0xFF] << 24) |
!                       (s[(col3 >> 16) & 0xFF] << 16) |
!                       (s[(col2 >>  8) & 0xFF] << 8) |
!                       (s[col1 & 0xFF]);
!       ncol1 = (s[(col1 >> 24) & 0xFF] << 24) |
!                       (s[(col0 >> 16) & 0xFF] << 16) |
!                       (s[(col3 >>  8) & 0xFF] << 8) |
!                       (s[col2 & 0xFF]);
!       ncol2 = (s[(col2 >> 24) & 0xFF] << 24) |
!                       (s[(col1 >> 16) & 0xFF] << 16) |
!                       (s[(col0 >>  8) & 0xFF] << 8) |
!                       (s[col3 & 0xFF]);
!       ncol3 = (s[(col3 >> 24) & 0xFF] << 24) |
!                       (s[(col2 >> 16) & 0xFF] << 16) |
!                       (s[(col1 >>  8) & 0xFF] << 8) |
!                       (s[col0 & 0xFF]);
        ncol3 ^= ks[--keyIndex];
        ncol2 ^= ks[--keyIndex];
--- 428,447 ----
  
        /* Perform the last round, which omits InvMixColumns() */
!       ncol0 = (((ILInt32)(s[(col0 >> 24) & 0xFF])) << 24) |
!                       (((ILInt32)(s[(col3 >> 16) & 0xFF])) << 16) |
!                       (((ILInt32)(s[(col2 >>  8) & 0xFF])) << 8) |
!                       (((ILInt32)(s[col1 & 0xFF])));
!       ncol1 = (((ILInt32)(s[(col1 >> 24) & 0xFF])) << 24) |
!                       (((ILInt32)(s[(col0 >> 16) & 0xFF])) << 16) |
!                       (((ILInt32)(s[(col3 >>  8) & 0xFF])) << 8) |
!                       (((ILInt32)(s[col2 & 0xFF])));
!       ncol2 = (((ILInt32)(s[(col2 >> 24) & 0xFF])) << 24) |
!                       (((ILInt32)(s[(col1 >> 16) & 0xFF])) << 16) |
!                       (((ILInt32)(s[(col0 >>  8) & 0xFF])) << 8) |
!                       (((ILInt32)(s[col3 & 0xFF])));
!       ncol3 = (((ILInt32)(s[(col3 >> 24) & 0xFF])) << 24) |
!                       (((ILInt32)(s[(col2 >> 16) & 0xFF])) << 16) |
!                       (((ILInt32)(s[(col1 >>  8) & 0xFF])) << 8) |
!                       (((ILInt32)(s[col0 & 0xFF])));
        ncol3 ^= ks[--keyIndex];
        ncol2 ^= ks[--keyIndex];





reply via email to

[Prev in Thread] Current Thread [Next in Thread]