Changeset 335 for trunk/CrypPlugins/TEA


Ignore:
Timestamp:
Jun 1, 2009, 6:32:24 PM (13 years ago)
Author:
Sören Rinne
Message:
  • added XXTEA (Corrected Block TEA) in TEA plugin
  • adjusted description of TEA
  • adjusted description of BFP
Location:
trunk/CrypPlugins/TEA
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/TEA/DetailedDescription/Description.xaml

    r329 r335  
    3030      <Run FontSize="14.6666666666667" xml:lang="de-de">Like TEA, XTEA is a 64-bit block Feistel network with a 128-bit key and a suggested 64 rounds. Several differences from TEA are apparent, including a somewhat more complex key-schedule and a rearrangement of the shifts, XORs, and additions.</Run>
    3131  </Paragraph>
     32 
     33  <Paragraph>
     34      <Run FontWeight="Bold" FontSize="18.6666666666667" xml:lang="de-de">
     35          <Run.TextDecorations>
     36              <TextDecoration Location="Underline" />
     37          </Run.TextDecorations> XXTEA (Corrected Block TEA)
     38      </Run>
     39  </Paragraph>
     40  <Paragraph>
     41      <Run FontSize="14.6666666666667" xml:lang="de-de">In cryptography, Corrected Block TEA (often referred to as XXTEA) is a block cipher designed to correct weaknesses in the original Block TEA (Tiny Encryption Algorithm), which was first published together with a paper on TEA extensions (XTEA).</Run>
     42  </Paragraph>
     43  <Paragraph>
     44      <Run FontSize="14.6666666666667" xml:lang="de-de">The cipher's designers were Roger Needham and David Wheeler of the Cambridge Computer Laboratory, and the algorithm was presented in an unpublished technical report in October 1998 (Wheeler and Needham, 1998). It is not subject to any patents.</Run>
     45  </Paragraph>
     46  <Paragraph>
     47      <Run FontSize="14.6666666666667" xml:lang="de-de">Formally speaking, XXTEA is a consistent incomplete source-heavy heterogeneous UFN (unbalanced Feistel network) block cipher. XXTEA operates on variable-length blocks that are some arbitrary multiple of 32 bits in size (minimum 64 bits). The number of full cycles depends on the block size, but there are at least six (rising to 32 for small block sizes). The original Block TEA applies the XTEA round function to each word in the block and combines it additively with its leftmost neighbour. Slow diffusion rate of the decryption process was immediately exploited to break the cipher. Corrected Block TEA uses a more involved round function which makes use of both immediate neighbours in processing each word in the block.</Run>
     48  </Paragraph>
    3249</FlowDocument>
  • trunk/CrypPlugins/TEA/TEA.cs

    r329 r335  
    232232
    233233                uint[] key = new uint[4];
     234                long[] longKey = new long[4];
    234235                long keybytes = inputKey.Length;
    235236                GuiLogMessage("inputKey length [byte]: " + keybytes.ToString(), NotificationLevel.Debug);
     
    242243                else
    243244                {
    244                     key[0] = BitConverter.ToUInt32(inputKey, 0);
    245                     key[1] = BitConverter.ToUInt32(inputKey, 4);
    246                     key[2] = BitConverter.ToUInt32(inputKey, 8);
    247                     key[3] = BitConverter.ToUInt32(inputKey, 12);
     245                    if (settings.Version != 2)
     246                    {
     247                        key[0] = BitConverter.ToUInt32(inputKey, 0);
     248                        key[1] = BitConverter.ToUInt32(inputKey, 4);
     249                        key[2] = BitConverter.ToUInt32(inputKey, 8);
     250                        key[3] = BitConverter.ToUInt32(inputKey, 12);
     251                    }
     252                    else
     253                    {
     254                        longKey[0] = (long)BitConverter.ToUInt32(inputKey, 0);
     255                        longKey[1] = (long)BitConverter.ToUInt32(inputKey, 4);
     256                        longKey[2] = (long)BitConverter.ToUInt32(inputKey, 8);
     257                        longKey[3] = (long)BitConverter.ToUInt32(inputKey, 12);
     258                    }
    248259                }
    249260
     
    253264               
    254265                uint[] vector = new uint[2];
     266                long[] longVector = new long[2];
    255267
    256268                if (action == 0)
     
    271283                        {
    272284                            encode_xtea((uint)settings.Rounds, vector, key);
     285                            StatusChanged((int)TEAImage.EncodeX);
     286                        }
     287                        else if (settings.Version == 2)
     288                        {
     289                            btea(vector, 2, key);
    273290                            StatusChanged((int)TEAImage.EncodeX);
    274291                        }
     
    296313                        {
    297314                            decode_xtea((uint)settings.Rounds, vector, key);
     315                            StatusChanged((int)TEAImage.DecodeX);
     316                        }
     317                        else if (settings.Version == 2)
     318                        {
     319                            btea(vector, -2, key);
    298320                            StatusChanged((int)TEAImage.DecodeX);
    299321                        }
     
    459481            v[1] = z;
    460482        }
     483
     484        private uint btea(uint[] v, int n, uint[] k) {
     485            int m = n;
     486            if (n < -1) m = -n;
     487            uint z=v[m-1], y=v[0], sum=0, e, DELTA=0x9e3779b9;
     488           
     489            int p, q;
     490
     491            uint MX;
     492
     493            if (n > 1) {          /* Coding Part */
     494              q = 6 + 52/n;
     495              while (q-- > 0) {
     496                sum += DELTA;
     497                e = (sum >> 2) & 3;
     498                for (p=0; p<n-1; p++) {
     499                    y = v[p+1];
     500                    MX = (z>>5^y<<2) + (y>>3^z<<4)^(sum^y) + (k[p&3^e]^z);
     501                    z = v[p] += MX;
     502                }
     503                y = v[0];
     504                GuiLogMessage("y: " + y.ToString("X"), NotificationLevel.Info);
     505                MX = (z >> 5 ^ y << 2) + (y >> 3 ^ z << 4) ^ (sum ^ y) + (k[p & 3 ^ e] ^ z);
     506                z = v[n-1] += MX;
     507                GuiLogMessage("z: " + z.ToString("X"), NotificationLevel.Info);
     508              }
     509
     510              GuiLogMessage("v[n-1]: " + v[n - 1].ToString("X"), NotificationLevel.Info);
     511              GuiLogMessage("v[0]: " + v[0].ToString("X"), NotificationLevel.Info);
     512
     513              return 0 ;
     514            } else if (n < -1) {  /* Decoding Part */
     515              n = -n;
     516              q = 6 + 52/n;
     517              sum = (uint)q*DELTA ;
     518              while (sum != 0) {
     519                e = (sum >> 2) & 3;
     520                for (p = n - 1; p > 0; p--)
     521                {
     522                    z = v[p - 1];
     523                    MX = (z >> 5 ^ y << 2) + (y >> 3 ^ z << 4) ^ (sum ^ y) + (k[p & 3 ^ e] ^ z);
     524                    y = v[p] -= MX;
     525                }
     526                z = v[n - 1];
     527                MX = (z >> 5 ^ y << 2) + (y >> 3 ^ z << 4) ^ (sum ^ y) + (k[p & 3 ^ e] ^ z);
     528                y = v[0] -= MX;
     529                sum -= DELTA;
     530              }
     531              return 0;
     532            }
     533            return 1;
     534        }
     535
    461536
    462537        public void Encrypt()
  • trunk/CrypPlugins/TEA/TEASettings.cs

    r328 r335  
    2323        private int action = 0; //0=encrypt, 1=decrypt
    2424        private int padding = 0; //0="Zeros"=default, 1="None", 2="PKCS7"
    25         private int version = 0; //0="TEA"=default, 1="XTEA"
     25        private int version = 0; //0="TEA"=default, 1="XTEA, 2=XXTEA"
    2626        private int rounds = 64;
    2727
     
    4747        }
    4848
    49         [ContextMenu("TEA version", "Select the version of TEA you want to use.", 4, DisplayLevel.Beginner, ContextMenuControlType.ComboBox, null, "TEA", "XTEA")]
    50         [TaskPane("TEA version", "Select the version of TEA you want to use.", "", 4, false, DisplayLevel.Experienced, ControlType.ComboBox, new String[] { "TEA (1994)", "XTEA (1997)" })]
     49        [ContextMenu("TEA version", "Select the version of TEA you want to use.", 4, DisplayLevel.Beginner, ContextMenuControlType.ComboBox, null, "TEA", "XTEA", "XXTEA")]
     50        [TaskPane("TEA version", "Select the version of TEA you want to use.", "", 4, false, DisplayLevel.Experienced, ControlType.ComboBox, new String[] { "TEA (1994)", "XTEA (1997)", "XXTEA (1998)" })]
    5151        public int Version
    5252        {
Note: See TracChangeset for help on using the changeset viewer.